Chinaunix首页 | 论坛 | 博客
  • 博客访问: 660599
  • 博文数量: 186
  • 博客积分: 1875
  • 博客等级: 上尉
  • 技术积分: 2117
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-23 23:21
个人简介

有时候,就是想窥视一下不知道的东东,因为好奇!

文章分类

全部博文(186)

文章存档

2024年(2)

2023年(3)

2020年(1)

2019年(1)

2018年(1)

2017年(2)

2016年(69)

2015年(53)

2014年(14)

2013年(1)

2012年(5)

2011年(25)

2010年(9)

分类: 其他平台

2015-05-11 20:30:40

              建立rt-thread基于stm32f103的最小系统试运行
一、烧录前设置

 

否则会在烧录时出现以下错误

 

二、烧录运行

查看代码得知,有一个以函数led_thread_entry()为执行主体的线程,会用GPE.2以1HZ频率控制led的闪烁。

1、将编译链接后得到的文件烧录进STM32F103ZET6红牛开发板。用示波器查看GPE.2对应的引脚,并没有预期的1HZ方波出现。

2、用开发板的串口一接上window电脑,上电时,在window电脑上用串口调试助手可以得到如下输出信息。表明代码已经在运行,由于有故障而没有得到预期的输出。

 

3、通过在执行路径上加入打印语句rt_kprintf("\n [%s-%d]!\n", __FILE__, __LINE__);定位到故障点:rt_init_thread_entry()-->finsh_set_device()-->RT_ASSERT()

4、直接将rt_init_thread_entry()函数中调用finsh_set_device()的语句注释掉。然后重新编译链接烧录到开发板上。再用示波器查看GPE.2状态,看到预期的方波输出。

三、添加线程
    在application.c文件内int rt_application_init(void)函数之前添加如下代码

点击(此处)折叠或打开

  1. char thread1_stack[256];
  2. char thread2_stack[256];

  3. struct rt_thread thread1;
  4. struct rt_thread thread2;

  5. void thread1_entry(void* parameter)
  6. {
  7.     rt_uint32_t i = 0;
  8.     
  9.     while (1)
  10.     {
  11.         rt_kprintf("thread1 --> %d\n", ++i);
  12.         rt_thread_delay(100);
  13.     }
  14. }

  15. void thread2_entry(void* parameter)
  16. {
  17.     int count = 0;
  18.     while (1)
  19.     {
  20.         rt_kprintf("Thread2 count:%d\n", ++count);
  21.         rt_thread_delay(50);
  22.     }
  23. }

  24. void thread_test()
  25. {
  26.     rt_err_t result;
  27.     
  28.      result = rt_thread_init(&thread1,
  29.         "thread1",
  30.         thread1_entry, RT_NULL,
  31.         &thread1_stack[0], sizeof(thread1_stack),
  32.         20, 15);
  33.     if (result == RT_EOK)
  34.     {
  35.         rt_thread_startup(&thread1);
  36.     }
  37.     
  38.     result = rt_thread_init(&thread2,
  39.         "thread2",
  40.         thread2_entry, RT_NULL,
  41.         &thread2_stack[0], sizeof(thread2_stack),
  42.         25, 10);
  43.     if (result == RT_EOK)
  44.     {
  45.         rt_thread_startup(&thread2);
  46.     }
  47. }
  48. FINSH_FUNCTION_EXPORT(thread_test, perform thread test)
在int rt_application_init(void)函数内代码
        if (result == RT_EOK)
        {
            rt_thread_startup(&led_thread);
        }
      之后添加thread_test();
      然后重新编译链接烧录到开发板上。window电脑上用串口调试助手可以得到如下输出信息
    


阅读(3934) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~