
【STM32F429心得\疑问】+最新FreeRtos(版本8.0)上手指南 最近折腾一块stm32f107rc的板子,摸索了一下FreeRTOS 的使用 发现起步不太难有点经验和大家分享。 1,先从官网http://www.freertos.org/下载 FreeRTOS 8.0.0 : V# Y" I2 ]5 ? 2,用标准库(STM32F10x_StdPeriph_Lib_V3.5.0)模板建工程) i! o- Z' ~* h5 }- F2 ]8 d: ] 3, 在工程中添加FreeRTOS 文件。tasks.c list.c queue.c heap_2.c# g9 g% h( u: z. V/ ? port.c 其中port.C是cotex M3的移植文件。选择目录..\..\Source\portable\RVDS\ARM_CM3\8 {1 r+ G) e) O: d+ c0 E* U+ L 下的port.c 3,修改启动代码(.s文件)如下,主要是链接FreeRTOS的三个中断函数 + N6 j8 _! T9 b; J IMPORT xPortPendSVHandler4 N; w/ F1 R6 E! d1 l& b IMPORT xPortSysTickHandler/ X4 i( \" C0 V( N* s! m IMPORT vPortSVCHandler .....* P8 R t3 m* R7 Y! \9 v+ H0 S DCD vPortSVCHandler ; SVCall Handler& J! ~* b/ p' |- e DCD DebugMon_Handler ; Debug Monitor Handler DCD 0 ; Reserved DCD xPortPendSVHandler ; PendSV Handler2 o0 ]) l9 S$ e1 V9 D. r8 o DCD xPortSysTickHandler ; SysTick Handler 9 Q) ]' {# p- `) u o/ m% e5 o 4.在main中建立自己任务开始 rtos /* Create one task. */ xTaskCreate( vTask1, /* Pointer to the function that implements the task. */& o3 G' w6 h( ]. M$ X) `& I f "Task 1", /* Text name for the task. This is to facilitate debugging only. */ 200, /* Stack depth in words. */ NULL, /* We are not using the task parameter. */8 c& K2 @6 F& j0 Z+ ` 1, /* This task will run at priority 1. */ NULL ); /* We are not using the task handle. */4 r1 p' u0 S' z. F7 k. s9 C/ c# ~ /* Create one task. */" e% c2 C& X! k( o* D xTaskCreate( vTask2, /* Pointer to the function that implements the task. */# V: Z/ W" L9 E" I1 e "Task 2", /* Text name for the task. This is to facilitate debugging only. *// I. b4 r- G! {, z2 F/ B 200, /* Stack depth in words. */* I$ ?& P) D* K NULL, /* We are not using the task parameter. */ 2, /* This task will run at priority 1. */' p" u: I4 F- U. L# Y( \) f NULL ); /* We are not using the task handle. */) C/ y# y8 n* J- R; T; v- J /* Start the scheduler so our tasks start executing. */& u9 `% @7 h) ^& X4 m) w v) p3 r# b vTaskStartScheduler();' w, c) s ?( ?" } t .............. ..............; s0 k! [0 q- o5 {( h8 Z0 b% H) ^! D+ R void vTask1( void *pvParameters ) {# y1 }/ q9 N6 u4 w' Y /* As per most tasks, this task is implemented in an infinite loop. */8 c& h( X7 D, Q( F o while(1)6 G8 d2 Y3 d( g0 O) m, z {1 U+ f4 s2 B" z) x5 @ LED_Toggle(0); LED_Toggle(2);+ j- J! N5 C) Z6 p vTaskDelay(800);4 o5 \7 M* ]* U0 ^) u7 E }6 ^1 n& o' r0 }7 F } void vTask2( void *pvParameters ). |% q- L" U& v% i& q8 ]5 a { /* As per most tasks, this task is implemented in an infinite loop. */ while(1) { LED_Toggle(1); LED_Toggle(3); vTaskDelay(1600); } } |