mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(psram): suspend external cache during CPU freq switch on esp32p4
Suspend the external-memory cache around the boot CPU frequency switch so PSRAM-XIP / write-back cache state cannot be corrupted mid-switch.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "esp_private/esp_sleep_internal.h"
|
#include "esp_private/esp_sleep_internal.h"
|
||||||
#include "esp_private/esp_clk.h"
|
#include "esp_private/esp_clk.h"
|
||||||
#include "esp_private/esp_pmu.h"
|
#include "esp_private/esp_pmu.h"
|
||||||
|
#include "esp_private/esp_cache_private.h"
|
||||||
#include "esp_rom_serial_output.h"
|
#include "esp_rom_serial_output.h"
|
||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
|
|
||||||
@@ -49,6 +50,22 @@ void IRAM_ATTR esp_rtc_init(void)
|
|||||||
#endif //SOC_PMU_SUPPORTED
|
#endif //SOC_PMU_SUPPORTED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform the CPU frequency switch with the external memory (PSRAM) cache
|
||||||
|
* suspended. The frequency switch stalls the HP_ROOT clock and toggles PLL /
|
||||||
|
* clock gating; when the switch code runs from PSRAM-XIP, a cache-coherency
|
||||||
|
* transient during the switch can corrupt the external .bss region. Suspending
|
||||||
|
* the external-memory cache for the duration of the switch keeps the CPU off
|
||||||
|
* the XIP path, isolating the two.
|
||||||
|
* Must be IRAM-resident because it runs while the external cache is suspended.
|
||||||
|
*/
|
||||||
|
static void IRAM_ATTR esp_clk_cpu_freq_set_config_isolated(const rtc_cpu_freq_config_t *config)
|
||||||
|
{
|
||||||
|
esp_cache_suspend_ext_mem_cache();
|
||||||
|
rtc_clk_cpu_freq_set_config(config);
|
||||||
|
esp_cache_resume_ext_mem_cache();
|
||||||
|
}
|
||||||
|
|
||||||
__attribute__((weak)) void esp_clk_init(void)
|
__attribute__((weak)) void esp_clk_init(void)
|
||||||
{
|
{
|
||||||
assert(rtc_clk_xtal_freq_get() == SOC_XTAL_FREQ_40M);
|
assert(rtc_clk_xtal_freq_get() == SOC_XTAL_FREQ_40M);
|
||||||
@@ -110,7 +127,7 @@ __attribute__((weak)) void esp_clk_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
rtc_clk_cpu_freq_set_config(&new_config);
|
esp_clk_cpu_freq_set_config_isolated(&new_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re calculate the ccount to make time calculation correct.
|
// Re calculate the ccount to make time calculation correct.
|
||||||
|
|||||||
Reference in New Issue
Block a user