From 7b75cd256356082096ab3f68bfff525a1729d24a Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 23 Aug 2024 13:16:00 +0200 Subject: [PATCH] Add UART patch for FPGA in sa-fpga tests --- overlay.nix | 1 + sa-fpga-uart.patch | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 sa-fpga-uart.patch diff --git a/overlay.nix b/overlay.nix index abac0e8..a3266f0 100644 --- a/overlay.nix +++ b/overlay.nix @@ -86,6 +86,7 @@ final: prev: patches = [ #./sa-fpga-crt.patch #./sa-fpga-text-address.patch + ./sa-fpga-uart.patch ]; buildPhase = '' cd fpga_core_bridge/simulator/tests/c_tests/ diff --git a/sa-fpga-uart.patch b/sa-fpga-uart.patch new file mode 100644 index 0000000..eed755a --- /dev/null +++ b/sa-fpga-uart.patch @@ -0,0 +1,31 @@ +diff --git a/fpga_core_bridge/simulator/tests/c_tests/common/syscalls.c b/fpga_core_bridge/simulator/tests/c_tests/common/syscalls.c +index 278ea97..287e5fc 100644 +--- a/fpga_core_bridge/simulator/tests/c_tests/common/syscalls.c ++++ b/fpga_core_bridge/simulator/tests/c_tests/common/syscalls.c +@@ -592,8 +592,18 @@ int uart_is_transmit_empty() { + + // Function to write a character to the UART + void uart_write_char(char c) { +- while (!uart_is_transmit_empty()); ++ //while (!uart_is_transmit_empty()); ++ ++ /* Delay it a bit, as checking the transmit holding register doesn't seem to ++ * work in the FPGA */ ++ for (volatile long i = 0; i < 10000; i++) ++ ; ++ + *(volatile uint8_t *)(UART_BASE + UART_THR) = c; ++ ++ /* Make new line go back to the start of the line */ ++ if (c == '\n') ++ uart_write_char('\r'); + } + + // Function to write a string to the UART +@@ -602,4 +612,4 @@ void uart_write_string(const char* str) { + uart_write_char(*str++); + asm("fence"); + } +-} +\ No newline at end of file ++}