Losing the REPL when an IRQ is triggered
Re: Losing the REPL when an IRQ is triggered
@holdenweb I get these same issues with timer irqs and the REPL (usually via station-mode WiFi in my case).
I've tried several variations, including different timers, 16 bit and 32 bit, and irq handlers (always very simple, and fine when called directly).
Does anyone know if there's a fundamental issue with timer irqs and the REPL please?
I'm running MicroPython v1.8.3-17-g2196799 on 2016-08-15; WiPy with CC3200, and I got the same with v1.8.2.
Thanks,
Jim
I've tried several variations, including different timers, 16 bit and 32 bit, and irq handlers (always very simple, and fine when called directly).
Does anyone know if there's a fundamental issue with timer irqs and the REPL please?
I'm running MicroPython v1.8.3-17-g2196799 on 2016-08-15; WiPy with CC3200, and I got the same with v1.8.2.
Thanks,
Jim
Re: Losing the REPL when an IRQ is triggered
Thanks for the input. I haven't made any progress on this, so I am hoping someone with the ability to debug the implementation will be able to explain what blocks the REPL.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Losing the REPL when an IRQ is triggered
Is it reasonable to expect code to run 'in the background' concurrently with the REPL? Perhaps Dave (@dhylands) can comment. Every application I've written with interrupts has a main loop which runs while the interrupts are handled and exchanges data with the interrupt handlers. When the program terminates (whether by design, by ctrl-C or by throwing an exception) the REPL returns.
At this point the object whose method is the interrupt handler will be out of scope: the handler must stop running at this point. After all, an object whose method is an interrupt handler could go out of scope in the course of program execution whereupon its presence in RAM could be garbage collected. MicroPython must handle this auto-magically.
So the 'normal' state of affairs is (presumably) that when the REPL is present interrupt handlers cease being called.
At this point the object whose method is the interrupt handler will be out of scope: the handler must stop running at this point. After all, an object whose method is an interrupt handler could go out of scope in the course of program execution whereupon its presence in RAM could be garbage collected. MicroPython must handle this auto-magically.
So the 'normal' state of affairs is (presumably) that when the REPL is present interrupt handlers cease being called.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Losing the REPL when an IRQ is triggered
Interrupt will keep running when you return to the REPL, up until the time you hit Control-D.
The objects associated with the interrupt handlers will still be "in scope" and will be consuming memory from the heap, since they can't be GC'd (the timer still has a pointer to the callback routine).
On the pyboard, for example, you can do something like this: and you'll see dots printed while you're at the REPL. You can still use the REPL: I'm not familiar enough with the WiPy to know whether having the interrupts still running when you get to the REPL will be problematic or not.
The objects associated with the interrupt handlers will still be "in scope" and will be consuming memory from the heap, since they can't be GC'd (the timer still has a pointer to the callback routine).
On the pyboard, for example, you can do something like this:
Code: Select all
pyb.Timer(2, freq=4, callback=lambda t: print('.', end=''))
Code: Select all
>>> pyb.Timer(2, freq=4, callback=lambda t: print('.', end=''))
Timer(2, freq=4, prescaler=0, period=10499999, mode=UP, div=1)
>>> .........p.r.int....(..'..t.his. i.s .a ..t.es.t..'..).
this is a test
>>> ..........................................
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Losing the REPL when an IRQ is triggered
Interesting! Thank you. I suspect that, depending on the application, that feature could bite back - I'd naively assumed that ctrl-C stopped everything in its tracks. Do you think I should update the "Writing interrupt handlers" doc?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Losing the REPL when an IRQ is triggered
It's probably worth mentioning.
For interrupts which are self-contained (like a LED flasher or my dot-printer example) the interrupt will just happily continue.
For interrupts which generate data and need somebody to consume that data (or the inverse), you could have interesting issues depending on how the interrupt handler is coded.
For interrupts which are self-contained (like a LED flasher or my dot-printer example) the interrupt will just happily continue.
For interrupts which generate data and need somebody to consume that data (or the inverse), you could have interesting issues depending on how the interrupt handler is coded.
-
- Posts: 7
- Joined: Sun Aug 28, 2016 9:21 pm
Re: Losing the REPL when an IRQ is triggered
Has anyone definitively gotten this to work on the WiPy?
I'm using the expansion board with this code:
What's weird is that about 1 out of every 4 times, the above doesn't lock up the REPL/Telnet/FTP on the first button push. The second button push does lock REPL/Telnet/FTP up.
I can still see "callback" whenever I push the button but no serial REPL, Telnet and FTP access.
I'm still fiddling with various permutations but so far no luck.
Thanks,
aw
I'm using the expansion board with this code:
Code: Select all
from machine import Pin
def pincb(pin):
print("callback")
return
pin_int = Pin('GP17', Pin.IN, Pin.PULL_UP)
pin_int.irq(trigger=Pin.IRQ_FALLING, handler=pincb)
I can still see "callback" whenever I push the button but no serial REPL, Telnet and FTP access.
I'm still fiddling with various permutations but so far no luck.
Thanks,
aw
Re: Losing the REPL when an IRQ is triggered
Have you tried toggling an LED instead of printing something. It's possible that printing from inside the IRQ is what's causing the problem.
-
- Posts: 7
- Joined: Sun Aug 28, 2016 9:21 pm
Re: Losing the REPL when an IRQ is triggered
This is exhibiting the same behavior:
I also tried a return in pincb but that did not work either.
Thanks,
aw
Code: Select all
from machine import Pin
led=Pin('GP16', Pin.OUT)
pin_int = Pin('GP17', Pin.IN, Pin.PULL_UP)
def pincb(pin):
global led
led.toggle()
pin_int.irq(trigger=Pin.IRQ_FALLING, handler=pincb)
Thanks,
aw
Re: Losing the REPL when an IRQ is triggered
Are there any news regarding this topic?