[STM32U5] 【NUCLEO-U575ZI-Q测评】RT-Thread 点灯

[复制链接]
688|1
 楼主| lulugl 发表于 2023-2-22 20:12 | 显示全部楼层 |阅读模式
RT-Thread 是国产操作系统,提供了U575的开发BSP包,这里带大家体验一下超级简单的入门
1、下载BSPrt-thread: RT-Thread是一个来自中国的开源物联网操作系统,它提供了非常强的可伸缩能力:从一个可以运行在ARM Cortex-M0芯片上的极小内核,到中等的ARM Cortex-M3/4/7系统,甚至是多核,64位的ARM Cortex-A,MIPS32/64处理器的功能丰富系统 (gitee.com)
2、下载后,解压,在bsp目录下面删除除rt-thread-master\bsp\stm32\stm32u575-st-nucleo的其他bsp。当然如果你的硬盘大,可以留下。
3、进入stm32u575-st-nucleo,打开menuconfig.(具体入门资料可以去RT-Thread查看文档,这里不做说明)
659363f60411a919f.png
4、输入menuconfig进入配置,由于我们使用默认配置,可以save后退出。然后使用scons --target=mdk5,更新工程
8783763f604c93bfc0.png
1063163f604f13844f.png
5、在目录下面打开keil工程:
3426063f60520d4ba4.png
6、找到Applications下的main.c,看到系统已经生成了LED1的闪灯任务。我们编译后下载到开发板,就可以实现LED1的闪烁了:
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date           Author       Notes
  8. * 2018-11-06     SummerGift   first version
  9. */

  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include <board.h>

  13. /* defined the LED1 pin: PC7 */
  14. /* defined the LED0 pin: PG2 */

  15. #define LED0_PIN    GET_PIN(G, 2)

  16. #define LED1_PIN    GET_PIN(C, 7)
  17. #define THREAD_PRIORITY         25
  18. #define THREAD_STACK_SIZE       512
  19. #define THREAD_TIMESLICE        5

  20. /* 线程led 的对象和运行时用到的栈 */


  21. static struct rt_thread thread_led;
  22. static rt_uint8_t thread_led_stack[512];

  23. /*  线程led 入口 */
  24. void thread_led_entry(void* parameter)
  25. {
  26.         rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
  27.         while(1)
  28.         {
  29.                 rt_pin_write(LED1_PIN,PIN_HIGH);
  30.                 rt_thread_mdelay(500);
  31.                 rt_pin_write(LED1_PIN, PIN_LOW);
  32.                 rt_thread_mdelay(500);
  33.         }
  34. }

  35. /* 线程LED1 初始化 */
  36. int thread_sample(void)
  37. {
  38.         rt_thread_t threadled_ptr;
  39.         rt_err_t result;
  40.        
  41.         /*
  42.         * 初始化 线程LED1
  43.         * 线程的入口是 thread_led_entry, 参数是RT_NULLL
  44.         * 线程栈是thread_led_stack
  45.         * 优先级是25,时间片是5 OS Tick
  46.                
  47.         */
  48.         result = rt_thread_init(&thread_led,
  49.                                                                                                         "thread led",
  50.                                                                                                         thread_led_entry, RT_NULL,
  51.                                                                                                         &thread_led_stack[0], sizeof(thread_led_stack),
  52.                                                                                                                 THREAD_PRIORITY-1,THREAD_TIMESLICE);
  53.         /*  启动线程 */
  54.         if(result == RT_EOK) rt_thread_startup(&thread_led);
  55.         return 0;
  56. }

  57. int main(void)
  58. {
  59.     int count = 1;
  60.     /* set LED0 pin mode to output */
  61.     rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
  62.                 thread_sample();
  63.     while (count++)
  64.     {
  65.         rt_pin_write(LED0_PIN, PIN_HIGH);
  66.         rt_thread_mdelay(500);
  67.         rt_pin_write(LED0_PIN, PIN_LOW);
  68.         rt_thread_mdelay(500);
  69.     }

  70.     return RT_EOK;
  71. }
7、打开串口终端,可以看到经典的启动界面:
5075563f60673cdcb6.png
【小结】RT-Thread 与ST的合作,对NUCLEO-U575ZI-Q开发板提供了板级支持,使得开发非常容易。
Bowclad 发表于 2024-1-12 16:23 | 显示全部楼层
RT-Thread最低可以跑在多少资源芯片上啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

188

主题

844

帖子

12

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