← index #9674PR #16996
Off-topic · high · value 6.668
QUERY · ISSUE

ESP32_C3: timer_group: timer_init(271): HW TIMER NUM ERROR

openby iBoundaryopened 2022-10-19updated 2026-03-19
bugport-esp32

from machine import*
tim = Timer(-1)
tim.init(period=1000,callback = lambda t:print('rtos'))
E (6078630) timer_group: timer_init(271): HW TIMER NUM ERROR
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: (-258, 'ESP_ERR_INVALID_ARG')

I found out that virtual timer is not available in ESP32_C3 chip.

CANDIDATE · PULL REQUEST

ports/stm32/timer.c: Add support for STM32H5 Timer 1.

mergedby mattytrentiniopened 2025-03-23updated 2025-04-03
port-stm32

Summary

The STM32H5 build was lacking support for timer 1 (TIM1). The micro has hardware support for Timer 1 but MicroPython wasn't correctly configured to use it. Instead, when trying to construct the timer, a ValueError would occur:

>>> from pyb import Timer
>>> Timer(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Timer(1) doesn't exist

After integrating this PR:

>>> from pyb import Timer
>>> Timer(1)
Timer(1)

Testing

Tested PWM using Timer 1 on the Nucleo H563ZI.

All Timers appear to be instantiated correctly now:

=== from pyb import Timer
=== timers = []
=== for x in range(24):
===     try:
===         timers.append(Timer(x))
===     except ValueError as e:
===         print(e)
===
=== print(timers)
===
Timer(0) doesn't exist
Timer(9) doesn't exist
Timer(10) doesn't exist
Timer(11) doesn't exist
Timer(18) doesn't exist
Timer(19) doesn't exist
Timer(20) doesn't exist
Timer(21) doesn't exist
Timer(22) doesn't exist
Timer(23) doesn't exist
[Timer(1), Timer(2), Timer(3), Timer(4), Timer(5), Timer(6), Timer(7), Timer(8), Timer(12), Timer(13), Timer(14), Timer(15), Timer(16), Timer(17)]

Extra detail

The Datasheet's (DS14151 or DS14258 depending on the specific H5) show TIM1 as a 16bit advanced timer:

image

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied