Skip to content

Commit 1f433c7

Browse files
dhylandsdpgeorge
authored andcommitted
stmhal: Fix linker map for STM32L476 chips.
In particular, this makes the L4 .isr_vector section 16K in size so it's the same as the F4/F7 MCUs. The patch also moves the L4 filesystem to the end of flash, which allows for 512K filesystem on the 1Mb devices like the STM32L476DISC.
1 parent bd925b5 commit 1f433c7

6 files changed

Lines changed: 23 additions & 10 deletions

File tree

stmhal/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,13 @@ else
313313
$(Q)$(DFU_UTIL) -a 0 -d $(DEVICE) -D $<
314314
endif
315315

316+
TEXT_ADDR ?= 0x08020000
317+
316318
deploy-stlink: $(BUILD)/firmware.dfu
317319
$(ECHO) "Writing $(BUILD)/firmware0.bin to the board via ST-LINK"
318320
$(Q)$(STFLASH) write $(BUILD)/firmware0.bin 0x08000000
319321
$(ECHO) "Writing $(BUILD)/firmware1.bin to the board via ST-LINK"
320-
$(Q)$(STFLASH) --reset write $(BUILD)/firmware1.bin 0x08020000
322+
$(Q)$(STFLASH) --reset write $(BUILD)/firmware1.bin $(TEXT_ADDR)
321323

322324
deploy-openocd: $(BUILD)/firmware.dfu
323325
$(ECHO) "Writing $(BUILD)/firmware{0,1}.bin to the board via ST-LINK using OpenOCD"
@@ -327,7 +329,7 @@ $(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
327329
$(ECHO) "Create $@"
328330
$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $(BUILD)/firmware0.bin
329331
$(Q)$(OBJCOPY) -O binary -j .text -j .data $^ $(BUILD)/firmware1.bin
330-
$(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/firmware0.bin -b 0x08020000:$(BUILD)/firmware1.bin $@
332+
$(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/firmware0.bin -b $(TEXT_ADDR):$(BUILD)/firmware1.bin $@
331333

332334
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
333335
$(ECHO) "Create $@"

stmhal/boards/LIMIFROG/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ MCU_SERIES = l4
22
CMSIS_MCU = STM32L476xx
33
AF_FILE = boards/stm32l476_af.csv
44
LD_FILE = boards/stm32l476xe.ld
5+
TEXT_ADDR = 0x08004000

stmhal/boards/STM32L476DISC/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ MCU_SERIES = l4
22
CMSIS_MCU = STM32L476xx
33
AF_FILE = boards/stm32l476_af.csv
44
LD_FILE = boards/stm32l476xg.ld
5+
TEXT_ADDR = 0x08004000

stmhal/boards/stm32l476xe.ld

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
MEMORY
77
{
88
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
9-
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0000800 /* sector 0, 2 KiB */
10-
FLASH_FS (r) : ORIGIN = 0x08000800, LENGTH = 0x001F800 /* sectors 1-63 (2K each = 126 KiB) */
11-
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x0060000 /* Sector starting @ 64 */
9+
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sectors 0-7, 16 KiB */
10+
FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 0x005C000 /* sectors 8-191, 368 KiB */
11+
FLASH_FS (r) : ORIGIN = 0x08060000, LENGTH = 0x0020000 /* sectors 192-255, 128 KiB */
1212
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
1313
SRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
1414
}
@@ -30,3 +30,6 @@ _ram_start = ORIGIN(RAM);
3030
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
3131
_heap_start = _ebss; /* heap starts just after statically allocated memory */
3232
_heap_end = 0x20014000; /* tunable */
33+
34+
_flash_fs_start = ORIGIN(FLASH_FS);
35+
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);

stmhal/boards/stm32l476xg.ld

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
MEMORY
77
{
88
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
9-
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0000800 /* sector 0, 2 KiB */
10-
FLASH_FS (r) : ORIGIN = 0x08000800, LENGTH = 0x001F800 /* sectors 1-63 (2K each = 126 KiB) */
11-
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x0080000 /* Sector starting @ 64 */
9+
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sectors 0-7, 16 KiB */
10+
FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 0x007C000 /* sectors 8-255, 496 KiB */
11+
FLASH_FS (r) : ORIGIN = 0x08080000, LENGTH = 0x0080000 /* sectors 256-511 512 KiB */
1212
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
1313
SRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
1414
}
@@ -32,3 +32,6 @@ _ram_start = ORIGIN(RAM);
3232
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
3333
_heap_start = _ebss; /* heap starts just after statically allocated memory */
3434
_heap_end = 0x20014000; /* tunable */
35+
36+
_flash_fs_start = ORIGIN(FLASH_FS);
37+
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);

stmhal/storage.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,14 @@ STATIC byte flash_cache_mem[0x4000] __attribute__((aligned(4))); // 16k
8686

8787
#elif defined(STM32L476xx)
8888

89+
extern uint8_t _flash_fs_start;
90+
extern uint8_t _flash_fs_end;
91+
8992
// The STM32L476 doesn't have CCRAM, so we use the 32K SRAM2 for this.
9093
#define CACHE_MEM_START_ADDR (0x10000000) // SRAM2 data RAM, 32k
9194
#define FLASH_SECTOR_SIZE_MAX (0x00800) // 2k max
92-
#define FLASH_MEM_SEG1_START_ADDR (0x08000800) // sector 1
93-
#define FLASH_MEM_SEG1_NUM_BLOCKS (252) // 1 Block=512 Bytes Reserve 126 kBytes
95+
#define FLASH_MEM_SEG1_START_ADDR ((long)&_flash_fs_start)
96+
#define FLASH_MEM_SEG1_NUM_BLOCKS ((&_flash_fs_end - &_flash_fs_start) / 512)
9497

9598
#else
9699
#error "no storage support for this MCU"

0 commit comments

Comments
 (0)