summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2025-08-06 15:47:15 +1000
committerDamien George <damien@micropython.org>2025-08-07 16:55:23 +1000
commitce109af712452474dfe3864f82b5430f4e2a5ff0 (patch)
tree91c990177b7e89e507d36f932eebd824e432da4c
parentd5ecda05eb743839e9011f3d23657b39cd05e6c0 (diff)
esp32/machine_timer: Enable timer clock source for ESP32C6.
Otherwise the PLL is not enabled. These changes are adapted from `timer_legacy.h` in ESP-IDF. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
-rw-r--r--ports/esp32/machine_timer.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ports/esp32/machine_timer.c b/ports/esp32/machine_timer.c
index a104288f6..faa47d59a 100644
--- a/ports/esp32/machine_timer.c
+++ b/ports/esp32/machine_timer.c
@@ -38,6 +38,8 @@
#include "hal/timer_hal.h"
#include "hal/timer_ll.h"
#include "soc/timer_periph.h"
+#include "esp_private/esp_clk_tree_common.h"
+#include "esp_private/periph_ctrl.h"
#include "machine_timer.h"
#define TIMER_DIVIDER 8
@@ -163,8 +165,18 @@ static void machine_timer_isr_handler(machine_timer_obj_t *self) {
void machine_timer_enable(machine_timer_obj_t *self) {
// Initialise the timer.
timer_hal_init(&self->hal_context, self->group, self->index);
+
+ PERIPH_RCC_ACQUIRE_ATOMIC(timer_group_periph_signals.groups[self->index].module, ref_count) {
+ if (ref_count == 0) {
+ timer_ll_enable_bus_clock(self->index, true);
+ timer_ll_reset_register(self->index);
+ }
+ }
+
timer_ll_enable_counter(self->hal_context.dev, self->index, false);
+ esp_clk_tree_enable_src(GPTIMER_CLK_SRC_DEFAULT, true);
timer_ll_set_clock_source(self->hal_context.dev, self->index, GPTIMER_CLK_SRC_DEFAULT);
+ timer_ll_enable_clock(self->hal_context.dev, self->index, true);
timer_ll_set_clock_prescale(self->hal_context.dev, self->index, TIMER_DIVIDER);
timer_hal_set_counter_value(&self->hal_context, 0);
timer_ll_set_count_direction(self->hal_context.dev, self->index, GPTIMER_COUNT_UP);