diff options
author | robert-hh <robert@hammelrath.com> | 2025-03-29 09:12:28 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-05-14 11:58:36 +1000 |
commit | 1d4bf8ac40236e22d0a67b103b4330d1ee6659d4 (patch) | |
tree | c0754f9c1e93b851d058def2a380209e3f657f12 | |
parent | d7371124d288cc85d2386b63ea39cfa4fa803194 (diff) |
esp32/machine_timer: Fix timer.value() for an uninitialized timer.
Raises a value error in that case, which happens after a timer was created
but not initialized, or after calling `timer.deinit()`.
Fixes issue #17033.
Signed-off-by: robert-hh <robert@hammelrath.com>
-rw-r--r-- | ports/esp32/machine_timer.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/ports/esp32/machine_timer.c b/ports/esp32/machine_timer.c index 82b432bba..34d49c79d 100644 --- a/ports/esp32/machine_timer.c +++ b/ports/esp32/machine_timer.c @@ -246,6 +246,9 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init) static mp_obj_t machine_timer_value(mp_obj_t self_in) { machine_timer_obj_t *self = self_in; + if (self->handle == NULL) { + mp_raise_ValueError(MP_ERROR_TEXT("timer not set")); + } uint64_t result = timer_ll_get_counter_value(self->hal_context.dev, self->index); return MP_OBJ_NEW_SMALL_INT((mp_uint_t)(result / (TIMER_SCALE / 1000))); // value in ms } |