Skip to content

Commit 9761672

Browse files
committed
Linker file restructure, TCM and MPU additions
1 parent 47a5d83 commit 9761672

36 files changed

+406
-1133
lines changed

ports/stm/Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ endif
9393
# MCU Series is defined by the HAL package and doesn't need to be specified here
9494
C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT)
9595

96-
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
96+
CFLAGS += $(INC) -Werror -Wall -std=gnu11 $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
97+
# Removed -nostdlib since it conflicts with stm32 startup files
9798

9899
# Undo some warnings.
99100
# STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs
@@ -107,6 +108,7 @@ MCU_FLAGS_F7 = -mcpu=cortex-m7
107108
MCU_FLAGS_H7 = -mcpu=cortex-m7
108109
CFLAGS += $(MCU_FLAGS_$(MCU_SERIES))
109110

111+
# Select HAL file for distribution via mpconfigport
110112
CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES_LOWER)xx_hal.h>'
111113

112114
# Floating point settings
@@ -132,7 +134,7 @@ ifndef BOOTLOADER_OFFSET
132134
BOOTLOADER_OFFSET := 0x8000000
133135
endif
134136

135-
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
137+
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-T,$(LD_COMMON) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
136138
LIBS := -lgcc -lc
137139

138140
LDFLAGS += -mthumb $(MCU_FLAGS_$(MCU_SERIES))
@@ -143,7 +145,13 @@ LIBS += -lm
143145
endif
144146

145147
# TinyUSB defines
146-
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_STM32$(MCU_SERIES) -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128
148+
CFLAGS += \
149+
-DCFG_TUSB_MCU=OPT_MCU_STM32$(MCU_SERIES) \
150+
-DCFG_TUD_CDC_RX_BUFSIZE=1024 \
151+
-DCFG_TUD_CDC_TX_BUFSIZE=1024 \
152+
-DCFG_TUD_MSC_BUFSIZE=4096 \
153+
-DCFG_TUD_MIDI_RX_BUFSIZE=128 \
154+
-DCFG_TUD_MIDI_TX_BUFSIZE=128
147155

148156
SRC_STM32 = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_,\
149157
hal_adc.c \
@@ -218,7 +226,7 @@ endif
218226

219227
SRC_S = \
220228
supervisor/cpu.s \
221-
boards/startup_$(MCU_VARIANT_LOWER).s
229+
st_driver/CMSIS/Device/ST/STM32$(MCU_SERIES)xx/Source/Templates/gcc/startup_$(MCU_VARIANT_LOWER).s
222230

223231
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
224232
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
@@ -241,6 +249,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
241249
ifeq ($(INTERNAL_LIBM),1)
242250
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
243251
endif
252+
#OBJ += $(addprefix $(BUILD)/, $(SRC_O))
244253
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
245254
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
246255

ports/stm/boards/STM32F401xd_fs.ld

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
GNU linker script for STM32F401 with bootloader (such as the Meowbit)
2+
GNU linker script for STM32F401 with filesystem
33
*/
44

