ESP8266 non_os串口打印重定向到uart1

版权声明:本文为博主(SimonLiu)原创文章,未经博主允许不得转载。 https://blog.csdn.net/toopoo/article/details/87970746

通常我们会使用ESP8266的uart0和外设通讯,uart1的RXD1用于和Flash通讯,但是TXD1可以用于打印log。
查看uart.c

void ICACHE_FLASH_ATTR
uart_init_2(UartBautRate uart0_br, UartBautRate uart1_br)
{
    // rom use 74880 baut_rate, here reinitialize
    UartDev.baut_rate = uart0_br;
    UartDev.exist_parity = STICK_PARITY_EN;
    UartDev.parity = EVEN_BITS;
    UartDev.stop_bits = ONE_STOP_BIT;
    UartDev.data_bits = EIGHT_BITS;
	
    uart_config(UART0);
    UartDev.baut_rate = uart1_br;
    uart_config(UART1);
    ETS_UART_INTR_ENABLE();

    // install uart1 putc callback
    os_install_putc1((void *)uart1_write_char);//print output at UART1
}

最后一行就是重定向串口打印。
所以我们只需要在初始化的时候,使用uart_init_2()就可以了。

uart_init_2(115200,115200);

猜你喜欢

转载自blog.csdn.net/toopoo/article/details/87970746
今日推荐