commit 4db5a73bf8811b1e44c1cc5ef977f525f5723afa
parent 0910282b64f2b903349da9cfb91f0e7725115df8
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 13 Aug 2025 07:47:59 +0900
enable sio
Diffstat:
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/ex3_spi/main.s b/ex3_spi/main.s
@@ -68,11 +68,24 @@ unreset_chk:
// set gpio functions
ldr r3, io_bank0_base
+ // set pins 0 and 1 for uart
mov r0, #2 // uart0
mov r1, #0x4
str r0, [r3, r1] // IO_BANK0: GPIO0_CTRL
mov r1, #0xc
str r0, [r3, r1] // IO_BANK0: GPIO1_CTRL
+ // set pins 24 and 25 to SIO for led blink.
+ mov r0, #5 // sio
+ mov r1, #0xc4
+ str r0, [r3, r1] // IO_BANK0: GPIO24_CTRL
+ mov r1, #0xcc
+ str r0, [r3, r1] // IO_BANK0: GPIO24_CTRL
+
+ // enable sio output
+ ldr r3, sio_base
+ mov r0, #0b11
+ lsl r0, r0, #24
+ str r0, [r3, #0x24] // SIO: GPIO_OE
// setup xosc
ldr r3, xosc_base
@@ -150,11 +163,10 @@ wait_vco:
// set fifo level to 0
mov r2, #0
str r2, [r1, #0x34] // UART: UARTIFLS
- bl delay
- ldr r0, [r1, #0x3c] // UART: UARTRIS
- bl printh
loop:
+ bl bled0
+ bl bled1
wfe
b loop
@@ -183,6 +195,8 @@ alpha:
bge printh_loop
pop {r4, r5, r6, r7, pc}
+ // putbyte sends a byte specified by r0 to uart0.
+ // It busy-waits for the buffer to become available.
putbyte:
ldr r3, uart0_base
mov r1, #1
@@ -196,6 +210,8 @@ txff:
str r0, [r3, #0] // UART: UARTDR
bx lr
+ // getbyte reads a byte from uart0 and returns it on r0
+ // It busy-waits for a data.
getbyte:
ldr r3, uart0_base
mov r1, #1
@@ -213,7 +229,7 @@ rxfe:
// can be used anywhare without pushing and popping
// registers.
- // Print register content with 2 leds, lsb first.
+ // pled prints register content with 2 leds on the pins 24 and 25, lsb first.
pled:
push {r0, r1, r2, r3, r4, r5, r6, lr}
mov r4, r0
@@ -232,6 +248,7 @@ pled1:
bne pled_loop
pop {r0, r1, r2, r3, r4, r5, r6, pc}
+ // bled0 blinks the led on the pin 24 once.
bled0:
push {r0, r1, r2, r3, lr}
mov r0, #1
@@ -239,6 +256,7 @@ bled0:
bl bled
pop {r0, r1, r2, r3, pc}
+ // bled1 blinks the led on the pin 25 once.
bled1:
push {r0, r1, r2, r3, lr}
mov r0, #1
@@ -246,6 +264,7 @@ bled1:
bl bled
pop {r0, r1, r2, r3, pc}
+ // bled blinks the led on the pin specified by r0 once.
bled:
push {r0, r1, r2, r3, r4, r5, lr}
ldr r4, sio_base
@@ -256,6 +275,7 @@ bled:
bl delay
pop {r0, r1, r2, r3, r4, r5, pc}
+ // delay delays for a moment by counting down a register.
delay:
push {r0}
mov r0, #1
@@ -266,6 +286,7 @@ delay_loop:
pop {r0}
bx lr
+ // uart_interrupt_handler echos the data arrived at uart0
uart_interrupt_handler:
push {lr}
bl getbyte