Skip to content

Commit f407fab

Browse files
committed
Merge branch 'feat/support_gptimer_on_h4' into 'master'
feat(gptimer): support gptimer on esp32h4 Closes IDF-12373 and IDF-12374 See merge request espressif/esp-idf!38168
2 parents 83cb9d7 + 2cbc297 commit f407fab

File tree

39 files changed

+410
-273
lines changed

39 files changed

+410
-273
lines changed

components/driver/deprecated/timer_legacy.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
*/
@@ -332,8 +332,8 @@ esp_err_t timer_init(timer_group_t group_num, timer_idx_t timer_num, const timer
332332
GPTIMER_CLOCK_SRC_ATOMIC() {
333333
// although `clk_src` is of `timer_src_clk_t` type, but it's binary compatible with `gptimer_clock_source_t`,
334334
// as the underlying enum entries come from the same `soc_module_clk_t`
335-
timer_ll_set_clock_source(p_timer_obj[group_num][timer_num]->hal.dev, timer_num, (gptimer_clock_source_t)clk_src);
336-
timer_ll_enable_clock(hal->dev, timer_num, true);
335+
timer_ll_set_clock_source(group_num, timer_num, (gptimer_clock_source_t)clk_src);
336+
timer_ll_enable_clock(group_num, timer_num, true);
337337
}
338338
timer_ll_set_clock_prescale(hal->dev, timer_num, config->divider);
339339
timer_ll_set_count_direction(p_timer_obj[group_num][timer_num]->hal.dev, timer_num, config->counter_dir);
@@ -362,7 +362,7 @@ esp_err_t timer_deinit(timer_group_t group_num, timer_idx_t timer_num)
362362

363363
// disable the source clock
364364
GPTIMER_CLOCK_SRC_ATOMIC() {
365-
timer_ll_enable_clock(hal->dev, hal->timer_id, false);
365+
timer_ll_enable_clock(group_num, hal->timer_id, false);
366366
}
367367
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
368368
timer_ll_enable_intr(hal->dev, TIMER_LL_EVENT_ALARM(timer_num), false);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2-
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |
1+
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- |

components/esp_driver_gptimer/src/gptimer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ esp_err_t gptimer_del_timer(gptimer_handle_t timer)
195195
ESP_LOGD(TAG, "del timer (%d,%d)", group_id, timer_id);
196196
// disable the source clock
197197
GPTIMER_CLOCK_SRC_ATOMIC() {
198-
timer_ll_enable_clock(hal->dev, hal->timer_id, false);
198+
timer_ll_enable_clock(group_id, hal->timer_id, false);
199199
}
200200
timer_hal_deinit(hal);
201201
// recycle memory resource

components/esp_driver_gptimer/src/gptimer_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ esp_err_t gptimer_select_periph_clock(gptimer_t *timer, gptimer_clock_source_t s
9090
{
9191
uint32_t counter_src_hz = 0;
9292
int timer_id = timer->timer_id;
93-
93+
int group_id = timer->group->group_id;
9494
// TODO: [clk_tree] to use a generic clock enable/disable or acquire/release function for all clock source
9595
#if SOC_TIMER_GROUP_SUPPORT_RC_FAST
9696
if (src_clk == GPTIMER_CLK_SRC_RC_FAST) {
@@ -134,7 +134,7 @@ esp_err_t gptimer_select_periph_clock(gptimer_t *timer, gptimer_clock_source_t s
134134
#endif // CONFIG_IDF_TARGET_ESP32C2
135135

136136
if (need_pm_lock) {
137-
sprintf(timer->pm_lock_name, "gptimer_%d_%d", timer->group->group_id, timer_id); // e.g. gptimer_0_0
137+
sprintf(timer->pm_lock_name, "gptimer_%d_%d", group_id, timer_id); // e.g. gptimer_0_0
138138
ESP_RETURN_ON_ERROR(esp_pm_lock_create(pm_lock_type, 0, timer->pm_lock_name, &timer->pm_lock),
139139
TAG, "create pm lock failed");
140140
}
@@ -145,8 +145,8 @@ esp_err_t gptimer_select_periph_clock(gptimer_t *timer, gptimer_clock_source_t s
145145
// on some ESP chip, different peripheral's clock source setting are mixed in the same register
146146
// so we need to make this done in an atomic way
147147
GPTIMER_CLOCK_SRC_ATOMIC() {
148-
timer_ll_set_clock_source(timer->hal.dev, timer_id, src_clk);
149-
timer_ll_enable_clock(timer->hal.dev, timer_id, true);
148+
timer_ll_set_clock_source(group_id, timer_id, src_clk);
149+
timer_ll_enable_clock(group_id, timer_id, true);
150150
}
151151
timer->clk_src = src_clk;
152152
uint32_t prescale = counter_src_hz / resolution_hz; // potential resolution loss here
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2-
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |
1+
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- |

components/esp_hw_support/port/esp32h4/esp_clk_tree.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@ uint32_t *freq_value)
2727
uint32_t clk_src_freq = 0;
2828
switch (clk_src) {
2929
case SOC_MOD_CLK_XTAL:
30-
clk_src_freq = 32 * MHZ;
30+
clk_src_freq = SOC_XTAL_FREQ_32M * MHZ;
3131
break;
32-
case SOC_MOD_CLK_PLL_F80M:
33-
clk_src_freq = CLK_LL_PLL_80M_FREQ_MHZ * MHZ;
32+
case SOC_MOD_CLK_PLL_F48M:
33+
clk_src_freq = CLK_LL_PLL_48M_FREQ_MHZ * MHZ;
3434
break;
35-
case SOC_MOD_CLK_PLL_F160M:
36-
clk_src_freq = CLK_LL_PLL_160M_FREQ_MHZ * MHZ;
35+
case SOC_MOD_CLK_PLL_F64M:
36+
clk_src_freq = CLK_LL_PLL_64M_FREQ_MHZ * MHZ;
3737
break;
38-
case SOC_MOD_CLK_PLL_F240M:
39-
clk_src_freq = CLK_LL_PLL_240M_FREQ_MHZ * MHZ;
38+
case SOC_MOD_CLK_PLL_F96M:
39+
clk_src_freq = CLK_LL_PLL_96M_FREQ_MHZ * MHZ;
4040
break;
4141
default:
4242
break;
4343
}
4444

45-
ESP_RETURN_ON_FALSE(clk_src_freq, ESP_FAIL, TAG,
46-
"freq shouldn't be 0, calibration failed");
45+
ESP_RETURN_ON_FALSE(clk_src_freq, ESP_FAIL, TAG, "freq shouldn't be 0, calibration failed");
4746
*freq_value = clk_src_freq;
4847
return ESP_OK;
4948
}

components/esp_hw_support/port/esp32h4/rtc_clk.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
static const char *TAG = "rtc_clk";
2525

26-
// Current PLL frequency, in 480MHz. Zero if PLL is not enabled.
26+
// Current PLL frequency, in 96MHz. Zero if PLL is not enabled.
2727
static int s_cur_pll_freq;
2828

2929
static uint32_t s_bbpll_digi_consumers_ref_count = 0; // Currently, it only tracks whether the 48MHz PHY clock is in-use by USB Serial/JTAG
@@ -57,7 +57,7 @@ void rtc_clk_32k_enable_external(void)
5757

5858
void rtc_clk_32k_bootstrap(uint32_t cycle)
5959
{
60-
/* No special bootstrapping needed for ESP32-C6, 'cycle' argument is to keep the signature
60+
/* No special bootstrapping needed for ESP32-H4, 'cycle' argument is to keep the signature
6161
* same as for the ESP32. Just enable the XTAL here.
6262
*/
6363
(void)cycle;
@@ -183,7 +183,7 @@ static void rtc_clk_cpu_freq_to_8m(void)
183183
*/
184184
static void rtc_clk_cpu_freq_to_pll_mhz(int cpu_freq_mhz)
185185
{
186-
clk_ll_cpu_set_hs_divider(CLK_LL_PLL_480M_FREQ_MHZ / cpu_freq_mhz);
186+
clk_ll_cpu_set_hs_divider(CLK_LL_PLL_96M_FREQ_MHZ / cpu_freq_mhz);
187187
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_PLL);
188188
esp_rom_set_cpu_ticks_per_us(cpu_freq_mhz);
189189
}
@@ -206,20 +206,20 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
206206

207207
source_freq_mhz = xtal_freq;
208208
source = SOC_CPU_CLK_SRC_XTAL;
209-
} else if (freq_mhz == 80) {
209+
} else if (freq_mhz == 16) {
210210
real_freq_mhz = freq_mhz;
211211
source = SOC_CPU_CLK_SRC_PLL;
212-
source_freq_mhz = CLK_LL_PLL_480M_FREQ_MHZ;
212+
source_freq_mhz = CLK_LL_PLL_96M_FREQ_MHZ;
213213
divider = 6;
214-
} else if (freq_mhz == 120) {
214+
} else if (freq_mhz == 24) {
215215
real_freq_mhz = freq_mhz;
216216
source = SOC_CPU_CLK_SRC_PLL;
217-
source_freq_mhz = CLK_LL_PLL_480M_FREQ_MHZ;
217+
source_freq_mhz = CLK_LL_PLL_96M_FREQ_MHZ;
218218
divider = 4;
219-
} else if (freq_mhz == 160) {
219+
} else if (freq_mhz == 32) {
220220
real_freq_mhz = freq_mhz;
221221
source = SOC_CPU_CLK_SRC_PLL;
222-
source_freq_mhz = CLK_LL_PLL_480M_FREQ_MHZ;
222+
source_freq_mhz = CLK_LL_PLL_96M_FREQ_MHZ;
223223
divider = 3;
224224
} else {
225225
// unsupported frequency

components/esp_system/port/soc/esp32c6/clk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ __attribute__((weak)) void esp_perip_clk_init(void)
255255
rmt_ll_enable_group_clock(0, false);
256256
ledc_ll_enable_clock(&LEDC, false);
257257
ledc_ll_enable_bus_clock(false);
258-
timer_ll_enable_clock(&TIMERG0, 0, false);
259-
timer_ll_enable_clock(&TIMERG1, 0, false);
258+
timer_ll_enable_clock(0, 0, false);
259+
timer_ll_enable_clock(1, 0, false);
260260
_timer_ll_enable_bus_clock(0, false);
261261
_timer_ll_enable_bus_clock(1, false);
262262
twai_ll_enable_clock(0, false);

components/esp_system/port/soc/esp32h2/clk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ __attribute__((weak)) void esp_perip_clk_init(void)
244244
rmt_ll_enable_group_clock(0, false);
245245
ledc_ll_enable_clock(&LEDC, false);
246246
ledc_ll_enable_bus_clock(false);
247-
timer_ll_enable_clock(&TIMERG0, 0, false);
248-
timer_ll_enable_clock(&TIMERG1, 0, false);
247+
timer_ll_enable_clock(0, 0, false);
248+
timer_ll_enable_clock(1, 0, false);
249249
_timer_ll_enable_bus_clock(0, false);
250250
_timer_ll_enable_bus_clock(1, false);
251251
twai_ll_enable_clock(0, false);

components/esp_system/port/soc/esp32h4/Kconfig.cpu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
choice ESP_DEFAULT_CPU_FREQ_MHZ
22
prompt "CPU frequency"
3-
default ESP_DEFAULT_CPU_FREQ_MHZ_64 if IDF_ENV_FPGA
3+
default ESP_DEFAULT_CPU_FREQ_MHZ_32 if IDF_ENV_FPGA
44
help
55
CPU frequency to be set on application startup.
66

0 commit comments

Comments
 (0)