← index #1128PR #735
Related · high · value 0.125
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 · PULL REQUEST

Add timer_deinit and call it just before doing a soft-restart

mergedby dhylandsopened 2014-06-30updated 2015-11-08

This fixes #733.

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