本帖最后由 dirty123 于 2024-4-26 00:10 编辑
本篇讲述AT-START-F405开发板FreeRTOS系统移植运行。由于官方已经做好了demo,这里主要讲下移植与系统运行测验。
一.FreeRTOS系统移植
开发板MCUAT32F405RCT7-7微控制器,ARM Cortex-M4核,96+6KB RAM,256KB Flash ,资源是足够FreeRTOS系统移植的。
1.打开官方SDK里FreeRTOS工程如下。路径:AT32F402_405_Firmware_Library_V2.0.7\utilities\at32f402_405_freertos_demo
图1:FreeRTOS系统工程
2.在at32f402_405_int.c里屏蔽SVC_Handler,PendSV_Handler,SysTick_Handler
图2:屏蔽函数
3.定义引用系统时钟。在FreeRTOSConfig.h里有系统时钟频率configCPU_CLOCK_HZ宏定义,随时间节拍提供系统心跳
4.在main函数创建系统任务,启动调度器。
int main(void)
{
system_clock_config();
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
/* init led2 and led3 */
at32_led_init(LED2);
at32_led_init(LED3);
/* init usart1 */
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_led_toggle(LED2);
printf("LED2 led_toggle\r\n");
vTaskDelay(1000);
}
}
/* led3 task function */
void led3_task_function(void *pvParameters)
{
while(1)
{
at32_led_toggle(LED3);
printf("LED3 led_toggle\r\n");
vTaskDelay(500);
}
}
二.编译烧录运行
编译烧录运行后,可看到系统跑起来了。LED灯交替闪烁。
图3:FreeRTOS运行日志
至此,AT-START-F405开发板成功运行FreeRTOS系统。
|