Skip to content

Commit 64c0620

Browse files
committed
fix(esp_hw_support): invalidate L1DCache before enter hardware sleep
1 parent 157c5b5 commit 64c0620

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

components/esp_hw_support/lowpower/cpu_retention/port/esp32p4/sleep_cpu_asm.S

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,6 @@ rv_core_critical_regs_save:
117117
mv t3, t0
118118
csrr t0, mscratch
119119
sw t0, RV_SLP_CTX_T0(t3)
120-
121-
/* writeback dcache is required here!!! */
122-
la t0, CACHE_SYNC_MAP_REG
123-
li t1, 0x10 /* map l1 dcache */
124-
sw t1, 0x0(t0) /* set EXTMEM_CACHE_SYNC_MAP_REG bit 4 */
125-
la t2, CACHE_SYNC_ADDR_REG
126-
sw zero, 0x0(t2) /* clear EXTMEM_CACHE_SYNC_ADDR_REG */
127-
la t0, CACHE_SYNC_SIZE_REG
128-
sw zero, 0x0(t0) /* clear EXTMEM_CACHE_SYNC_SIZE_REG */
129-
130-
la t1, CACHE_SYNC_CTRL_REG
131-
lw t2, 0x0(t1)
132-
ori t2, t2, 0x4
133-
sw t2, 0x0(t1)
134-
135-
li t0, 0x10 /* SYNC_DONE bit */
136-
wait_sync_done:
137-
lw t2, 0x0(t1)
138-
and t2, t0, t2
139-
beqz t2, wait_sync_done
140-
141-
lw t0, RV_SLP_CTX_T0(t3)
142120
lw t1, RV_SLP_CTX_T1(t3)
143121
lw t2, RV_SLP_CTX_T2(t3)
144122
lw t3, RV_SLP_CTX_T3(t3)

components/esp_hw_support/port/esp32p4/pmu_sleep.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#include "esp_err.h"
1313
#include "esp_attr.h"
1414
#include "esp_private/regi2c_ctrl.h"
15+
#include "esp32p4/rom/cache.h"
1516
#include "soc/chip_revision.h"
1617
#include "soc/soc.h"
1718
#include "soc/regi2c_syspll.h"
1819
#include "soc/regi2c_cpll.h"
1920
#include "soc/rtc.h"
21+
#include "soc/cache_reg.h"
2022
#include "soc/pau_reg.h"
2123
#include "soc/pmu_reg.h"
2224
#include "soc/pmu_struct.h"
@@ -285,6 +287,11 @@ void pmu_sleep_shutdown_ldo(void) {
285287
CLEAR_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_HP_ACTIVE_HP_REGULATOR_XPD);
286288
}
287289

290+
FORCE_INLINE_ATTR void sleep_writeback_l1_dcache(void) {
291+
Cache_WriteBack_All(CACHE_MAP_L1_DCACHE);
292+
while (!REG_GET_BIT(CACHE_SYNC_CTRL_REG, CACHE_SYNC_DONE));
293+
}
294+
288295
TCM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp)
289296
{
290297
lp_aon_hal_inform_wakeup_type(dslp);
@@ -297,6 +304,8 @@ TCM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt,
297304
pmu_ll_hp_clear_reject_intr_status(PMU_instance()->hal->dev);
298305
pmu_ll_hp_clear_reject_cause(PMU_instance()->hal->dev);
299306

307+
sleep_writeback_l1_dcache();
308+
300309
/* Start entry into sleep mode */
301310
pmu_ll_hp_set_sleep_enable(PMU_instance()->hal->dev);
302311

0 commit comments

Comments
 (0)