Skip to content

Commit c1cf801

Browse files
committed
Merge branch 'stm32-loader-linkers' into stm32-f407-disco
2 parents ab031bc + a10e5d1 commit c1cf801

File tree

12 files changed

+66
-74
lines changed

12 files changed

+66
-74
lines changed

ports/stm32f4/Makefile

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
# Select the board to build for.
2828
ifeq ($(BOARD),)
29-
$(error You must provide a BOARD parameter)
29+
$(error You must provide a BOARD parameter)
3030
else
31-
ifeq ($(wildcard boards/$(BOARD)/.),)
32-
$(error Invalid BOARD specified)
33-
endif
31+
ifeq ($(wildcard boards/$(BOARD)/.),)
32+
$(error Invalid BOARD specified)
33+
endif
3434
endif
3535

3636
# If the build directory is not given, make it reflect the board name.
@@ -80,19 +80,16 @@ INC += -I../../supervisor/shared/usb
8080

8181
#Debugging/Optimization
8282
ifeq ($(DEBUG), 1)
83-
CFLAGS += -ggdb
84-
# You may want to enable these flags to make setting breakpoints easier.
85-
CFLAGS += -fno-inline -fno-ipa-sra
83+
CFLAGS += -ggdb
84+
# You may want to enable these flags to make setting breakpoints easier.
85+
CFLAGS += -fno-inline -fno-ipa-sra
8686
else
87-
CFLAGS += -Os -DNDEBUG
88-
CFLAGS += -ggdb
89-
# TODO: Test with -flto
90-
### CFLAGS += -flto
87+
CFLAGS += -Os -DNDEBUG
88+
CFLAGS += -ggdb
89+
# TODO: Test with -flto
90+
### CFLAGS += -flto
9191
endif
9292

93-
ifndef BOOTLOADER_OFFSET
94-
BOOTLOADER_OFFSET := 0x8000000
95-
endif
9693

9794
C_DEFS = -DMCU_PACKAGE=$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(CMSIS_MCU)
9895

@@ -115,6 +112,22 @@ CFLAGS += \
115112
# TODO: check this
116113
CFLAGS += -D__START=main
117114

115+
#need both command and valid file to use uf2 bootloader
116+
ifndef LD_FILE
117+
ifneq ($(and $(UF2_BOOTLOADER),$(LD_BOOT)),)
118+
LD_FILE = $(LD_BOOT)
119+
BOOTLOADER_OFFSET = $(UF2_OFFSET)
120+
CFLAGS += -DUF2_BOOTLOADER_ENABLED
121+
else
122+
LD_FILE = $(LD_FS)
123+
endif
124+
endif
125+
126+
# Add bootloader specific items
127+
ifndef BOOTLOADER_OFFSET
128+
BOOTLOADER_OFFSET := 0x8000000
129+
endif
130+
118131
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
119132
LIBS := -lgcc -lc
120133

@@ -210,12 +223,12 @@ SRC_S = \
210223
boards/startup_$(MCU_SUB_VARIANT).s
211224

212225
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
213-
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
214-
$(addprefix common-hal/, $(SRC_COMMON_HAL))
226+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
227+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
215228

216229
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
217-
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
218-
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
230+
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
231+
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
219232

220233

221234
ifneq ($(FROZEN_MPY_DIR),)

ports/stm32f4/boards/STM32F401_boot.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
/* Specify the memory areas */
66
MEMORY
77
{
8-
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 512K - 64K /* entire flash */
9-
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 64K
10-
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sector 4 is 64K, sectors 5,6,7 are 128K */
8+
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 512K - 64K /* entire flash, sans bootloader region */
9+
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 64K /* sector 4 */
10+
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5,6,7 are 128K */
1111
RAM (xrw) : ORIGIN = 0x20000194, LENGTH = 96K - 0x194
1212
}
1313

ports/stm32f4/boards/STM32F401.ld renamed to ports/stm32f4/boards/STM32F405_boot.ld

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
/*
2-
GNU linker script for STM32F401 with bootloader (from Meowbit Micropython)
3-
Doesn't work:
4-
5-
Traceback (most recent call last):
6-
File "../../tools/build_memory_info.py", line 64, in <module>
7-
regions[region] = int(eval(space))
8-
File "<string>", line 1, in <module>
9-
NameError: name 'FLASH_ISR' is not defined
2+
GNU linker script for STM32F405 with bootloader
3+
Based on Micropython
104
*/
115

126
/* Specify the memory areas */
13-
/* FLASH_FS (rx) : ORIGIN = 0x08020000, LENGTH = 128K */
14-
/* sectors 5 128K */
157
MEMORY
168
{
17-
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 512K - 64K /* entire flash */
18-
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 64K /* sector 4, sec 0~3 reserved for booloader */
19-
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5, 6,7 are 128K */
20-
RAM (xrw) : ORIGIN = 0x20000194, LENGTH = 96K - 0x194
9+
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 1024K - 64K /* entire flash, sans bootloader region */
10+
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 64K /* sector 0 */
11+
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 1024K - 64K - 64K /* sectors 5+ */
12+
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
13+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
2114
}
2215

