[rt-thread nano] 添加串口rt-printf打印

硬件:gd32f303

宏定义

定义宏定义

#define RT_USING_CONSOLE

#define RT_USING_DEVICE

#define RT_CONSOLE_DEVICE_NAME "uart1"

输出

#ifdef RT_USING_CONSOLE
void rt_hw_console_output( const char *str )
{
    
    /* 进入临界段 */
    rt_enter_critical();
    /* 直到字符串结束 */
    while ( *str != '\0' )
    { 
        // 换行
        if ( *str == '\n')  
        {
            usart_data_transmit(DEBUG_COM, (uint8_t)'\r');
            while(RESET == usart_flag_get(DEBUG_COM, USART_FLAG_TBE));
        }
        usart_data_transmit(DEBUG_COM, (uint8_t)*str++);
        while(RESET == usart_flag_get(DEBUG_COM, USART_FLAG_TBE));
    }       
    
    /* 退出临界段 */
    rt_exit_critical();
}
#endif

你可能感兴趣的:(linux,运维,服务器)