Skip to content

Commit

Permalink
os/arch/arm/armv7-a, amebasmart: Add flush log uart before printing f…
Browse files Browse the repository at this point in the history
…ault 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 <[email protected]>
  • Loading branch information
ewoodev committed Feb 10, 2025
1 parent 1d1a304 commit 9e0b6b9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
41 changes: 41 additions & 0 deletions os/arch/arm/src/amebasmart/amebasmart_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions os/arch/arm/src/armv7-a/arm_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down Expand Up @@ -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");

Expand Down
10 changes: 10 additions & 0 deletions os/include/tinyara/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e0b6b9

Please sign in to comment.