From a377b21825cd79e3a75824214d46d743a69ac6ce Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Mon, 10 Jun 2024 14:20:28 +0300 Subject: [PATCH 1/2] SN32: serial: only calculate FD if required High precision is not always required. Since the chip doesn't have an FPU, calculating the FD precisely is expensive on resources. Make FD usage optional --- os/hal/ports/SN32/LLD/SN32F2xx/UART/hal_serial_lld.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/UART/hal_serial_lld.c b/os/hal/ports/SN32/LLD/SN32F2xx/UART/hal_serial_lld.c index 3c3748ed2a..16a22a933c 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/UART/hal_serial_lld.c +++ b/os/hal/ports/SN32/LLD/SN32F2xx/UART/hal_serial_lld.c @@ -68,6 +68,7 @@ static const SerialConfig default_config = {SERIAL_DEFAULT_BITRATE, /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ +#if SN32_UART_USE_FD || defined(__DOXYGEN__) void UART_divisor_CAL(uint32_t baudrate,uint32_t UART_PCLK,uint8_t Oversampling,uint8_t *dlm,uint8_t *dll,uint8_t *d_divaddval,uint8_t *d_mulval) { float expected_val; @@ -156,6 +157,8 @@ void UART_divisor_CAL(uint32_t baudrate,uint32_t UART_PCLK,uint8_t Oversampling, *d_divaddval = divaddval[0]; } } +#endif + /** * @brief UART initialization. * @details This function must be invoked with interrupts disabled. @@ -173,7 +176,15 @@ static void uart_init(SerialDriver *sdp, const SerialConfig *config) { apbclock = (SN32_HCLK); // Calculate divider +#if SN32_UART_USE_FD || defined(__DOXYGEN__) UART_divisor_CAL(config->speed,apbclock,oversampling,&dlm,&dll,&divaddval,&mulval); +#else + uint32_t divisor = (uint32_t)(apbclock/oversampling/config->speed); + dlm = (divisor>>8)&0xff; + dll = divisor&0xff; + divaddval = 0; + mulval = 1; +#endif // SN32_UART_USE_FD // Update the registers u->LC = UART_Divisor_Latch_Access_Enable; From 1496db37a73102cb35130ff1bd87c0b1d9db1170 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Mon, 10 Jun 2024 16:19:30 +0300 Subject: [PATCH 2/2] sn32: sn32f260: don't build UART The peripheral is not present at all on this chip --- os/hal/ports/SN32/SN32F260/platform.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/os/hal/ports/SN32/SN32F260/platform.mk b/os/hal/ports/SN32/SN32F260/platform.mk index 1c0e8cc196..1b8774133b 100644 --- a/os/hal/ports/SN32/SN32F260/platform.mk +++ b/os/hal/ports/SN32/SN32F260/platform.mk @@ -27,7 +27,6 @@ include ${CHIBIOS_CONTRIB}/os/hal/ports/SN32/LLD/SN32F2xx/SysTick/driver.mk include ${CHIBIOS_CONTRIB}/os/hal/ports/SN32/LLD/SN32F2xx/SPI/driver.mk include ${CHIBIOS_CONTRIB}/os/hal/ports/SN32/LLD/SN32F2xx/I2C/driver.mk include ${CHIBIOS_CONTRIB}/os/hal/ports/SN32/LLD/SN32F2xx/WDT/driver.mk -include ${CHIBIOS_CONTRIB}/os/hal/ports/SN32/LLD/SN32F2xx/UART/driver.mk # Shared variables ALLCSRC += $(PLATFORMSRC_CONTRIB)