From 9e0b6b94ad3f06a9097988426aa6c416be4f156f Mon Sep 17 00:00:00 2001 From: "eunwoo.nam" Date: Thu, 6 Feb 2025 17:53:08 +0900 Subject: [PATCH] os/arch/arm/armv7-a, amebasmart: Add flush log uart before printing fault log. since, The system fault is occured, uart log is stil in the uart buffer and not printed. So, we can't see last log. Therefore, Add flusing log uart buffer when fault is occured. Signed-off-by: eunwoo.nam --- .../arm/src/amebasmart/amebasmart_serial.c | 41 +++++++++++++++++++ os/arch/arm/src/armv7-a/arm_assert.c | 17 ++++++++ os/include/tinyara/arch.h | 10 +++++ 3 files changed, 68 insertions(+) diff --git a/os/arch/arm/src/amebasmart/amebasmart_serial.c b/os/arch/arm/src/amebasmart/amebasmart_serial.c index 2d9d16329d..9e4106d2c2 100644 --- a/os/arch/arm/src/amebasmart/amebasmart_serial.c +++ b/os/arch/arm/src/amebasmart/amebasmart_serial.c @@ -512,6 +512,9 @@ static uart_dev_t g_uart4port = { }; #endif +#ifdef CONFIG_UART4_SERIAL_CONSOLE +static bool g_log_flush_running; +#endif /**************************************************************************** * Private Functions ****************************************************************************/ @@ -1377,6 +1380,44 @@ int up_getc(void) return ch; } +/**************************************************************************** + * Name: up_flush_console + * + * Description: + * This function is used to ensure that all characters in the UART buffer + * are transmitted. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ +void up_flush_console(void) +{ +#ifdef CONFIG_UART4_SERIAL_CONSOLE + uint16_t nbyte; + irqstate_t flags = enter_critical_section(); + + /* To avoid duplicated calling up_flush_console(). */ + if (g_log_flush_running) { + leave_critical_section(flags); + return; + } + g_log_flush_running = true; + + do { + while (!LOGUART_Ready()); + nbyte = uart_xmitchars(&CONSOLE_DEV); + } while (nbyte); + + g_log_flush_running = false; + + leave_critical_section(flags); +#endif +} + #else /* USE_SERIALDRIVER */ /**************************************************************************** * Name: up_putc diff --git a/os/arch/arm/src/armv7-a/arm_assert.c b/os/arch/arm/src/armv7-a/arm_assert.c index f41582599c..0247bdcb56 100644 --- a/os/arch/arm/src/armv7-a/arm_assert.c +++ b/os/arch/arm/src/armv7-a/arm_assert.c @@ -549,6 +549,21 @@ static inline void print_assert_detail(const uint8_t *filename, int lineno, stru } +/**************************************************************************** + * Name: flush_console + ****************************************************************************/ + +static inline void flush_console(void) +{ + if (!IS_SECURE_STATE()) { + lldbg_noarg("\n===========================================================\n"); + lldbg_noarg("Flush console log\n"); + lldbg_noarg("===========================================================\n\n"); + up_flush_console(); + lldbg_noarg("\n"); + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -612,6 +627,8 @@ void up_assert(const uint8_t *filename, int lineno) /* Heap corruption check */ check_heap_corrupt(fault_tcb); + flush_console(); + /* Closing log line */ lldbg_noarg("##########################################################################################################################################\n"); diff --git a/os/include/tinyara/arch.h b/os/include/tinyara/arch.h index ded6e5d630..1cf2cf001f 100644 --- a/os/include/tinyara/arch.h +++ b/os/include/tinyara/arch.h @@ -2530,6 +2530,16 @@ int up_getc(void); void up_puts(FAR const char *str); +/**************************************************************************** + * Name: up_flush_console + * + * Description: + * This function is used to ensure that all characters in the UART buffer + * are transmitted. + * + ****************************************************************************/ +void up_flush_console(void); + #ifdef CONFIG_WATCHDOG_FOR_IRQ /**************************************************************************** * Name: up_wdog_init