8000 Merge pull request #2568 from hierophect/stm32-loader-linkers · pdp7/circuitpython@65045eb · GitHub
[go: up one dir, main page]

Skip to content

Commit 65045eb

Browse files
authored
Merge pull request adafruit#2568 from hierophect/stm32-loader-linkers
STM32: UF2 build option for STM32F405
2 parents c10479f + 3ce6fc8 commit 65045eb

File tree

13 files changed

+174
-75
lines changed

13 files changed

+174
-75
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_DEFAULT)
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

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

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

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
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 via Micropython
103
*/
114

125
/* Specify the memory areas */
13-
/* FLASH_FS (rx) : ORIGIN = 0x08020000, LENGTH = 128K */
14-
/* sectors 5 128K */
156
MEMORY
167
{
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
8+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
9+
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
10+
FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 1008K /* sectors 0-7*/
11+
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
12+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
2113
}
2214

2315
/* produce a link error if there is not this amount of RAM for these sections */
2416
_minimum_stack_size = 2K;
2517
_minimum_heap_size = 16K;
2618

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 */
19+
/* Define tho top end of the stack. The stack is full descending so begins just
20+
above last byte of RAM. Note that EABI requires the stack to be 8-byte
21+
aligned for a call. */
22+
_estack = ORIGIN(RAM) + LENGTH(RAM);
3123

3224
/* RAM extents for the garbage collector */
3325
_ram_start = ORIGIN(RAM);
3426
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
35-
_heap_start = _ebss; /* heap starts just after statically allocated memory */
36-
_heap_end = _sstack;
3727

3828
ENTRY(Reset_Handler)
3929

@@ -47,25 +37,8 @@ SECTIONS
4737
KEEP(*(.isr_vector)) /* Startup code */
4838

4939
/* 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*)
40+
about 400 bytes. Micropython pads this with files, but this didn't
41+
work with the size of Circuitpython's ff object. */
6942

7043
. = ALIGN(4);
7144
} >FLASH_ISR
@@ -130,3 +103,5 @@ SECTIONS
130103

131104
.ARM.attributes 0 : { *(.ARM.attributes) }
132105
}
106+
107+

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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ 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+
# Default includes filesystem, but uses external flash
19+
LD_DEFAULT = boards/STM32F405_default.ld
20+
LD_BOOT = boards/STM32F405_boot.ld # UF2 boot option
21+
UF2_OFFSET = 0x8010000
22+

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ MCU_VARIANT = stm32f4
1212
MCU_SUB_VARIANT = stm32f405xx
1313
MCU_PACKAGE = 64
1414
CMSIS_MCU = STM32F405xx
15-
LD_FILE = boards/STM32F405.ld
16-
TEXT0_ADDR = 0x08000000
17-
TEXT1_ADDR = 0x08010000
15+
LD_FILE = boards/STM32F405_fs.ld
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+

ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ MCU_SUB_VARIANT = stm32f411xe
1313
MCU_PACKAGE = 100
1414
CMSIS_MCU = STM32F411xE
1515
LD_FILE = boards/STM32F411VETx_FLASH.ld
16-
TEXT0_ADDR = 0x08000000
17-
TEXT1_ADDR = 0x08020000
16+

ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ MCU_SUB_VARIANT = stm32f412zx
1818
MCU_PACKAGE = 144
1919
CMSIS_MCU = STM32F412Zx
2020
LD_FILE = boards/STM32F412ZGTx_FLASH.ld
21-
TEXT0_ADDR = 0x08000000
22-
TEXT1_ADDR = 0x08020000
21+
2322

0 commit comments

Comments
 (0)
0