Skip to content

Commit 339bdcc

Browse files
committed
Merge pull request adafruit#803 from dhylands/ld-opt
Put some code into the first 16K of flash
2 parents 8f81b5c + 3688414 commit 339bdcc

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

stmhal/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
200200
OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
201201
OBJ += $(BUILD)/pins_$(BOARD).o
202202

203+
# We put ff.o and stm32f4xx_hal_sd.o into the first 16K section with the ISRs.
204+
# If we compile these using -O0 then it won't fit. So if you really want these
205+
# to be compiled with -O0, then edit stm32f405.ld (in the .isr_vector section)
206+
# and comment out the following 2 lines.
207+
$(BUILD)/$(FATFS_DIR)/src/ff.o: COPT += -Os
208+
$(BUILD)/$(HAL_DIR)/src/stm32f4xx_hal_sd.o: COPT += -Os
209+
203210
all: $(BUILD)/firmware.dfu $(BUILD)/firmware.hex
204211

205212
.PHONY: deploy

stmhal/stm32f405.ld

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@ SECTIONS
3434
. = ALIGN(4);
3535
KEEP(*(.isr_vector)) /* Startup code */
3636

37+
/* This first flash block is 16K annd the isr vectors only take up
38+
about 400 bytes. So we pull in a couple of object files to pad it
39+
out. */
40+
41+
. = ALIGN(4);
42+
*/ff.o(.text*)
43+
*/stm32f4xx_hal_sd.o(.text*)
44+
3745
. = ALIGN(4);
3846
} >FLASH_ISR
3947

4048
/* The program code and other data goes into FLASH */
4149
.text :
4250
{
4351
. = ALIGN(4);
44-
*(.text) /* .text sections (code) */
4552
*(.text*) /* .text* sections (code) */
46-
*(.rodata) /* .rodata sections (constants, strings, etc.) */
4753
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
4854
/* *(.glue_7) */ /* glue arm to thumb code */
4955
/* *(.glue_7t) */ /* glue thumb to arm code */
@@ -78,7 +84,6 @@ SECTIONS
7884
. = ALIGN(4);
7985
_sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
8086
_ram_start = .; /* create a global symbol at ram start for garbage collector */
81-
*(.data) /* .data sections */
8287
*(.data*) /* .data* sections */
8388

8489
. = ALIGN(4);
@@ -90,7 +95,6 @@ SECTIONS
9095
{
9196
. = ALIGN(4);
9297
_sbss = .; /* define a global symbol at bss start; used by startup code */
93-
*(.bss)
9498
*(.bss*)
9599
*(COMMON)
96100

0 commit comments

Comments
 (0)