Skip to content

Commit 3519fbd

Browse files
committed
Merge branch 'feature/esp32h4_clock_support' into 'master'
feat(clk): Add basic clock support for esp32h4 Closes IDF-12285, IDF-12912, and IDF-12499 See merge request espressif/esp-idf!40166
2 parents 39d2225 + b3fd9b6 commit 3519fbd

File tree

79 files changed

+918
-1138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+918
-1138
lines changed

Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ mainmenu "Espressif IoT Development Framework Configuration"
149149
bool
150150
default "y" if IDF_TARGET="esp32h4"
151151
select IDF_TARGET_ARCH_RISCV
152-
select IDF_ENV_FPGA
153152
select IDF_ENV_BRINGUP
154153

155154
config IDF_TARGET_LINUX

components/bootloader/Kconfig.projbuild

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ menu "Bootloader config"
3939

4040
orsource "Kconfig.log"
4141

42+
config BOOTLOADER_CPU_CLK_FREQ_MHZ
43+
int
44+
default 64 if IDF_TARGET_ESP32H2
45+
default 48 if IDF_TARGET_ESP32H21 || IDF_TARGET_ESP32H4
46+
default 90 if IDF_TARGET_ESP32P4
47+
default 80
48+
help
49+
The CPU clock frequency to be at least raised to in 2nd bootloader. Invisible for users.
50+
4251
menu "Serial Flash Configurations"
4352
config BOOTLOADER_SPI_CUSTOM_WP_PIN
4453
bool "Use custom SPI Flash WP Pin when flash pins set in eFuse (read help)"

components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h21.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ void IRAM_ATTR bootloader_configure_spi_pins(int drv)
8181

8282
static void IRAM_ATTR bootloader_flash_clock_init(void)
8383
{
84-
// To raise the MSPI clock to 64MHz, needs to enable the 64MHz clock source, which is XTAL_X2_CLK
85-
// (FPGA image fixed MSPI0/1 clock to 64MHz)
86-
clk_ll_xtal_x2_enable();
87-
_mspi_timing_ll_set_flash_clk_src(0, FLASH_CLK_SRC_PLL_F64M);
84+
// // To raise the MSPI clock to 64MHz, needs to enable the 64MHz clock source, which is XTAL_X2_CLK
85+
// // (FPGA image fixed MSPI0/1 clock to 64MHz)
86+
// clk_ll_xtal_x2_enable();
87+
// _mspi_timing_ll_set_flash_clk_src(0, FLASH_CLK_SRC_PLL_F64M);
88+
_mspi_timing_ll_set_flash_clk_src(0, FLASH_CLK_SRC_PLL_F48M);
8889
}
8990

9091
static void update_flash_config(const esp_image_header_t *bootloader_hdr)

components/bootloader_support/src/bootloader_clock_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ __attribute__((weak)) void bootloader_clock_configure(void)
3434
esp_rom_output_tx_wait_idle(0);
3535

3636
/* Set CPU to a higher certain frequency. Keep other clocks unmodified. */
37-
int cpu_freq_mhz = CPU_CLK_FREQ_MHZ_BTLD;
37+
int cpu_freq_mhz = CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ;
3838

