Skip to content

Commit

Permalink
doc + cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizoku-oh committed May 15, 2020
1 parent 37da12f commit 5f768c9
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 99 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

# Because a PR results in a push; this workflow will run when a PR is merged
# or when a commit is pushed directly to any branch.
on:
push:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1

- name: Install pio and its dependencies
run: |
python -m pip install --upgrade pip
pip install platformio
- name: Run PlatformIO build on selected platforms
run: platformio run -e nucleo_f767zi

# - name: Code static analysis
# run: platformio check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish
name: Release

on:
push:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<!-- ![](https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg) -->
![](https://github.com/kaizoku-619/pio-freertos/workflows/Publish/badge.svg)
![](https://github.com/kaizoku-619/pio_ci_example/workflows/Build/badge.svg)
![](https://github.com/kaizoku-619/pio_ci_example/workflows/Release/badge.svg)
8 changes: 4 additions & 4 deletions include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function. */
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5

/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
Expand All @@ -119,9 +119,9 @@ header file. */

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

#endif /* FREERTOS_CONFIG_H */

25 changes: 24 additions & 1 deletion include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
* @{
*/
#include "stm32f7xx_nucleo_144.h"
#include "cmsis_os.h"
/**
* @}
*/
Expand All @@ -51,6 +50,10 @@
/** @defgroup main_defines Defines
* @{
*/
/* Boolean defines */
#define TRUE (bool)(1==1)
#define FALSE (bool)(0==1)

/* Pins Config */
#define USARTx_TX_PIN GPIO_PIN_8
#define USARTx_RX_PIN GPIO_PIN_9
Expand Down Expand Up @@ -87,6 +90,26 @@
* @}
*/

/*-----------------------------------------------------------------------------------------------*/
/* Exported types */
/*-----------------------------------------------------------------------------------------------*/
/** @defgroup main_types Exported types
* @{
*/
typedef unsigned char bool;
/**
* @}
*/
/*-----------------------------------------------------------------------------------------------*/
/* Exported function prototypes ------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------*/
/** @defgroup main_exported_function_prototypes Exported function prototypes
* @{
*/
bool usart_get_handle(UART_HandleTypeDef *stHandle);
/**
* @}
*/
/**
* @}
*/
Expand Down
137 changes: 77 additions & 60 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @{
*/
#include "main.h"
#include "cmsis_os.h"
/**
* @}
*/
Expand All @@ -38,9 +39,30 @@
/** @defgroup main_defines Defines
* @{
*/
#define USART_BAUDRATE 115200
#define RX_BUFFER_SIZE 32
#define QUEUE_ITEMS_COUNT 1
#define USART_BAUDRATE 115200
#define USART_TX_TIMEOUT_MS 100
#define RX_BUFFER_SIZE 32
#define QUEUE_ITEMS_COUNT 8
#define QUEUE_MESSAGE (uint32_t)0xFF
/**
* @}
*/
/*-----------------------------------------------------------------------------------------------*/
/* Private types */
/*-----------------------------------------------------------------------------------------------*/
/** @defgroup main_types Private types
* @{
*/
/** MAIN data context structure */
typedef struct
{
osThreadId stThreadHandle; /**< Thread handler */
osMessageQId stQueue; /**< Queue handler */
UART_HandleTypeDef stUsartHandle; /**< USART handle */
uint8_t u08RxBuffer[RX_BUFFER_SIZE]; /**< USART rx buffer */
uint8_t u08RxByte; /**< USART rx byte */
volatile uint8_t u08Index; /**< USART rx byte index */
}main_ctx_t;
/**
* @}
*/
Expand All @@ -51,14 +73,7 @@
/** @defgroup main_private_variables Private variables
* @{
*/
uint8_t u08RxByte;
volatile uint8_t u08Index;
UART_HandleTypeDef stUsartHandle;
uint8_t u08RxBuffer[RX_BUFFER_SIZE];

osThreadId stLedThreadHandle;
osThreadId stUsartThreadHandle;
osMessageQId stQueue;
static main_ctx_t stMainCtx;
/**
* @}
*/
Expand All @@ -70,8 +85,7 @@ osMessageQId stQueue;
* @{
*/
static void usart_init(void);
static void led_thread_handler(void const * argument);
static void usart_thread_handler(void const * argument);
static void thread_handler(void const * argument);
/**
* @}
*/
Expand All @@ -90,18 +104,34 @@ int main(void)
{
HAL_Init();

osThreadDef(led, led_thread_handler, osPriorityNormal, 0, 128);
osThreadDef(usart, usart_thread_handler, osPriorityNormal, 0, 128);
osThreadDef(thread, thread_handler, osPriorityNormal, 0, 128);
osMessageQDef(queue, QUEUE_ITEMS_COUNT, uint32_t);

stLedThreadHandle = osThreadCreate(osThread(led), NULL);
stUsartThreadHandle = osThreadCreate(osThread(usart), NULL);
stQueue = osMessageCreate(osMessageQ(queue), stLedThreadHandle);
stMainCtx.stThreadHandle = osThreadCreate(osThread(thread), NULL);
stMainCtx.stQueue = osMessageCreate(osMessageQ(queue), stMainCtx.stThreadHandle);

osKernelStart();

while(1) {}
}

/**************************************************************************************************
* @brief Get usart handle
* @param stHandle usart handle
* @return Returns a boolean indicating if we get the handle successfully or not
********************************************************************************************** */
bool usart_get_handle(UART_HandleTypeDef *stHandle)
{
bool bRet;

bRet = FALSE;
if(stHandle)
{
*stHandle = stMainCtx.stUsartHandle;
bRet = TRUE;
}
return bRet;
}
/**
* @}
*/
Expand All @@ -117,46 +147,31 @@ int main(void)
* @param argument argument pointer to be passed to thread handler
* @return Returns nothing
********************************************************************************************** */
static void led_thread_handler(void const * argument)
static void thread_handler(void const * argument)
{
osEvent stEvent;
const uint32_t u32BlinkDelayMs = 1000;

usart_init();
HAL_UART_Receive_IT(&stMainCtx.stUsartHandle, &stMainCtx.u08RxByte, sizeof(stMainCtx.u08RxByte));

BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);

BSP_LED_Init(LED_GREEN);
BSP_LED_Init(LED_BLUE);
BSP_LED_Init(LED_RED);
for(;;)
{
stEvent = osMessageGet(stQueue, osWaitForever);
stEvent = osMessageGet(stMainCtx.stQueue, osWaitForever);
if(osEventMessage == stEvent.status)
{
HAL_UART_Transmit(&stMainCtx.stUsartHandle,
(uint8_t *)"Button pressed!\n",
(sizeof("Button pressed!\n")-1),
USART_TX_TIMEOUT_MS);
BSP_LED_Toggle(LED_GREEN);
BSP_LED_Toggle(LED_BLUE);
BSP_LED_Toggle(LED_RED);
}
osDelay(u32BlinkDelayMs);
}
}

/**************************************************************************************************
* @brief USART thread handler
* @param argument argument pointer to be passed to thread handler
* @return Returns nothing
********************************************************************************************** */
static void usart_thread_handler(void const * argument)
{
const uint32_t u32MsgDelayMs = 1000;

usart_init();
HAL_UART_Receive_IT(&stUsartHandle, &u08RxByte, sizeof(u08RxByte));
for(;;)
{
HAL_UART_Transmit(&stUsartHandle,
(uint8_t *)"Hello world\n",
(sizeof("Hello world\n")-1),
100);
osDelay(u32MsgDelayMs);
}
}

Expand All @@ -180,22 +195,22 @@ static void usart_init(void)
stUsartGpio.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(USARTx_GPIO_PORT, &stUsartGpio);

/* Initialize usart intrrupt */
/* Initialize usart interrupt */
HAL_NVIC_SetPriority(USART3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);

/* Initialize usart configs */
stUsartHandle.Instance = USARTx;
stUsartHandle.Init.BaudRate = USART_BAUDRATE;
stUsartHandle.Init.WordLength = UART_WORDLENGTH_8B;
stUsartHandle.Init.StopBits = UART_STOPBITS_1;
stUsartHandle.Init.Parity = UART_PARITY_NONE;
stUsartHandle.Init.Mode = UART_MODE_TX_RX;
stUsartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
stUsartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
stUsartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
stUsartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if(HAL_OK != HAL_UART_Init(&stUsartHandle))
stMainCtx.stUsartHandle.Instance = USARTx;
stMainCtx.stUsartHandle.Init.BaudRate = USART_BAUDRATE;
stMainCtx.stUsartHandle.Init.WordLength = UART_WORDLENGTH_8B;
stMainCtx.stUsartHandle.Init.StopBits = UART_STOPBITS_1;
stMainCtx.stUsartHandle.Init.Parity = UART_PARITY_NONE;
stMainCtx.stUsartHandle.Init.Mode = UART_MODE_TX_RX;
stMainCtx.stUsartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
stMainCtx.stUsartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
stMainCtx.stUsartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
stMainCtx.stUsartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if(HAL_OK != HAL_UART_Init(&stMainCtx.stUsartHandle))
{
while(1) {}
}
Expand All @@ -210,7 +225,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t u16GpioPin)
{
if(USER_BUTTON_PIN == u16GpioPin)
{
osMessagePut(stQueue, (uint32_t)0xFF, 0);
osMessagePut(stMainCtx.stQueue, QUEUE_MESSAGE, 0);
}
}

Expand All @@ -223,12 +238,14 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *stHandle)
{
if(USART3 == stHandle->Instance)
{
if(RX_BUFFER_SIZE == u08Index)
if(RX_BUFFER_SIZE == stMainCtx.u08Index)
{
u08Index = 0;
stMainCtx.u08Index = 0;
}
u08RxBuffer[u08Index++] = u08RxByte;
HAL_UART_Receive_IT(&stUsartHandle, &u08RxByte, sizeof(u08RxByte));
stMainCtx.u08RxBuffer[stMainCtx.u08Index++] = stMainCtx.u08RxByte;
HAL_UART_Receive_IT(&stMainCtx.stUsartHandle,
&stMainCtx.u08RxByte,
sizeof(stMainCtx.u08RxByte));
}
}
/**
Expand Down

0 comments on commit 5f768c9

Please sign in to comment.