mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
Merge branch 'bugfix/fix_c6_wakeup_access_flash_v5.1' into 'release/v5.1'
fix(hal): fix esp32c6 clock bug workaround access flash in wakeup process (v5.1) See merge request espressif/esp-idf!29245
This commit is contained in:
commit
f87ee9c4ec
@ -198,6 +198,17 @@ menu "Hardware Settings"
|
||||
|
||||
NOTE: Enabling these callbacks may change sleep duration calculations based on time spent in
|
||||
callback and hence it is highly recommended to keep them as short as possible.
|
||||
|
||||
config ESP_SLEEP_CACHE_SAFE_ASSERTION
|
||||
bool "Check the cache safety of the sleep wakeup code in sleep process"
|
||||
default n
|
||||
select ESP_PANIC_HANDLER_IRAM
|
||||
help
|
||||
Enabling it will check the cache safety of the code before the flash power is ready after
|
||||
light sleep wakeup, and check PM_SLP_IRAM_OPT related code cache safety. This option is
|
||||
only for code quality inspection. Enabling it will increase the time overhead of entering
|
||||
and exiting sleep. It is not recommended to enable it in the release version.
|
||||
|
||||
endmenu
|
||||
|
||||
menu "ESP_SLEEP_WORKAROUND"
|
||||
|
@ -416,6 +416,23 @@ void esp_deep_sleep_deregister_hook(esp_deep_sleep_cb_t old_dslp_cb)
|
||||
portEXIT_CRITICAL(&spinlock_rtc_deep_sleep);
|
||||
}
|
||||
|
||||
static int s_cache_suspend_cnt = 0;
|
||||
|
||||
static void IRAM_ATTR suspend_cache(void) {
|
||||
s_cache_suspend_cnt++;
|
||||
if (s_cache_suspend_cnt == 1) {
|
||||
cache_hal_suspend(CACHE_TYPE_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
static void IRAM_ATTR resume_cache(void) {
|
||||
s_cache_suspend_cnt--;
|
||||
assert(s_cache_suspend_cnt >= 0 && "cache resume doesn't match suspend ops");
|
||||
if (s_cache_suspend_cnt == 0) {
|
||||
cache_hal_resume(CACHE_TYPE_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
// [refactor-todo] provide target logic for body of uart functions below
|
||||
static void IRAM_ATTR flush_uarts(void)
|
||||
{
|
||||
@ -489,7 +506,12 @@ static bool light_sleep_uart_prepare(uint32_t pd_flags, int64_t sleep_duration)
|
||||
#if !SOC_PM_SUPPORT_TOP_PD || !CONFIG_ESP_CONSOLE_UART
|
||||
suspend_uarts();
|
||||
#else
|
||||
if (pd_flags & PMU_SLEEP_PD_TOP) {
|
||||
#ifdef CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION
|
||||
#define FORCE_FLUSH_CONSOLE_UART 1
|
||||
#else
|
||||
#define FORCE_FLUSH_CONSOLE_UART 0
|
||||
#endif
|
||||
if (FORCE_FLUSH_CONSOLE_UART || (pd_flags & PMU_SLEEP_PD_TOP)) {
|
||||
if ((s_config.wakeup_triggers & RTC_TIMER_TRIG_EN) &&
|
||||
// +1 is for cover the last character flush time
|
||||
(sleep_duration < (int64_t)((UART_LL_FIFO_DEF_LEN - uart_ll_get_txfifo_len(CONSOLE_UART_DEV) + 1) * UART_FLUSH_US_PER_CHAR) + SLEEP_UART_FLUSH_DONE_TO_SLEEP_US)) {
|
||||
@ -799,8 +821,8 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
|
||||
#endif
|
||||
#endif // SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY
|
||||
} else {
|
||||
/* Wait cache idle in cache suspend to avoid cache load wrong data after spi io isolation */
|
||||
cache_hal_suspend(CACHE_TYPE_ALL);
|
||||
/* Cache Suspend 1: will wait cache idle in cache suspend to avoid cache load wrong data after spi io isolation */
|
||||
suspend_cache();
|
||||
/* On esp32c6, only the lp_aon pad hold function can only hold the GPIO state in the active mode.
|
||||
In order to avoid the leakage of the SPI cs pin, hold it here */
|
||||
#if (CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND)
|
||||
@ -834,8 +856,8 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/* Resume cache for continue running */
|
||||
cache_hal_resume(CACHE_TYPE_ALL);
|
||||
/* Cache Resume 1: Resume cache for continue running*/
|
||||
resume_cache();
|
||||
}
|
||||
|
||||
#if CONFIG_ESP_SLEEP_SYSTIMER_STALL_WORKAROUND
|
||||
@ -845,6 +867,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION
|
||||
if (pd_flags & RTC_SLEEP_PD_VDDSDIO) {
|
||||
/* Cache Suspend 2: If previous sleep powerdowned the flash, suspend cache here so that the
|
||||
access to flash before flash ready can be explicitly exposed. */
|
||||
suspend_cache();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Restore CPU frequency
|
||||
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
|
||||
if (pmu_sleep_pll_already_enabled()) {
|
||||
@ -1034,6 +1064,13 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
|
||||
esp_rom_delay_us(flash_enable_time_us);
|
||||
}
|
||||
|
||||
#if CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION
|
||||
if (pd_flags & RTC_SLEEP_PD_VDDSDIO) {
|
||||
/* Cache Resume 2: flash is ready now, we can resume the cache and access flash safely after */
|
||||
resume_cache();
|
||||
}
|
||||
#endif
|
||||
|
||||
return reject;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
CONFIG_PM_SLP_IRAM_OPT=y
|
||||
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
|
||||
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
|
@ -19,7 +19,7 @@ typedef enum {
|
||||
MODEM_CLOCK_EXT32K_CODE = 2
|
||||
} modem_clock_32k_clk_src_code_t;
|
||||
|
||||
void modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap)
|
||||
void IRAM_ATTR modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap)
|
||||
{
|
||||
HAL_ASSERT(domain < MODEM_CLOCK_DOMAIN_MAX);
|
||||
switch (domain)
|
||||
|
Loading…
x
Reference in New Issue
Block a user