Skip to content

Commit bc92441

Browse files
committed
switch nvm.ByteArray to use new nrf_nvm_safe_flash_page_write
adafruit#1610
1 parent cd69db7 commit bc92441

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ports/nrf/common-hal/nvm/ByteArray.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <stdio.h>
3030
#include <string.h>
3131

32-
#include "nrf_nvmc.h"
32+
#include "peripherals/nrf/nvm.h"
3333

3434
uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) {
3535
return self->len;
@@ -38,18 +38,14 @@ uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) {
3838
static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_t *bytes) {
3939
// Write a whole page to flash, buffering it first and then erasing and rewriting
4040
// it since we can only clear a whole page at a time.
41-
// TODO (maybe) check if only clearing bits (don't need to erase)
42-
// XXX should this suspend interrupts so erase/write is atomic?
4341

4442
if (offset == 0 && len == FLASH_PAGE_SIZE) {
45-
nrf_nvmc_page_erase(page_addr);
46-
nrf_nvmc_write_bytes(page_addr, bytes, FLASH_PAGE_SIZE);
43+
nrf_nvm_safe_flash_page_write(page_addr, bytes);
4744
} else {
4845
uint8_t buffer[FLASH_PAGE_SIZE];
4946
memcpy(buffer, (uint8_t *)page_addr, FLASH_PAGE_SIZE);
5047
memcpy(buffer + offset, bytes, len);
51-
nrf_nvmc_page_erase(page_addr);
52-
nrf_nvmc_write_bytes(page_addr, buffer, FLASH_PAGE_SIZE);
48+
nrf_nvm_safe_flash_page_write(page_addr, buffer);
5349
}
5450
}
5551

0 commit comments

Comments
 (0)