commit 2abd2bbbc4ddb143e60f6eea043a7b9be4c290a3
parent e09ab3fc5d61c36c60025e289bcc7b404ca73953
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 1 Mar 2024 09:00:48 +0900
try to load main program to sram
Diffstat:
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/ex3/boot2.s b/ex3/boot2.s
@@ -2,15 +2,31 @@
.thumb
.section .boot2
-setup_xip:
+boot2:
+ // setup xip
ldr r3, rom_base
-
ldrh r0, [r3, #0x14] // rom_func_table
ldr r1, =('C' | 'X' << 8) // _flash_enter_cmd_xip()
ldrh r2, [r3, #0x18] // rom_table_lookup
blx r2
blx r0
+ // copy main code to SRAM
+ ldr r0, =start_text
+ ldr r1, =text_size
+ mov r2, #0
+ ldr r3, rom_base
+ ldr r4, sram_base
+copy:
+ cmp r2, r1
+ beq end
+ ldr r5, [r0, r2]
+ str r5, [r4, r2]
+ add r2, #4
+ b copy
+end:
+
+ // set vector table
ldr r0, =vectors
ldr r1, m0plus_vtor
str r0, [r1, #0] // M0PLUS: VTOR
@@ -22,6 +38,8 @@ setup_xip:
.align 2
rom_base:
.word 0x00000000
+sram_base:
+ .word 0x20000000
m0plus_vtor:
.word 0xe0000000 + 0xed08
literals:
diff --git a/ex3/memmap.ld b/ex3/memmap.ld
@@ -10,9 +10,13 @@ SECTIONS
*(.boot2)
. = 0x100;
} > FLASH
-
+ .vectors : {
+ *(.vectors)
+ } > FLASH
+ start_text = .;
.text : {
*(.text)
- } > FLASH
+ } > SRAM AT > FLASH
+ text_size = SIZEOF(.text);
}
diff --git a/ex3/start.s b/ex3/start.s
@@ -1,7 +1,7 @@
.cpu cortex-m0plus
.thumb
- .section .text
+ .section .vectors
.global vectors
vectors:
.word 0x20040000 // 0 initial SP
@@ -22,6 +22,7 @@ vectors:
.word reset+1 // 15 systick
.word isr_alarm+1 // 16 alarm_0
+ .section .text
reset:
bl main
loop: