From d13ec1241cd97542694190c6496087b8725e399c Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 18 Jun 2021 13:24:54 +0800 Subject: [PATCH] In RAM execution using all RAM when loading via SWD. --- Makefile | 38 ++++++++++++++++++++++++++++++-------- generic.ld | 6 ++++-- startup.ram.c | 4 ++-- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 3b7bb48..1571ce9 100644 --- a/Makefile +++ b/Makefile @@ -41,23 +41,41 @@ SIZE = $(BINPFX)size PROJECT = f030f4 -# In RAM Execution +### Memory Models + +# In RAM Execution, load and start by USART bootloader # Bootloader uses first 2K of RAM, execution from bootloader #FLASHSTART = 0x20000800 #FLASHSIZE = 2K #RAMSTART = 0x20000000 #RAMSIZE = 2K +# In RAM Execution, load and start via SWD +# 4K RAM available, execution via SWD +#FLASHSTART = 0x20000000 +#FLASHSIZE = 3K +#RAMSTART = 0x20000C00 +#RAMSIZE = 1K + # In Flash Execution -# if FLASHSTART is not at beginning of FLASH: execution from bootloader +# if FLASHSTART is not at beginning of FLASH: execution via bootloader or SWD FLASHSTART = 0x08000000 FLASHSIZE = 16K RAMSTART = 0x20000000 RAMSIZE = 4K # ISR vector copied and mapped to RAM if FLASHSTART != 0x08000000 -ifneq ($(FLASHSTART),0x08000000) - RAMISRV := 1 +ifdef FLASHSTART + ifneq ($(FLASHSTART),0x08000000) + ifeq ($(FLASHSTART),0x20000000) + # Map isr vector in RAM + RAMISRV := 1 + else + # Copy and map isr vector in RAM + RAMISRV := 2 + endif + endif + FNAMLOC = .$(FLASHSTART) endif #SRCS = boot.c @@ -90,8 +108,10 @@ WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter CFLAGS = $(CPU) -g $(WARNINGS) -Os $(CDEFINES) LD_SCRIPT = generic.ld -LDOPTS =--defsym FLASHSTART=$(FLASHSTART) --defsym FLASHSIZE=$(FLASHSIZE) -LDOPTS +=--defsym RAMSTART=$(RAMSTART) --defsym RAMSIZE=$(RAMSIZE) +ifdef FLASHSTART + LDOPTS =--defsym FLASHSTART=$(FLASHSTART) --defsym FLASHSIZE=$(FLASHSIZE) + LDOPTS +=--defsym RAMSTART=$(RAMSTART) --defsym RAMSIZE=$(RAMSIZE) +endif LDOPTS +=-Map=$(subst .elf,.map,$@) -cref --print-memory-usage comma :=, space :=$() # one space before the comment @@ -101,7 +121,7 @@ LDFLAGS =-Wl,$(subst $(space),$(comma),$(LDOPTS)) .PHONY: clean all version -all: $(PROJECT).hex $(PROJECT).$(FLASHSTART).bin +all: $(PROJECT).hex $(PROJECT)$(FNAMLOC).bin version: @echo make $(MAKE_VERSION) $(MAKE_HOST) @@ -125,11 +145,13 @@ cstartup.elf: cstartup.o $(SIZE) -G $@ $(OBJDUMP) -hS $@ > $(subst .elf,.lst,$@) +ifdef FNAMLOC %.bin: %.elf @echo $@ $(OBJCOPY) -O binary $< $@ +endif -%.$(FLASHSTART).bin: %.elf +%$(FNAMLOC).bin: %.elf @echo $@ $(OBJCOPY) -O binary $< $@ diff --git a/generic.ld b/generic.ld index e099913..fc77aa0 100644 --- a/generic.ld +++ b/generic.ld @@ -11,8 +11,10 @@ MEMORY { /* FLASH means code, read only data and data initialization */ - FLASH (rx) : ORIGIN = FLASHSTART, LENGTH = FLASHSIZE - RAM (rwx) : ORIGIN = RAMSTART, LENGTH = RAMSIZE + FLASH (rx) : ORIGIN = DEFINED(FLASHSTART) ? FLASHSTART : 0x08000000, + LENGTH = DEFINED(FLASHSIZE) ? FLASHSIZE : 16K + RAM (rwx) : ORIGIN = DEFINED(RAMSTART) ? RAMSTART : 0x20000000, + LENGTH = DEFINED(RAMSIZE) ? RAMSIZE : 4K } /* Linker script to place sections and symbol values. Should be used together diff --git a/startup.ram.c b/startup.ram.c index d4a8c04..5bec5ef 100644 --- a/startup.ram.c +++ b/startup.ram.c @@ -110,7 +110,7 @@ isr_p const isr_vector[ 16 + 32] __attribute__((section(".isr_vector"))) = { USB_Handler } ; -#if RAMISRV +#if RAMISRV == 2 # define ISRV_SIZE (sizeof isr_vector / sizeof *isr_vector) isr_p ram_vector[ ISRV_SIZE] __attribute__((section(".ram_vector"))) ; #endif @@ -121,7 +121,7 @@ void Reset_Handler( void) { const long *f ; /* from, source constant data from FLASH */ long *t ; /* to, destination in RAM */ -#if RAMISRV +#if RAMISRV == 2 /* Copy isr vector to beginning of RAM */ for( unsigned i = 0 ; i < ISRV_SIZE ; i++) ram_vector[ i] = isr_vector[ i] ;