Skip to content

Commit 18714a2

Browse files
committed
Merge branch 'refactor/update_lpperi_regs_for_h2_eco5_v5.3' into 'release/v5.3'
refactor(lpperi): compatible refactor for H2 ECO5 (v5.3) See merge request espressif/esp-idf!36336
2 parents 16023f1 + 90457a9 commit 18714a2

File tree

11 files changed

+816
-329
lines changed

11 files changed

+816
-329
lines changed

components/bootloader_support/src/esp32h2/bootloader_esp32h2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "hal/lpwdt_ll.h"
4343
#include "soc/lp_wdt_reg.h"
4444
#include "soc/pmu_reg.h"
45+
#include "soc/lpperi_struct.h"
4546
#include "hal/efuse_hal.h"
4647
#include "modem/modem_lpcon_reg.h"
4748

@@ -107,6 +108,9 @@ esp_err_t bootloader_init(void)
107108
{
108109
esp_err_t ret = ESP_OK;
109110

111+
// Assign the compatible LPPERI register address in case it is used in the bootloader
112+
lpperi_compatible_reg_addr_init();
113+
110114
bootloader_hardware_init();
111115
bootloader_ana_reset_config();
112116
bootloader_super_wdt_auto_feed();

components/esp_system/port/cpu_start.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -61,6 +61,7 @@
6161
#include "esp32h2/rtc.h"
6262
#include "esp32h2/rom/cache.h"
6363
#include "esp_memprot.h"
64+
#include "soc/lpperi_struct.h"
6465
#elif CONFIG_IDF_TARGET_ESP32C2
6566
#include "esp32c2/rtc.h"
6667
#include "esp32c2/rom/cache.h"
@@ -459,6 +460,13 @@ void IRAM_ATTR call_start_cpu0(void)
459460
}
460461
#endif
461462

463+
#if CONFIG_IDF_TARGET_ESP32H2
464+
// Some modules' register layout are not binary compatible among the different chip revisions,
465+
// they will be wrapped into a new compatible instance which will point to the correct register address according to the revision.
466+
// To ensure the compatible instance is initialized before used, the initialization is done after BBS is cleared
467+
lpperi_compatible_reg_addr_init();
468+
#endif
469+
462470
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP && !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE && !SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
463471
// It helps to fix missed cache settings for other cores. It happens when bootloader is unicore.
464472
do_multicore_settings();

