QUERY · ISSUE
Performing operations on non-initialized Timer leads to crashes/lockups
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
This fixes #733.