Skip to content

Commit 4be1897

Browse files
Raffael Rostagnodleach02
authored andcommitted
drivers: counter: systimer: esp32c2: Fix clock parameters
Fix clock source frequency for systimer and GP timer. Signed-off-by: Raffael Rostagno <[email protected]>
1 parent cf36768 commit 4be1897

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

drivers/counter/counter_esp32_tmr.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ static void counter_esp32_isr(void *arg)
256256
timer_ll_clear_intr_status(data->hal_ctx.dev, TIMER_LL_EVENT_ALARM(data->hal_ctx.timer_id));
257257
}
258258

259+
#if defined(CONFIG_SOC_SERIES_ESP32C2)
260+
#define CLK_LL_PLL_40M_FREQ MHZ(40)
261+
#define CLOCK_SOURCE_FREQ CLK_LL_PLL_40M_FREQ
262+
#else
263+
#define CLOCK_SOURCE_FREQ APB_CLK_FREQ
264+
#endif
265+
259266
#define ESP32_COUNTER_GET_CLK_DIV(idx) \
260267
(((DT_INST_PROP(idx, prescaler) & UINT16_MAX) < 2) ? \
261268
2 : (DT_INST_PROP(idx, prescaler) & UINT16_MAX))
@@ -265,11 +272,11 @@ static void counter_esp32_isr(void *arg)
265272
static struct counter_esp32_data counter_data_##idx; \
266273
\
267274
static const struct counter_esp32_config counter_config_##idx = { \
268-
.counter_info = { \
269-
.max_top_value = UINT32_MAX, \
270-
.freq = (APB_CLK_FREQ / ESP32_COUNTER_GET_CLK_DIV(idx)), \
271-
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
272-
.channels = 1 \
275+
.counter_info = { \
276+
.max_top_value = UINT32_MAX, \
277+
.freq = (CLOCK_SOURCE_FREQ / ESP32_COUNTER_GET_CLK_DIV(idx)), \
278+
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
279+
.channels = 1 \
273280
}, \
274281
.config = { \
275282
.alarm_en = TIMER_ALARM_DIS, \

soc/espressif/common/Kconfig.defconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ config ISR_STACK_SIZE
2121
config ATOMIC_OPERATIONS_C
2222
default y
2323

24+
config XTAL_FREQ_HZ
25+
int
26+
default $(dt_node_int_prop_int,/cpus/cpu@0,xtal-freq)
27+
2428
config SYS_CLOCK_HW_CYCLES_PER_SEC
25-
default 12000000 if SOC_SERIES_ESP32C2
26-
default 16000000 if SOC_SERIES_ESP32C3 || SOC_SERIES_ESP32C6
29+
default 10400000 if XTAL_FREQ_HZ = 26000000
30+
default 16000000 if XTAL_FREQ_HZ = 40000000
2731

2832
config SYS_CLOCK_TICKS_PER_SEC
2933
default 1000

0 commit comments

Comments
 (0)