From 5f768c9fc43bab418ae8ba50dfcfb7f858d3ff34 Mon Sep 17 00:00:00 2001 From: kaizoku-619 Date: Fri, 15 May 2020 15:36:47 +0100 Subject: [PATCH] doc + cleaning --- .github/workflows/build_workflow.yml | 29 ++++ .../{workflow.yml => publish_workflow.yml} | 2 +- README.md | 3 +- include/FreeRTOSConfig.h | 8 +- include/main.h | 25 +++- src/main.c | 137 ++++++++++-------- src/stm32f7xx_it.c | 42 ++---- 7 files changed, 147 insertions(+), 99 deletions(-) create mode 100644 .github/workflows/build_workflow.yml rename .github/workflows/{workflow.yml => publish_workflow.yml} (95%) diff --git a/.github/workflows/build_workflow.yml b/.github/workflows/build_workflow.yml new file mode 100644 index 0000000..dfed3a5 --- /dev/null +++ b/.github/workflows/build_workflow.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/workflow.yml b/.github/workflows/publish_workflow.yml similarity index 95% rename from .github/workflows/workflow.yml rename to .github/workflows/publish_workflow.yml index 851fe8f..2c6bf74 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/publish_workflow.yml @@ -1,4 +1,4 @@ -name: Publish +name: Release on: push: diff --git a/README.md b/README.md index 56f88c3..a8d892b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -![](https://github.com/kaizoku-619/pio-freertos/workflows/Publish/badge.svg) \ No newline at end of file +![](https://github.com/kaizoku-619/pio_ci_example/workflows/Build/badge.svg) +![](https://github.com/kaizoku-619/pio_ci_example/workflows/Release/badge.svg) diff --git a/include/FreeRTOSConfig.h b/include/FreeRTOSConfig.h index 0343d6f..fe8c74d 100644 --- a/include/FreeRTOSConfig.h +++ b/include/FreeRTOSConfig.h @@ -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. */ @@ -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 */ diff --git a/include/main.h b/include/main.h index ac0961a..4beecb6 100644 --- a/include/main.h +++ b/include/main.h @@ -40,7 +40,6 @@ * @{ */ #include "stm32f7xx_nucleo_144.h" -#include "cmsis_os.h" /** * @} */ @@ -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 @@ -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); +/** + * @} + */ /** * @} */ diff --git a/src/main.c b/src/main.c index 1f8354f..1b0a076 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ * @{ */ #include "main.h" +#include "cmsis_os.h" /** * @} */ @@ -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; /** * @} */ @@ -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; /** * @} */ @@ -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); /** * @} */ @@ -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; +} /** * @} */ @@ -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); } } @@ -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) {} } @@ -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); } } @@ -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)); } } /** diff --git a/src/stm32f7xx_it.c b/src/stm32f7xx_it.c index 0790ca1..c9aa2f1 100644 --- a/src/stm32f7xx_it.c +++ b/src/stm32f7xx_it.c @@ -34,12 +34,12 @@ */ /*-----------------------------------------------------------------------------------------------*/ -/* Imported variables */ +/* Private variables */ /*-----------------------------------------------------------------------------------------------*/ -/** @defgroup stm32f7xx_it_imported_variables Imported variables +/** @defgroup stm32f7xx_it_private_variables Private variables * @{ */ -extern UART_HandleTypeDef stUsartHandle; +UART_HandleTypeDef stUsartHandle; /** * @} */ @@ -65,7 +65,10 @@ void EXTI15_10_IRQHandler(void) ********************************************************************************************** */ void USART3_IRQHandler(void) { - HAL_UART_IRQHandler(&stUsartHandle); + if(TRUE == usart_get_handle(&stUsartHandle)) + { + HAL_UART_IRQHandler(&stUsartHandle); + } } /************************************************************************************************** @@ -74,39 +77,14 @@ void USART3_IRQHandler(void) * @return Returns nothing ********************************************************************************************** */ void NMI_Handler(void) -{ -} +{} + /************************************************************************************************** * @brief Handle debug monitor * @return Returns nothing ********************************************************************************************** */ void DebugMon_Handler(void) -{ -} - - -/************************************************************************************************** - * @brief Handle system tick timer - * @return Returns nothing - ********************************************************************************************** */ -// void SysTick_Handler(void) -// { -// HAL_IncTick(); -// } - -/************************************************************************************************** - * @brief Handle system service call via SWI instruction - * @return Returns nothing - ********************************************************************************************** */ -// void SVC_Handler(void) -// {} - -/************************************************************************************************** - * @brief Handle pendable request for system service - * @return Returns nothing - ********************************************************************************************** */ -// void PendSV_Handler(void) -// {} +{} /************************************************************************************************** * @brief Handle hard fault interrupt