Skip to content

Commit ce109af

Browse files
projectgusdpgeorge
authored andcommitted
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>
1 parent d5ecda0 commit ce109af

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ports/esp32/machine_timer.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "hal/timer_hal.h"
3939
#include "hal/timer_ll.h"
4040
#include "soc/timer_periph.h"
41+
#include "esp_private/esp_clk_tree_common.h"
42+
#include "esp_private/periph_ctrl.h"
4143
#include "machine_timer.h"
4244

4345
#define TIMER_DIVIDER 8
@@ -163,8 +165,18 @@ static void machine_timer_isr_handler(machine_timer_obj_t *self) {
163165
void machine_timer_enable(machine_timer_obj_t *self) {
164166
// Initialise the timer.
165167
timer_hal_init(&self->hal_context, self->group, self->index);
168+
169+
PERIPH_RCC_ACQUIRE_ATOMIC(timer_group_periph_signals.groups[self->index].module, ref_count) {
170+
if (ref_count == 0) {
171+
timer_ll_enable_bus_clock(self->index, true);
172+
timer_ll_reset_register(self->index);
173+
}
174+
}
175+
166176
timer_ll_enable_counter(self->hal_context.dev, self->index, false);
177+
esp_clk_tree_enable_src(GPTIMER_CLK_SRC_DEFAULT, true);
167178
timer_ll_set_clock_source(self->hal_context.dev, self->index, GPTIMER_CLK_SRC_DEFAULT);
179+
timer_ll_enable_clock(self->hal_context.dev, self->index, true);
168180
timer_ll_set_clock_prescale(self->hal_context.dev, self->index, TIMER_DIVIDER);
169181
timer_hal_set_counter_value(&self->hal_context, 0);
170182
timer_ll_set_count_direction(self->hal_context.dev, self->index, GPTIMER_COUNT_UP);

0 commit comments

Comments
 (0)