Skip to content

Commit cfe4bf3

Browse files
committed
feat(driver_gptimer): esp32h21 add basic gptimer support
1 parent 4f2105d commit cfe4bf3

File tree

24 files changed

+258
-196
lines changed

24 files changed

+258
-196
lines changed
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-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-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |
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-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-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |

components/esp_driver_gptimer/test_apps/gptimer/main/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ endif()
1515

1616
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
1717
# the component can be registered as WHOLE_ARCHIVE
18-
idf_component_register(SRCS ${srcs}
19-
PRIV_REQUIRES unity esp_driver_gptimer esp_driver_gpio
20-
WHOLE_ARCHIVE)
18+
idf_component_register(
19+
SRCS ${srcs}
20+
PRIV_REQUIRES unity esp_driver_gptimer esp_driver_gpio
21+
WHOLE_ARCHIVE
22+
)

components/esp_driver_gptimer/test_apps/gptimer/main/test_gptimer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ TEST_CASE("gptimer_wallclock_with_various_clock_sources", "[gptimer]")
103103
printf("get raw count of gptimer %d: %llu\r\n", i, value);
104104
// convert the raw count to us
105105
value = value * 1000000 / timer_resolution_hz[i];
106-
TEST_ASSERT_UINT_WITHIN(200, 20000, value);
106+
TEST_ASSERT_UINT_WITHIN(400, 20000, value); //200 more threshold for cpu on stop process
107107
}
108108
printf("restart timers\r\n");
109109
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
@@ -121,7 +121,7 @@ TEST_CASE("gptimer_wallclock_with_various_clock_sources", "[gptimer]")
121121
printf("get raw count of gptimer %d: %llu\r\n", i, value);
122122
// convert the raw count to us
123123
value = value * 1000000 / timer_resolution_hz[i];
124-
TEST_ASSERT_UINT_WITHIN(400, 40000, value);
124+
TEST_ASSERT_UINT_WITHIN(600, 40000, value); //same 200 for cpu time
125125
}
126126
printf("disable timers\r\n");
127127
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {

components/esp_hw_support/port/esp32h21/esp_clk_tree.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ uint32_t *freq_value)
2424
ESP_RETURN_ON_FALSE(precision < ESP_CLK_TREE_SRC_FREQ_PRECISION_INVALID, ESP_ERR_INVALID_ARG, TAG, "unknown precision");
2525
ESP_RETURN_ON_FALSE(freq_value, ESP_ERR_INVALID_ARG, TAG, "null pointer");
2626

27+
#if !SOC_CLK_TREE_SUPPORTED
28+
// Have only XTAL 32M before clock tree supported
29+
assert(clk_src == SOC_MOD_CLK_XTAL);
30+
#endif
2731
uint32_t clk_src_freq = 0;
2832
switch (clk_src) {
33+
case SOC_MOD_CLK_XTAL:
34+
clk_src_freq = SOC_XTAL_FREQ_32M * MHZ;
35+
break;
2936
case SOC_MOD_CLK_PLL_F48M:
3037
clk_src_freq = CLK_LL_PLL_48M_FREQ_MHZ * MHZ;
3138
break;
@@ -39,8 +46,7 @@ uint32_t *freq_value)
3946
break;
4047
}
4148

42-
ESP_RETURN_ON_FALSE(clk_src_freq, ESP_FAIL, TAG,
43-
"freq shouldn't be 0, calibration failed");
49+
ESP_RETURN_ON_FALSE(clk_src_freq, ESP_FAIL, TAG, "freq shouldn't be 0, calibration failed");
4450
*freq_value = clk_src_freq;
4551
return ESP_OK;
4652
}

components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if(CONFIG_SOC_ETM_SUPPORTED)
2121
list(APPEND srcs "test_etm_core.c")
2222
endif()
2323

24-
if(CONFIG_SOC_GPTIMER_SUPPORTED)
24+
if(CONFIG_SOC_GPTIMER_SUPPORTED AND CONFIG_SOC_GPSPI_SUPPORTED)
2525
list(APPEND srcs "test_intr_alloc.c")
2626
endif()
2727

components/esp_system/int_wdt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#endif // SOC_TIMER_GROUPS > 1
5454

