commit 2775db91ea25347616694020b2429fb76b9ed27a
parent 0e128d270d951765ee0068d2799915c26c6d6d69
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 8 Apr 2023 10:24:52 +0900
try to copy and exec from sram.
I need to tell assembler or linker to use base address
of sram: 0x20000000, instead of xip base: 0x10000000
Diffstat:
3 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -27,8 +27,8 @@ start.o: start.s
boot2_crc.o: boot2/boot2_crc.S
$(AS) $(ASFLAGS) -o boot2_crc.o boot2/boot2_crc.S
-boot2/boot2_crc.S: boot2/boot2_generic.s bincrc
- $(AS) $(ASFLAGS) -o boot2/boot2.o boot2/boot2_generic.s
+boot2/boot2_crc.S: boot2/boot2_sram.s bincrc
+ $(AS) $(ASFLAGS) -o boot2/boot2.o boot2/boot2_sram.s
$(OBJCOPY) -O binary boot2/boot2.o boot2/boot2.bin
./bincrc boot2/boot2.bin boot2/boot2_crc.S
diff --git a/boot2/boot2_sram.s b/boot2/boot2_sram.s
@@ -0,0 +1,49 @@
+.cpu cortex-m0plus
+.thumb
+
+.equ XIP_BASE, 0x10000000
+.equ XIP_SSI_BASE, 0x18000000
+.equ SRAM_BASE, 0x20000000
+.equ PPB_BASE, 0xe0000000
+
+boot2:
+ ldr r4, =XIP_SSI_BASE
+
+ // set SSI standard SPI
+ mov r1, #0
+ str r1, [r4, #0x8] // SSI: SSIENR
+ mov r1, #4
+ str r1, [r4, #0x14] // SSI: BAUDR
+ mov r1, #1
+ mov r2, #0xf0
+ str r1, [r4, r2] // SSI: RX_SAMPLE_DLY
+ ldr r1, =((31 << 16) | (3 << 8))
+ str r1, [r4, #0x0] // SSI: CTRLR0
+ mov r1, #0 // NDF = 0
+ str r1, [r4, #0x4] // SSI: CTRLR1
+ ldr r1, =((0x03 << 24) | (2 << 8) | (6 << 2))
+ mov r0, #0xf4
+ str r1, [r4, r0] // SSI: SPI_CTRLR0
+ mov r1, #1
+ str r1, [r4, #0x8] // SSI: SSIENR
+
+ // copy program data from flash to sram
+ ldr r2, =(XIP_BASE + 0x100)
+ ldr r3, =SRAM_BASE
+ ldr r0, =0x1000
+sram_cpy:
+ ldr r1, [r2, #0]
+ str r1, [r3, #0]
+ add r2, r2, #0x4
+ add r3, r3, #0x4
+ sub r0, r0, #0x4
+ bne sram_cpy
+
+ // exit from boot2
+ ldr r0, =(XIP_BASE + 0x100)
+ ldr r1, =(PPB_BASE + 0xed08)
+ str r0, [r1, #0] // M0PLUS: VTOR
+ ldr r1, [r0, #4]
+ ldr r0, [r0, #0]
+ mov sp, r0
+ bx r1
diff --git a/mach.s b/mach.s
@@ -119,6 +119,17 @@ pll_lock:
lsl r1, r1, #5
str r1, [r0, #0x2c] // UART0_UARTLCR_H
+ mov r1, #8
+ ldr r2, =0x20000000
+loop:
+ ldr r0, [r2, #0]
+ bl printh
+ mov r0, #0x0A
+ bl putchar
+ add r2, #4
+ sub r1, #1
+ bne loop
+
pop {pc}
unreset: