diff --git a/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld b/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld index 8a700d6109..2587a19e34 100644 --- a/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld +++ b/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld @@ -11,7 +11,6 @@ 0x000ED000..0x000F3FFF (28KB ) Private Config Data (Bonding, Keys, etc.) 0x000AD000..0x000ECFFF (256KB) User Filesystem - 0x00026000..0x000ACFFF (540KB) Application Code (including ISR vector) 0x00001000..0x00025FFF (148KB) SoftDevice 0x00000000..0x00000FFF (4KB) Master Boot Record diff --git a/ports/nrf/common-hal/nvm/ByteArray.c b/ports/nrf/common-hal/nvm/ByteArray.c index d69abbdaca..ee270f79bb 100644 --- a/ports/nrf/common-hal/nvm/ByteArray.c +++ b/ports/nrf/common-hal/nvm/ByteArray.c @@ -31,8 +31,15 @@ #include "peripherals/nrf/nvm.h" +// defined in linker +extern uint32_t __fatfs_flash_start_addr[]; +extern uint32_t __fatfs_flash_length[]; + +#define NVM_START_ADDR ((uint32_t)__fatfs_flash_start_addr + \ + (uint32_t)__fatfs_flash_length - CIRCUITPY_INTERNAL_NVM_SIZE) + uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) { - return self->len; + return CIRCUITPY_INTERNAL_NVM_SIZE; } static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_t *bytes) { @@ -52,7 +59,7 @@ static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_ bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self, uint32_t start_index, uint8_t* values, uint32_t len) { - uint32_t address = self->start_address + start_index; + uint32_t address = NVM_START_ADDR + start_index; uint32_t offset = address % FLASH_PAGE_SIZE; uint32_t page_addr = address - offset; @@ -69,5 +76,5 @@ bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self, void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self, uint32_t start_index, uint32_t len, uint8_t* values) { - memcpy(values, (uint8_t *)(self->start_address + start_index), len); + memcpy(values, (uint8_t *)(NVM_START_ADDR + start_index), len); } diff --git a/ports/nrf/peripherals/nrf/nvm.c b/ports/nrf/peripherals/nrf/nvm.c index f9cc1b806a..d8fddc4dcf 100644 --- a/ports/nrf/peripherals/nrf/nvm.c +++ b/ports/nrf/peripherals/nrf/nvm.c @@ -25,7 +25,6 @@ * THE SOFTWARE. */ -//#include "py/obj.h" #include "py/runtime.h" #include @@ -33,12 +32,12 @@ #include "nrf_nvmc.h" +#define FLASH_PAGE_SIZE (4096) + #ifdef BLUETOOTH_SD #include "ble_drv.h" #include "nrf_sdm.h" -#define FLASH_PAGE_SIZE (4096) - STATIC void sd_flash_operation_start(void) { sd_flash_operation_status = SD_FLASH_OPERATION_IN_PROGRESS; } diff --git a/ports/nrf/supervisor/internal_flash.c b/ports/nrf/supervisor/internal_flash.c index 9aaaf9b5d1..016d970760 100644 --- a/ports/nrf/supervisor/internal_flash.c +++ b/ports/nrf/supervisor/internal_flash.c @@ -67,7 +67,7 @@ uint32_t supervisor_flash_get_block_size(void) { } uint32_t supervisor_flash_get_block_count(void) { - return ((uint32_t) __fatfs_flash_length) / FILESYSTEM_BLOCK_SIZE ; + return ((uint32_t) __fatfs_flash_length - CIRCUITPY_INTERNVAL_NVM_SIZE) / FILESYSTEM_BLOCK_SIZE ; } mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) {