From 3565b1f27e7bbeed82a2fe73d807f9c5cd2df151 Mon Sep 17 00:00:00 2001 From: IOsetting Date: Mon, 23 Jan 2023 02:42:37 +0800 Subject: [PATCH] feat: ll freertos example --- .../FreeRTOS/Tasks/LL_Blink/FreeRTOSConfig.h | 92 +++++++++++++++ Examples/FreeRTOS/Tasks/LL_Blink/main.c | 105 ++++++++++++++++++ Examples/FreeRTOS/Tasks/LL_Blink/main.h | 24 ++++ .../FreeRTOS/Tasks/LL_Blink/py32f0xx_it.c | 17 +++ .../FreeRTOS/Tasks/LL_Blink/py32f0xx_it.h | 16 +++ 5 files changed, 254 insertions(+) create mode 100644 Examples/FreeRTOS/Tasks/LL_Blink/FreeRTOSConfig.h create mode 100644 Examples/FreeRTOS/Tasks/LL_Blink/main.c create mode 100644 Examples/FreeRTOS/Tasks/LL_Blink/main.h create mode 100644 Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.c create mode 100644 Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.h diff --git a/Examples/FreeRTOS/Tasks/LL_Blink/FreeRTOSConfig.h b/Examples/FreeRTOS/Tasks/LL_Blink/FreeRTOSConfig.h new file mode 100644 index 0000000..81e760a --- /dev/null +++ b/Examples/FreeRTOS/Tasks/LL_Blink/FreeRTOSConfig.h @@ -0,0 +1,92 @@ +/* + * FreeRTOS V202112.00 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* Ensure definitions are only used by the compiler, and not by the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + #include + extern uint32_t SystemCoreClock; +#endif + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 2 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 64 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 3 * 512 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 + +/* This is the raw value as per the Cortex-M3 NVIC. Values can be 255 +(lowest) to 0 (1?) (highest). */ +#define configKERNEL_INTERRUPT_PRIORITY 255 +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 10-111111, or priority 2. */ + +/* Use MACRO to replace the handlers without changing startup file */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler + + +#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file diff --git a/Examples/FreeRTOS/Tasks/LL_Blink/main.c b/Examples/FreeRTOS/Tasks/LL_Blink/main.c new file mode 100644 index 0000000..78a68e9 --- /dev/null +++ b/Examples/FreeRTOS/Tasks/LL_Blink/main.c @@ -0,0 +1,105 @@ +#include "main.h" +#include "py32f0xx_bsp_printf.h" +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" + + +static void APP_SystemClockConfig(void); +static void APP_GPIOConfig(void); + +void task1(void *pvParameters) +{ + (void)(pvParameters); // Suppress "unused parameter" warning + + while (1) + { + LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_5); + vTaskDelay(500); + } +} + +void task2(void *pvParameters) +{ + (void)(pvParameters); + + while (1) + { + printf("task2 echo\r\n"); + vTaskDelay(1000); + } +} + +int main(void) +{ + BaseType_t xReturned; + + APP_SystemClockConfig(); + APP_GPIOConfig(); + + BSP_USART_Config(115200); + printf("SystemClk:%ld\r\n", SystemCoreClock); + + /* Create task 1 */ + xReturned = xTaskCreate( + task1, // Task function point + "Task1", // Task name + configMINIMAL_STACK_SIZE, // Use the minimum stack size, each take 4 bytes(32bit) + NULL, // Parameters + 2, // Priority + NULL); // Task handler + if (xReturned != pdPASS) + { + APP_ErrorHandler(); + } + + /* Create task 2 */ + xReturned = xTaskCreate(task2, "Task2", configMINIMAL_STACK_SIZE, NULL, 2, NULL); + if (xReturned != pdPASS) + { + APP_ErrorHandler(); + } + + printf("FreeRTOS Scheduler starting...\r\n"); + /* Start the scheduler. */ + vTaskStartScheduler(); + + /* Will only get here if there was not enough heap space to create the idle task. */ + return 0; +} + +static void APP_SystemClockConfig(void) +{ + LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct; + + LL_RCC_HSI_Enable(); + /* Change this value to adjust frequency */ + LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz); + while(LL_RCC_HSI_IsReady() != 1); + + UTILS_ClkInitStruct.AHBCLKDivider = LL_RCC_SYSCLK_DIV_1; + UTILS_ClkInitStruct.APB1CLKDivider = LL_RCC_APB1_DIV_1; + LL_PLL_ConfigSystemClock_HSI(&UTILS_ClkInitStruct); + + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL); + + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + /* Don't invoke this in FreeRTOS */ + // LL_InitTick(48000000, 1000U); + /* Update global SystemCoreClock(or through SystemCoreClockUpdate function) */ + LL_SetSystemCoreClock(48000000); +} + +static void APP_GPIOConfig(void) +{ + LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB); + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT); +} + +void APP_ErrorHandler(void) +{ + while (1); +} diff --git a/Examples/FreeRTOS/Tasks/LL_Blink/main.h b/Examples/FreeRTOS/Tasks/LL_Blink/main.h new file mode 100644 index 0000000..5f41582 --- /dev/null +++ b/Examples/FreeRTOS/Tasks/LL_Blink/main.h @@ -0,0 +1,24 @@ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "py32f0xx_ll_rcc.h" +#include "py32f0xx_ll_bus.h" +#include "py32f0xx_ll_system.h" +#include "py32f0xx_ll_exti.h" +#include "py32f0xx_ll_cortex.h" +#include "py32f0xx_ll_utils.h" +#include "py32f0xx_ll_pwr.h" +#include "py32f0xx_ll_dma.h" +#include "py32f0xx_ll_gpio.h" + +void APP_ErrorHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.c b/Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.c new file mode 100644 index 0000000..b5abf84 --- /dev/null +++ b/Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.c @@ -0,0 +1,17 @@ +#include "main.h" +#include "py32f0xx_it.h" + +/** + * @brief This function handles Non maskable interrupt. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard fault interrupt. + */ +void HardFault_Handler(void) +{ + while (1); +} diff --git a/Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.h b/Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.h new file mode 100644 index 0000000..160f858 --- /dev/null +++ b/Examples/FreeRTOS/Tasks/LL_Blink/py32f0xx_it.h @@ -0,0 +1,16 @@ +#ifndef __PY32F0XX_IT_H +#define __PY32F0XX_IT_H + +#ifdef __cplusplus +extern "C" { +#endif + +void NMI_Handler(void); +void HardFault_Handler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __PY32F0XX_IT_H */