Skip to content

Commit 9602933

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'fix/p4_rev3_further_fixes_v5.5' into 'release/v5.5'
fix(esp_hw_support): p4 rev3 further fixes (v5.5) See merge request espressif/esp-idf!42942
2 parents 8b465a2 + 3b2a14f commit 9602933

File tree

25 files changed

+321
-49
lines changed

25 files changed

+321
-49
lines changed

components/bootloader_support/src/bootloader_common_loader.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,11 @@ rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void)
263263
#ifdef BOOTLOADER_BUILD
264264

265265
#if ESP_ROM_HAS_LP_ROM
266+
#if CONFIG_IDF_TARGET_ESP32P4
267+
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_LOW + CONFIG_P4_REV3_MSPI_WORKAROUND_SIZE)
268+
#else
266269
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_LOW)
270+
#endif
267271
#else
268272
/* Since the structure containing the retain_mem_t is aligned on 8 by the linker, make sure we align this
269273
* structure size here too */

components/esp_hw_support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if(NOT non_os_build)
5656
list(APPEND srcs "sleep_modem.c"
5757
"sleep_modes.c"
5858
"sleep_console.c"
59+
"sleep_mspi.c"
5960
"sleep_usb.c"
6061
"sleep_gpio.c"
6162
"sleep_event.c"

components/esp_hw_support/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,5 @@ menu "Hardware Settings"
309309
bool "Place esp_intr_alloc functions in IRAM" if SPI_FLASH_AUTO_SUSPEND
310310
default y
311311

312+
orsource "./lowpower/port/esp32p4/Kconfig.p4_rev3_mspi_workaround"
312313
endmenu

components/esp_hw_support/include/esp_private/esp_pmu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,6 @@ void pmu_init(void);
346346
*/
347347
uint32_t pmu_sleep_get_wakup_retention_cost(void);
348348

349-
/**
350-
* Workaround for esp32p4 v3 MPSI access failure after power up.
351-
*/
352-
void pmu_sleep_p4_rev3_workaround(void);
353-
354349
#endif //#if SOC_PMU_SUPPORTED
355350

356351
#ifdef __cplusplus
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
#include <stdint.h>
9+
#include "sdkconfig.h"
10+
#include "soc/soc_caps.h"
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
#if CONFIG_IDF_TARGET_ESP32P4 && (CONFIG_ESP_REV_MIN_FULL == 300)
17+
/**
18+
* Workaround for esp32p4 v3 MPSI access failure after power up.
19+
*/
20+
void sleep_flash_p4_rev3_workaround(void);
21+
#endif
22+
23+
#ifdef __cplusplus
24+
}
25+
#endif

components/esp_hw_support/linker.lf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ entries:
3535
rtc_sleep:rtc_sleep_pu (noflash)
3636
if SOC_PMU_SUPPORTED = y && SOC_LIGHT_SLEEP_SUPPORTED = y:
3737
pmu_sleep (noflash)
38+
sleep_mspi (noflash)
3839
if SPIRAM_FLASH_LOAD_TO_PSRAM = y:
3940
pmu_init (noflash)
4041
pmu_param (noflash)

