查看: 3366|回复: 0

[原创] 【野火i.MX RT1052学习笔记】3.适配FreeRTOS

[复制链接]
  • TA的每日心情
    开心
    2018-6-21 08:39
  • 签到天数: 8 天

    连续签到: 2 天

    [LV.3]偶尔看看II

    发表于 2018-6-4 23:02:43 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 jasonwangse 于 2018-6-4 23:09 编辑

    官方sdk中带有freertos的包和demo,但版本是9.0.0的。freertos拥抱了amazon之后,版本就直接升级到了10.0.0,目前最新的版本是10.0.1,与10.0.0相比只有少许改动。我们先到官网上把最新版下载下来,然后基于野火的库例程工程创建RTOS工程吧
    https://www.freertos.org/a00104.html
    1. 先创建freertos目录,然后把官方解压包中FreeRTOS目录里的Source文件夹全部拷贝过去
    2. 创建freertos组,添加内核源文件和port目前下对应CM7的文件,以及内存管理文件heap_4.c
    pic1.jpg

    3. 在Include Paths中添加FreeRTOS及porting的头文件路径
    pic2.jpg

    4. 把sdk中的简单rtos demo,freertos_hello,中的FreeRTOSConfig.h拷贝到user目录下
    5.将main.c改为app.c并参考freertos_hello demo中的的实现创建任务打印Hello world
    1. /* FreeRTOS kernel includes. */
    2. #include "FreeRTOS.h"
    3. #include "task.h"
    4. #include "queue.h"
    5. #include "timers.h"

    6. /* Freescale includes. */
    7. #include "fsl_device_registers.h"
    8. #include "fsl_debug_console.h"
    9. #include "board.h"

    10. #include "pin_mux.h"
    11. #include "clock_config.h"
    12. /*******************************************************************************
    13. * Definitions
    14. ******************************************************************************/

    15. /* Task priorities. */
    16. #define hello_task_PRIORITY (configMAX_PRIORITIES - 1)
    17. /*******************************************************************************
    18. * Prototypes
    19. ******************************************************************************/
    20. static void hello_task(void *pvParameters);

    21. /*******************************************************************************
    22. * Code
    23. ******************************************************************************/
    24. /*!
    25. * @brief Application entry point.
    26. */
    27. int main(void)
    28. {
    29.     /* Init board hardware. */
    30.     BOARD_ConfigMPU();
    31.     BOARD_InitPins();
    32.     BOARD_BootClockRUN();
    33.     BOARD_InitDebugConsole();
    34.     if (xTaskCreate(hello_task, "Hello_task", configMINIMAL_STACK_SIZE + 10, NULL, hello_task_PRIORITY, NULL) != pdPASS)
    35.     {
    36.         PRINTF("Task creation failed!.\r\n");
    37.         while (1)
    38.             ;
    39.     }
    40.     vTaskStartScheduler();
    41.     for (;;)
    42.         ;
    43. }

    44. /*!
    45. * @brief Task responsible for printing of "Hello world." message.
    46. */
    47. static void hello_task(void *pvParameters)
    48. {
    49.     for (;;)
    50.     {
    51.         PRINTF("Hello world.\r\n");
    52.         vTaskSuspend(NULL);
    53.     }
    54. }
    复制代码

    6. 直接编译,会发现有问题,首先是报头文件freertos_tasks_c_addtions.h找不到
    pic3.jpg

    源码中也没有此文件,应该是其他架构或者老版本中会有用,没事,直接将对应的配置项定义为0即可。其次又报找不到SystemCoreClock
    pic4.jpg

    system_MIMXRT1052.h中有对此变量的外部声明,在FreeRTOSConfig.h前面加上以下代码就好
    1. /* For SystemCoreClock */
    2. #include "system_MIMXRT1052.h"
    复制代码

    编译成功,下载后直接正常运行
    pic5.jpg

    不过目前只是证明在FreeRTOS中创建任务打印没问题了,系统时钟、任务切换有没有问题呢?再创建个简单的测试任务试试看吧,修改app中的代码,添加一个delay打印的代码
    1. int main(void)
    2. {
    3.     /* Init board hardware. */
    4.     BOARD_ConfigMPU();
    5.     BOARD_InitPins();
    6.     BOARD_BootClockRUN();
    7.     BOARD_InitDebugConsole();
    8.     if (xTaskCreate(hello_task, "Hello_task", configMINIMAL_STACK_SIZE + 10, NULL, hello_task_PRIORITY, NULL) != pdPASS)
    9.     {
    10.         PRINTF("Task creation failed!.\r\n");
    11.         while (1)
    12.             ;
    13.     }
    14.    
    15.         /* debug console thread, simply counts seconds */
    16.         xTaskCreate(vDebugConsoleTask, "vDebugConsole",
    17.                                 configMINIMAL_STACK_SIZE, NULL, debugConsole_task_PRIORITY,
    18.                                 (TaskHandle_t *) NULL);

    19.     vTaskStartScheduler();
    20.     for (;;)
    21.         ;
    22. }

    23. /* debug console thread */
    24. static void vDebugConsoleTask(void *pvParameters) {
    25.         int tickCnt = 0;

    26.         while (1) {
    27.                 PRINTF("SysTick: %d \r\n", tickCnt);
    28.                 tickCnt++;

    29.                 /* About a 1s delay here */
    30.                 vTaskDelay(configTICK_RATE_HZ);
    31.         }
    32. }
    复制代码

    SysTick一秒打印一次,输出正常
    pic6.jpg

    目前来看FreeRTOS已经正常运行起来了,下一步就是移植fatfs和tcpip协议栈了





    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-4-24 19:34 , Processed in 0.107001 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.