From 266be307770abe11c220eb493388807920914b7a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 25 Aug 2017 13:00:27 -0700 Subject: atmel-samd: Introduce a nvm module for non-volatile byte-level memory access. (#203) * atmel-samd: Introduce a nvm module for non-volatile byte-level memory access. This allows for persisting small configuration values even when the file system is read-only from CircuitPython. Fixes #160 * Review feedback: * Add tests. * Fix non-zero index. * Fix len() --- atmel-samd/boards/arduino_zero/mpconfigboard.h | 2 ++ atmel-samd/boards/circuitplayground_express/mpconfigboard.h | 6 +++++- atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h | 2 ++ atmel-samd/boards/feather_m0_basic/mpconfigboard.h | 2 ++ atmel-samd/boards/feather_m0_express/mpconfigboard.h | 6 +++++- atmel-samd/boards/gemma_m0/mpconfigboard.h | 2 ++ atmel-samd/boards/metro_m0_express/mpconfigboard.h | 6 +++++- atmel-samd/boards/samd21x18-bootloader-crystalless.ld | 4 ++-- .../boards/samd21x18-bootloader-external-flash-crystalless.ld | 3 ++- atmel-samd/boards/samd21x18-bootloader-external-flash.ld | 2 +- atmel-samd/boards/samd21x18-bootloader.ld | 2 +- atmel-samd/boards/samd21x18-external-flash.ld | 3 ++- atmel-samd/boards/samd21x18.ld | 3 ++- atmel-samd/boards/trinket_m0/mpconfigboard.h | 2 ++ 14 files changed, 35 insertions(+), 10 deletions(-) (limited to 'atmel-samd/boards') diff --git a/atmel-samd/boards/arduino_zero/mpconfigboard.h b/atmel-samd/boards/arduino_zero/mpconfigboard.h index dd4ec88d3..149963840 100644 --- a/atmel-samd/boards/arduino_zero/mpconfigboard.h +++ b/atmel-samd/boards/arduino_zero/mpconfigboard.h @@ -12,4 +12,6 @@ #include "internal_flash.h" +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/atmel-samd/boards/circuitplayground_express/mpconfigboard.h index 9499d25a2..f9ff05084 100644 --- a/atmel-samd/boards/circuitplayground_express/mpconfigboard.h +++ b/atmel-samd/boards/circuitplayground_express/mpconfigboard.h @@ -25,7 +25,11 @@ #include "spi_flash.h" -#define BOARD_FLASH_SIZE (0x00040000 - 0x2000) +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code. +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) #include "flash_S25FL216K.h" #include "flash_GD25Q16C.h" diff --git a/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h b/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h index f1b9dfcbe..2a2d21dd3 100644 --- a/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h +++ b/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h @@ -11,4 +11,6 @@ #include "internal_flash.h" +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/atmel-samd/boards/feather_m0_basic/mpconfigboard.h b/atmel-samd/boards/feather_m0_basic/mpconfigboard.h index ff6088c3a..a8a8247fa 100644 --- a/atmel-samd/boards/feather_m0_basic/mpconfigboard.h +++ b/atmel-samd/boards/feather_m0_basic/mpconfigboard.h @@ -11,4 +11,6 @@ #include "internal_flash.h" +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/atmel-samd/boards/feather_m0_express/mpconfigboard.h b/atmel-samd/boards/feather_m0_express/mpconfigboard.h index 929a8c0f3..896a04dd8 100644 --- a/atmel-samd/boards/feather_m0_express/mpconfigboard.h +++ b/atmel-samd/boards/feather_m0_express/mpconfigboard.h @@ -23,7 +23,11 @@ #include "spi_flash.h" -#define BOARD_FLASH_SIZE (0x00040000 - 0x2000) +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code. +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) #include "flash_S25FL216K.h" #include "flash_GD25Q16C.h" diff --git a/atmel-samd/boards/gemma_m0/mpconfigboard.h b/atmel-samd/boards/gemma_m0/mpconfigboard.h index ae1aa24a1..8988c9a63 100644 --- a/atmel-samd/boards/gemma_m0/mpconfigboard.h +++ b/atmel-samd/boards/gemma_m0/mpconfigboard.h @@ -11,6 +11,8 @@ #define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA24 | PORT_PA25) #define MICROPY_PORT_B (0) +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + #include "internal_flash.h" #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/atmel-samd/boards/metro_m0_express/mpconfigboard.h b/atmel-samd/boards/metro_m0_express/mpconfigboard.h index 9bb9a2f79..cbc28dc78 100644 --- a/atmel-samd/boards/metro_m0_express/mpconfigboard.h +++ b/atmel-samd/boards/metro_m0_express/mpconfigboard.h @@ -25,7 +25,11 @@ #include "spi_flash.h" -#define BOARD_FLASH_SIZE (0x00040000 - 0x2000) +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code. +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) #include "flash_S25FL216K.h" #include "flash_GD25Q16C.h" diff --git a/atmel-samd/boards/samd21x18-bootloader-crystalless.ld b/atmel-samd/boards/samd21x18-bootloader-crystalless.ld index 96527ab7e..56ae5feb4 100644 --- a/atmel-samd/boards/samd21x18-bootloader-crystalless.ld +++ b/atmel-samd/boards/samd21x18-bootloader-crystalless.ld @@ -5,8 +5,8 @@ /* Specify the memory areas */ MEMORY { - /* Leave 8KiB for the bootloader, 256b for persistent config (clock), and 64k for the flash file system. */ - FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 - 0x010000 + /* Leave 8KiB for the bootloader, 256b for persistent config (clock), 64k for the flash file system and 256b for the user config. */ + FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 - 0x010000 - 0x100 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */ } diff --git a/atmel-samd/boards/samd21x18-bootloader-external-flash-crystalless.ld b/atmel-samd/boards/samd21x18-bootloader-external-flash-crystalless.ld index a6be02f90..1c0424747 100644 --- a/atmel-samd/boards/samd21x18-bootloader-external-flash-crystalless.ld +++ b/atmel-samd/boards/samd21x18-bootloader-external-flash-crystalless.ld @@ -5,7 +5,8 @@ /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000 + 0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 /* Leave 8KiB for the bootloader and 256b for config. */ + /* Leave 8KiB for the bootloader, 256b for internal config and 256b for user config. */ + FLASH (rx) : ORIGIN = 0x00000000 + 0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 - 0x100 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */ } diff --git a/atmel-samd/boards/samd21x18-bootloader-external-flash.ld b/atmel-samd/boards/samd21x18-bootloader-external-flash.ld index bb1d3fdc4..4346c170c 100644 --- a/atmel-samd/boards/samd21x18-bootloader-external-flash.ld +++ b/atmel-samd/boards/samd21x18-bootloader-external-flash.ld @@ -5,7 +5,7 @@ /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000 + 0x2000, LENGTH = 0x00040000 - 0x2000 /* Leave 8KiB for the bootloader. */ + FLASH (rx) : ORIGIN = 0x00000000 + 0x2000, LENGTH = 0x00040000 - 0x2000 - 0x100 /* Leave 8KiB for the bootloader and 256b for user config. */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */ } diff --git a/atmel-samd/boards/samd21x18-bootloader.ld b/atmel-samd/boards/samd21x18-bootloader.ld index 0ea475ede..13a3f75c1 100644 --- a/atmel-samd/boards/samd21x18-bootloader.ld +++ b/atmel-samd/boards/samd21x18-bootloader.ld @@ -5,7 +5,7 @@ /* Specify the memory areas */ MEMORY { - /* Leave 8KiB for the bootloader and 64k for the flash file system. */ + /* Leave 8KiB for the bootloader, and 64k for the flash file system. */ FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000 - 0x2000 - 0x010000 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */ } diff --git a/atmel-samd/boards/samd21x18-external-flash.ld b/atmel-samd/boards/samd21x18-external-flash.ld index 90cb6160a..f5797cf6f 100644 --- a/atmel-samd/boards/samd21x18-external-flash.ld +++ b/atmel-samd/boards/samd21x18-external-flash.ld @@ -5,7 +5,8 @@ /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 - 0x100 /* 256 KiB but leave 256b for config */ + /* 256 KiB but leave 256b for internal config and 256b for user config (protected eeprom) */ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 - 0x100 - 0x100 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */ } diff --git a/atmel-samd/boards/samd21x18.ld b/atmel-samd/boards/samd21x18.ld index 98a24a811..a68094758 100644 --- a/atmel-samd/boards/samd21x18.ld +++ b/atmel-samd/boards/samd21x18.ld @@ -5,7 +5,8 @@ /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 - 0x100 - 0x010000 /* Leave 256b for config and 64k for the flash file system. */ + /* Leave 256b for internal config, 64k for the flash file system and 256b for user config. */ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 - 0x100 - 0x010000 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x008000 /* 32 KiB */ } diff --git a/atmel-samd/boards/trinket_m0/mpconfigboard.h b/atmel-samd/boards/trinket_m0/mpconfigboard.h index 7bb4f14cf..8fc70f22d 100644 --- a/atmel-samd/boards/trinket_m0/mpconfigboard.h +++ b/atmel-samd/boards/trinket_m0/mpconfigboard.h @@ -12,4 +12,6 @@ #include "internal_flash.h" +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) -- cgit v1.2.3