3939
#if CONFIG_IDF_TARGET_ESP32
4040
/* On ESP32 rev 0, switching to 80/160 MHz if clock was previously set to
@@ -57,7 +57,7 @@ __attribute__((weak)) void bootloader_clock_configure(void)
5757
// RTC_SLOW clock source will be switched according to Kconfig selection at application startup
5858
clk_cfg.slow_clk_src = rtc_clk_slow_src_get();
5959
if (clk_cfg.slow_clk_src == SOC_RTC_SLOW_CLK_SRC_INVALID) {
60-
clk_cfg.slow_clk_src = SOC_RTC_SLOW_CLK_SRC_RC_SLOW;
60+
clk_cfg.slow_clk_src = SOC_RTC_SLOW_CLK_SRC_DEFAULT;
6161
}
6262

6363
// Use RTC_FAST clock source sel register field's default value, XTAL_DIV, for 2nd stage bootloader

components/bootloader_support/src/bootloader_random.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -26,16 +26,16 @@
2626

2727
#if !defined CONFIG_IDF_TARGET_ESP32S3
2828
#if (defined CONFIG_IDF_TARGET_ESP32C6 || defined CONFIG_IDF_TARGET_ESP32H2)
29-
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 16) // Keep the byte sampling frequency in the ~62KHz range which has been
29+
#define RNG_CPU_WAIT_CYCLE_NUM (CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ * 16) // Keep the byte sampling frequency in the ~62KHz range which has been
3030
// tested.
3131
#elif CONFIG_IDF_TARGET_ESP32P4
3232
// bootloader tested with around 63 KHz bytes reading frequency
33-
#define RNG_CPU_WAIT_CYCLE_NUM (CPU_CLK_FREQ_MHZ_BTLD * 16)
33+
#define RNG_CPU_WAIT_CYCLE_NUM (CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ * 16)
3434
#else
35-
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 32 * 2) /* extra factor of 2 is precautionary */
35+
#define RNG_CPU_WAIT_CYCLE_NUM (CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ * 32 * 2) /* extra factor of 2 is precautionary */
3636
#endif
3737
#else
38-
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 23) /* 45 KHz reading frequency is the maximum we have tested so far on S3 */
38+
#define RNG_CPU_WAIT_CYCLE_NUM (CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ * 23) /* 45 KHz reading frequency is the maximum we have tested so far on S3 */
3939
#endif
4040

4141
__attribute__((weak)) void bootloader_fill_random(void *buffer, size_t length)

components/bootloader_support/src/esp32h4/bootloader_esp32h4.c

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
#include "esp_rom_efuse.h"
1414
#include "esp_rom_serial_output.h"
1515
#include "esp_rom_sys.h"
16-
#include "esp_rom_spiflash.h"
1716
#include "soc/gpio_sig_map.h"
1817
#include "esp_cpu.h"
1918
#include "soc/rtc.h"
20-
#include "soc/spi_periph.h"
2119
#include "soc/cache_reg.h"
2220
#include "soc/io_mux_reg.h"
2321
#include "soc/pcr_reg.h"
@@ -28,8 +26,6 @@
2826
#include "bootloader_flash_config.h"
2927
#include "bootloader_mem.h"
3028
#include "esp_private/regi2c_ctrl.h"
31-
// #include "soc/regi2c_lp_bias.h"
32-
// #include "soc/regi2c_bias.h"
3329
#include "soc/hp_system_reg.h"
3430
#include "bootloader_console.h"
3531
#include "bootloader_flash_priv.h"
@@ -83,39 +79,18 @@ static void bootloader_super_wdt_auto_feed(void)
8379
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
8480
}
8581

86-
void spi_flash_din_num_set(uint8_t spi_num, uint8_t din_num)
87-
{
88-
uint32_t reg_val = (REG_READ(SPI_MEM_DIN_NUM_REG(spi_num)) & (~(SPI_MEM_DIN0_NUM_M | SPI_MEM_DIN1_NUM_M | SPI_MEM_DIN2_NUM_M | SPI_MEM_DIN3_NUM_M | SPI_MEM_DIN4_NUM_M | SPI_MEM_DIN5_NUM_M | SPI_MEM_DIN6_NUM_M | SPI_MEM_DIN7_NUM_M | SPI_MEM_DINS_NUM_M)))
89-
| (din_num << SPI_MEM_DIN0_NUM_S) | (din_num << SPI_MEM_DIN1_NUM_S) | (din_num << SPI_MEM_DIN2_NUM_S) | (din_num << SPI_MEM_DIN3_NUM_S)
90-
| (din_num << SPI_MEM_DIN4_NUM_S) | (din_num << SPI_MEM_DIN5_NUM_S) | (din_num << SPI_MEM_DIN6_NUM_S) | (din_num << SPI_MEM_DIN7_NUM_S) | (din_num << SPI_MEM_DINS_NUM_S);
91-
REG_WRITE(SPI_MEM_DIN_NUM_REG(spi_num), reg_val);
92-
REG_SET_BIT(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_TIMING_CALI_UPDATE);
93-
}
94-
95-
void spi_flash_extra_dummy_set(uint8_t spi_num, uint8_t extra_dummy)
96-
{
97-
rom_spiflash_legacy_data->dummy_len_plus[spi_num] = extra_dummy;
98-
}
99-
100-
/*
101-
* din mode din_num dummy
102-
1 0 1
103-
0 0 0
104-
1 0 2
105-
0 0 1
106-
1 0 3
107-
0 0 2
108-
1 0 4
109-
0 0 3
110-
*/
11182
static inline void bootloader_hardware_init(void)
11283
{
113-
// TODO: IDF-12285 RF disable?
84+
/* Disable RF pll by default */
85+
CLEAR_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_RFPLL);
86+
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_FORCE_RFPLL);
11487

