ESP32-S3 flush UART in wake stub example
Posted: Wed Nov 22, 2023 11:52 pm
The following shows code that can be used inside of a wake stub to achieve a flush of the UART before continuing.
This example is for UART 0 but could be changed for other UARTS.
Code that works for earlier ESP processors, but which does not work on the ESP32-S3 due to changes in the register structures, is also shown.
I hope this might save someone some time and effort.
This example is for UART 0 but could be changed for other UARTS.
Code that works for earlier ESP processors, but which does not work on the ESP32-S3 due to changes in the register structures, is also shown.
I hope this might save someone some time and effort.
Code: Select all
#include "soc/uart_reg.h" // needed for UART_STATUS_REG
#include "soc/timer_group_reg.h" // needed for TIMG_WDTFEED_REG
#define uS_PER_CHARACTER 95 // 95uS per char at 115200 baud //
// Wait for UART to end transmitting.
// the following line works with ESP32 but not ESP32-S3
// while (REG_GET_FIELD(UART_STATUS_REG(0), UART_ST_UTX_OUT))
// the following line works for ESP32-S3
while (REG_GET_FIELD(UART_FSM_STATUS_REG(0), UART_ST_UTX_OUT))
{
// feed the watchdog
REG_WRITE(TIMG_WDTFEED_REG(0), 1);
ets_delay_us(uS_PER_CHARACTER); // 95 uS per character at 115200 baud
}