Merge branch 'bugfix/fix_wakeup_failed_if_powerdown_flash_in_lightsleep_v4.3' into 'release/v4.3'

Power Management: fixed flash funcs called in sleep wakeup process (backport v4.3)

See merge request espressif/esp-idf!24006
This commit is contained in:
Jiang Jiang Jian
2023-06-06 11:50:59 +08:00

View File

@ -350,8 +350,12 @@ static void IRAM_ATTR flush_uarts(void)
} }
} }
static void IRAM_ATTR suspend_uarts(void) /**
* Suspend enabled uarts and return suspended uarts bit map
*/
static uint32_t IRAM_ATTR suspend_uarts(void)
{ {
uint32_t suspended_uarts_bmap = 0;
for (int i = 0; i < SOC_UART_NUM; ++i) { for (int i = 0; i < SOC_UART_NUM; ++i) {
#ifndef CONFIG_IDF_TARGET_ESP32 #ifndef CONFIG_IDF_TARGET_ESP32
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) { if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) {
@ -359,6 +363,7 @@ static void IRAM_ATTR suspend_uarts(void)
} }
#endif #endif
uart_ll_force_xoff(i); uart_ll_force_xoff(i);
suspended_uarts_bmap |= BIT(i);
#if SOC_UART_SUPPORT_FSM_TX_WAIT_SEND #if SOC_UART_SUPPORT_FSM_TX_WAIT_SEND
uint32_t uart_fsm = 0; uint32_t uart_fsm = 0;
do { do {
@ -368,17 +373,16 @@ static void IRAM_ATTR suspend_uarts(void)
while (uart_ll_get_fsm_status(i) != 0) {} while (uart_ll_get_fsm_status(i) != 0) {}
#endif #endif
} }
return suspended_uarts_bmap;
} }
static void IRAM_ATTR resume_uarts(void) static void IRAM_ATTR resume_uarts(uint32_t uarts_resume_bmap)
{ {
for (int i = 0; i < SOC_UART_NUM; ++i) { for (int i = 0; i < SOC_UART_NUM; ++i) {
#ifndef CONFIG_IDF_TARGET_ESP32 if (uarts_resume_bmap & 0x1) {
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) { uart_ll_force_xon(i);
continue;
} }
#endif uarts_resume_bmap >>= 1;
uart_ll_force_xon(i);
} }
} }
@ -533,6 +537,7 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags)
// For light sleep, suspend UART output — it will resume after wakeup. // For light sleep, suspend UART output — it will resume after wakeup.
// For deep sleep, wait for the contents of UART FIFO to be sent. // For deep sleep, wait for the contents of UART FIFO to be sent.
bool deep_sleep = pd_flags & RTC_SLEEP_PD_DIG; bool deep_sleep = pd_flags & RTC_SLEEP_PD_DIG;
uint32_t suspended_uarts_bmap = 0;
#if !CONFIG_FREERTOS_UNICORE && CONFIG_IDF_TARGET_ESP32S3 && CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP #if !CONFIG_FREERTOS_UNICORE && CONFIG_IDF_TARGET_ESP32S3 && CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
/* Currently only safe to use deep sleep wake stub & RTC memory as heap in single core mode. /* Currently only safe to use deep sleep wake stub & RTC memory as heap in single core mode.
@ -546,7 +551,7 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags)
if (deep_sleep) { if (deep_sleep) {
flush_uarts(); flush_uarts();
} else { } else {
suspend_uarts(); suspended_uarts_bmap = suspend_uarts();
} }
#if SOC_RTC_SLOW_CLOCK_SUPPORT_8MD256 #if SOC_RTC_SLOW_CLOCK_SUPPORT_8MD256
@ -694,7 +699,7 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags)
#endif #endif
// re-enable UART output // re-enable UART output
resume_uarts(); resume_uarts(suspended_uarts_bmap);
return result; return result;
} }