diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 7d2982ca0d..2f01abc4f6 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -285,6 +285,8 @@ SRC_COMMON_HAL = \ analogio/__init__.c \ analogio/AnalogIn.c \ analogio/AnalogOut.c \ + nvm/__init__.c \ + nvm/ByteArray.c \ pulseio/__init__.c \ pulseio/PulseIn.c \ pulseio/PulseOut.c \ @@ -293,9 +295,7 @@ SRC_COMMON_HAL = \ usb_hid/Device.c \ audioio/__init__.c \ audioio/AudioOut.c \ -# nvm/__init__.c \ - audiobusio/PDMIn.c \ - nvm/ByteArray.c \ +# audiobusio/PDMIn.c \ touchio/__init__.c \ touchio/TouchIn.c \ diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h index 02802a6a90..73d45f2cf8 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h @@ -42,8 +42,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h index ef13bcafec..56e9c8bb71 100644 --- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h @@ -35,8 +35,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h index 883d7a2e53..5bc74d5a74 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h @@ -37,8 +37,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h index bd56a7bdfa..6e10222562 100644 --- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h @@ -19,8 +19,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 8192 #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h index 675b9a30db..a7ecd27ea8 100644 --- a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h @@ -35,8 +35,8 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) #include "external_flash/devices.h" diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h index 7f6319152d..63fbc8cb8b 100644 --- a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h @@ -19,8 +19,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 8192 #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h index c8ceaa386b..a433e99495 100644 --- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h @@ -36,8 +36,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h index e2b7f9982e..7012037717 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h @@ -22,8 +22,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 8192 #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h index 7af9767caa..206d85465e 100644 --- a/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h @@ -49,8 +49,7 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 8192 #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/boards/samd51x18-bootloader-external-flash.ld b/ports/atmel-samd/boards/samd51x18-bootloader-external-flash.ld index 0bd2a8297c..c0e812ce19 100644 --- a/ports/atmel-samd/boards/samd51x18-bootloader-external-flash.ld +++ b/ports/atmel-samd/boards/samd51x18-bootloader-external-flash.ld @@ -5,8 +5,8 @@ /* Specify the memory areas */ MEMORY { - /* Leave 16KiB for the bootloader. */ - FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 256K - 16K + /* Leave 16KiB for the bootloader. 8K for user data*/ + FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 256K - 16K - 8K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K } @@ -76,7 +76,7 @@ SECTIONS .stack : { . = ALIGN(4); - . = . + 2K; /* Reserve a minimum of 2K for the stack. */ + . = . + 10K; /* Reserve a minimum of 10K for the stack. nvm will temporarily store 8k on the stack when writing. */ . = ALIGN(4); } >RAM diff --git a/ports/atmel-samd/boards/samd51x19-bootloader-external-flash.ld b/ports/atmel-samd/boards/samd51x19-bootloader-external-flash.ld index b6b4f32650..253a764c9b 100644 --- a/ports/atmel-samd/boards/samd51x19-bootloader-external-flash.ld +++ b/ports/atmel-samd/boards/samd51x19-bootloader-external-flash.ld @@ -5,8 +5,8 @@ /* Specify the memory areas */ MEMORY { - /* Leave 16KiB for the bootloader. */ - FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K + /* Leave 16KiB for the bootloader. 8K for user data*/ + FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K - 8K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K } @@ -76,7 +76,7 @@ SECTIONS .stack : { . = ALIGN(4); - . = . + 2K; /* Reserve a minimum of 2K for the stack. */ + . = . + 10K; /* Reserve a minimum of 10K for the stack. nvm will temporarily store 8k on the stack when writing. */ . = ALIGN(4); } >RAM diff --git a/ports/atmel-samd/boards/samd51x19-bootloader.ld b/ports/atmel-samd/boards/samd51x19-bootloader.ld index 4876e82277..56786a37af 100644 --- a/ports/atmel-samd/boards/samd51x19-bootloader.ld +++ b/ports/atmel-samd/boards/samd51x19-bootloader.ld @@ -5,8 +5,8 @@ /* Specify the memory areas */ MEMORY { - /* Leave 16KiB for the bootloader and 256KiB for the internal file system. */ - FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K - 256K + /* Leave 16KiB for the bootloader, 256KiB for the internal file system, and 8KiB for user binary data. */ + FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K - 256K - 8K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K } @@ -76,7 +76,7 @@ SECTIONS .stack : { . = ALIGN(4); - . = . + 2K; /* Reserve a minimum of 2K for the stack. */ + . = . + 10K; /* Reserve a minimum of 10K for the stack. nvm will temporarily store 8k on the stack when writing. */ . = ALIGN(4); } >RAM diff --git a/ports/atmel-samd/boards/samd51x20-bootloader-external-flash.ld b/ports/atmel-samd/boards/samd51x20-bootloader-external-flash.ld index 3a1611279c..598915b1b7 100644 --- a/ports/atmel-samd/boards/samd51x20-bootloader-external-flash.ld +++ b/ports/atmel-samd/boards/samd51x20-bootloader-external-flash.ld @@ -6,7 +6,7 @@ MEMORY { /* Leave 16KiB for the bootloader. */ - FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 1M - 16K + FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 1M - 16K - 8K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K } @@ -76,7 +76,7 @@ SECTIONS .stack : { . = ALIGN(4); - . = . + 2K; /* Reserve a minimum of 2K for the stack. */ + . = . + 10K; /* Reserve a minimum of 10K for the stack. nvm will temporarily store 8k on the stack when writing. */ . = ALIGN(4); } >RAM diff --git a/ports/atmel-samd/boards/samd51x20-bootloader.ld b/ports/atmel-samd/boards/samd51x20-bootloader.ld index d3d37de3b2..49d4d87914 100644 --- a/ports/atmel-samd/boards/samd51x20-bootloader.ld +++ b/ports/atmel-samd/boards/samd51x20-bootloader.ld @@ -5,8 +5,8 @@ /* Specify the memory areas */ MEMORY { - /* Leave 16KiB for the bootloader and 512k for the filesystem. */ - FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 1M - 16K - 512K + /* Leave 16KiB for the bootloader, 512k for the filesystem and 8k for user config data. */ + FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 1M - 16K - 512K - 8K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K } @@ -76,7 +76,7 @@ SECTIONS .stack : { . = ALIGN(4); - . = . + 2K; /* Reserve a minimum of 2K for the stack. */ + . = . + 10K; /* Reserve a minimum of 10K for the stack. nvm will temporarily store 8k on the stack when writing. */ . = ALIGN(4); } >RAM diff --git a/ports/atmel-samd/boards/samd51x20-external-flash.ld b/ports/atmel-samd/boards/samd51x20-external-flash.ld index e31f31a580..d3ed90476e 100644 --- a/ports/atmel-samd/boards/samd51x20-external-flash.ld +++ b/ports/atmel-samd/boards/samd51x20-external-flash.ld @@ -5,7 +5,7 @@ /* Specify the memory areas */ MEMORY { - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1M + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1M - 8K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K } @@ -74,7 +74,7 @@ SECTIONS .stack : { . = ALIGN(4); - . = . + 2K; /* Reserve a minimum of 2K for the stack. */ + . = . + 10K; /* Reserve a minimum of 10K for the stack. nvm will temporarily store 8k on the stack when writing. */ . = ALIGN(4); } >RAM diff --git a/ports/atmel-samd/boards/samd51x20.ld b/ports/atmel-samd/boards/samd51x20.ld index 4c44c7fa8f..e203c5b7a9 100644 --- a/ports/atmel-samd/boards/samd51x20.ld +++ b/ports/atmel-samd/boards/samd51x20.ld @@ -5,8 +5,8 @@ /* Specify the memory areas */ MEMORY { - /* 1024 KiB minus 512KiB for the internal file system. */ - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1M - 512K + /* 1024 KiB minus 512KiB for the internal file system and 8KiB for the user nvm. */ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1M - 512K - 8K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K } @@ -75,7 +75,7 @@ SECTIONS .stack : { . = ALIGN(4); - . = . + 2K; /* Reserve a minimum of 2K for the stack. */ + . = . + 10K; /* Reserve a minimum of 10K for the stack. nvm will temporarily store 8k on the stack when writing. */ . = ALIGN(4); } >RAM diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h index 340e25e59b..ea45c1f8b8 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h @@ -44,8 +44,8 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) #include "external_flash/devices.h" diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.h b/ports/atmel-samd/boards/ugame10/mpconfigboard.h index b9ae952a8c..1652314ed8 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.h +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.h @@ -37,8 +37,8 @@ // 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 CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) #include "external_flash/devices.h" diff --git a/ports/atmel-samd/clocks.c b/ports/atmel-samd/clocks.c index 87da2e8629..be2fe0836b 100644 --- a/ports/atmel-samd/clocks.c +++ b/ports/atmel-samd/clocks.c @@ -74,10 +74,12 @@ bool gclk_enabled(uint8_t gclk) { void disable_gclk(uint8_t gclk) { #ifdef SAMD51 + while ((GCLK->SYNCBUSY.vec.GENCTRL & (1 << gclk)) != 0) {} GCLK->GENCTRL[gclk].bit.GENEN = false; while ((GCLK->SYNCBUSY.vec.GENCTRL & (1 << gclk)) != 0) {} #endif #ifdef SAMD21 + while (GCLK->STATUS.bit.SYNCBUSY == 1) {} GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(gclk); while (GCLK->STATUS.bit.SYNCBUSY == 1) {} #endif diff --git a/ports/atmel-samd/common-hal/microcontroller/__init__.c b/ports/atmel-samd/common-hal/microcontroller/__init__.c index 5839ed5131..4b8c33182f 100644 --- a/ports/atmel-samd/common-hal/microcontroller/__init__.c +++ b/ports/atmel-samd/common-hal/microcontroller/__init__.c @@ -85,13 +85,13 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = { // NVM is only available on Express boards for now. #if CIRCUITPY_INTERNAL_NVM_SIZE > 0 // The singleton nvm.ByteArray object. -// const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { -// .base = { -// .type = &nvm_bytearray_type, -// }, -// .len = NVMCTRL_ROW_SIZE, -// .start_address = (uint8_t*) (FLASH_SIZE - NVMCTRL_ROW_SIZE) -// }; +const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { + .base = { + .type = &nvm_bytearray_type, + }, + .len = CIRCUITPY_INTERNAL_NVM_SIZE, + .start_address = (uint8_t*) (FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) +}; #endif // This maps MCU pin names to pin objects. diff --git a/ports/atmel-samd/common-hal/nvm/ByteArray.c b/ports/atmel-samd/common-hal/nvm/ByteArray.c index df8b5790e2..ab9cd7d804 100644 --- a/ports/atmel-samd/common-hal/nvm/ByteArray.c +++ b/ports/atmel-samd/common-hal/nvm/ByteArray.c @@ -26,7 +26,7 @@ #include "common-hal/nvm/ByteArray.h" -#include "asf/sam0/drivers/nvm/nvm.h" +#include "hal_flash.h" #include #include @@ -36,48 +36,12 @@ uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) { } bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self, - uint32_t start_index, uint8_t* values, uint32_t len) { - uint32_t total_written = 0; - for (uint32_t i = 0; i < self->len / NVMCTRL_ROW_SIZE; i++) { - uint32_t row_start = NVMCTRL_ROW_SIZE * i; - if (row_start + NVMCTRL_ROW_SIZE < start_index || start_index + len < row_start) { - continue; - } - uint8_t temp_row[NVMCTRL_ROW_SIZE]; - memcpy(temp_row, - self->start_address + row_start, - NVMCTRL_ROW_SIZE); - enum status_code error_code; - do { - error_code = nvm_erase_row((uint32_t) self->start_address + row_start); - } while (error_code == STATUS_BUSY); - if (error_code != STATUS_OK) { - return false; - } - uint32_t data_start = 0; - if (start_index > row_start) { - data_start = start_index - row_start; - } - uint32_t data_len = len; - uint32_t data_remaining = data_len - total_written; - uint32_t row_remaining = NVMCTRL_ROW_SIZE - data_start; - if (data_remaining > row_remaining) { - data_len = row_remaining; - } - memcpy(temp_row + data_start, - values + total_written, - data_len); - for (int page = 0; page < NVMCTRL_ROW_SIZE / NVMCTRL_PAGE_SIZE; page++) { - do { - error_code = nvm_write_buffer((uint32_t) self->start_address + row_start + page * NVMCTRL_PAGE_SIZE, - temp_row + page * NVMCTRL_PAGE_SIZE, - NVMCTRL_PAGE_SIZE); - } while (error_code == STATUS_BUSY); - if (error_code != STATUS_OK) { - return false; - } - } - } + uint32_t start_index, uint8_t* values, uint32_t len) { + // We don't use features that use any advanced NVMCTRL features so we can fake the descriptor + // whenever we need it instead of storing it long term. + struct flash_descriptor desc; + desc.dev.hw = NVMCTRL; + flash_write(&desc, (uint32_t) self->start_address + start_index, values, len); return true; } diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index eafb9b7857..963817dbf8 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -147,35 +147,6 @@ safe_mode_t port_init(void) { return USER_SAFE_MODE; } - // #if CIRCUITPY_INTERNAL_NVM_SIZE > 0 - // // Upgrade the nvm flash to include one sector for eeprom emulation. - // struct nvm_fusebits fuses; - // if (nvm_get_fuses(&fuses) == STATUS_OK && - // fuses.eeprom_size == NVM_EEPROM_EMULATOR_SIZE_0) { - // #ifdef INTERNAL_FLASH_FS - // // Shift the internal file system up one row. - // for (uint8_t row = 0; row < TOTAL_INTERNAL_FLASH_SIZE / NVMCTRL_ROW_SIZE; row++) { - // uint32_t new_row_address = INTERNAL_FLASH_MEM_SEG1_START_ADDR + row * NVMCTRL_ROW_SIZE; - // nvm_erase_row(new_row_address); - // nvm_write_buffer(new_row_address, - // (uint8_t*) (new_row_address + CIRCUITPY_INTERNAL_EEPROM_SIZE), - // NVMCTRL_ROW_SIZE); - // } - // #endif - // uint32_t nvm_size = CIRCUITPY_INTERNAL_NVM_SIZE; - // uint8_t enum_value = 6; - // while (nvm_size > 256 && enum_value != 255) { - // nvm_size /= 2; - // enum_value -= 1; - // } - // if (enum_value != 255 && nvm_size == 256) { - // // Mark the last section as eeprom now. - // fuses.eeprom_size = (enum nvm_eeprom_emulator_size) enum_value; - // nvm_set_fuses(&fuses); - // } - // } - // #endif - return NO_SAFE_MODE; } diff --git a/shared-bindings/nvm/ByteArray.c b/shared-bindings/nvm/ByteArray.c index f4e0463781..8b17820456 100644 --- a/shared-bindings/nvm/ByteArray.c +++ b/shared-bindings/nvm/ByteArray.c @@ -36,12 +36,13 @@ //| ================================================================================ //| //| Non-volatile memory is available as a byte array that persists over reloads -//| and power cycles. +//| and power cycles. Each assignment causes an erase and write cycle so its recommended to assign +//| all values to change at once. //| //| Usage:: //| //| import microcontroller -//| microcontroller.nvm[0] = 0xcc +//| microcontroller.nvm[0:] = b"\xcc\x10\x00" //| //| .. class:: ByteArray()