Page 1 of 1

disable_irq for inline assembler has time limits.

Posted: Tue May 29, 2018 9:27 pm
by pdbperks
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
print("loop done")

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
s8i(a5, a2, 0) # turn off led
movi(a6, 0x4fffff) # delay loop
s8i(a4, a2, 0) # turn on led
movi(a6,0x8fffff) # delay loop
s8i(a5, a2, 0) # turn off led
sub(a3, a3, a4) # dec loop count
bnez(a3, loop_start)

Re: disable_irq for inline assembler has time limits.

Posted: Wed May 30, 2018 7:22 am
by Roberthh
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.

Re: disable_irq for inline assembler has time limits.

Posted: Wed May 30, 2018 11:14 am
by pdbperks
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 ... 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.