刚开始接触 XR806, 根据官方指导說明一步步将 wifi_skylark
demo 編譯了出來,使用 ckermit 終端查看打印,發現很凌亂。具體效果是:
實在是不美觀,因爲之前碰到過類似的問題簡單來說就是沒有將 \n 識別出回車 \r 的效果。這種現象的解決方法有多種。
這次我選擇了修改putchar() 的方法。通過一步步的跟蹤代碼,發現 console 的基本流程是:
int __wrap_putchar(int c)
// stdio_set_write(stdout_write)
board_uart_write()
我修改的部分在 stdio_set_write 函數,具體是:
diff --git a/xr806/xr_skylark/project/common/startup/gcc/retarget_stdout.c b/xr806/xr_skylark/project/common/startup/gcc/retarget_stdout.c
index 487c75b..9cd725f 100755
--- a/xr806/xr_skylark/project/common/startup/gcc/retarget_stdout.c
+++ b/xr806/xr_skylark/project/common/startup/gcc/retarget_stdout.c
@@ -175,7 +175,17 @@ static int stdout_write(const char *buf, int len)
}
#endif
- return board_uart_write(g_stdout_uart_id, buf, len);
+ if (buf[len - 1] == '\n')
+ {
+ char r_ch[1] = {'\r'};
+ int rlen = board_uart_write(g_stdout_uart_id, buf, len);
+ board_uart_write(g_stdout_uart_id, r_ch, 1);
+ return rlen;
+ }
+ else
+ {
+ return board_uart_write(g_stdout_uart_id, buf, len);
+ }
}
測試之後發現打印信息變成了這樣:
命令行的顯示效果還是會出現問題,繼續跟蹤代碼,修改部分:
diff --git a/xr806/xr_skylark/src/console/console.c b/xr806/xr_skylark/src/console/console.c
index 457ee23..72b5a0b 100755
--- a/xr806/xr_skylark/src/console/console.c
+++ b/xr806/xr_skylark/src/console/console.c
@@ -439,7 +439,16 @@ int console_write(uint8_t *buf, int32_t len)
console_priv_t *console;
console = &g_console;
- return HAL_UART_Transmit_Poll(console->uart_id, buf, len);
+ if (buf[len - 1] == '\n')
+ {
+ uint8_t r_ch[1] = {'\r'};
+ HAL_UART_Transmit_Poll(console->uart_id, buf, len);
+ return HAL_UART_Transmit_Poll(console->uart_id, r_ch, 1);
+ }
+ else
+ {
+ return HAL_UART_Transmit_Poll(console->uart_id, buf, len);
+ }
}
/**
打上以上連個補丁後,console 的輸出就美觀多了。