From 9f4df86016d8181dc06683d528dbd85473a1dbb9 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 2 Jul 2022 16:26:17 +0200 Subject: [PATCH] samd/boards: Move the flash filesystem definitions to the linker files. They used to be in mpconfigmcu.h, but have to be different for different chip variants, like the SAMD51x20. --- ports/samd/boards/samd21x18a.ld | 3 +++ ports/samd/boards/samd51g19a.ld | 3 +++ ports/samd/boards/samd51j19a.ld | 3 +++ ports/samd/boards/samd51p19a.ld | 3 +++ ports/samd/mcu/samd21/mpconfigmcu.h | 2 -- ports/samd/mcu/samd51/mpconfigmcu.h | 7 +------ ports/samd/samd_flash.c | 6 ++++-- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ports/samd/boards/samd21x18a.ld b/ports/samd/boards/samd21x18a.ld index b7d59c315b..81a84a15d7 100644 --- a/ports/samd/boards/samd21x18a.ld +++ b/ports/samd/boards/samd21x18a.ld @@ -13,5 +13,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 8K; +_oflash_fs = ORIGIN(FLASH) + 192K - 8K; +_sflash_fs = LENGTH(FLASH) - 192K + 8K - 1; + _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/boards/samd51g19a.ld b/ports/samd/boards/samd51g19a.ld index e0baa9bba0..cd03320ba4 100644 --- a/ports/samd/boards/samd51g19a.ld +++ b/ports/samd/boards/samd51g19a.ld @@ -13,5 +13,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 16K; +_oflash_fs = ORIGIN(FLASH) + 384K - 16K; +_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1; + _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/boards/samd51j19a.ld b/ports/samd/boards/samd51j19a.ld index e0baa9bba0..cd03320ba4 100644 --- a/ports/samd/boards/samd51j19a.ld +++ b/ports/samd/boards/samd51j19a.ld @@ -13,5 +13,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 16K; +_oflash_fs = ORIGIN(FLASH) + 384K - 16K; +_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1; + _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/boards/samd51p19a.ld b/ports/samd/boards/samd51p19a.ld index e0baa9bba0..cd03320ba4 100644 --- a/ports/samd/boards/samd51p19a.ld +++ b/ports/samd/boards/samd51p19a.ld @@ -13,5 +13,8 @@ MEMORY _estack = ORIGIN(RAM) + LENGTH(RAM) - 8; _sstack = _estack - 16K; +_oflash_fs = ORIGIN(FLASH) + 384K - 16K; +_sflash_fs = LENGTH(FLASH) - 384K + 16K - 1; + _sheap = _ebss; _eheap = _sstack; diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index 9329a6eb89..7ee23b59b1 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -12,8 +12,6 @@ #define MICROPY_PY_MATH (0) #define MICROPY_PY_CMATH (0) -#define MICROPY_HW_FLASH_STORAGE_BASE (0x30000) -#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF) #define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages; #define MICROPY_HW_UART_TXBUF (1) diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 0e5a885655..19193992f0 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -19,12 +19,7 @@ unsigned long trng_random_u32(void); // Due to a limitation in the TC counter for us, the ticks period is 2**29 #define MICROPY_PY_UTIME_TICKS_PERIOD (0x20000000) -// MicroPython configs -// samd_flash.c flash parameters -// Build a 128k Flash storage at top. 512k-128k=384k=0x60000 -// 512*1024= 0x80000 minus 128*1024= 0x20000 = 0x60000 -#define MICROPY_HW_FLASH_STORAGE_BASE (0x60000) -#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF) + #define VFS_BLOCK_SIZE_BYTES (1536) // #define MICROPY_HW_UART_TXBUF (1) diff --git a/ports/samd/samd_flash.c b/ports/samd/samd_flash.c index 2fffd614f9..6d9ee96895 100644 --- a/ports/samd/samd_flash.c +++ b/ports/samd/samd_flash.c @@ -53,11 +53,13 @@ typedef struct _samd_flash_obj_t { uint32_t flash_size; } samd_flash_obj_t; +extern uint8_t _oflash_fs, _sflash_fs; + // Build a Flash storage at top. STATIC samd_flash_obj_t samd_flash_obj = { .base = { &samd_flash_type }, - .flash_base = MICROPY_HW_FLASH_STORAGE_BASE, // Board specific: mpconfigboard.h - .flash_size = MICROPY_HW_FLASH_STORAGE_BYTES, // Board specific: mpconfigboard.h + .flash_base = (uint32_t)&_oflash_fs, // Get from MCU-Specific loader script. + .flash_size = (uint32_t)&_sflash_fs, // Get from MCU-Specific loader script. }; // FLASH stuff