From 806023778b8bf804cd84bda04a41fb44b641c2a4 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 23 Aug 2024 17:42:55 +0200 Subject: [PATCH] Initialize UART in bootrom Unless the UART is properly initialized, the console won't display any message until a next stage intializes it (OpenSBI) and then we will start to see messages after uploading the next bootroms. Follows the OpenSBI initialization for the UART setting the baud rate to 115200 and assuming a clock of 50 MHz. --- bootrom/rbootrom.S | 72 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/bootrom/rbootrom.S b/bootrom/rbootrom.S index 04454d8..9a7f02b 100644 --- a/bootrom/rbootrom.S +++ b/bootrom/rbootrom.S @@ -12,6 +12,28 @@ #define DRAM_BASE 0x80000000 #define UART_BASE 0x40001000 +#define UART_BAUDRATE 115200 +#define UART_CLOCK 50000000 + +#define UART_BDIV ((UART_CLOCK + 8 * UART_BAUDRATE) / (16 * UART_BAUDRATE)) +#define UART_SHIFT 2 + +#define UART_RBR_OFFSET (0<> 8) & 0xff // Set divisor high byte + sb t1, UART_DLM_OFFSET(t0) + + la t1, 0x03 // 8 bits, no parity, one stop bit + sb t1, UART_LCR_OFFSET(t0) + la t1, 0x01 // Enable FIFO + sb t1, UART_FCR_OFFSET(t0) + la t1, 0x00 // No modem control DTR RTS + sb t1, UART_MCR_OFFSET(t0) + + /* TODO: Clear line status */ + /* TODO: Read receive buffer */ + + la t1, 0x00 // Set scratchpad to 0 + sb t1, UART_SCR_OFFSET(t0) - // Write the character now - la t0, UART_BASE // Transmitter Holding Buffer - sb a0, 0(t0) // Write a0 byte ret print_hello: