分享

[原创]freeRTOS在F429上的移植

 知芯世界 2020-10-28

项目中要用到嵌入式操作系统,考虑到免费开源,我首先想到了freeRTOS,之前只是在使用,对于移植没有在意,今天花了一些时间进行移植,平台是STM32F429,编译器是MDK5,由于,我们不需要理会汇编部分的内容,freeRTOS的官方源码包里面已经针对很多平台将接口对接好了,官方源码包里的demo是我们移植时的一个重要参考,里面囊括了很多平台,我们只需要找到我们 自己的平台便可轻松移植,下面是移植的过程:

1、在freeRTOS官网下载freeRTOS的源码[img=0,1]file:///C:\Users\Administrator.W8-201508102146\AppData\Roaming\Tencent\Users\274571483\QQ\WinTemp\RichOle\9ISY2203CXVJ[225A%[JH]T.png[/img],如图1和图2,我下载的版本为最新版V8.2.3
2、解压之后可看见如图所示内容,如图3,我们用的是FreeRTOS文件下中的内容,打开该文件夹,我们可以看见如图4所示内容,demo中是针对很多平台和编译器移植好了的范例,作为我们移植的一个参考,source文件夹就是我们将要用到的源文件
3、打开source文件夹,如图5,我们将queue.c tasks.c list.c timer.c和source/portable/RVDS路径下的port.c以及source/portable/MemMang路径下的heap_4加入我们的工程中,如图6。编译出现错误,提示找不到portmacro.h文件,这个文件是和平台对应的,我的是F4平台,该文件位于source/portable/RVDS/ARM_CM4F路径,将其加入工程中,
4、由于F4有硬件浮点机制,freeRTOS代码设计到了该机制,我们在编译时一定要记得打开,首先是在MDK的target设置中打开选择use single precision,然后在stm32f4xx.h中将宏__FPU_PRESENT置1,通过这两步,我们便打开了硬件浮点
5、将freeRTOSconfig.h加入该工程中,该文件是对系统的一些配置,一些开关量就在该文件中,由于我的平台是F4,故我直接在Demo文件下的针对STM32F407平台下的freeRTOSconfig.h拷贝到了工程中,并且对其中进行一些很小的修改,比如系统时钟频率等,
6、既然是操作系统,就会有滴答中断服务函数以及软切换,freeRTOS在freeRTOSconfig.h的末尾直接通过3个宏定义
  1. #define vPortSVCHandler SVC_Handler

  2. #define xPortPendSVHandler PendSV_Handler

  3. #define xPortSysTickHandler SysTick_Handler

复制代码

将底层与系统接口函数对接了起来,而底层也是由freeRTOS根据平台写好了的
到这里,移植过程已经完成,我的主函数就是建立两个LED任务,一个led以500ms闪烁,另一个以1000MS闪烁,经测试,系统调度正常
  1. void LED3_Task( void *pvParameters )

  2. {

  3. int i;

  4. while(1)

  5. {

  6. Toogle_LED3();

  7. vTaskDelay(500);

  8. }

  9. }

  10. void vTask2( void *pvParameters )

  11. {

  12. int i;

  13. while(1)

  14. {

  15. Toogle_LED4();

  16. vTaskDelay(1000);

  17. }

  18. }

  19. int main()

  20. {

  21. while(1)

  22. {

  23. xTaskCreate( LED3_Task, /* Pointer to the function that implements the task. */

  24. "LED3", /* Text name for the task. This is to facilitate debugging only. */

  25. 500, /* Stack depth in words. */

  26. NULL, /* We are not using the task parameter. */

  27. 1, /* This task will run at priority 1. */

  28. NULL ); /* We are not using the task handle. */

  29. xTaskCreate( vTask2, /* Pointer to the function that implements the task. */

  30. "Task 2", /* Text name for the task. This is to facilitate debugging only. */

  31. 500, /* Stack depth in words. */

  32. NULL, /* We are not using the task parameter. */

  33. 2, /* This task will run at priority 1. */

  34. NULL ); /* We are not using the task handle. */

  35. vTaskStartScheduler();

  36. while(1);

  37. }

  38. }

复制代码



移植完成


>>>点此了解最新活动

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多