From f53178d7124055ac4af44d16f9918e9a69254000 Mon Sep 17 00:00:00 2001 From: Jamey Hicks Date: Mon, 28 Oct 2024 15:04:28 -0400 Subject: [PATCH] feat: add uart_with_dynamic_baudrate to SoCCore --- litex/soc/cores/uart.py | 4 ++-- litex/soc/integration/soc.py | 10 +++++----- litex/soc/integration/soc_core.py | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/litex/soc/cores/uart.py b/litex/soc/cores/uart.py index f4e0fec28..7f30b249c 100644 --- a/litex/soc/cores/uart.py +++ b/litex/soc/cores/uart.py @@ -202,14 +202,14 @@ def _get_uart_fifo(depth, sink_cd="sys", source_cd="sys"): else: return stream.SyncFIFO([("data", 8)], depth, buffered=True) -def UARTPHY(pads, clk_freq, baudrate): +def UARTPHY(pads, clk_freq, baudrate, with_dynamic_baudrate=False): # FT245 Asynchronous FIFO mode (baudrate ignored) if hasattr(pads, "rd_n") and hasattr(pads, "wr_n"): from litex.soc.cores.usb_fifo import FT245PHYAsynchronous return FT245PHYAsynchronous(pads, clk_freq) # RS232 else: - return RS232PHY(pads, clk_freq, baudrate) + return RS232PHY(pads, clk_freq, baudrate, with_dynamic_baudrate=with_dynamic_baudrate) class UART(LiteXModule, UARTInterface): def __init__(self, phy=None, diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 0fbc544f2..e523a33d2 100644 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -1511,7 +1511,7 @@ class LiteXSoC(SoC): self.add_config(name, identifier) # Add UART ------------------------------------------------------------------------------------- - def add_uart(self, name="uart", uart_name="serial", uart_pads=None, baudrate=115200, fifo_depth=16): + def add_uart(self, name="uart", uart_name="serial", uart_pads=None, baudrate=115200, fifo_depth=16, with_dynamic_baudrate=False): # Imports. from litex.soc.cores.uart import UART, UARTCrossover @@ -1550,7 +1550,7 @@ class LiteXSoC(SoC): # Crossover + UARTBone. elif uart_name in ["crossover+uartbone"]: - self.add_uartbone(baudrate=baudrate) + self.add_uartbone(baudrate=baudrate, with_dynamic_baudrate=with_dynamic_baudrate) uart = UARTCrossover(**uart_kwargs) # JTAG UART. @@ -1588,7 +1588,7 @@ class LiteXSoC(SoC): # Regular UART. else: from litex.soc.cores.uart import UARTPHY - uart_phy = UARTPHY(uart_pads, clk_freq=self.sys_clk_freq, baudrate=baudrate) + uart_phy = UARTPHY(uart_pads, clk_freq=self.sys_clk_freq, baudrate=baudrate, with_dynamic_baudrate=with_dynamic_baudrate) uart = UART(uart_phy, **uart_kwargs) # Add PHY/UART. @@ -1604,7 +1604,7 @@ class LiteXSoC(SoC): self.add_constant("UART_POLLING", check_duplicate=False) # Add UARTbone --------------------------------------------------------------------------------- - def add_uartbone(self, name="uartbone", uart_name="serial", clk_freq=None, baudrate=115200, cd="sys"): + def add_uartbone(self, name="uartbone", uart_name="serial", clk_freq=None, baudrate=115200, cd="sys", with_dynamic_baudrate=False): # Imports. from litex.soc.cores import uart @@ -1612,7 +1612,7 @@ class LiteXSoC(SoC): if clk_freq is None: clk_freq = self.sys_clk_freq self.check_if_exists(name) - uartbone_phy = uart.UARTPHY(self.platform.request(uart_name), clk_freq, baudrate) + uartbone_phy = uart.UARTPHY(self.platform.request(uart_name), clk_freq, baudrate, with_dynamic_baudrate=with_dynamic_baudrate) uartbone = uart.UARTBone( phy = uartbone_phy, clk_freq = clk_freq, diff --git a/litex/soc/integration/soc_core.py b/litex/soc/integration/soc_core.py index 0373c5058..33b5c0073 100644 --- a/litex/soc/integration/soc_core.py +++ b/litex/soc/integration/soc_core.py @@ -100,6 +100,7 @@ class SoCCore(LiteXSoC): uart_name = "serial", uart_baudrate = 115200, uart_fifo_depth = 16, + uart_with_dynamic_baudrate = False, # Timer parameters. with_timer = True, @@ -255,11 +256,11 @@ class SoCCore(LiteXSoC): # Add UARTBone. if with_uartbone: - self.add_uartbone(baudrate=uart_baudrate) + self.add_uartbone(baudrate=uart_baudrate, fifo_depth=uart_fifo_depth, with_dynamic_baudrate=with_dynamic_baudrate) # Add UART. if with_uart: - self.add_uart(name="uart", uart_name=uart_name, baudrate=uart_baudrate, fifo_depth=uart_fifo_depth) + self.add_uart(name="uart", uart_name=uart_name, baudrate=uart_baudrate, fifo_depth=uart_fifo_depth, with_dynamic_baudrate=uart_with_dynamic_baudrate) # Add JTAGBone. if with_jtagbone: