Skip to content

Commit 1360584

Browse files
robert-hhdpgeorge
authored andcommitted
esp32/machine_timer: Restrict timer numbers for ESP32C6 to 0 and 1.
The ESP32C6 has only one timer in each of the two groups. Also add a check for valid timer numbers. Addresses issue micropython#16438. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent 8b6bd43 commit 1360584

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ports/esp32/machine_timer.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
6666
machine_timer_obj_t *self = self_in;
6767
qstr mode = self->repeat ? MP_QSTR_PERIODIC : MP_QSTR_ONE_SHOT;
6868
uint64_t period = self->period / (TIMER_SCALE / 1000); // convert to ms
69-
#if CONFIG_IDF_TARGET_ESP32C3
69+
#if SOC_TIMER_GROUP_TIMERS_PER_GROUP == 1
7070
mp_printf(print, "Timer(%u, mode=%q, period=%lu)", self->group, mode, period);
7171
#else
7272
mp_printf(print, "Timer(%u, mode=%q, period=%lu)", (self->group << 1) | self->index, mode, period);
@@ -76,7 +76,7 @@ static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
7676
machine_timer_obj_t *machine_timer_create(mp_uint_t timer) {
7777

7878
machine_timer_obj_t *self = NULL;
79-
#if CONFIG_IDF_TARGET_ESP32C3
79+
#if SOC_TIMER_GROUP_TIMERS_PER_GROUP == 1
8080
mp_uint_t group = timer & 1;
8181
mp_uint_t index = 0;
8282
#else
@@ -108,7 +108,11 @@ static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
108108
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
109109

110110
// Create the new timer.
111-
machine_timer_obj_t *self = machine_timer_create(mp_obj_get_int(args[0]));
111+
uint32_t timer_number = mp_obj_get_int(args[0]);
112+
if (timer_number >= SOC_TIMER_GROUP_TOTAL_TIMERS) {
113+
mp_raise_ValueError(MP_ERROR_TEXT("invalid Timer number"));
114+
}
115+
machine_timer_obj_t *self = machine_timer_create(timer_number);
112116

113117
if (n_args > 1 || n_kw > 0) {
114118
mp_map_t kw_args;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy