Skip to content

Commit 31c20c0

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=xxxK in mpconfigmcu.mk for the MCU family as default or in mpconfigboard.mk for a specific board. 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 e8b4b3a commit 31c20c0

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

ports/samd/Makefile

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

59-
LDFLAGS += -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref
59+
LDDEFINES = \
60+
-DMICROPY_HW_CODESIZE=$(MICROPY_HW_CODESIZE)
61+
62+
LDFLAGS += -nostdlib -Map=$@.map --cref
6063

6164
LIBS += $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
6265

@@ -169,8 +172,10 @@ endif
169172
all: $(BUILD)/firmware.uf2
170173

171174
$(BUILD)/firmware.elf: $(OBJ)
175+
$(ECHO) "PREPROCESS LINK $@"
176+
$(Q)$(CC) -E -x c $(LDDEFINES) $(LD_FILES)| grep -v '^#' > $(BUILD)/link.ld
172177
$(ECHO) "LINK $@"
173-
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
178+
$(Q)$(LD) -T$(BUILD)/link.ld $(LDFLAGS) -o $@ $^ $(LIBS)
174179
$(Q)$(SIZE) $@
175180

176181
$(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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ CFLAGS_MCU += -mtune=cortex-m0plus -mcpu=cortex-m0plus -msoft-float
22

33
MPY_CROSS_MCU_ARCH = armv6m
44

5+
MICROPY_HW_CODESIZE ?= 184K
6+
57
SRC_S += shared/runtime/gchelper_thumb1.s
68

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

ports/samd/mcu/samd51/mpconfigmcu.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ 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 ?= 368K
6+
57
MICROPY_VFS_LFS2 ?= 1
68
MICROPY_VFS_FAT ?= 1
79
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