← index #7871Issue #16438
Related · high · value 2.998
QUERY · ISSUE

ESP32C3 timer issue

openby bdambrosioopened 2021-10-02updated 2026-03-24
port-esp32

When using the micropython ble repl example (works on regular esp32), I receive the following error:
dupterm: Exception in write() method, deactivating: Traceback (most recent call last):
File "bluetooth_repl.py", line 74, in write
File "bluetooth_repl.py", line 29, in schedule_in
OSError: (-258, 'ESP_ERR_INVALID_ARG')

this traces back to:
_timer.init(mode=machine.Timer.ONE_SHOT, period=delay_ms, callback=_wrap)

I have tried creating timers from repl for the ESP32C3, and always get the error above on calling init, regardless of the subset of arguments provided or the values used. For reference:

from machine import Timer
t1=Timer(-1)
t1
Timer(3fccd9c0; alarm_en=1073741823, auto_reload=1070351008, counter_en=1070350504)
t1.init(mode=Timer.ONE_SHOT, period=10, callback=p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: (-258, 'ESP_ERR_INVALID_ARG')

I realize C3 support is a work in progress, and am delighted overall, tnx! Perhaps the timers aren't fully supported yet on this device?

tnx

CANDIDATE · ISSUE

ESP32C6 Timers: Only Timer(0) and Timer(2) are functional for ESP32-C6 v1.24

closedby mattklapmanopened 2024-12-17updated 2024-12-20
bug

Port, board and/or hardware

esp32-c6, generic board

MicroPython version

Micropython 1.24 custom compile only adding graphics library that does not use timer

Reproduction

not (likely) a build issue (I did not test on stock release firmware)

Expected behaviour

examples from Micropython documentation on Timer class:

WORKS CORRECTLY:
from machine import Timer
tim0 = Timer(0)
tim0.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(0))

FAILS:
from machine import Timer
tim1 = Timer(1)
tim1.init(period=2000, mode=Timer.ONE_SHOT, callback=lambda t:print(1))

WORKS CORRECTLY:
from machine import Timer
tim2 = Timer(2)
tim2.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(2))

FAILS:
from machine import Timer
tim3 = Timer(3)
tim3.init(period=2000, mode=Timer.ONE_SHOT, callback=lambda t:print(3))

Observed behaviour

code for Timer0 returns a '0'
code for Timer1 returns nothing
code for Timer2 returns a '2'
code for Timer3 returns nothing

Additional Information

The fix is to make the timer code for the ESP32-C6 behave like the ESP32-C3:

it appears the fix should be in the esp32 port file machine_timer.c line 79 which should be changed from:
#if CONFIG_IDF_TARGET_ESP32C3
to
#if CONFIG_IDF_TARGET_ESP32C3 or CONFIG_IDF_TARGET_ESP32C6 (or something like that because I do not know the syntax)

Code of Conduct

Yes, I agree

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