rp2040

RP2040 Programming without SDK
Log | Files | Refs

commit b6befe55d289bcee8a73e339af2e0a4093de7aee
parent 8f94806cfd789d3aca81d1efa6c5588e253b7474
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 24 Feb 2024 09:52:24 +0900

implement systick interrupt

Diffstat:
Mex3/main.s | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mex3/memmap.ld | 7+------
2 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/ex3/main.s b/ex3/main.s @@ -1,12 +1,6 @@ .cpu cortex-m0plus .thumb - .section .rodata - .global vectors -vectors: - .word 0x20040000 // initial SP - .word (reset+1) // entry point - .section .text reset: // unreset gpio, pll_sys, uart0 @@ -97,14 +91,22 @@ wait_vco: ldr r1, =0xe018 str r0, [r3, r1] // M0PLUS: SYST_CVR // set reset value - ldr r0, =0xf423f // 1 sec + ldr r0, =0xf23f // 1 sec ldr r1, =0xe014 str r0, [r3, r1] // M0PLUS: SYST_RVR // enable systick timer sub r1, r1, #4 - mov r0, #1 + ldr r0, =(1 << 1 | 1) // TICKINT | ENABLE str r0, [r3, r1] // M0PLUS: SYST_CSR + // setup NMI + ldr r3, syscfg_base + mov r0, #1 + lsl r0, #14 + str r0, [r3, #0] // SYSCFG: PROC0_NMI_MASK + + bl int_systick + ldr r4, ppb_base ldr r5, =0xe018 loop: @@ -112,10 +114,31 @@ loop: bl putbyte ldr r0, [r4, r5] // M0PLUS: SYST_CVR bl printh + ldr r0, ='\n' + bl putbyte + ldr r0, ='\r' + bl putbyte + mov r0, sp + bl printh + ldr r0, ='\n' + bl putbyte + wfi b loop // functions +int_systick: + push {lr} + ldr r0, ='\r' + bl putbyte + ldr r3, ppb_base + ldr r1, =0xe010 + ldr r0, [r3, r1] // SYSCFG: PROC0_NMI_MASK + bl printh + ldr r0, ='\n' + bl putbyte + pop {pc} + // print r0 in hex for debugging. printh: push {r4, r5, r6, r7, lr} @@ -229,6 +252,8 @@ atomic_set: .word 0x00002000 atomic_clr: .word 0x00003000 +syscfg_base: + .word 0x40004000 clocks_base: .word 0x40008000 resets_base: @@ -245,3 +270,23 @@ sio_base: .word 0xd0000000 ppb_base: .word 0xe0000000 + + .align 8 + .global vectors +vectors: + .word 0x20040000 // 0 initial SP + .word (reset+1) // 1 entry point + .word (reset+1) // 2 + .word (reset+1) // 3 + .word (reset+1) // 4 + .word (reset+1) // 5 + .word (reset+1) // 6 + .word (reset+1) // 7 + .word (reset+1) // 8 + .word (reset+1) // 9 + .word (reset+1) // 10 + .word (reset+1) // 11 + .word (reset+1) // 12 + .word (reset+1) // 13 + .word (reset+1) // 14 + .word (int_systick+1) // 15 systick diff --git a/ex3/memmap.ld b/ex3/memmap.ld @@ -1,7 +1,6 @@ MEMORY { - FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 1m - VTOR(rx) : ORIGIN = 0x10100000, LENGTH = 1m + FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2m SRAM(rwx) : ORIGIN = 0x20000000, LENGTH = 264k } @@ -15,9 +14,5 @@ SECTIONS .text : { *(.text) } > FLASH - - .rodata : { - *(.rodata) - } > VTOR }