Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_wakeup_failed_if_powerdown_flash_in_lightsle…
Browse files Browse the repository at this point in the history
…ep_v5.1' into 'release/v5.1'

Power Management: fixed flash funcs called in sleep wakeup process (backport v5.1)

See merge request espressif/esp-idf!24009
  • Loading branch information
jack0c committed Jun 2, 2023
2 parents ddc16a4 + 03832db commit cb88d20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions components/esp_hw_support/linker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ entries:
mspi_timing_config (noflash)
if ADC_ONESHOT_CTRL_FUNC_IN_IRAM = y:
sar_periph_ctrl (noflash)
else:
sar_periph_ctrl: sar_periph_ctrl_power_enable (noflash)
25 changes: 15 additions & 10 deletions components/esp_hw_support/sleep_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,20 @@ 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) {
#ifndef CONFIG_IDF_TARGET_ESP32
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) {
continue;
}
#endif
uart_ll_force_xoff(i);
suspended_uarts_bmap |= BIT(i);
#if SOC_UART_SUPPORT_FSM_TX_WAIT_SEND
uint32_t uart_fsm = 0;
do {
Expand All @@ -403,17 +408,16 @@ static void IRAM_ATTR suspend_uarts(void)
while (uart_ll_get_fsm_status(i) != 0) {}
#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) {
#ifndef CONFIG_IDF_TARGET_ESP32
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) {
continue;
if (uarts_resume_bmap & 0x1) {
uart_ll_force_xon(i);
}
#endif
uart_ll_force_xon(i);
uarts_resume_bmap >>= 1;
}
}

Expand Down Expand Up @@ -478,6 +482,8 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t mo
// For deep sleep, wait for the contents of UART FIFO to be sent.
bool deep_sleep = (mode == ESP_SLEEP_MODE_DEEP_SLEEP);
bool should_skip_sleep = false;
uint32_t suspended_uarts_bmap = 0;


if (deep_sleep) {
flush_uarts();
Expand All @@ -488,7 +494,7 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t mo
} else
#endif
{
suspend_uarts();
suspended_uarts_bmap = suspend_uarts();
}
}

Expand Down Expand Up @@ -713,8 +719,7 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t mo
}

// re-enable UART output
resume_uarts();

resume_uarts(suspended_uarts_bmap);
return result;
}

Expand Down

0 comments on commit cb88d20

Please sign in to comment.