55
/* Specify the memory areas */
@@ -24,84 +24,3 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
2424
/* RAM extents for the garbage collector */
2525
_ram_start = ORIGIN(RAM);
2626
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
27-
28-
ENTRY(Reset_Handler)
29-
30-
/* define output sections */
31-
SECTIONS
32-
{
33-
/* The startup code goes first into FLASH */
34-
.isr_vector :
35-
{
36-
. = ALIGN(4);
37-
KEEP(*(.isr_vector)) /* Startup code */
38-
39-
/* This first flash block is 16K annd the isr vectors only take up
40-
about 400 bytes. Micropython pads this with files, but this didn't
41-
work with the size of Circuitpython's ff object. */
42-
43-
. = ALIGN(4);
44-
} >FLASH_ISR
45-
46-
/* The program code and other data goes into FLASH */
47-
.text :
48-
{
49-
. = ALIGN(4);
50-
*(.text*) /* .text* sections (code) */
51-
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
52-
/* *(.glue_7) */ /* glue arm to thumb code */
53-
/* *(.glue_7t) */ /* glue thumb to arm code */
54-
55-
. = ALIGN(4);
56-
_etext = .; /* define a global symbol at end of code */
57-
} >FLASH_TEXT
58-
59-
/* used by the startup to initialize data */
60-
_sidata = LOADADDR(.data);
61-
62-
/* This is the initialized data section
63-
The program executes knowing that the data is in the RAM
64-
but the loader puts the initial values in the FLASH (inidata).
65-
It is one task of the startup to copy the initial values from FLASH to RAM. */
66-
.data :
67-
{
68-
. = ALIGN(4);
69-
_sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
70-
*(.data*) /* .data* sections */
71-
72-
. = ALIGN(4);
73-
_edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
74-
} >RAM AT> FLASH_TEXT
75-
76-
/* Uninitialized data section */
77-
.bss :
78-
{
79-
. = ALIGN(4);
80-
_sbss = .; /* define a global symbol at bss start; used by startup code */
81-
*(.bss*)
82-
*(COMMON)
83-
84-
. = ALIGN(4);
85-
_ebss = .; /* define a global symbol at bss end; used by startup code and GC */
86-
} >RAM
87-
88-
/* this is to define the start of the heap, and make sure we have a minimum size */
89-
.heap :
90-
{
91-
. = ALIGN(4);
92-
. = . + _minimum_heap_size;
93-
. = ALIGN(4);
94-
} >RAM
95-
96-
/* this just checks there is enough RAM for the stack */
97-
.stack :
98-
{
99-
. = ALIGN(4);
100-
. = . + _minimum_stack_size;
101-
. = ALIGN(4);
102-
} >RAM
103-
104-
.ARM.attributes 0 : { *(.ARM.attributes) }
105-
}
106-
107-

ports/stm/boards/STM32F401xe_boot.ld

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
GNU linker script for STM32F401 with bootloader (such as the Meowbit)
2+
GNU linker script for STM32F401 with bootloader (such as the Meowbit). No internal fs.
33
*/
44

55
/* Specify the memory areas */
@@ -24,83 +24,3 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
2424
_ram_start = ORIGIN(RAM);
2525
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
2626

27-
ENTRY(Reset_Handler)
28-
29-
/* define output sections */
30-
SECTIONS
31-
{
32-
/* The startup code goes first into FLASH */
33-
.isr_vector :
34-
{
35-
. = ALIGN(4);
36-
KEEP(*(.isr_vector)) /* Startup code */
37-
38-
/* This first flash block is 16K annd the isr vectors only take up
39-
about 400 bytes. Micropython pads this with files, but this didn't
40-
work with the size of Circuitpython's ff object. */
41-
42-
. = ALIGN(4);
43-
} >FLASH_ISR
44-
45-
/* The program code and other data goes into FLASH */
46-
.text :
47-
{
48-
. = ALIGN(4);
49-
*(.text*) /* .text* sections (code) */
50-
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
51-
/* *(.glue_7) */ /* glue arm to thumb code */
52-
/* *(.glue_7t) */ /* glue thumb to arm code */
53-
54-
. = ALIGN(4);
55-
_etext = .; /* define a global symbol at end of code */
56-
} >FLASH_TEXT
57-
58-
/* used by the startup to initialize data */
59-
_sidata = LOADADDR(.data);
60-
61-
/* This is the initialized data section
62-
The program executes knowing that the data is in the RAM
63-
but the loader puts the initial values in the FLASH (inidata).
64-
It is one task of the startup to copy the initial values from FLASH to RAM. */
65-
.data :
66-
{
67-
. = ALIGN(4);
68-
_sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
69-
*(.data*) /* .data* sections */
70-
71-
. = ALIGN(4);
72-
_edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
73-
} >RAM AT> FLASH_TEXT
74-
75-
/* Uninitialized data section */
76-
.bss :
77-
{
78-
. = ALIGN(4);
79-
_sbss = .; /* define a global symbol at bss start; used by startup code */
80-
*(.bss*)
81-
*(COMMON)
82-
83-
. = ALIGN(4);
84-
_ebss = .; /* define a global symbol at bss end; used by startup code and GC */
85-
} >RAM
86-
87-
/* this is to define the start of the heap, and make sure we have a minimum size */
88-
.heap :
89-
{
90-
. = ALIGN(4);
91-
. = . + _minimum_heap_size;
92-
. = ALIGN(4);
93-
} >RAM
94-
95-
/* this just checks there is enough RAM for the stack */
96-
.stack :
97-
{
98-
. = ALIGN(4);
99-
. = . + _minimum_stack_size;
100-
. = ALIGN(4);
101-
} >RAM
102-
103-
.ARM.attributes 0 : { *(.ARM.attributes) }
104-
}
105-
106-

