From 9b3a80cc372a4942f19e6f328f141c3712eddb1c Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Wed, 19 May 2021 17:03:36 +0900 Subject: [PATCH] arch: cxd56xx: Fix uart getting stuck during a clock change UART driver is stopped and re-started during a clock change. When a UART interrupt is generated in each process, the unexpected behavior will occur and a console will get stuck with UART driver. This commit fixed each process is performed atomically. --- arch/arm/src/cxd56xx/cxd56_uart.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/src/cxd56xx/cxd56_uart.c b/arch/arm/src/cxd56xx/cxd56_uart.c index b8b2f3caeb..3ddfac640e 100644 --- a/arch/arm/src/cxd56xx/cxd56_uart.c +++ b/arch/arm/src/cxd56xx/cxd56_uart.c @@ -206,11 +206,15 @@ static void cxd56_uart_pincontrol(int ch, bool on) static void cxd56_uart_start(int ch) { + irqstate_t flags = enter_critical_section(); + cxd56_setbaud(CONSOLE_BASE, CONSOLE_BASEFREQ, CONSOLE_BAUD); putreg32(g_lcr, g_uartdevs[ch].uartbase + CXD56_UART_LCR_H); putreg32(g_cr, g_uartdevs[ch].uartbase + CXD56_UART_CR); + + leave_critical_section(flags); } /**************************************************************************** @@ -226,6 +230,8 @@ static void cxd56_uart_stop(int ch) { uint32_t cr; + irqstate_t flags = enter_critical_section(); + while (UART_FR_BUSY & getreg32(g_uartdevs[ch].uartbase + CXD56_UART_FR)); cr = getreg32(g_uartdevs[ch].uartbase + CXD56_UART_CR); @@ -235,6 +241,8 @@ static void cxd56_uart_stop(int ch) g_lcr = getreg32(g_uartdevs[ch].uartbase + CXD56_UART_LCR_H); putreg32(0, g_uartdevs[ch].uartbase + CXD56_UART_LCR_H); + + leave_critical_section(flags); } /****************************************************************************