disable_irq for inline assembler has time limits.

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
pdbperks
Posts: 2
Joined: Mon May 28, 2018 7:31 pm

disable_irq for inline assembler has time limits.

Post by pdbperks » Tue May 29, 2018 9:27 pm

I have been playing with Roberthh's inline assembler code sample viewtopic.php?f=18&t=4238&start=10 to blink the onboard blue led on GPIO2.
I can have more blinks or longer flashes, but not both: disable_irq() helped increase the duration but too many loops and the board crashes. The code below blinks 10 times: if I increase loop count to 12, the program will crash. Any ideas?

def loop():
import machine
machine.Pin(2, machine.Pin.OUT, value=1)
isr = machine.disable_irq() # Disable interrupt requests
do_loop()
machine.enable_irq(isr)
print("loop done")

@micropython.asm_xtensa
def do_loop():
movi(a2, 0x60000330) # GPIO Pin2 address
movi(a5, 0) # p2 off
movi(a3, 10) # loop count
movi(a4, 1) # loop decrement also p2 on
label(loop_start)
s8i(a5, a2, 0) # turn off led
movi(a6, 0x4fffff) # delay loop
label(delay1)
sub(a6,a6,a4)
bnez(a6,delay1)
s8i(a4, a2, 0) # turn on led
movi(a6,0x8fffff) # delay loop
label(delay2)
sub(a6,a6,a4)
bnez(a6,delay2)
s8i(a5, a2, 0) # turn off led
sub(a3, a3, a4) # dec loop count
bnez(a3, loop_start)

Online
User avatar
Roberthh
Posts: 1009
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: disable_irq for inline assembler has time limits.

Post by Roberthh » Wed May 30, 2018 7:22 am

I would assume that this is the expected behaviour. Interrupts should be disabled for a minimal time only, in the range of clearly below 1 ms. if longer, you should get an watchdog reset. In the sample you cite I had a short burst of 10 pulse, total duration a few µs. Please consider, whether your code needs to disable the interrupts.

pdbperks
Posts: 2
Joined: Mon May 28, 2018 7:31 pm

Re: disable_irq for inline assembler has time limits.

Post by pdbperks » Wed May 30, 2018 11:14 am

The code is diagnostic. Inline assembler is probably not the best way to blink an led.
Without disabling the interrupts I was struggling to get a long enough blink to see the intervals. With disable_irq() (suggested by your viper example) I was able to get a sequence of visible blinks but the code still crashes if extended by number of blinks or length of blink.
I had then experimenting with extending loop times on Damien's Micro:Bit example https://github.com/bbcmicrobit/micropyt ... asmleds.py with no problems so I suspect this may just be expected behaviour for the ESP8266.
I am having fun trying to learn the intricacies of the inline assembler decorator: it is a great feature but not easy to find documentation. Your examples have been helpful.

Post Reply