components/esp_hw_support/lowpower/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ if(CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP OR
1818
endif()
1919
endif()
2020

21+
if(CONFIG_P4_REV3_MSPI_CRASH_AFTER_POWER_UP_WORKAROUND)
22+
list(APPEND srcs "port/esp32p4/p4_rev3_mspi_workaround.S")
23+
set_property(TARGET ${COMPONENT_LIB}
24+
APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u p4_rev3_mspi_workaround")
25+
endif()
26+
2127
if(CONFIG_SOC_PM_MMU_TABLE_RETENTION_WHEN_TOP_PD AND CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP)
2228
list(APPEND srcs "port/${target}/sleep_mmu.c")
2329
endif()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
config P4_REV3_MSPI_CRASH_AFTER_POWER_UP_WORKAROUND
2+
bool
3+
depends on IDF_TARGET_ESP32P4
4+
default y if ESP32P4_REV_MIN_300
5+
6+
config P4_REV3_MSPI_WORKAROUND_SIZE
7+
hex
8+
depends on IDF_TARGET_ESP32P4
9+
default 0x100 if ESP32P4_REV_MIN_300
10+
default 0
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "soc/reg_base.h"
8+
9+
#define HP_SYSTEM_CORE_ERR_RESP_DIS_REG (DR_REG_HP_SYS_BASE + 0x1a4)
10+
11+
/* Clock related */
12+
#define DR_REG_LP_CLKRST_BASE (DR_REG_LPAON_BASE + 0x1000)
13+
#define LP_CLKRST_HPCPU_RESET_CTRL0_REG (DR_REG_LP_CLKRST_BASE + 0x14)
14+
#define LP_CLKRST_HPCORE0_STAT_VECTOR_SEL (1 << 15)
15+
16+
#define HP_SYS_CLKRST_HP_RST_EN0_REG (DR_REG_HP_SYS_CLKRST_BASE + 0xc0)
17+
#define HP_SYS_CLKRST_REG_RST_EN_MSPI_AXI (1 << 22)
18+
#define HP_SYS_CLKRST_REG_RST_EN_MSPI_APB (1 << 24)
19+
20+
21+
/* SPIMEM related */
22+
#define DR_REG_FLASH_SPI0_BASE (DR_REG_HPPERIPH0_BASE + 0x8C000)
23+
#define SPI_MEM_C_CACHE_FCTRL_REG (DR_REG_FLASH_SPI0_BASE + 0x3c)
24+
#define SPI_MEM_C_CLOSE_AXI_INF_EN (1 << 31)
25+
#define SPI_MEM_C_AXI_REQ_EN (1 << 0)
26+
27+
#define SPI_MEM_C_MMU_ITEM_INDEX_REG (DR_REG_FLASH_SPI0_BASE + 0x380)
28+
#define SPI_MEM_C_MMU_ITEM_CONTENT_REG (DR_REG_FLASH_SPI0_BASE + 0x37c)
29+
30+
.macro REG_SET_BIT addr, value
31+
li a0, \addr
32+
li a1, \value
33+
lw a2, (a0)
34+
or a2, a2, a1
35+
sw a2, (a0)
36+
.endm
37+
38+
.macro REG_CLR_BIT addr, value
39+
li a0, \addr
40+
/* Since all our parameters will be constants, we can pre-calculate it at assemble time */
41+
li a1, ~\value
42+
lw a2, (a0)
43+
and a2, a2, a1
44+
sw a2, (a0)
45+
.endm
46+
47+
.macro REG_WRITE addr, value
48+
li a0, \addr
49+
li a1, \value
50+
sw a1, (a0)
51+
.endm
52+
53+
.macro REG_READ addr
54+
li a0, \addr
55+
lw a1, (a0)
56+
.endm
57+
58+
.macro DELAY_US us
59+
li t3, (40 * \us) /* CPU @40MHz after reset */
60+
csrr t0, cycle
61+
add t1, t0, t3
62+
1: csrr t2, cycle
63+
blt t2, t1, 1b
64+
.endm
65+
66+
/**
67+
* @brief Workaround for MSPI issues on ESP32-P4 revision 3
68+
*
69+
* This function implements a workaround for MSPI-related issues on ESP32-P4 revision 3.
70+
* It performs 2 flash dummy reads to stabilize the MSPI functionality before jumping to
71+
* ROM code after deepsleep wakeup.
72+
*/
73+
.global p4_rev3_mspi_workaround
74+
.section .p4_rev3_mspi_workaround.rtc_text,"ax"
75+
76+
p4_rev3_mspi_workaround:
77+
# Recover the reset vector to HP ROM
78+
REG_SET_BIT LP_CLKRST_HPCPU_RESET_CTRL0_REG, LP_CLKRST_HPCORE0_STAT_VECTOR_SEL
79+
80+
# Clear the bit to close AXI interface and then set the AXI request enable bit
81+
REG_CLR_BIT SPI_MEM_C_CACHE_FCTRL_REG, SPI_MEM_C_CLOSE_AXI_INF_EN
82+
REG_SET_BIT SPI_MEM_C_CACHE_FCTRL_REG, SPI_MEM_C_AXI_REQ_EN
83+
84+
# Set 1 mspi mmu entry for axi addr to flash addr
85+
REG_WRITE SPI_MEM_C_MMU_ITEM_INDEX_REG, 0
86+
REG_WRITE SPI_MEM_C_MMU_ITEM_CONTENT_REG, 0x1000
87+
88+
# Disable cpu get error response
89+
REG_WRITE HP_SYSTEM_CORE_ERR_RESP_DIS_REG, 0x7
90+
91+
# Perform dummy reads
92+
REG_READ 0x80000000
93+
# Perform dummy reads again
94+
REG_READ 0x80000080
95+
96+
# Delay 1us to wait MSPI read transmission done
97+
DELAY_US 1
98+
99+
# Enable cpu get error response
100+
REG_WRITE HP_SYSTEM_CORE_ERR_RESP_DIS_REG, 0
101+
102+
# Reset MSPI AXI and APB interfaces
103+
REG_SET_BIT HP_SYS_CLKRST_HP_RST_EN0_REG, HP_SYS_CLKRST_REG_RST_EN_MSPI_AXI
104+
REG_SET_BIT HP_SYS_CLKRST_HP_RST_EN0_REG, HP_SYS_CLKRST_REG_RST_EN_MSPI_APB
105+
REG_CLR_BIT HP_SYS_CLKRST_HP_RST_EN0_REG, HP_SYS_CLKRST_REG_RST_EN_MSPI_AXI
106+
REG_CLR_BIT HP_SYS_CLKRST_HP_RST_EN0_REG, HP_SYS_CLKRST_REG_RST_EN_MSPI_APB
107+
108+
# Jump to HP ROM first stage boot code
109+
li a5, 0x4fc00000
110+
jr a5

components/esp_hw_support/lowpower/port/esp32p4/sleep_cpu.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ static TCM_IRAM_ATTR esp_err_t do_cpu_retention(sleep_cpu_entry_cb_t goto_sleep,
402402
}
403403
#endif
404404

405-
return (*goto_sleep)(wakeup_opt, reject_opt, lslp_mem_inf_fpu, dslp);
405+
uint32_t reject = (*goto_sleep)(wakeup_opt, reject_opt, lslp_mem_inf_fpu, dslp);
406+
if (reject) {
407+
restore_mstatus(mstatus);
408+
return reject;
409+
}
406410
}
407411
#if CONFIG_PM_CHECK_SLEEP_RETENTION_FRAME
408412
else {

0 commit comments

Comments
 (0)