From bc9244180388860c831fb795d89fed2c09aa7a76 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Thu, 4 Apr 2019 15:42:33 +1100 Subject: [PATCH] switch nvm.ByteArray to use new nrf_nvm_safe_flash_page_write adafruit/circuitpython#1610 --- ports/nrf/common-hal/nvm/ByteArray.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ports/nrf/common-hal/nvm/ByteArray.c b/ports/nrf/common-hal/nvm/ByteArray.c index 7393ce0a59..d69abbdaca 100644 --- a/ports/nrf/common-hal/nvm/ByteArray.c +++ b/ports/nrf/common-hal/nvm/ByteArray.c @@ -29,7 +29,7 @@ #include #include -#include "nrf_nvmc.h" +#include "peripherals/nrf/nvm.h" uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) { return self->len; @@ -38,18 +38,14 @@ uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) { static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_t *bytes) { // Write a whole page to flash, buffering it first and then erasing and rewriting // it since we can only clear a whole page at a time. - // TODO (maybe) check if only clearing bits (don't need to erase) - // XXX should this suspend interrupts so erase/write is atomic? if (offset == 0 && len == FLASH_PAGE_SIZE) { - nrf_nvmc_page_erase(page_addr); - nrf_nvmc_write_bytes(page_addr, bytes, FLASH_PAGE_SIZE); + nrf_nvm_safe_flash_page_write(page_addr, bytes); } else { uint8_t buffer[FLASH_PAGE_SIZE]; memcpy(buffer, (uint8_t *)page_addr, FLASH_PAGE_SIZE); memcpy(buffer + offset, bytes, len); - nrf_nvmc_page_erase(page_addr); - nrf_nvmc_write_bytes(page_addr, buffer, FLASH_PAGE_SIZE); + nrf_nvm_safe_flash_page_write(page_addr, buffer); } }