2316
/* produce a link error if there is not this amount of RAM for these sections */
2417
_minimum_stack_size = 2K;
2518
_minimum_heap_size = 16K;
2619

27-
/* Define the stack. The stack is full descending so begins just above last byte
28-
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
29-
_estack = ORIGIN(RAM) + LENGTH(RAM) - _estack_reserve;
30-
_sstack = _estack - 16K; /* tunable */
20+
/* Define tho top end of the stack. The stack is full descending so begins just
21+
above last byte of RAM. Note that EABI requires the stack to be 8-byte
22+
aligned for a call. */
23+
_estack = ORIGIN(RAM) + LENGTH(RAM);
3124

3225
/* RAM extents for the garbage collector */
3326
_ram_start = ORIGIN(RAM);
3427
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
35-
_heap_start = _ebss; /* heap starts just after statically allocated memory */
36-
_heap_end = _sstack;
3728

3829
ENTRY(Reset_Handler)
3930

@@ -47,25 +38,8 @@ SECTIONS
4738
KEEP(*(.isr_vector)) /* Startup code */
4839

4940
/* This first flash block is 16K annd the isr vectors only take up
50-
about 400 bytes. So we pull in a couple of object files to pad it
51-
out. */
52-
53-
. = ALIGN(4);
54-
55-
/* NOTE: If you update the list of files contained in .isr_vector,
56-
then be sure to also update smhal/Makefile where it forcibly
57-
builds each of these files with -Os */
58-
59-
*/ff.o(.text*)
60-
*/vfs_fat_*.o(.text*)
61-
*/py/formatfloat.o(.text*)
62-
*/py/parsenum.o(.text*)
63-
*/py/mpprint.o(.text*)
64-
65-
*/py/compile.o(.text*)
66-
*/py/objset.o(.text*)
67-
*/py/mpz.o(.text*)
68-
*/py/vm.o(.text*)
41+
about 400 bytes. Micropython pads this with files, but this didn't
42+
work with the size of Circuitpython's ff object. */
6943

7044
. = ALIGN(4);
7145
} >FLASH_ISR
@@ -130,3 +104,5 @@ SECTIONS
130104

131105
.ARM.attributes 0 : { *(.ARM.attributes) }
132106
}
107+
108+

ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
#define SPI_FLASH_SCK_PIN (&pin_PB03)
4141
#define SPI_FLASH_CS_PIN (&pin_PA15)
4242

43+
// Bootloader only
44+
#ifdef UF2_BOOTLOADER_ENABLED
45+
#define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader
46+
#endif
47+
4348
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
4449
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
4550

ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.mk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ MCU_VARIANT = stm32f4
1414
MCU_SUB_VARIANT = stm32f405xx
1515
MCU_PACKAGE = 64
1616
CMSIS_MCU = STM32F405xx
17-
LD_FILE = boards/STM32F405.ld
18-
TEXT0_ADDR = 0x08000000
19-
TEXT1_ADDR = 0x08010000
17+
18+
LD_FS = boards/STM32F405_fs.ld # Default to internal FS
19+
LD_BOOT = boards/STM32F405_boot.ld # UF2 boot option
20+
UF2_OFFSET = 0x8010000
21+

ports/stm32f4/boards/meowbit_v121/mpconfigboard.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ MCU_SUB_VARIANT = stm32f401xe
2020
MCU_PACKAGE = 64
2121
CMSIS_MCU = STM32F401xE
2222
LD_FILE = boards/STM32F401_boot.ld
23-
# LD_FILE = boards/STM32F401_fs.ld #use for internal flash
23+
# LD_FILE = boards/STM32F401_fs.ld # use for internal flash
24+

ports/stm32f4/boards/pyb_nano_v2/mpconfigboard.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ MCU_SUB_VARIANT = stm32f411xe
1515
MCU_PACKAGE = 48
1616
CMSIS_MCU = STM32F411xE
1717
LD_FILE = boards/STM32F411VETx_FLASH.ld
18-
TEXT0_ADDR = 0x08000000
19-
TEXT1_ADDR = 0x08020000
18+

ports/stm32f4/boards/pyboard_v11/mpconfigboard.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ MCU_SUB_VARIANT = stm32f405xx
1313
MCU_PACKAGE = 64
1414
CMSIS_MCU = STM32F405xx
1515
LD_FILE = boards/STM32F405.ld
16-
TEXT0_ADDR = 0x08000000
17-
TEXT1_ADDR = 0x08010000
16+

ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ MCU_SUB_VARIANT = stm32f411xe
1818
MCU_PACKAGE = 48
1919
CMSIS_MCU = STM32F411xE
2020
LD_FILE = boards/STM32F411VETx_FLASH.ld
21-
TEXT0_ADDR = 0x08000000
22-
TEXT1_ADDR = 0x08020000
21+

0 commit comments

Comments
 (0)