commit 8f3193fe9dc3807d94e89209f4c060105e58a7cd
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 3 Mar 2023 15:01:26 +0900
first commit
Diffstat:
5 files changed, 174 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,37 @@
+AS = arm-none-eabi-as
+LD = arm-none-eabi-ld
+CC = arm-none-eabi-gcc
+ELF2UF2 = ../pico-sdk/build/elf2uf2/elf2uf2
+
+MCPU = -mcpu=cortex-m0plus
+
+ASFLAGS = $(MCPU) -g
+CFLAGS = $(MCPU) -ffreestanding -g -O0 -fpic -mthumb -c
+LDFLAGS = -norelax -nostdlib -nostartfiles
+
+all: led.uf2
+
+clean:
+ rm -f *.o
+ rm -f *.elf
+ rm -f *.uf2
+
+start.o: start.S
+ $(AS) $(ASFLAGS) -o start.o start.S
+
+boot2.o: boot2/bs2_default_padded_checksummed.S
+ $(AS) $(ASFLAGS) -o boot2.o boot2/bs2_default_padded_checksummed.S
+
+main.o: main.s
+ $(CC) $(CFLAGS) -o main.o main.s
+
+led.elf: start.o boot2.o main.o
+ $(LD) $(LFLAGS) -o led.elf -T memmap.ld start.o boot2.o main.o
+
+led.uf2: led.elf
+ $(ELF2UF2) led.elf led.uf2
+
+flash: led.uf2
+ doas mount /dev/sd3i /mnt
+ doas cp led.uf2 /mnt
+
diff --git a/boot2/bs2_default_padded_checksummed.S b/boot2/bs2_default_padded_checksummed.S
@@ -0,0 +1,23 @@
+// Padded and checksummed version of: /home/kenji/code/pico/pico-sdk/build/src/rp2_common/boot_stage2/bs2_default.bin
+
+.cpu cortex-m0plus
+.thumb
+
+.section .boot2, "ax"
+
+.byte 0x00, 0xb5, 0x32, 0x4b, 0x21, 0x20, 0x58, 0x60, 0x98, 0x68, 0x02, 0x21, 0x88, 0x43, 0x98, 0x60
+.byte 0xd8, 0x60, 0x18, 0x61, 0x58, 0x61, 0x2e, 0x4b, 0x00, 0x21, 0x99, 0x60, 0x02, 0x21, 0x59, 0x61
+.byte 0x01, 0x21, 0xf0, 0x22, 0x99, 0x50, 0x2b, 0x49, 0x19, 0x60, 0x01, 0x21, 0x99, 0x60, 0x35, 0x20
+.byte 0x00, 0xf0, 0x44, 0xf8, 0x02, 0x22, 0x90, 0x42, 0x14, 0xd0, 0x06, 0x21, 0x19, 0x66, 0x00, 0xf0
+.byte 0x34, 0xf8, 0x19, 0x6e, 0x01, 0x21, 0x19, 0x66, 0x00, 0x20, 0x18, 0x66, 0x1a, 0x66, 0x00, 0xf0
+.byte 0x2c, 0xf8, 0x19, 0x6e, 0x19, 0x6e, 0x19, 0x6e, 0x05, 0x20, 0x00, 0xf0, 0x2f, 0xf8, 0x01, 0x21
+.byte 0x08, 0x42, 0xf9, 0xd1, 0x00, 0x21, 0x99, 0x60, 0x1b, 0x49, 0x19, 0x60, 0x00, 0x21, 0x59, 0x60
+.byte 0x1a, 0x49, 0x1b, 0x48, 0x01, 0x60, 0x01, 0x21, 0x99, 0x60, 0xeb, 0x21, 0x19, 0x66, 0xa0, 0x21
+.byte 0x19, 0x66, 0x00, 0xf0, 0x12, 0xf8, 0x00, 0x21, 0x99, 0x60, 0x16, 0x49, 0x14, 0x48, 0x01, 0x60
+.byte 0x01, 0x21, 0x99, 0x60, 0x01, 0xbc, 0x00, 0x28, 0x00, 0xd0, 0x00, 0x47, 0x12, 0x48, 0x13, 0x49
+.byte 0x08, 0x60, 0x03, 0xc8, 0x80, 0xf3, 0x08, 0x88, 0x08, 0x47, 0x03, 0xb5, 0x99, 0x6a, 0x04, 0x20
+.byte 0x01, 0x42, 0xfb, 0xd0, 0x01, 0x20, 0x01, 0x42, 0xf8, 0xd1, 0x03, 0xbd, 0x02, 0xb5, 0x18, 0x66
+.byte 0x18, 0x66, 0xff, 0xf7, 0xf2, 0xff, 0x18, 0x6e, 0x18, 0x6e, 0x02, 0xbd, 0x00, 0x00, 0x02, 0x40
+.byte 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x07, 0x00, 0x00, 0x03, 0x5f, 0x00, 0x21, 0x22, 0x00, 0x00
+.byte 0xf4, 0x00, 0x00, 0x18, 0x22, 0x20, 0x00, 0xa0, 0x00, 0x01, 0x00, 0x10, 0x08, 0xed, 0x00, 0xe0
+.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0xb2, 0x4e, 0x7a
diff --git a/main.s b/main.s
@@ -0,0 +1,63 @@
+ .section .text
+ .global main
+main:
+ // reset gpio
+ ldr r0, reset_reg
+ mov r1, #0x1
+ lsl r1, r1, #5
+ str r1, [r0, #0]
+
+ // check if reset is done
+reset_chk:
+ ldr r0, reset_done
+ ldr r2, [r0, #0]
+ and r1, r1, r2
+ beq reset_chk
+
+ // set gpio25 as sio
+ ldr r0, gpio25_ctrl
+ mov r1, #5
+ str r1, [r0, #0]
+
+ // enable output
+ ldr r0, gpio_oe_set
+ mov r1, #1
+ lsl r1, r1, #25
+ str r1, [r0, #0]
+
+ ldr r0, gpio_out
+ mov r3, #0
+loop:
+ // assert gpio25
+ str r1, [r0, #0]
+ bl delay
+ // deassert gpio25
+ str r3, [r0, #0]
+ bl delay
+
+ b loop
+
+delay:
+ mov r2, #1
+ lsl r2, r2, #20
+del_loop:
+ sub r2, r2, #1
+ bne del_loop
+ bx lr
+
+ .align 2
+
+reset_reg:
+ .word 0x4000f000
+
+reset_done:
+ .word 0x4000c008
+
+gpio25_ctrl:
+ .word 0x400140cc
+
+gpio_out:
+ .word 0xd0000010
+
+gpio_oe_set:
+ .word 0xd0000024
diff --git a/memmap.ld b/memmap.ld
@@ -0,0 +1,28 @@
+MEMORY
+{
+ FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2048k
+ RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
+}
+
+ENTRY(reset)
+
+SECTIONS
+{
+ /*
+ boot2 section is for embed the precompiled boot2.
+ this code from memmap_default.ld in pico-sdk
+ */
+ .boot2 : {
+ __boot2_start__ = .;
+ KEEP(*(.boot2))
+ __boot2_end__ = .;
+ } > FLASH
+
+ ASSERT(__boot2_end__ - __boot2_start__ == 256,
+ "ERROR: Pico second stage bootloader must be 256 bytes in size")
+ .text : {
+ KEEP(*(.vectors))
+ KEEP(*(.text*))
+ } > FLASH
+}
+
diff --git a/start.S b/start.S
@@ -0,0 +1,23 @@
+ .cpu cortex-m0plus
+ .thumb
+
+/* vector table */
+ .section .vectors, "ax"
+ .align 2
+ .global __vectors
+__vectors:
+.word 0x20001000
+.word reset
+
+/* reset handler */
+ .thumb_func
+ .global reset
+reset:
+ ldr r0, =0x20001000
+ mov sp, r0
+ bl main
+ b hang
+
+.thumb_func
+hang: b .
+