基于gd32f103和RTTHREAD实现rt_kprintf()重映射

[复制链接]
1063|0
 楼主| zeshoufx 发表于 2019-7-16 17:38 | 显示全部楼层 |阅读模式
一、控制台重映射函数
  1. void rt_hw_console_output(const char *str)
  2. {
  3.         rt_enter_critical();
  4.        
  5.         while(*str!='\0')
  6.         {
  7.                 if(*str=='\n')
  8.                 {
  9.                         usart_data_transmit(USART0,'\r');
  10.                         while(usart_flag_get(USART0,USART_FLAG_TBE)==RESET);
  11.                 }
  12.                 usart_data_transmit(USART0,*str++);
  13.                 while(usart_flag_get(USART0,USART_FLAG_TBE)==RESET);
  14.         }
  15.         rt_exit_critical();
  16. }
二、主函数
  1. #include "board.h"
  2. #include "rtthread.h"

  3. static rt_thread_t led1_thread=RT_NULL;
  4. //static rt_thread_t usart_thread=RT_NULL;


  5. static void led1_thread_entry(void *parameter);
  6. //static void usart_thread_entry(void *parameter);


  7. int main(void)
  8. {
  9.         led1_thread=rt_thread_create("led1",led1_thread_entry,RT_NULL,512,3,20);               
  10.         if(led1_thread!=RT_NULL)
  11.         {
  12.                 rt_thread_startup(led1_thread);
  13.         }
  14.         else
  15.         {
  16.                 return -1;
  17.         }
  18.        
  19. //        usart_thread=rt_thread_create("usart0",usart_thread_entry,RT_NULL,512,2,20);
  20. //        if(usart_thread!=RT_NULL)
  21. //        {
  22. //                rt_thread_startup(usart_thread);
  23. //        }
  24. //        else
  25. //        {
  26. //                return -1;
  27. //        }
  28.        
  29. }


  30. static void led1_thread_entry(void *parameter)
  31. {
  32.         while(1)
  33.         {
  34.                 led1=1;
  35.                 rt_thread_delay(1500);
  36.                 rt_kprintf("led1_thread is running,LED1_ON\r\n");

  37.                 led1=0;
  38.                 rt_thread_delay(1500);
  39.                 rt_kprintf("led1_thread is running,LED1_OFF\r\n");

  40.         }

  41. }       


  42. //static void usart_thread_entry(void *parameter)
  43. //{
  44. //        while(1)
  45. //        {
  46. //                usart_data_transmit(USART0,0x01);
  47. //                rt_thread_delay(500);
  48. //        }
  49. //}

三、结果
473235d2d9afcd624c.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则

67

主题

1991

帖子

15

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