Skip to content

Commit e6e629e

Browse files
committed
Merge branch 'feature/esp32h21_clock_support' into 'master'
feat(clk): Add basic clock support for esp32h21 Closes IDF-11521, IDF-11906, and IDF-12114 See merge request espressif/esp-idf!39066
2 parents d4f3bce + 6d293c8 commit e6e629e

File tree

90 files changed

+833
-858
lines changed

Some content is hidden

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

90 files changed

+833
-858
lines changed

Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ mainmenu "Espressif IoT Development Framework Configuration"
141141
default "y" if IDF_TARGET="esp32h21"
142142
select FREERTOS_UNICORE
143143
select IDF_TARGET_ARCH_RISCV
144-
select IDF_ENV_FPGA
145144
select IDF_ENV_BRINGUP
146145

147146
config IDF_TARGET_ESP32H4

components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h21.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -18,6 +18,7 @@
1818
#include "hal/cache_hal.h"
1919
#include "hal/cache_ll.h"
2020
#include "hal/mspi_ll.h"
21+
#include "hal/clk_tree_ll.h"
2122
#include "soc/pcr_reg.h"
2223

2324
static const char *TAG = "boot.esp32h21";
@@ -80,7 +81,9 @@ void IRAM_ATTR bootloader_configure_spi_pins(int drv)
8081

8182
static void IRAM_ATTR bootloader_flash_clock_init(void)
8283
{
83-
// At this moment, BBPLL should be enabled, safe to switch MSPI clock source to PLL_F64M (default clock src) to raise speed
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();
8487
_mspi_timing_ll_set_flash_clk_src(0, FLASH_CLK_SRC_PLL_F64M);
8588
}
8689

components/bootloader_support/src/bootloader_clock_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "soc/pmu_reg.h"
1919
#endif
2020

21-
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C5
21+
#if CONFIG_IDF_TARGET_ESP32
2222
#include "hal/clk_tree_ll.h"
2323
#endif
2424
#include "esp_rom_sys.h"

components/bootloader_support/src/esp32h21/bootloader_esp32h21.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ static inline void bootloader_hardware_init(void)
9090
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_FORCE_RFPLL);
9191

9292
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
93-
regi2c_ctrl_ll_master_force_enable_clock(true); // TODO: IDF-11548 Remove this?
9493
regi2c_ctrl_ll_master_configure_clock();
9594
}
9695

components/esp_hw_support/esp_clk.c

Lines changed: 4 additions & 4 deletions
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
*/
@@ -85,10 +85,10 @@ int IRAM_ATTR esp_clk_cpu_freq(void)
8585
int IRAM_ATTR esp_clk_apb_freq(void)
8686
{
8787
// TODO: IDF-5173 Require cleanup, implementation should be unified
88-
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 || CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C61
89-
return rtc_clk_apb_freq_get();
90-
#else
88+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2
9189
return MIN(s_get_cpu_freq_mhz() * MHZ, APB_CLK_FREQ);
90+
#else // for all later targets
91+
return rtc_clk_apb_freq_get();
9292
#endif
9393
}
9494

components/esp_hw_support/include/esp_private/esp_clk_tree_common.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,33 @@ uint32_t esp_clk_tree_lp_fast_get_freq_hz(esp_clk_tree_src_freq_precision_t prec
9090
*/
9191
esp_err_t esp_clk_tree_enable_src(soc_module_clk_t clk_src, bool enable);
9292

93-
#if SOC_CLOCK_TREE_MANAGEMENT_SUPPORTED
9493
/**
95-
* @brief Set the clock source not in use on the clock tree to the gated state.
94+
* @brief Initialize clock circuit power and clock gating
95+
*
96+
* Set the clock source not in uses on the clock tree to the gated state,
97+
* and initialize reference counters for clock circuit power and clock gating.
9698
*/
9799
void esp_clk_tree_initialize(void);
98-
#endif
100+
101+
/**
102+
* @brief Enable / Disable the power of the clock circuit
103+
*
104+
* @param[in] clk_circuit Clock circuits, in soc_root_clk_circuit_t
105+
* @param[in] enable Enable / Disable the power of the clock circuit
106+
*
107+
* @return
108+
* - ESP_OK Success
109+
*/
110+
esp_err_t esp_clk_tree_enable_power(soc_root_clk_circuit_t clk_circuit, bool enable);
111+
112+
/**
113+
* @brief Get the power status of the clock circuit
114+
*
115+
* @param[in] clk_circuit Clock circuits, in soc_root_clk_circuit_t
116+
*
117+
* @return True if the clock circuit power is on, false otherwise
118+
*/
119+
bool esp_clk_tree_is_power_on(soc_root_clk_circuit_t clk_circuit);
99120

100121
#ifdef __cplusplus
101122
}

