打印

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

[复制链接]
793|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
一、控制台重映射函数
void rt_hw_console_output(const char *str)
{
        rt_enter_critical();
       
        while(*str!='\0')
        {
                if(*str=='\n')
                {
                        usart_data_transmit(USART0,'\r');
                        while(usart_flag_get(USART0,USART_FLAG_TBE)==RESET);
                }
                usart_data_transmit(USART0,*str++);
                while(usart_flag_get(USART0,USART_FLAG_TBE)==RESET);
        }
        rt_exit_critical();
}
二、主函数
#include "board.h"
#include "rtthread.h"

static rt_thread_t led1_thread=RT_NULL;
//static rt_thread_t usart_thread=RT_NULL;


static void led1_thread_entry(void *parameter);
//static void usart_thread_entry(void *parameter);


int main(void)
{
        led1_thread=rt_thread_create("led1",led1_thread_entry,RT_NULL,512,3,20);               
        if(led1_thread!=RT_NULL)
        {
                rt_thread_startup(led1_thread);
        }
        else
        {
                return -1;
        }
       
//        usart_thread=rt_thread_create("usart0",usart_thread_entry,RT_NULL,512,2,20);
//        if(usart_thread!=RT_NULL)
//        {
//                rt_thread_startup(usart_thread);
//        }
//        else
//        {
//                return -1;
//        }
       
}


static void led1_thread_entry(void *parameter)
{
        while(1)
        {
                led1=1;
                rt_thread_delay(1500);
                rt_kprintf("led1_thread is running,LED1_ON\r\n");

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

        }

}       


//static void usart_thread_entry(void *parameter)
//{
//        while(1)
//        {
//                usart_data_transmit(USART0,0x01);
//                rt_thread_delay(500);
//        }
//}

三、结果

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

66

主题

1948

帖子

14

粉丝