Skip to content

Commit cd225d0

Browse files
committed
Merge branch 'fix/fix_flash_clock_changed_after_sleep' into 'master'
fix(esp_hw_support): fix mspi clock freq changed after lightsleep Closes PM-231 and PM-299 See merge request espressif/esp-idf!34982
2 parents 2c31596 + 7d0d95b commit cd225d0

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

components/esp_hw_support/sleep_modes.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@
5858

5959
#include "hal/cache_hal.h"
6060
#include "hal/cache_ll.h"
61+
#include "hal/clk_tree_ll.h"
6162
#include "hal/wdt_hal.h"
6263
#include "hal/uart_hal.h"
6364
#if SOC_TOUCH_SENSOR_SUPPORTED
6465
#include "hal/touch_sensor_hal.h"
6566
#include "hal/touch_sens_hal.h"
6667
#endif
68+
#include "hal/mspi_timing_tuning_ll.h"
6769

6870
#include "sdkconfig.h"
6971
#include "esp_rom_uart.h"
@@ -75,7 +77,9 @@
7577
#include "esp_private/esp_clk.h"
7678
#include "esp_private/esp_task_wdt.h"
7779
#include "esp_private/sar_periph_ctrl.h"
80+
#if MSPI_TIMING_LL_FLASH_CPU_CLK_SRC_BINDED
7881
#include "esp_private/mspi_timing_tuning.h"
82+
#endif
7983

8084
#ifdef CONFIG_IDF_TARGET_ESP32
8185
#include "esp32/rom/cache.h"
@@ -159,7 +163,7 @@
159163
#define DEFAULT_SLEEP_OUT_OVERHEAD_US (318)
160164
#define DEFAULT_HARDWARE_OUT_OVERHEAD_US (56)
161165
#elif CONFIG_IDF_TARGET_ESP32C61
162-
#define DEFAULT_SLEEP_OUT_OVERHEAD_US (1148) //TODO: PM-231
166+
#define DEFAULT_SLEEP_OUT_OVERHEAD_US (318)
163167
#define DEFAULT_HARDWARE_OUT_OVERHEAD_US (107)
164168
#elif CONFIG_IDF_TARGET_ESP32H2
165169
#define DEFAULT_SLEEP_OUT_OVERHEAD_US (118)
@@ -795,8 +799,10 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
795799
}
796800
#endif
797801

802+
#if MSPI_TIMING_LL_FLASH_CPU_CLK_SRC_BINDED
798803
// Will switch to XTAL turn down MSPI speed
799804
mspi_timing_change_speed_mode_cache_safe(true);
805+
#endif
800806

801807
#if SOC_PM_RETENTION_SW_TRIGGER_REGDMA
802808
if (!deep_sleep && (pd_flags & PMU_SLEEP_PD_TOP)) {
@@ -1132,8 +1138,8 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
11321138
misc_modules_wake_prepare(pd_flags);
11331139
}
11341140

1135-
#if SOC_SPI_MEM_SUPPORT_TIMING_TUNING
1136-
if (cpu_freq_config.source == SOC_CPU_CLK_SRC_PLL) {
1141+
#if MSPI_TIMING_LL_FLASH_CPU_CLK_SRC_BINDED
1142+
if (cpu_freq_config.source_freq_mhz > clk_ll_xtal_load_freq_mhz()) {
11371143
// Turn up MSPI speed if switch to PLL
11381144
mspi_timing_change_speed_mode_cache_safe(false);
11391145
}

components/esp_pm/pm_impl.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
#include "esp_private/periph_ctrl.h"
2525

2626
#include "soc/rtc.h"
27+
#include "hal/clk_tree_ll.h"
2728
#include "hal/uart_ll.h"
2829
#include "hal/uart_types.h"
30+
#include "hal/mspi_timing_tuning_ll.h"
31+
2932
#include "driver/gpio.h"
3033

3134
#include "freertos/FreeRTOS.h"
@@ -35,10 +38,6 @@
3538
#include "xtensa/core-macros.h"
3639
#endif
3740

38-
#if SOC_SPI_MEM_SUPPORT_TIMING_TUNING
39-
#include "esp_private/mspi_timing_tuning.h"
40-
#endif
41-
4241
#include "esp_private/pm_impl.h"
4342
#include "esp_private/pm_trace.h"
4443
#include "esp_private/esp_timer_private.h"
@@ -48,6 +47,9 @@
4847
#include "esp_private/sleep_gpio.h"
4948
#include "esp_private/sleep_modem.h"
5049
#include "esp_private/uart_share_hw_ctrl.h"
50+
#if MSPI_TIMING_LL_FLASH_CPU_CLK_SRC_BINDED
51+
#include "esp_private/mspi_timing_tuning.h"
52+
#endif
5153
#include "esp_sleep.h"
5254
#include "esp_memory_utils.h"
5355

@@ -665,16 +667,16 @@ static void IRAM_ATTR do_switch(pm_mode_t new_mode)
665667
if (switch_down) {
666668
on_freq_update(old_ticks_per_us, new_ticks_per_us);
667669
}
668-
#if SOC_SPI_MEM_SUPPORT_TIMING_TUNING
669-
if (new_config.source == SOC_CPU_CLK_SRC_PLL) {
670-
rtc_clk_cpu_freq_set_config_fast(&new_config);
671-
mspi_timing_change_speed_mode_cache_safe(false);
672-
} else {
673-
mspi_timing_change_speed_mode_cache_safe(true);
674-
rtc_clk_cpu_freq_set_config_fast(&new_config);
675-
}
670+
#if MSPI_TIMING_LL_FLASH_CPU_CLK_SRC_BINDED
671+
if (new_config.source_freq_mhz > clk_ll_xtal_load_freq_mhz()) {
672+
rtc_clk_cpu_freq_set_config_fast(&new_config);
673+
mspi_timing_change_speed_mode_cache_safe(false);
674+
} else {
675+
mspi_timing_change_speed_mode_cache_safe(true);
676+
rtc_clk_cpu_freq_set_config_fast(&new_config);
677+
}
676678
#else
677-
rtc_clk_cpu_freq_set_config_fast(&new_config);
679+
rtc_clk_cpu_freq_set_config_fast(&new_config);
678680
#endif
679681
if (!switch_down) {
680682
on_freq_update(old_ticks_per_us, new_ticks_per_us);

components/hal/esp32s3/include/hal/mspi_timing_tuning_ll.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extern "C" {
3737

3838
#define MSPI_TIMING_LL_CORE_CLOCK_MHZ_DEFAULT 80
3939

40+
#define MSPI_TIMING_LL_FLASH_CPU_CLK_SRC_BINDED 1
41+
4042
typedef enum {
4143
MSPI_TIMING_LL_FLASH_OPI_MODE = BIT(0),
4244
MSPI_TIMING_LL_FLASH_QIO_MODE = BIT(1),

0 commit comments

Comments
 (0)