[Review of Arteli Development Board AT32F421] 3. FreeRTOS porting [with source code]
[Copy link]
The goal of this article is to create two tasks and ultimately achieve the alternating flashing of the two LEDs on the development board.
AT provides a complete set of BSP&Pack for development (can be found in the Baidu network disk link). It mainly includes at32f4xx peripheral driver library, kernel related files, complete application routines and Pack files that can support multiple development environments such as Keil_v5, Keil_v4, IAR_v6, IAR_v7, IAR_v8, etc.
1. The core of AT32F421 is Cortex -M4F. Copy the CM4 core file. The CM4 file source code path is: BSP\AT32F4xx_StdPeriph_Lib_V1.2.9\Libraries\CMSIS\CM4\CoreSupport
AT startup file source code path: BSP\AT32F4xx_StdPeriph_Lib_V1.2.9\Libraries\CMSIS\CM4\DeviceSupport\startup\mdk
For the selection of startup files, please refer to 2.2 BSP usage in the document "AT32F4xx Standard Library BSP&Pack Application Guide.pdf". Because the transplantation is relatively simple, the following is a transplantation from scratch. If the FreeRTOS framework already exists in the project, you only need to replace it.
2. Get FreeRTOS source code
Method 1: * FreeRTOS official website: http://www.freertos.org/ *
Finally, copy the FreeRTOSConfig.h file to the user folder, that is, together with main.c (can be stored freely).
The FreeRTOSConfig.h file is the FreeRTOS project configuration file.
It is mainly used to configure and tailor the FreeRTOS kernel.
After the transplant is OK, Main.cw enain
#include <stdio.h>
#include "at32_board.h"
#include "FreeRTOS.h"
#include "task.h"
/** @addtogroup AT32Fxx_StdPeriph_Templates
* @{
*/
/** @addtogroup FreeRTOS_Demo
* @{
*/
/* Private define ------------------------------------------------------------*/
TaskHandle_t LED2_Handler;
TaskHandle_t LED3_Handler;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* LED2 task */
void LED2_task_Function(void *pvParameters);
/* LED3 task */
void LED3_task_Function(void *pvParameters);
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
/*Configure LED2/3 in AT_START_BOARD*/
AT32_LEDn_Init(LED2);
AT32_LEDn_Init(LED3);
AT32_LEDn_OFF(LED2);
AT32_LEDn_OFF(LED3);
UART_Print_Init(115200);
/* Enter critical */
taskENTER_CRITICAL();
/* Create LED2 task */
if(xTaskCreate((TaskFunction_t )LED2_task_Function,
(const char* )"LED2_task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )2,
(TaskHandle_t* )&LED2_Handler) != pdPASS)
{
printf("LED2 task could not be created as there was insufficient heap memory remaining.\r\n");
}
else
{
printf("LED2 task was created successfully.\r\n");
}
/* Create LED3 task */
if(xTaskCreate((TaskFunction_t )LED3_task_Function,
(const char* )"LED3_task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )2,
(TaskHandle_t* )&LED3_Handler) != pdPASS)
{
printf("LED3 task could not be created as there was insufficient heap memory remaining.\r\n");
}
else
{
printf("LED3 task was created successfully.\r\n");
}
/* Exit critical */
taskEXIT_CRITICAL();
/* Start Scheduler */
vTaskStartScheduler();
}
/* LED2 task function */
void LED2_task_Function(void *pvParameters)
{
while(1)
{
AT32_LEDn_Toggle(LED2);
vTaskDelay(1000);
}
}
/* LED3 task function */
void LED3_task_Function(void *pvParameters)
{
while(1)
{
AT32_LEDn_Toggle(LED3);
vTaskDelay(500);
}
}
|