components/esp_hw_support/linker.lf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ entries:
1717
rtc_clk (noflash)
1818
rtc_time (noflash_text)
1919
esp_clk_tree: esp_clk_tree_enable_src (noflash)
20+
esp_clk_tree: esp_clk_tree_enable_power (noflash)
21+
esp_clk_tree: esp_clk_tree_is_power_on (noflash)
2022
if IDF_TARGET_ESP32 = y:
2123
rtc_clk:rtc_clk_cpu_freq_to_pll_mhz (noflash)
2224
rtc_clk:rtc_clk_cpu_freq_to_xtal (noflash)

components/esp_hw_support/port/esp32/esp_clk_tree.c

Lines changed: 17 additions & 1 deletion
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
*/
@@ -70,6 +70,22 @@ uint32_t *freq_value)
7070
return ESP_OK;
7171
}
7272

73+
void esp_clk_tree_initialize(void)
74+
{
75+
}
76+
77+
bool esp_clk_tree_is_power_on(soc_root_clk_circuit_t clk_circuit)
78+
{
79+
(void)clk_circuit;
80+
return false;
81+
}
82+
83+
esp_err_t esp_clk_tree_enable_power(soc_root_clk_circuit_t clk_circuit, bool enable)
84+
{
85+
(void)clk_circuit; (void)enable;
86+
return ESP_OK; // TODO: PM-354
87+
}
88+
7389
esp_err_t esp_clk_tree_enable_src(soc_module_clk_t clk_src, bool enable)
7490
{
7591
(void)clk_src; (void)enable;

components/esp_hw_support/port/esp32/rtc_clk.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
#define XTAL_32K_BOOTSTRAP_TIME_US 7
3636

37-
static void rtc_clk_cpu_freq_to_8m(void);
37+
static void rtc_clk_cpu_freq_to_rc_fast(void);
3838
static void rtc_clk_cpu_freq_to_pll_mhz(int cpu_freq_mhz);
3939

4040
// Current PLL frequency, in MHZ (320 or 480). Zero if PLL is not enabled.
@@ -387,7 +387,7 @@ void rtc_clk_cpu_freq_to_xtal(int cpu_freq, int div)
387387
REG_SET_FIELD(RTC_CNTL_REG, RTC_CNTL_DIG_DBIAS_WAK, dbias);
388388
}
389389

390-
static void rtc_clk_cpu_freq_to_8m(void)
390+
static void rtc_clk_cpu_freq_to_rc_fast(void)
391391
{
392392
esp_rom_set_cpu_ticks_per_us(8);
393393
REG_SET_FIELD(RTC_CNTL_REG, RTC_CNTL_DIG_DBIAS_WAK, DIG_DBIAS_XTAL);
@@ -542,7 +542,7 @@ void rtc_clk_cpu_freq_set_config(const rtc_cpu_freq_config_t* config)
542542
rtc_clk_bbpll_configure(rtc_clk_xtal_freq_get(), config->source_freq_mhz);
543543
rtc_clk_cpu_freq_to_pll_mhz(config->freq_mhz);
544544
} else if (config->source == SOC_CPU_CLK_SRC_RC_FAST) {
545-
rtc_clk_cpu_freq_to_8m();
545+
rtc_clk_cpu_freq_to_rc_fast();
546546
}
547547
}
548548

components/esp_hw_support/port/esp32c2/esp_clk_tree.c

Lines changed: 17 additions & 1 deletion
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
*/
@@ -64,6 +64,22 @@ uint32_t *freq_value)
6464
return ESP_OK;
6565
}
6666

67+
void esp_clk_tree_initialize(void)
68+
{
69+
}
70+
71+
bool esp_clk_tree_is_power_on(soc_root_clk_circuit_t clk_circuit)
72+
{
73+
(void)clk_circuit;
74+
return false;
75+
}
76+
77+
esp_err_t esp_clk_tree_enable_power(soc_root_clk_circuit_t clk_circuit, bool enable)
78+
{
79+
(void)clk_circuit; (void)enable;
80+
return ESP_OK; // TODO: PM-354
81+
}
82+
6783
esp_err_t esp_clk_tree_enable_src(soc_module_clk_t clk_src, bool enable)
6884
{
6985
(void)clk_src; (void)enable;

0 commit comments

Comments
 (0)