rp2040

RP2040 Programming without SDK
Log | Files | Refs

commit a3157fd6220eb81509b1007815db8602b3297566
parent e09ab3fc5d61c36c60025e289bcc7b404ca73953
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  1 Mar 2024 10:06:11 +0900

try to copy to sram

Diffstat:
Mex3/boot2.s | 21+++++++++++++++++++--
Mex3/main.c | 8++++----
Mex3/memmap.ld | 6+++++-
Mex3/start.s | 5++++-
4 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/ex3/boot2.s b/ex3/boot2.s @@ -2,15 +2,30 @@ .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 + // load main program to sram + ldr r0, =text_start + ldr r1, =text_size + mov r2, #0 + ldr r3, sram_base +copy: + cmp r1, r2 + beq end + ldr r4, [r0, r2] + str r4, [r3, r2] + add r2, #4 + b copy +end: + + // setup vector table ldr r0, =vectors ldr r1, m0plus_vtor str r0, [r1, #0] // M0PLUS: VTOR @@ -22,6 +37,8 @@ setup_xip: .align 2 rom_base: .word 0x00000000 +sram_base: + .word 0x20000000 m0plus_vtor: .word 0xe0000000 + 0xed08 literals: diff --git a/ex3/main.c b/ex3/main.c @@ -6,7 +6,10 @@ void set_alarm(unsigned int); int main(void) { init(); - puts("C file"); + for ( int i = 0; i < 10; i++ ) { + printh(*(unsigned int *)(0x20000000 + 4 * i)); + puts(""); + } return 0; } @@ -15,11 +18,8 @@ isr_svcall(void) { puts("svcall"); } -int count = 0; - void isr_alarm(void) { - printh(count++); puts("alarm fired"); set_alarm(1000 * 1000); } diff --git a/ex3/memmap.ld b/ex3/memmap.ld @@ -10,9 +10,13 @@ SECTIONS *(.boot2) . = 0x100; } > FLASH - + .vectors : { + *(.vectors) + } > FLASH + text_start = .; .text : { *(.text) } > FLASH + text_size = SIZEOF(.text); } diff --git a/ex3/start.s b/ex3/start.s @@ -1,7 +1,8 @@ .cpu cortex-m0plus .thumb - .section .text + .align 8 + .section .vectors .global vectors vectors: .word 0x20040000 // 0 initial SP @@ -22,6 +23,8 @@ vectors: .word reset+1 // 15 systick .word isr_alarm+1 // 16 alarm_0 + .align 2 + .section .text reset: bl main loop: