mirror of
https://github.com/plctlab/riscv-operating-system-mooc.git
synced 2025-11-16 12:34:47 +00:00
Improve serial port printing compatibility
When using the ch34x USB2TTL adapter cable, garbled characters will be printed on the serial console. Detailed rootcause analysis, please see [1]. Learn the patch and update fsbl binaries and rvos serial port baud rate settings. However, according to my test observations, the ch34x chip is still not stable enough, and there will still be a small period of garbled code at the beginning of startup, so it is recommended to use FT232. Link [1]: https://community.milkv.io/t/set-the-baud-rate-to-115200-before-uboot/959 Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
This commit is contained in:
@@ -103,10 +103,18 @@ void uart_init()
|
||||
* See Datasheet @ https://github.com/milkv-duo/duo-files/tree/main/duo/datasheet
|
||||
* Chapter 12.2.4.1
|
||||
* Default UART working clock (UART_SCLK) is XTAL 25MHz.
|
||||
*
|
||||
* Strictly follow the TRM formula to calculate,
|
||||
* divisor = UART_CLOCKRATE / (16 * UART_BAUDRATE)
|
||||
* DLL = divisor & 0xff;
|
||||
* DLM = (divisor >> 8) & 0xff;
|
||||
* In theory, the value obtained by the division calculation
|
||||
* is approximately 13.56. However, the division result on the computer
|
||||
* will directly discard the decimal, resulting in 13.
|
||||
* The loss of accuracy is large. Using 14 has a smaller error.
|
||||
*/
|
||||
int divisor = 25000000 / (16 * 115200);
|
||||
uart_write_reg(DLL, (divisor & 0xff));
|
||||
uart_write_reg(DLM, ((divisor >> 8) & 0xff));
|
||||
uart_write_reg(DLL, 0x0e);
|
||||
uart_write_reg(DLM, 0x00);
|
||||
#else
|
||||
#warning "Unsupported Platform!"
|
||||
#endif
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user