components/hal/esp32h2/include/hal/lp_clkrst_ll.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -63,7 +63,7 @@ static inline void lp_clkrst_ll_select_modem_32k_clock_source(lp_clkrst_dev_t *h
6363
__attribute__((always_inline))
6464
static inline void _lp_clkrst_ll_enable_rng_clock(bool en)
6565
{
66-
LPPERI.clk_en.rng_ck_en = en;
66+
LPPERI.clk_en->rng_ck_en = en;
6767
}
6868

6969
/// LPPERI.clk_en is a shared register, so this function must be used in an atomic way

components/hal/esp32h2/include/hal/rtc_io_ll.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -38,8 +38,8 @@ typedef enum {
3838
*/
3939
static inline void _rtcio_ll_enable_io_clock(bool enable)
4040
{
41-
LPPERI.clk_en.lp_io_ck_en = enable;
42-
while (LPPERI.clk_en.lp_io_ck_en != enable) {
41+
LPPERI.clk_en->lp_io_ck_en = enable;
42+
while (LPPERI.clk_en->lp_io_ck_en != enable) {
4343
;
4444
}
4545
}

components/soc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if(target STREQUAL "esp32")
2727
list(APPEND srcs "${target_folder}/dport_access.c")
2828
endif()
2929

30+
if(target STREQUAL "esp32h2")
31+
list(APPEND srcs "${target_folder}/lpperi_struct.c")
32+
endif()
33+
3034
if(CONFIG_SOC_ADC_SUPPORTED)
3135
list(APPEND srcs "${target_folder}/adc_periph.c")
3236
endif()

components/soc/esp32h2/include/soc/lpperi_reg.h

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/**
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
1+
/*
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
4-
* SPDX-License-Identifier: Apache-2.0
4+
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#pragma once
77

@@ -11,6 +11,34 @@
1111
extern "C" {
1212
#endif
1313

14+
/** LPPERI_DATE_REG register
15+
* need_des
16+
*/
17+
#define LPPERI_DATE_REG (DR_REG_LPPERI_BASE + 0x3fc)
18+
/** LPPERI_LPPERI_DATE : R/W; bitpos: [30:0]; default: 36732976 (0x2308030);
19+
* need_des
20+
*/
21+
#define LPPERI_LPPERI_DATE 0x7FFFFFFFU
22+
#define LPPERI_LPPERI_DATE_M (LPPERI_LPPERI_DATE_V << LPPERI_LPPERI_DATE_S)
23+
#define LPPERI_LPPERI_DATE_V 0x7FFFFFFFU
24+
#define LPPERI_LPPERI_DATE_S 0
25+
/** LPPERI_CLK_EN : R/W; bitpos: [31]; default: 0;
26+
* need_des
27+
*/
28+
#define LPPERI_CLK_EN (BIT(31))
29+
#define LPPERI_CLK_EN_M (LPPERI_CLK_EN_V << LPPERI_CLK_EN_S)
30+
#define LPPERI_CLK_EN_V 0x00000001U
31+
#define LPPERI_CLK_EN_S 31
32+
33+
/**
34+
* @brief Get the register offset according to the register version
35+
* @note H2 ECO5 inserted a new register LPPERI_RNG_CFG_REG,
36+
* so the addressed of the rest registers are shifted 4 bytes
37+
* This macro can help to get the correct register offset according to the register version
38+
*/
39+
#define LPPERI_REG_OFFSET(offset) (REG_GET_FIELD(LPPERI_DATE_REG, LPPERI_LPPERI_DATE) >= 0x2308030 ? (offset) : (offset) - 4)
40+
41+
1442
/** LPPERI_CLK_EN_REG register
1543
* need_des
1644
*/
@@ -140,22 +168,40 @@ extern "C" {
140168
#define LPPERI_LP_CPU_RESET_EN_V 0x00000001U
141169
#define LPPERI_LP_CPU_RESET_EN_S 31
142170

171+
/** LPPERI_RNG_CFG_REG register
172+
* need_des
173+
*/
174+
#define LPPERI_RNG_CFG_REG (DR_REG_LPPERI_BASE + 0x8)
175+
/** LPPERI_RNG_CFG_ENABLE : R/W; bitpos: [1:0]; default: 0;
176+
* need_des
177+
* Note: this register only exist on the chips that LPPERI_LPPERI_DATE >= 0x2308030,
178+
* i.e., ESP32-H2 chip_revision >= 1.2
179+
*/
180+
#define LPPERI_RNG_CFG_ENABLE 0x00000003U
181+
#define LPPERI_RNG_CFG_ENABLE_M (LPPERI_RNG_CFG_ENABLE_V << LPPERI_RNG_CFG_ENABLE_S)
182+
#define LPPERI_RNG_CFG_ENABLE_V 0x00000003U
183+
#define LPPERI_RNG_CFG_ENABLE_S 0
184+
143185
/** LPPERI_RNG_DATA_REG register
144186
* need_des
187+
* Note: this register address is different on different H2 revisions,
188+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
145189
*/
146-
#define LPPERI_RNG_DATA_REG (DR_REG_LPPERI_BASE + 0x8)
190+
#define LPPERI_RNG_DATA_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0xc))
147191
/** LPPERI_RNG_DATA : RO; bitpos: [31:0]; default: 0;
148192
* need_des
149193
*/
150-
#define LPPERI_RNG_DATA 0xFFFFFFFFU
151-
#define LPPERI_RND_GATA_M (LPPERI_RND_GATA_V << LPPERI_RND_GATA_S)
152-
#define LPPERI_RND_GATA_V 0xFFFFFFFFU
153-
#define LPPERI_RND_GATA_S 0
194+
#define LPPERI_RND_DATA 0xFFFFFFFFU
195+
#define LPPERI_RND_DATA_M (LPPERI_RND_DATA_V << LPPERI_RND_DATA_S)
196+
#define LPPERI_RND_DATA_V 0xFFFFFFFFU
197+
#define LPPERI_RND_DATA_S 0
154198

155199
/** LPPERI_CPU_REG register
156200
* need_des
201+
* Note: this register address is different on different H2 revisions,
202+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
157203
*/
158-
#define LPPERI_CPU_REG (DR_REG_LPPERI_BASE + 0xc)
204+
#define LPPERI_CPU_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x10))
159205
/** LPPERI_LPCORE_DBGM_UNAVALIABLE : R/W; bitpos: [31]; default: 1;
160206
* need_des
161207
*/
@@ -166,8 +212,10 @@ extern "C" {
166212

167213
/** LPPERI_BUS_TIMEOUT_REG register
168214
* need_des
215+
* Note: this register address is different on different H2 revisions,
216+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
169217
*/
170-
#define LPPERI_BUS_TIMEOUT_REG (DR_REG_LPPERI_BASE + 0x10)
218+
#define LPPERI_BUS_TIMEOUT_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x14))
171219
/** LPPERI_LP_PERI_TIMEOUT_THRES : R/W; bitpos: [29:14]; default: 65535;
172220
* need_des
173221
*/
@@ -192,8 +240,10 @@ extern "C" {
192240

193241
/** LPPERI_BUS_TIMEOUT_ADDR_REG register
194242
* need_des
243+
* Note: this register address is different on different H2 revisions,
244+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
195245
*/
196-
#define LPPERI_BUS_TIMEOUT_ADDR_REG (DR_REG_LPPERI_BASE + 0x14)
246+
#define LPPERI_BUS_TIMEOUT_ADDR_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x18))
197247
/** LPPERI_LP_PERI_TIMEOUT_ADDR : RO; bitpos: [31:0]; default: 0;
198248
* need_des
199249
*/
@@ -204,8 +254,10 @@ extern "C" {
204254

205255
/** LPPERI_BUS_TIMEOUT_UID_REG register
206256
* need_des
257+
* Note: this register address is different on different H2 revisions,
258+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
207259
*/
208-
#define LPPERI_BUS_TIMEOUT_UID_REG (DR_REG_LPPERI_BASE + 0x18)
260+
#define LPPERI_BUS_TIMEOUT_UID_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x1c))
209261
/** LPPERI_LP_PERI_TIMEOUT_UID : RO; bitpos: [6:0]; default: 0;
210262
* need_des
211263
*/
@@ -216,8 +268,10 @@ extern "C" {
216268

217269
/** LPPERI_MEM_CTRL_REG register
218270
* need_des
271+
* Note: this register address is different on different H2 revisions,
272+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
219273
*/
220-
#define LPPERI_MEM_CTRL_REG (DR_REG_LPPERI_BASE + 0x1c)
274+
#define LPPERI_MEM_CTRL_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x20))
221275
/** LPPERI_UART_WAKEUP_FLAG_CLR : WT; bitpos: [0]; default: 0;
222276
* need_des
223277
*/
@@ -256,8 +310,10 @@ extern "C" {
256310

257311
/** LPPERI_INTERRUPT_SOURCE_REG register
258312
* need_des
313+
* Note: this register address is different on different H2 revisions,
314+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
259315
*/
260-
#define LPPERI_INTERRUPT_SOURCE_REG (DR_REG_LPPERI_BASE + 0x20)
316+
#define LPPERI_INTERRUPT_SOURCE_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x24))
261317
/** LPPERI_LP_INTERRUPT_SOURCE : RO; bitpos: [5:0]; default: 0;
262318
* BIT5~BIT0: pmu_lp_int, modem_lp_int, lp_timer_lp_int, lp_uart_int, lp_i2c_int,
263319
* lp_io_int
@@ -269,8 +325,10 @@ extern "C" {
269325

270326
/** LPPERI_DEBUG_SEL0_REG register
271327
* need des
328+
* Note: this register address is different on different H2 revisions,
329+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
272330
*/
273-
#define LPPERI_DEBUG_SEL0_REG (DR_REG_LPPERI_BASE + 0x24)
331+
#define LPPERI_DEBUG_SEL0_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x28))
274332
/** LPPERI_DEBUG_SEL0 : R/W; bitpos: [6:0]; default: 0;
275333
* need des
276334
*/
@@ -302,8 +360,10 @@ extern "C" {
302360

303361
/** LPPERI_DEBUG_SEL1_REG register
304362
* need des
363+
* Note: this register address is different on different H2 revisions,
364+
* here uses LPPERI_REG_OFFSET to get the compatible offset.
305365
*/
306-
#define LPPERI_DEBUG_SEL1_REG (DR_REG_LPPERI_BASE + 0x28)
366+
#define LPPERI_DEBUG_SEL1_REG (DR_REG_LPPERI_BASE + LPPERI_REG_OFFSET(0x2c))
307367
/** LPPERI_DEBUG_SEL4 : R/W; bitpos: [6:0]; default: 0;
308368
* need des
309369
*/
@@ -312,25 +372,6 @@ extern "C" {
312372
#define LPPERI_DEBUG_SEL4_V 0x0000007FU
313373
#define LPPERI_DEBUG_SEL4_S 0
314374

315-
/** LPPERI_DATE_REG register
316-
* need_des
317-
*/
318-
#define LPPERI_DATE_REG (DR_REG_LPPERI_BASE + 0x3fc)
319-
/** LPPERI_LPPERI_DATE : R/W; bitpos: [30:0]; default: 35676464;
320-
* need_des
321-
*/
322-
#define LPPERI_LPPERI_DATE 0x7FFFFFFFU
323-
#define LPPERI_LPPERI_DATE_M (LPPERI_LPPERI_DATE_V << LPPERI_LPPERI_DATE_S)
324-
#define LPPERI_LPPERI_DATE_V 0x7FFFFFFFU
325-
#define LPPERI_LPPERI_DATE_S 0
326-
/** LPPERI_CLK_EN : R/W; bitpos: [31]; default: 0;
327-
* need_des
328-
*/
329-
#define LPPERI_CLK_EN (BIT(31))
330-
#define LPPERI_CLK_EN_M (LPPERI_CLK_EN_V << LPPERI_CLK_EN_S)
331-
#define LPPERI_CLK_EN_V 0x00000001U
332-
#define LPPERI_CLK_EN_S 31
333-
334375
#ifdef __cplusplus
335376
}
336377
#endif

0 commit comments

Comments
 (0)