← index #1128Issue #8934
Related · high · value 0.390
QUERY · ISSUE

Performing operations on non-initialized Timer leads to crashes/lockups

openby nadrimajstoropened 2015-02-22updated 2015-10-25
ports

After pressing RESET button and typing:

Micro Python v1.3.10 on 2015-02-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> n = 3
>>> def countdown(timer):
...     global n
...     if n <= 0:
...         print("Launch!")
...         timer.deinit()
...     else:
...         print(n)
...         n -= 1
... 
>>> tim = pyb.Timer(4, freq=1, callback=countdown)

At this moment REPL hangs and I need to press RESET to recover. :cry:

Probably related issue:

Micro Python v1.3.10 on 2015-02-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> n = 3
>>> def countdown(timer):
...     global n
...     if n <= 0:
...         print("Launch!")
...         timer.deinit()
...     else:
...         print(n)
...         n -= 1
... 
>>> tim = pyb.Timer(4)
>>> tim.callback(countdown)
>>> tim.init(freq=1)
>>> # Nothing happens :|

Nevertheless it does work if I continue and provide both kwargs:

>>> tim.init(freq=1, callback=countdown)
3
>>> 2
1
Launch!

However, if I continue with:

>>> tim.deinit()
>>> tim.callback(countdown)
>>> Launch!

I did not expect after issuing deinit() to have triggered callbacks without explicitly calling init with freq kwarg. :confused:
And after issuing a soft reset

PYB: sync filesystems
PYB: soft reboot
Micro Python v1.3.10 on 2015-02-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> tim = pyb.Timer(4, callback=print("I did not set freq option"))
I did not set freq option
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must specify either freq, or prescaler and period
>>> tim = pyb.Timer(4)
>>> tim.callback(print("I did not set freq option"))
I did not set freq option
>>> 

It certainly comes as a surprise that callback is still kicking without explicit freq

CANDIDATE · ISSUE

Timer: deinit(): lag

closedby PrimeTime416opened 2022-07-20updated 2022-07-23
port-esp32

Hello I was wonders if there is lag when de-initialising the timer at faster PERIODs < 5ms; in my application I require the faster period, please let me know if this is expected? If said behaviour expected I suppose I can use the counter_en return value to stop my code as needed? Thanks Team.

`from machine import Timer, freq
print(freq()) # get the current frequency of the CPU
freq(240000000) # set the CPU frequency to 240 MHz
print(freq())

count = 0
timeX = Timer(1)

def timer_callback(t):
print(t)
global count
print(count)
count += 1
if (count == 50):
timeX.deinit()

timeX.init(mode=Timer.PERIODIC, period=5, callback=timer_callback)`

Lag: Count should stop at 49 but goes to 53 when period=5
image

Good: Works great stops at 49 for period=10
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