Pi pico, micropython.asm_thumb: ADR Rd, <label> and LDR Rd, <label> not implemented? #12257
Replies: 5 comments 7 replies
-
Suggested workarounds may be here: How to load 32 bit constant from assembler with @micropython.asm_thumb - MicroPython Forum (Archive) |
Beta Was this translation helpful? Give feedback.
-
Hello @jc40h56, as it seems you are interested in getting the address of the actual machine code of your @micropython.viper
def rbit16_vip(v: int) -> int:
v = (v & 0x00ff) << 8 | (v & 0xff00) >> 8
v = (v & 0x0f0f) << 4 | (v & 0xf0f0) >> 4
v = (v & 0x3333) << 2 | (v & 0xcccc) >> 2
return (v & 0x5555) << 1 | (v & 0xaaaa) >> 1
def inspect(f, nbytes=16):
import machine
import array
import ubinascii
@micropython.asm_thumb
def dummy1():
pass
@micropython.viper
def dummy2() -> int:
return 0
if type(f) != type(dummy1) and type(f) != type(dummy2):
raise ValueError('expecting an inline-assembler or viper function')
baddr = bytes(array.array('O', [f]))
addr = int.from_bytes(baddr, 'little')
print('function object at: 0x%08x' % addr)
print('number of args: %u' % machine.mem32[addr + 4])
code_addr = machine.mem32[addr + 8]
print('machine code at: 0x%08x' % code_addr) # seems to fit even with viper : code begins with 'FE B5' and ends with 'FE BD'
print('-- code --')
for i in range(nbytes):
print('%02x' % machine.mem8[code_addr + i], end='')
print('\n----------')
def test():
inspect(rbit16_vip, 400)
test() You may have to try other values in To transplant this address into the interrupt vector table: There was an attempt of that already. Reportedly only partly successfull. |
Beta Was this translation helpful? Give feedback.
-
@jc40h56 A random thought. An ISR's return value is immaterial when run in response to an interrupt. I would guess that if you wrote your ISR so that it returned its own address, this wouldn't affect its runtime behaviour. The first instruction copies R15 (the PC) to another register (say R8). The last instruction copies R8 to R0 (the return value). So your Python code runs the ISR once to establish its location. Note this re using a suitable type hint. |
Beta Was this translation helpful? Give feedback.
-
For context the inline assembler supports a Many years ago I submitted a PR to fix this but it was never accepted - probably because it was something of a hack. |
Beta Was this translation helpful? Give feedback.
-
I never investigated writing ISR's in Assembler - it's long struck me as an interesting idea, but I've never had a requirement. I'm surprised you have found it necessary for a quadrature encoder. You might like to look at this solution (docs, code). The ISR's run in 36μs (dependent on platform). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Micropython Pico H version 1.20.0 using Thonny
I'm trying to set up Timer-based interrupts using @micropython.asm_thumb, but can't find a way to read the address of the interrupt handling code to put in the interrupt vector table.
It seems like LDR is not set up to work with < label > , and ADR is not implemented at all?
I'm new to this so maybe I'm missing something obvious?
Are there any tricks to get around this?
Thanks!
results in "SyntaxError: unsupported Thumb instruction 'ldr' with 2 arguments"
SyntaxError: unsupported Thumb instruction 'adr' with 2 arguments
Beta Was this translation helpful? Give feedback.
All reactions