diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 290453f50b..6f7c8fbd85 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -65,7 +65,10 @@ CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU) -fsingle CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__ CFLAGS += $(CFLAGS_EXTRA) +CFLAGS += -DMICROPY_HW_CODESIZE=$(MICROPY_HW_CODESIZE) + LDFLAGS += -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref +LDFLAGS += --defsym=_codesize=$(MICROPY_HW_CODESIZE) LIBS += $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) diff --git a/ports/samd/boards/samd21x18a.ld b/ports/samd/boards/samd21x18a.ld index 81a84a15d7..3ab051569f 100644 --- a/ports/samd/boards/samd21x18a.ld +++ b/ports/samd/boards/samd21x18a.ld @@ -2,10 +2,18 @@ GNU linker script for SAMD21 */ +/* +_codesize is defined in mpconfigmcu.mk or mpconfigboard.mk as +MICROPY_HW_CODESIZE and is set in Makefile +*/ + +_flashsize = 256K; /* The physical flash size */ +_bootloader = 8K; /* Must match the ORIGIN value of FLASH */ + /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00002000, LENGTH = 256K - 8K + FLASH (rx) : ORIGIN = 0x00002000, LENGTH = _codesize RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K } @@ -13,8 +21,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 8K; -_oflash_fs = ORIGIN(FLASH) + 192K - 8K; -_sflash_fs = LENGTH(FLASH) - 192K + 8K - 1; +_oflash_fs = ORIGIN(FLASH) + _codesize; +_sflash_fs = _flashsize - _codesize - _bootloader; _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/boards/samd51x19a.ld b/ports/samd/boards/samd51x19a.ld index cd03320ba4..30bc8e3328 100644 --- a/ports/samd/boards/samd51x19a.ld +++ b/ports/samd/boards/samd51x19a.ld @@ -2,10 +2,18 @@ GNU linker script for SAMD51 */ +/* +_codesize is defined in mpconfigmcu.mk or mpconfigboard.mk as +MICROPY_HW_CODESIZE and is set in Makefile +*/ + +_flashsize = 512K; /* The physical flash size */ +_bootloader = 16K; /* Must match the ORIGIN value of FLASH */ + /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00004000, LENGTH = 512K - 16K + FLASH (rx) : ORIGIN = 0x00004000, LENGTH = _codesize RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K } @@ -13,8 +21,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 16K; -_oflash_fs = ORIGIN(FLASH) + 384K - 16K; -_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1; +_oflash_fs = ORIGIN(FLASH) + _codesize; +_sflash_fs = _flashsize - _codesize - _bootloader; _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/boards/samd51x20a.ld b/ports/samd/boards/samd51x20a.ld index f0d5e5c6ae..472ab316c6 100644 --- a/ports/samd/boards/samd51x20a.ld +++ b/ports/samd/boards/samd51x20a.ld @@ -2,10 +2,18 @@ GNU linker script for SAMD51x20 */ +/* +_codesize is defined in mpconfigmcu.mk or mpconfigboard.mk as +MICROPY_HW_CODESIZE and is set in Makefile +*/ + +_flashsize = 1024K; /* The physical flash size */ +_bootloader = 16K; /* Must match the ORIGIN value of FLASH */ + /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00004000, LENGTH = 1024K - 16K + FLASH (rx) : ORIGIN = 0x00004000, LENGTH = _codesize RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K } @@ -13,8 +21,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 16K; -_oflash_fs = ORIGIN(FLASH) + 384K - 16K; -_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1; +_oflash_fs = ORIGIN(FLASH) + _codesize; +_sflash_fs = _flashsize - _codesize - _bootloader; _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/mcu/samd21/mpconfigmcu.mk b/ports/samd/mcu/samd21/mpconfigmcu.mk index ddd3e8b410..2e16d12a2d 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.mk +++ b/ports/samd/mcu/samd21/mpconfigmcu.mk @@ -2,6 +2,8 @@ CFLAGS_MCU += -mtune=cortex-m0plus -mcpu=cortex-m0plus -msoft-float MPY_CROSS_MCU_ARCH = armv6m +MICROPY_HW_CODESIZE ?= 184K + SRC_S += shared/runtime/gchelper_thumb1.s LIBM_SRC_C += $(addprefix lib/libm/,\ diff --git a/ports/samd/mcu/samd51/mpconfigmcu.mk b/ports/samd/mcu/samd51/mpconfigmcu.mk index 8596f59821..433404fd11 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.mk +++ b/ports/samd/mcu/samd51/mpconfigmcu.mk @@ -2,6 +2,8 @@ CFLAGS_MCU += -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=har MPY_CROSS_MCU_ARCH = armv7m +MICROPY_HW_CODESIZE ?= 368K + MICROPY_VFS_LFS2 ?= 1 MICROPY_VFS_FAT ?= 1 FROZEN_MANIFEST ?= mcu/$(MCU_SERIES_LOWER)/manifest.py