Where can we find information about the inline assembler for Pico?
Where can we find information about the inline assembler for Pico?
Hi,
I would like to do something with ADC and the inline assembler.
I am starting with the tutorial: http://docs.micropython.org/en/v1.9.3/p ... mbler.html
Where can I find such information like the equivalent for Pico for "stm.GPIOA"?
"rp2.GPIO" does not work.
movw does not work. - That seems to be because it is M0.
How can I load a 32bit constant into a register? ==> Solved via array of constants
Thanks for some hints!
Christof
I would like to do something with ADC and the inline assembler.
I am starting with the tutorial: http://docs.micropython.org/en/v1.9.3/p ... mbler.html
Where can I find such information like the equivalent for Pico for "stm.GPIOA"?
"rp2.GPIO" does not work.
movw does not work. - That seems to be because it is M0.
How can I load a 32bit constant into a register? ==> Solved via array of constants
Thanks for some hints!
Christof
Last edited by cebersp on Wed Feb 24, 2021 10:19 am, edited 1 time in total.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Where can we find information about the inline assembler for Pico?
There is also this doc. I haven't studied the Pico closely, there may well be incompatibilities besides the obvious one that the floating point instructions won't be supported.
If movw doesn't work then you could pass constants as args. In some of my code I pass an array of constants as a single arg which can then be accessed because arrays are stored in contiguous locations. Example code may be found in these repos fourier transforms and FIR filters.
A long time ago I submitted this PR to simplify access to data created with data statements, but it was not accepted. The data statement works but is hard to use in normal code.
If movw doesn't work then you could pass constants as args. In some of my code I pass an array of constants as a single arg which can then be accessed because arrays are stored in contiguous locations. Example code may be found in these repos fourier transforms and FIR filters.
A long time ago I submitted this PR to simplify access to data created with data statements, but it was not accepted. The data statement works but is hard to use in normal code.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Where can we find information about the inline assembler for Pico?
Thanks, Peter,
"an array of constants " - this is a good idea!
I was not able to use data().
Then I passed the address as an argument. But my even bigger problem was, that I was not able to find the information in the rp2040 datasheet, how to just set the output bit of the Pin. Funny: The instruction set of M0 seems to be not too difficult to understand. But these hardware pin control registers....
Christof
Edit: A fresh day, will try Bits OUTOVER in GPIO25_CTRL...
"an array of constants " - this is a good idea!
I was not able to use data().
Then I passed the address as an argument. But my even bigger problem was, that I was not able to find the information in the rp2040 datasheet, how to just set the output bit of the Pin. Funny: The instruction set of M0 seems to be not too difficult to understand. But these hardware pin control registers....
Christof
Edit: A fresh day, will try Bits OUTOVER in GPIO25_CTRL...
Last edited by cebersp on Wed Feb 24, 2021 8:36 am, edited 1 time in total.
Re: Where can we find information about the inline assembler for Pico?
I bought: Amazon: "MicroPython Inline Assembler By Example (English Edition) Kindle Ausgabe"
But it it is not very helpful for Pico.
But it it is not very helpful for Pico.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Where can we find information about the inline assembler for Pico?
Well the Pico chip is very new.
To make a very general point there is now a mechanism for creating loadable native C modules. You write code in C with specific interface features, then compile it to a .mpy file. It works well on the Pyboard. Given that the Pico arch is ARM I thought it might work on the Pico. But a quick test indicates it does not. I have raised an issue. Hopefully it will get well soon.
My DFT assembler code is optimised for ease of coding rather than performance but it is slower than the C code in numpy. The C compiler is evidently good at optimisation. So the justification for assembler is rather less than it was when I wrote those libraries.
None of which helps in accessing these peripherals, I'm afraid
To make a very general point there is now a mechanism for creating loadable native C modules. You write code in C with specific interface features, then compile it to a .mpy file. It works well on the Pyboard. Given that the Pico arch is ARM I thought it might work on the Pico. But a quick test indicates it does not. I have raised an issue. Hopefully it will get well soon.
My DFT assembler code is optimised for ease of coding rather than performance but it is slower than the C code in numpy. The C compiler is evidently good at optimisation. So the justification for assembler is rather less than it was when I wrote those libraries.
None of which helps in accessing these peripherals, I'm afraid
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Where can we find information about the inline assembler for Pico?
Ha, got it working, the most complicated way of blinking a LED!
It works via "SIO" chapter 2.3.1.2.
It works via "SIO" chapter 2.3.1.2.
Code: Select all
title= "inlineC.py" # http://docs.micropython.org/en/v1.9.3/pyboard/pyboard/tutorial/assembler.html
from rp2 import *
from machine import *
from time import *
import uarray
led= Pin(25,Pin.OUT)
led(1)
#sleep(2)
led(0)
@micropython.asm_thumb # works
def fun():
mov(r0, 42) # movw hat nicht funktioniert
add(r0, r0, 7) # nur kleine Werte <8
@micropython.asm_thumb # works
def asm_add(r0, r1):
add(r0, r0, r1)
regdata = uarray.array('i',[
0xd0000000 + 0x010, # 0 SIO OUT
0xd0000000 + 0x018, # 4 SIO OUT_CLR
0xd0000000 + 0x014, # 8 SIO OUT_SET
1<<25 # 12 LED
])
@micropython.asm_thumb
def led_peek(r0):
mov(r1,r0)
ldr(r2,[r1,0]) # register adress
ldr(r0,[r2,0])
@micropython.asm_thumb
def led_on(r0):
mov(r1,r0)
ldr(r2,[r1,8]) # register address
ldr(r0,[r1,12]) # mask data
str(r0,[r2,0])
@micropython.asm_thumb
def led_off(r0):
mov(r1,r0)
ldr(r2,[r1,4]) # register address
ldr(r0,[r1,12]) # mask data
str(r0,[r2,0])
print(title, fun(), asm_add(20_000_000,30))
print(led_peek(regdata))
print(led_on(regdata))
print(led_peek(regdata))
sleep(2)
print(led_off(regdata))
print(led_peek(regdata))
push - Solved
Hi,
if i write
I get:
"Traceback (most recent call last):
File "<stdin>", line 47, in dds
SyntaxError: unsupported Thumb instruction 'push' with 1 arguments"
For pop({r8,r9}) it is the same.
What's wrong here? - Solved: Only r0....r7 is supported at M0+.
Thank you very much! Christof
if i write
Code: Select all
@micropython.asm_thumb
def dds(r0, r1): # Buffer, ctrl-array
push({r8,r9})
...
"Traceback (most recent call last):
File "<stdin>", line 47, in dds
SyntaxError: unsupported Thumb instruction 'push' with 1 arguments"
For pop({r8,r9}) it is the same.
What's wrong here? - Solved: Only r0....r7 is supported at M0+.
Thank you very much! Christof
Last edited by cebersp on Wed Mar 03, 2021 10:19 am, edited 1 time in total.
Re: Where can we find information about the inline assembler for Pico?
Regarding push and pop:
Can I use this code from https://github.com/peterhinch/micropyth ... ter/asm.py on Pico M0+??
EDIT: Tried it, it crashes. Even without using these registers.
Can I use this code from https://github.com/peterhinch/micropyth ... ter/asm.py on Pico M0+??
EDIT: Tried it, it crashes. Even without using these registers.
Code: Select all
# Make r8-r11 safe to use by pushing them on the stack
@micropython.asm_thumb
def foo(r0):
data(2, 0xe92d, 0x0f00) # push r8,r9,r10,r11
mov(r8, r0) # Would otherwise crash the board!
data(2, 0xe8bd, 0x0f00) # pop r8,r9,r10,r11
Re: Where can we find information about the inline assembler for Pico?
OK, found it. Push and pop can only be used on low registers r0...r7. (((PUSH {<loreglist>})))
This seems to work:
This seems to work:
Code: Select all
mov(r5,r8)
mov(r6,r9)
mov(r7,r10)
push({r5,r6,r7})
.....
pop({r5,r6,r7})
mov(r8,r5)
mov(r9,r6)
mov(r10,r7)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Where can we find information about the inline assembler for Pico?
The MicroPython inline assembler supports a subset of the Thumb 7 instruction set. I gather the rp2 arch is Thumb 6.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.