I am starting to learn assembly language and ARM using the raspberry pi pico.
I have even been following the book RP2040 Assembly Language programming but there is no instruction about how to read an input pin using only assembly.
Here is my set up: I have a push button that send 3,3V when not pressed and 0V when pressed.
I would like to be able to read the different states this has using a GPIO pin but despite looking into the functions of the datasheet (that I barely understand as it's the first time i'm dealing with it), I don't know if what I am doing makes sense.
Here is my code:
led_loop:
@ set the control for the push
ldr r0, =ctrl2 @ control register for GPIO1 0x40014008
mov r1, #5 @ Function 5, select SIO for GPIO1 2.19.2
str r1, [r0] @ Store function_5 in GPIO1 control register
@ shifts over "1" the number of bits of GPIO pin
mov r2, #1 @ load a 1 into register 1
lsl r2, r2, #1 @ move the bit over to align with GPIO1
ldr r0, =sio_base @ SIO base 0xd0000000
str r1, [r0, #0x00000004] @ 0x004 GPIO input enable
ldr r0, =helloworld
BL printf
b led_loop @ do the loop again
.data
.align 4
helloworld: .asciz "Hello World %d\n"
So far I tried to consult the datasheet but I do not have enough knowledge to recognize if what I am doing is write or wrong.
You are on the right track but appear to be using wrong register values or using them the wrong way. You have a printf so that is very odd, and implies you have a ton, ton, more code which may or may not be helping.
This is C and uses the led on the original picos, which not sure if that is the case anymore.
finding all of those addresses and info strictly from docs is, well...
PUT32 is just a store word and GET32 is just a load word. and delay is just a counting to zero loop.
GPIO generally defaults/resets to inputs, the clearing of the out/oe and making it an input I probably got directly from their libraries, is it required? Do not know, could probably read those registers and see.
You do need to release reset on the I/O block for sure, so maybe you are doing that elsewhere.
The above blinks the led 5 times and then goes into a polling loop reading the gpio and isolating gpio 1 if high then light the led if low then not.
Trivial to convert this to asm and should be able to see the differences in what you did and what I did and decide if you need to clear the out/oe settings. You had wrong addresses and were writing things you should be reading and IO block out of reset at a minimum.