ports/stm/boards/STM32F401xe_fs.ld

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,84 +24,3 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
2424
/* RAM extents for the garbage collector */
2525
_ram_start = ORIGIN(RAM);
2626
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
27-
28-
ENTRY(Reset_Handler)
29-
30-
/* define output sections */
31-
SECTIONS
32-
{
33-
/* The startup code goes first into FLASH */
34-
.isr_vector :
35-
{
36-
. = ALIGN(4);
37-
KEEP(*(.isr_vector)) /* Startup code */
38-
39-
/* This first flash block is 16K annd the isr vectors only take up
40-
about 400 bytes. Micropython pads this with files, but this didn't
41-
work with the size of Circuitpython's ff object. */
42-
43-
. = ALIGN(4);
44-
} >FLASH_ISR
45-
46-
/* The program code and other data goes into FLASH */
47-
.text :
48-
{
49-
. = ALIGN(4);
50-
*(.text*) /* .text* sections (code) */
51-
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
52-
/* *(.glue_7) */ /* glue arm to thumb code */
53-
/* *(.glue_7t) */ /* glue thumb to arm code */
54-
55-
. = ALIGN(4);
56-
_etext = .; /* define a global symbol at end of code */
57-
} >FLASH_TEXT
58-
59-
/* used by the startup to initialize data */
60-
_sidata = LOADADDR(.data);
61-
62-
/* This is the initialized data section
63-
The program executes knowing that the data is in the RAM
64-
but the loader puts the initial values in the FLASH (inidata).
65-
It is one task of the startup to copy the initial values from FLASH to RAM. */
66-
.data :
67-
{
68-
. = ALIGN(4);
69-
_sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
70-
*(.data*) /* .data* sections */
71-
72-
. = ALIGN(4);
73-
_edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
74-
} >RAM AT> FLASH_TEXT
75-
76-
/* Uninitialized data section */
77-
.bss :
78-
{
79-
. = ALIGN(4);
80-
_sbss = .; /* define a global symbol at bss start; used by startup code */
81-
*(.bss*)
82-
*(COMMON)
83-
84-
. = ALIGN(4);
85-
_ebss = .; /* define a global symbol at bss end; used by startup code and GC */
86-
} >RAM
87-
88-
/* this is to define the start of the heap, and make sure we have a minimum size */
89-
.heap :
90-
{
91-
. = ALIGN(4);
92-
. = . + _minimum_heap_size;
93-
. = ALIGN(4);
94-
} >RAM
95-
96-
/* this just checks there is enough RAM for the stack */
97-
.stack :
98-
{
99-
. = ALIGN(4);
100-
. = . + _minimum_stack_size;
101-
. = ALIGN(4);
102-
} >RAM
103-
104-
.ARM.attributes 0 : { *(.ARM.attributes) }
105-
}
106-
107-

0 commit comments

Comments
 (0)