[LKS32 硬件] LKS32MC081评测 + rt-thread nano

[复制链接]
1022|1
 楼主| tlled 发表于 2022-6-19 23:24 | 显示全部楼层 |阅读模式
    移植rt-thread nano系统到开发板。
    一、配置rt-thread nano

移植参考的教程:https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-nano/nano-port-keil/an0039-nano-port-keil

    1.1、nano pack 安装
    001.png

    1.2、添加rt-thread nano到MDK软件
    002.png

    添加后,工程文件增加的有关RTOS的文件
    003.png

    二、修改代码

    rt-thread nano增加到工程后,修改和开发板有关的代码。
    2.1、添加systick配置和中断函数
    在工程其他文件中定义的systick中断函数屏蔽到,在board.c文件中增加
    004.png
        2.2、修改内存堆
    根据芯片RAM的大小来指定大小,这里我选择2K
    005.png
   
   2.3、测试代码

  1. #include "hardware_config.h"
  2. #include "led.h"
  3. //#include "usart.h"
  4. //#include <stdio.h>
  5. #include <rtthread.h>

  6. int main(void)
  7. {
  8.         u8 key = 0;
  9.         Hardware_init();   /* Ó²¼þ³õʼ»¯*/
  10.         init_led();
  11.        
  12.         while (1)
  13.         {
  14.                 led1_on();
  15.                 led2_off();
  16.                 rt_thread_mdelay(100);
  17.                 //led3_on();
  18.                 led1_off();
  19.                 led2_on();
  20.                 rt_thread_mdelay(100);
  21.                 //led3_off();
  22.         }
  23. }

    驱动LED指示灯,实现和上篇功能一样的LED灯交替点亮。


    三、在rt-thread nano 上添加控制台

    3.1、在rtconfig.h中,使能uart console
    006.png

    3.2、初始化串口和串口输出函数
    007.png

    四、创建任务

    4.1、创建两个任务

  1. #include "hardware_config.h"
  2. #include <rtthread.h>
  3. #include <rthw.h>
  4. #include "stdio.h"
  5. #include "string.h"
  6. #include "led.h"

  7. static rt_thread_t thread1;
  8. static rt_thread_t thread2;

  9. void thread1_entry(void *parameter)
  10. {
  11.         //init_ledd();
  12.         while(1)
  13.         {
  14.                 //leddisp();
  15.                 rt_kprintf("thread1 run \n");
  16.           rt_thread_mdelay(100);       
  17.                
  18.         }
  19. }

  20. void thread2_entry(void *parameter)
  21. {
  22.         while(1)
  23.         {
  24.                 rt_kprintf("thread2 run \n");
  25.           rt_thread_mdelay(200);       
  26.                
  27.         }
  28. }       

  29. void TaskInit(void)
  30. {
  31.         thread1 = rt_thread_create("thread1",
  32.                                                                                                                                 thread1_entry,
  33.                                                                                                                                 RT_NULL,
  34.                                                                                                                                 256,
  35.                                                                                                                                 2,                       
  36.                                                                                                                                 10);
  37.         if(thread1 != RT_NULL)
  38.         {
  39.                 rt_thread_startup(thread1);
  40.         }
  41.         else
  42.         {
  43.                 rt_kprintf("create thread1 fail\n\n");
  44.         }

  45.         thread2 = rt_thread_create("thread2",
  46.                                                                                                                                 thread2_entry,
  47.                                                                                                                                 RT_NULL,
  48.                                                                                                                                 256,
  49.                                                                                                                                 2,                       
  50.                                                                                                                                 10);
  51.         if(thread2 != RT_NULL)
  52.         {
  53.                 rt_thread_startup(thread2);
  54.         }
  55.         else
  56.         {
  57.                 rt_kprintf("create thread2 fail\n\n");
  58.         }
  59. }

    4.2、主程序   
  1. #include "hardware_config.h"
  2. #include <rtthread.h>
  3. #include "task.h"
  4. #include "led.h"

  5. int main(void)
  6. {
  7.         u8 key = 0;
  8.         Hardware_init();   /* Ó²¼þ³õʼ»¯*/
  9.         init_led();
  10.         TaskInit();
  11.        
  12.        
  13.         while (1)
  14.         {
  15.                 //rt_kprintf("https://www.linkosemi.com\r\n");
  16.                 led1_on();
  17.                 led2_off();
  18.                 rt_thread_mdelay(100);
  19.                 //led3_on();
  20.                 led1_off();
  21.                 led2_on();
  22.                 rt_thread_mdelay(100);
  23.                 //led3_off();
  24.         }
  25. }


    五、程序运行

    程序运行,串口输出:
    008.png




carpsnow 发表于 2022-6-22 20:36 | 显示全部楼层
上系统了,好快啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

132

主题

701

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部