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 · ISSUE
Timer interrupts aren't disabled on a soft reboot
If I run the following on y pyboard:
import pyb
class Heartbeat(object):
def __init__(self):
self.tick = 0
self.led = pyb.LED(4) # 4 = Blue
tim = pyb.Timer(4)
tim.init(freq=10)
tim.callback(self.heartbeat_cb)
def heartbeat_cb(self, tim):
if self.tick <= 3:
self.led.toggle()
self.tick = (self.tick + 1) % 10
Heartbeat()
then do:
import heartbeat_irq
everything works as normally. However, if I press Control-D to do a soft-reboot, the REPL locks up and I have to press the RESET button to recover.