PIO micropython pico simple jmp() stops PIO state machine??? #12770
Replies: 3 comments 1 reply
-
I realised that I had failed to put nop() in one place: This now loops repeatedly. This behaviour strikes me as potentially a micropython bug. Maybe there's a technical explanation for why it does this, but to a newbie this behaviour looks just plain wrong :-( Any thoughts anybody??? Thanks |
Beta Was this translation helpful? Give feedback.
-
You may want to look very hard at the discussion of PIO instructions in the rp2040 manual. I haven't refreshed my memory right now, but IIRC there is a weird interaction between jmp targets and the wrap target at the end of a program. I don't think you are seeing a micropython bug, but a PIO subtlety. |
Beta Was this translation helpful? Give feedback.
-
Yes - have a look at .wrap in rp2040 manual p317 in the online version. This marks the end of the PIO code and it will automatically wrap the beginning when the last instruction, so marked, is executed - but not if the last instruction is an unconditional jump or conditional jump where the condition is satisfied. In that case the jump target takes precedence. '.wrap' or wrap() in MicroPython is automatically applied to the last instruction if you don't specify it. Effectively the wrap marker is stored outside the program so that you don't need to use a valuable memory location to store the jump back to the beginning. 'nop()' isn't a jump so when wrap() is applied to it automatically it behaves as expected. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I was trying to write a simple PIO routine to detect a break sensor on a GPIO pin; calling back to micropython using an IRQ, but it just never seemed to trigger.
I boiled the code down to bare basics to try to figure out what was going on.
def irq_test():
irq(1)
jmp("continueloop")
label("continueloop")
This calls the interrupt hooked up function once and then never again. Maybe the state machine stops???
If I remove the jmp, ie.
def irq_test():
irq(1)
label("continueloop")
It calls the interrupt hooked up function repeatedly, as you would expect. (the reason for the jmp is that that is the place where the jmp test on GPIO input pin would be, but I was trying to boil things down to see why it wasn't working)
I have stuffed nop() [31]s in everywhere and that made no difference.
Does a jmp() do more than simply move execution to another point in the code?
Is it a bug in micropython implementation?
Am I missing something fundamental? (for sure yes, but specifically in my understanding here :-) ?!)
Thanks
Beta Was this translation helpful? Give feedback.
All reactions