5555
#if CONFIG_ESP_INT_WDT
56-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
56+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
5757
static const char* TAG = "int_wdt";
5858
static esp_err_t sleep_int_wdt_retention_init(void *arg)
5959
{
@@ -160,7 +160,7 @@ void esp_int_wdt_init(void)
160160
wdt_hal_enable(&iwdt_context);
161161
wdt_hal_write_protect_enable(&iwdt_context);
162162

163-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
163+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
164164
esp_int_wdt_retention_enable(IWDT_TIMER_GROUP);
165165
#endif
166166

components/esp_system/task_wdt/task_wdt_impl_timergroup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "esp_private/periph_ctrl.h"
2222
#include "esp_private/esp_task_wdt_impl.h"
2323

24-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
24+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
2525
#include "esp_private/sleep_retention.h"
2626
#endif
2727

@@ -46,7 +46,7 @@ typedef struct {
4646
* init function. */
4747
static twdt_ctx_hard_t init_context;
4848

49-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
49+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
5050
static const char* TAG = "task_wdt";
5151
static esp_err_t sleep_task_wdt_retention_init(void *arg)
5252
{
@@ -124,7 +124,7 @@ esp_err_t esp_task_wdt_impl_timer_allocate(const esp_task_wdt_config_t *config,
124124
/* Return the implementation context to the caller */
125125
*obj = (twdt_ctx_t) ctx;
126126

127-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
127+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
128128
esp_task_wdt_retention_enable(TWDT_TIMER_GROUP);
129129
#endif
130130
}
@@ -171,7 +171,7 @@ void esp_task_wdt_impl_timer_free(twdt_ctx_t obj)
171171
/* Deregister interrupt */
172172
ESP_ERROR_CHECK(esp_intr_free(ctx->intr_handle));
173173

174-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
174+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
175175
ESP_ERROR_CHECK(esp_task_wdt_retention_disable(TWDT_TIMER_GROUP));
176176
#endif
177177
}

components/esp_system/test_apps/esp_system_unity_tests/main/test_task_wdt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "soc/rtc.h"
1717
#include "soc/soc_caps.h"
1818

19-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
19+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
2020
#include "esp_sleep.h"
2121
#include "esp_private/esp_sleep_internal.h"
2222
#include "esp_private/sleep_cpu.h"
@@ -49,7 +49,7 @@ TEST_CASE("Task WDT task timeout", "[task_wdt]")
4949
TEST_ASSERT_EQUAL(ESP_OK, esp_task_wdt_deinit());
5050
}
5151

52-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_TIMER_SUPPORT_SLEEP_RETENTION
52+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_MWDT_SUPPORT_SLEEP_RETENTION
5353
TEST_CASE("Task WDT task timeout after peripheral powerdown lightsleep", "[task_wdt]")
5454
{
5555
timeout_flag = false;

components/hal/esp32h21/include/hal/mwdt_ll.h

Lines changed: 7 additions & 18 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
*/
@@ -276,31 +276,23 @@ FORCE_INLINE_ATTR void mwdt_ll_set_intr_enable(timg_dev_t *hw, bool enable)
276276
* @param hw Beginning address of the peripheral registers.
277277
* @param clk_src Clock source
278278
*/
279-
280279
FORCE_INLINE_ATTR void mwdt_ll_set_clock_source(timg_dev_t *hw, mwdt_clock_source_t clk_src)
281280
{
282-
uint8_t clk_id = 0;
281+
uint8_t group_id = (hw == &TIMERG0) ? 0 : 1;
283282
switch (clk_src) {
284283
case MWDT_CLK_SRC_XTAL:
285-
clk_id = 0;
284+
PCR.timergroup[group_id].timergroup_wdt_clk_conf.tg_wdt_clk_sel = 0;
286285
break;
287286
case MWDT_CLK_SRC_RC_FAST:
288-
clk_id = 1;
287+
PCR.timergroup[group_id].timergroup_wdt_clk_conf.tg_wdt_clk_sel = 1;
289288
break;
290289
case MWDT_CLK_SRC_PLL_F48M:
291-
clk_id = 2;
290+
PCR.timergroup[group_id].timergroup_wdt_clk_conf.tg_wdt_clk_sel = 2;
292291
break;
293292
default:
294293
HAL_ASSERT(false);
295294
break;
296295
}
297-
298-
299-
if (hw == &TIMERG0) {
300-
PCR.timergroup0_wdt_clk_conf.tg0_wdt_clk_sel = clk_id;
301-
} else {
302-
PCR.timergroup1_wdt_clk_conf.tg1_wdt_clk_sel = clk_id;
303-
}
304296
}
305297

306298
/**
@@ -312,11 +304,8 @@ FORCE_INLINE_ATTR void mwdt_ll_set_clock_source(timg_dev_t *hw, mwdt_clock_sourc
312304
__attribute__((always_inline))
313305
static inline void mwdt_ll_enable_clock(timg_dev_t *hw, bool en)
314306
{
315-
if (hw == &TIMERG0) {
316-
PCR.timergroup0_wdt_clk_conf.tg0_wdt_clk_en = en;
317-
} else {
318-
PCR.timergroup1_wdt_clk_conf.tg1_wdt_clk_en = en;
319-
}
307+
uint8_t group_id = (hw == &TIMERG0) ? 0 : 1;
308+
PCR.timergroup[group_id].timergroup_wdt_clk_conf.tg_wdt_clk_en = en;
320309
}
321310

322311
#ifdef __cplusplus

0 commit comments

Comments
 (0)