rp2040

RP2040 Programming without SDK
Log | Files | Refs

commit fffa152122240112565655f51547ef6c5a6c0a57
parent d4782618cbd2c8cc737cba77a7fec5379b8d6bee
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  8 Mar 2024 09:17:35 +0900

fix bug where the tail of the program is not copied to sram

Diffstat:
Mex3/Makefile | 6++++--
Mex3/boot2.s | 2+-
Mex3/main.c | 16+++++++++++++---
Mex3/memmap.ld | 10+++++++++-
Aex3/proc.s | 19+++++++++++++++++++
5 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/ex3/Makefile b/ex3/Makefile @@ -10,6 +10,8 @@ ASFLAGS = $(MCPU) CFLAGS = $(MCPU) -mthumb -ffreestanding -nostartfiles -O0 -fpic -c LDFLAGS = --no-relax -nostdlib +OBJS = boot2.o start.o main.o proc.o + all: tools a.uf2 clean: @@ -22,8 +24,8 @@ clean: .c.o: $(CC) $(CFLAGS) -o $@ $< -a.elf: boot2.o start.o main.o memmap.ld - $(LD) $(LDFLAGS) -o $@ -T memmap.ld boot2.o start.o main.o +a.elf: $(OBJS) memmap.ld + $(LD) $(LDFLAGS) -o $@ -T memmap.ld $(OBJS) a.bin: a.elf $(OBJCOPY) -O binary a.elf $@ diff --git a/ex3/boot2.s b/ex3/boot2.s @@ -11,7 +11,7 @@ boot2: blx r2 blx r0 - // clear sram contents + // Clear sram contents for debugging. mov r0, #0 ldr r3, sram_base ldr r4, sram_end diff --git a/ex3/main.c b/ex3/main.c @@ -1,14 +1,16 @@ void init(void); int puts(char *); -void printh(unsigned int); +void printh(void *); void set_alarm(unsigned int); +extern void *proc0; + // A proc represents a process in execution. typedef struct proc { // Id is the unique identifier of the process. unsigned int id; // R is the registers of the process with r[13] be sp, r[14] lr, r[15] pc. - unsigned int r[16]; + void *r[16]; } proc; // A proc_tab is the queue of waiting processes. @@ -27,7 +29,15 @@ int main(void) { init(); - proc *p0 = (proc *)0x20001000, *p1 = (proc *) 0x20001100; + proc *p0 = (proc *) 0x20041000, *p1 = (proc *) 0x20041100; // sram5 + + p0->r[13] = (void *) 0x20000100; // sp + p0->r[14] = (void *) 0xdeadbeef; // lr + p0->r[15] = (void *) 0x20000000; // pc + + p1->r[13] = (void *) 0x20000200; // sp + p1->r[14] = (void *) 0xdeadbeef; // lr + p1->r[15] = (void *) 0x20000100; // pc return 0; } diff --git a/ex3/memmap.ld b/ex3/memmap.ld @@ -13,6 +13,7 @@ SECTIONS *(.vectors) } > FLASH .text : { + kernel_start = .; *(.text) } > SRAM4 AT > FLASH .data : { @@ -20,8 +21,15 @@ SECTIONS } > SRAM4 AT > FLASH .rodata : { *(.rodata) + kernel_end = .; } > SRAM4 AT > FLASH prog_start = LOADADDR(.text); - prog_size = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata); + prog_size = kernel_end - kernel_start; + .proc0 0x20000000 : { + *(.proc0) + } > SRAM AT > FLASH + .proc1 0x20000100 : { + *(.proc1) + } > SRAM AT > FLASH } diff --git a/ex3/proc.s b/ex3/proc.s @@ -0,0 +1,19 @@ + .section .proc0 + .global proc0 +proc0: + ldr r0, msg0 + bl puts + b proc0 + +msg0: + .asciz "proc0" + + .section .proc1 + .global proc1 +proc1: + ldr r0, msg1 + bl puts + b proc1 + +msg1: + .asciz "proc1"