Skip to content

Commit 8e77db8

Browse files
committed
samd: Rearrange the mcu specific loader files.
Such that they are easier to adapt. The maximum code size is set by: MICROPY_HW_CODESIZE=xxx The value xxx must be set as plain integer bytes size, to allow size comparison in header files. It ca be set in mpconfigmcu.mk for the MCU family as default or in mpconfigboard.mk for a specific board. Actual default values: - SAMD21: 0x2e000 == 184k - SAMD51: 0x5c000 == 368k Setting the maximum code size allows the loader to raise and error if the code gets larger than the space dedicated for it.
1 parent 6ee8a5f commit 8e77db8

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

ports/samd/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU) -fsingle
6565
CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__
6666
CFLAGS += $(CFLAGS_EXTRA)
6767

68-
LDFLAGS += -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref
68+
LDDEFINES = \
69+
-DMICROPY_HW_CODESIZE=$(MICROPY_HW_CODESIZE)
70+
71+
LDFLAGS += -nostdlib -Map=$@.map --cref
6972

7073
LIBS += $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
7174

@@ -178,8 +181,10 @@ endif
178181
all: $(BUILD)/firmware.uf2
179182

180183
$(BUILD)/firmware.elf: $(OBJ)
184+
$(ECHO) "PREPROCESS LINK $@"
185+
$(Q)$(CC) -E -x c $(LDDEFINES) $(LD_FILES)| grep -v '^#' > $(BUILD)/link.ld
181186
$(ECHO) "LINK $@"
182-
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
187+
$(Q)$(LD) -T$(BUILD)/link.ld $(LDFLAGS) -o $@ $^ $(LIBS)
183188
$(Q)$(SIZE) $@
184189

185190
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf

ports/samd/boards/samd21x18a.ld

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
GNU linker script for SAMD21
33
*/
44

5+
/* MICROPY_HW_CODESIZE is defined in mpconfigmcu.mk or mpconfigboard.mk */
6+
7+
_flashsize = 256K; /* The physical flash size */
8+
_bootloader = 8K; /* Must match the ORIGIN value of FLASH */
9+
_codesize = MICROPY_HW_CODESIZE; /* the space dedicated to code */
10+
511
/* Specify the memory areas */
612
MEMORY
713
{
8-
FLASH (rx) : ORIGIN = 0x00002000, LENGTH = 256K - 8K
14+
FLASH (rx) : ORIGIN = 0x00002000, LENGTH = _codesize
915
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
1016
}
1117

1218
/* Top end of the stack, with room for double-tap variable */
1319
_estack = ORIGIN(RAM) + LENGTH(RAM) - 8;
1420
_sstack = _estack - 8K;
1521

16-
_oflash_fs = ORIGIN(FLASH) + 192K - 8K;
17-
_sflash_fs = LENGTH(FLASH) - 192K + 8K - 1;
22+
_oflash_fs = ORIGIN(FLASH) + _codesize;
23+
_sflash_fs = _flashsize - _codesize - _bootloader;
1824

1925
_sheap = _ebss;
2026
_eheap = _sstack;

ports/samd/boards/samd51x19a.ld

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
GNU linker script for SAMD51
33
*/
44

5+
/* MICROPY_HW_CODESIZE is defined in mpconfigmcu.mk or mpconfigboard.mk */
6+
7+
_flashsize = 512K; /* The physical flash size */
8+
_bootloader = 16K; /* Must match the ORIGIN value of FLASH */
9+
_codesize = MICROPY_HW_CODESIZE; /* the space dedicated to code */
10+
511
/* Specify the memory areas */
612
MEMORY
713
{
8-
FLASH (rx) : ORIGIN = 0x00004000, LENGTH = 512K - 16K
14+
FLASH (rx) : ORIGIN = 0x00004000, LENGTH = _codesize
915
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
1016
}
1117

1218
/* Top end of the stack, with room for double-tap variable */
1319
_estack = ORIGIN(RAM) + LENGTH(RAM) - 8;
1420
_sstack = _estack - 16K;
1521

16-
_oflash_fs = ORIGIN(FLASH) + 384K - 16K;
17-
_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1;
22+
_oflash_fs = ORIGIN(FLASH) + _codesize;
23+
_sflash_fs = _flashsize - _codesize - _bootloader;
1824

1925
_sheap = _ebss;
2026
_eheap = _sstack;

ports/samd/boards/samd51x20a.ld

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
GNU linker script for SAMD51x20
33
*/
44

5+
/* MICROPY_HW_CODESIZE is defined in mpconfigmcu.mk or mpconfigboard.mk */
6+
7+
_flashsize = 1024K; /* The physical flash size */
8+
_bootloader = 16K; /* Must match the ORIGIN value of FLASH */
9+
_codesize = MICROPY_HW_CODESIZE; /* the space dedicated to code */
10+
511
/* Specify the memory areas */
612
MEMORY
713
{
8-
FLASH (rx) : ORIGIN = 0x00004000, LENGTH = 1024K - 16K
14+
FLASH (rx) : ORIGIN = 0x00004000, LENGTH = _codesize
915
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
1016
}
1117

1218
/* Top end of the stack, with room for double-tap variable */
1319
_estack = ORIGIN(RAM) + LENGTH(RAM) - 8;
1420
_sstack = _estack - 16K;
1521

16-
_oflash_fs = ORIGIN(FLASH) + 384K - 16K;
17-
_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1;
22+
_oflash_fs = ORIGIN(FLASH) + _codesize;
23+
_sflash_fs = _flashsize - _codesize - _bootloader;
1824

1925
_sheap = _ebss;
2026
_eheap = _sstack;

ports/samd/mcu/samd21/mpconfigmcu.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ CFLAGS_MCU += -mtune=cortex-m0plus -mcpu=cortex-m0plus -msoft-float
22

33
MPY_CROSS_MCU_ARCH = armv6m
44

5+
# MICROPY_HW_CODESIZE must be give as plain integer. 0x2e000 == 184k
6+
MICROPY_HW_CODESIZE ?= 0x2e000
7+
8+
CFLAGS += -DMICROPY_HW_CODESIZE=$(MICROPY_HW_CODESIZE)
9+
510
SRC_S += shared/runtime/gchelper_thumb1.s
611

712
LIBM_SRC_C += $(addprefix lib/libm/,\

ports/samd/mcu/samd51/mpconfigmcu.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ CFLAGS_MCU += -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=har
22

33
MPY_CROSS_MCU_ARCH = armv7m
44

5+
# MICROPY_HW_CODESIZE must be give as plain integer: 0x5c000 == 368k
6+
MICROPY_HW_CODESIZE ?= 0x5c000
7+
8+
CFLAGS += -DMICROPY_HW_CODESIZE=$(MICROPY_HW_CODESIZE)
9+
510
MICROPY_VFS_LFS2 ?= 1
611
MICROPY_VFS_FAT ?= 1
712
FROZEN_MANIFEST ?= mcu/$(MCU_SERIES_LOWER)/manifest.py

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy