From 7fe7c55bb817c88981b1b237a8b4fa7762ff107a Mon Sep 17 00:00:00 2001 From: Brian Cooke Date: Fri, 18 Nov 2022 13:40:05 +0100 Subject: [PATCH] esp32/machine_timer: Fix ESP32C3 timer period doubling. The original ESP32 only supports timer source clock APB so it doesn't need and doesn't have a clk_src field. The ESP32C3 supports timer source clock APB and XTAL so it does have a clk_src field, and this needs to be configured to get the correct period. Fixes #8084. --- ports/esp32/machine_timer.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/esp32/machine_timer.c b/ports/esp32/machine_timer.c index 83fe81f6ee..c66cb2a48d 100644 --- a/ports/esp32/machine_timer.c +++ b/ports/esp32/machine_timer.c @@ -189,6 +189,9 @@ STATIC void machine_timer_enable(machine_timer_obj_t *self) { config.divider = TIMER_DIVIDER; config.intr_type = TIMER_INTR_LEVEL; config.counter_en = TIMER_PAUSE; + #if SOC_TIMER_GROUP_SUPPORT_XTAL + config.clk_src = TIMER_SRC_CLK_APB; + #endif check_esp_err(timer_init(self->group, self->index, &config)); check_esp_err(timer_set_counter_value(self->group, self->index, 0x00000000));