88+
#if !CONFIG_IDF_ENV_FPGA
11589
/* Enable analog i2c master clock */
11690
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
117-
regi2c_ctrl_ll_master_force_enable_clock(true); // TODO: IDF-12285 Remove this?
91+
regi2c_ctrl_ll_master_force_enable_clock(true); // TODO: IDF-12313 Remove this?
11892
regi2c_ctrl_ll_master_configure_clock();
93+
#endif
11994
}
12095

12196
static inline void bootloader_ana_reset_config(void)

components/esp_hw_support/port/esp32/include/soc/rtc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ typedef struct rtc_clk_config_s {
116116
*/
117117
#define RTC_CLK_CONFIG_DEFAULT() { \
118118
.xtal_freq = CONFIG_XTAL_FREQ, \
119-
.cpu_freq_mhz = 80, \
119+
.cpu_freq_mhz = CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ, \
120120
.fast_clk_src = SOC_RTC_FAST_CLK_SRC_RC_FAST, \
121121
.slow_clk_src = SOC_RTC_SLOW_CLK_SRC_RC_SLOW, \
122122
.clk_8m_div = 0, \

components/esp_hw_support/port/esp32c2/include/soc/rtc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ typedef struct {
186186
*/
187187
#define RTC_CLK_CONFIG_DEFAULT() { \
188188
.xtal_freq = CONFIG_XTAL_FREQ, \
189-
.cpu_freq_mhz = 80, \
189+
.cpu_freq_mhz = CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ, \
190190
.fast_clk_src = SOC_RTC_FAST_CLK_SRC_RC_FAST, \
191191
.slow_clk_src = SOC_RTC_SLOW_CLK_SRC_RC_SLOW, \
192192
.clk_rtc_clk_div = 0, \

components/esp_hw_support/port/esp32c3/include/soc/rtc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ typedef struct {
186186
*/
187187
#define RTC_CLK_CONFIG_DEFAULT() { \
188188
.xtal_freq = CONFIG_XTAL_FREQ, \
189-
.cpu_freq_mhz = 80, \
189+
.cpu_freq_mhz = CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ, \
190190
.fast_clk_src = SOC_RTC_FAST_CLK_SRC_RC_FAST, \
191191
.slow_clk_src = SOC_RTC_SLOW_CLK_SRC_RC_SLOW, \
192192
.clk_rtc_clk_div = 0, \

components/esp_hw_support/port/esp32c5/include/soc/rtc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ typedef struct {
147147
*/
148148
#define RTC_CLK_CONFIG_DEFAULT() { \
149149
.xtal_freq = CONFIG_XTAL_FREQ, \
150-
.cpu_freq_mhz = 80, \
150+
.cpu_freq_mhz = CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ, \
151151
.fast_clk_src = SOC_RTC_FAST_CLK_SRC_RC_FAST, \
152152
.slow_clk_src = SOC_RTC_SLOW_CLK_SRC_RC_SLOW, \
153153
.clk_rtc_clk_div = 0, \

0 commit comments

Comments
 (0)