; ARM assembly tutorial for Asmonite, example 04: on, off, again (Raspberry Pi Pico 2, Arm Cortex-M33).
; Adapted from the ARM-ASM-Tutorial by Niklas Guertler (examples Blink and Blink2); see LICENSE.txt.
;
; The LED is switched on and off in an endless loop. It runs so fast that the LED looks dimly lit: step
; through the loop with F7 and watch it change. 05_blink_delay.asm adds the waiting.
.target pico2
.arch thumb
.imagebase 0x20000000

_start:
    ldr  r1, resets_clr
    ldr  r0, reset_bits
    str  r0, [r1]               ; IO_BANK0 and PADS_BANK0 out of reset
    ldr  r1, resets_done
wait_reset:
    ldr  r2, [r1]
    and  r2, r2, r0
    cmp  r2, r0
    bne  wait_reset
    ldr  r1, pad25_clr
    mov  r0, #0x100
    str  r0, [r1]               ; pad of GPIO 25: no isolation
    ldr  r1, gpio25_ctrl
    movs r0, #5
    str  r0, [r1]               ; GPIO 25: SIO
    ldr  r1, sio_oe_set
    ldr  r0, led_bit
    str  r0, [r1]               ; GPIO 25: output

blink_loop:
    ldr  r1, sio_out_set
    ldr  r0, led_bit
    str  r0, [r1]               ; LED on
    ldr  r1, sio_out_clr
    ldr  r0, led_bit
    str  r0, [r1]               ; LED off
    b    blink_loop

    align 4
resets_clr:  dd 0x40023000
reset_bits:  dd 0x00000240
resets_done: dd 0x40020008
pad25_clr:   dd 0x4003b068
gpio25_ctrl: dd 0x400280cc
sio_oe_set:  dd 0xd0000038
sio_out_set: dd 0xd0000018      ; SIO.GPIO_OUT_SET
sio_out_clr: dd 0xd0000020      ; SIO.GPIO_OUT_CLR
led_bit:     dd 0x02000000
