From 59f08a3079ccecaeb91b637e7d311f3f98d10c42 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 25 Sep 2022 17:34:11 -0700 Subject: [PATCH] altos/samd21: Automatically erase flash when writing Need to erase pages before writing them. Signed-off-by: Keith Packard --- src/samd21/ao_flash_samd21.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/samd21/ao_flash_samd21.c b/src/samd21/ao_flash_samd21.c index c1cee3f8..b0d91c5c 100644 --- a/src/samd21/ao_flash_samd21.c +++ b/src/samd21/ao_flash_samd21.c @@ -101,6 +101,9 @@ ao_flash_erase_page(uint32_t *page) uint32_t row_size = samd21_nvmctrl_row_size(); uint32_t rows = (row_size + 255) / 256; + if ((uintptr_t) page & (row_size - 1)) + return; + ao_arch_block_interrupts(); if (((uintptr_t) row & (row_size - 1)) == 0) { @@ -121,6 +124,8 @@ ao_flash_page(uint32_t *page, uint32_t *src) uint32_t i; uint32_t per_page = page_size / sizeof(uint32_t); + ao_flash_erase_page(page); + ao_arch_block_interrupts(); while(pages--) { -- 2.30.2