rp2040

RP2040 Programming without SDK
Log | Files | Refs

commit 6d366168dd82dc32fe0ef335bdaec73fedbd564e
parent 030f016560d104689d415fbb5d8cf9c240f03626
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Thu, 27 Apr 2023 08:43:23 +0900

copy to ex2

Diffstat:
Aex2/Makefile | 36++++++++++++++++++++++++++++++++++++
Aex2/boot2.s | 31+++++++++++++++++++++++++++++++
Aex2/main.s | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aex2/memmap.ld | 19+++++++++++++++++++
4 files changed, 146 insertions(+), 0 deletions(-)

diff --git a/ex2/Makefile b/ex2/Makefile @@ -0,0 +1,36 @@ +AS = arm-none-eabi-as +LD = arm-none-eabi-ld +OBJCOPY = arm-none-eabi-objcopy +BINCRC = ../tools/bincrc +BIN2UF2 = ../tools/bin2uf2 + +MCPU = -mcpu=cortex-m0plus +ASFLAGS = $(MCPU) +CFLAGS = $(MCPU) -ffreestanding -nostartfiles -O0 -fpic -mthumb -c +LDFLAGS = --no-relax -nostdlib + +all: tools led.uf2 + +clean: + rm -f *.o *.elf *.uf2 *.bin + cd ../tools && make clean + +.s.o: + $(AS) $(ASFLAGS) -o $@ $< + +led.elf: boot2.o main.o memmap.ld + $(LD) $(LDFLAGS) -o $@ -T memmap.ld boot2.o main.o + +led.bin: led.elf + $(OBJCOPY) -O binary led.elf $@ + +led.uf2: led.bin + $(BINCRC) led.bin led_crc.bin + $(BIN2UF2) led_crc.bin $@ + +flash: all + mount /dev/disk/by-label/RPI-RP2 /mnt + cp led.uf2 /mnt + +tools: + cd ../tools && make diff --git a/ex2/boot2.s b/ex2/boot2.s @@ -0,0 +1,31 @@ +.cpu cortex-m0plus +.thumb + + .section .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 + + ldr r0, flash_main + ldr r1, m0plus_vtor + str r0, [r1, #0] // M0PLUS: VTOR + ldr r1, [r0, #4] // entry point + ldr r0, [r0, #0] // stack pointer + mov sp, r0 + bx r1 + + .align 2 +rom_base: + .word 0x00000000 +flash_main: + .word 0x10000000 + 0x100 +m0plus_vtor: + .word 0xe0000000 + 0xed08 +literals: + .ltorg + diff --git a/ex2/main.s b/ex2/main.s @@ -0,0 +1,60 @@ +.cpu cortex-m0plus +.thumb + + .section .vectors +vectors: + .word 0x20040000 // initial SP + .word (reset+1) // entry point + + .section .text +reset: + // unreset gpio + mov r0, #1 + lsl r0, r0, #5 // io_bank0 + ldr r3, resets_base + ldr r1, atomic_clr + str r0, [r3, r1] // RESETS: RESET + +reset_chk: + ldr r1, [r3, #0x8] // RESETS: RESET_DONE + tst r0, r1 + beq reset_chk + + // set gpio functions + ldr r3, io_bank0_base + mov r0, #5 // sio + mov r1, #0xcc + str r0, [r3, r1] // IO_BANK0: GPIO25_CTRL + + // enable gpio output + ldr r3, sio_base + mov r0, #1 + lsl r0, r0, #25 // gpio25 + str r0, [r3, #0x24] // SIO: GPIO_OE + + // blink led on gpio25 + ldr r4, sio_base + mov r5, r0 +loop: + str r5, [r4, #0x1c] // SIO_GPIO_OUT_XOR + bl delay + b loop + +delay: + mov r0, #1 + lsl r0, r0, #20 +delay_loop: + sub r0, r0, #1 + bne delay_loop + bx lr + +// literals + .align 2 +atomic_clr: + .word 0x00003000 +resets_base: + .word 0x4000c000 +io_bank0_base: + .word 0x40014000 +sio_base: + .word 0xd0000000 diff --git a/ex2/memmap.ld b/ex2/memmap.ld @@ -0,0 +1,19 @@ +MEMORY +{ + FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2048k + SRAM(rwx) : ORIGIN = 0x20000000, LENGTH = 264k +} + +SECTIONS +{ + .boot2 : { + *(.boot2) + . = 0x100; + } > FLASH + + .text : { + *(.vectors) + *(.text) + } > FLASH +} +