From 8187f9f159f8c1da7ed8fa790af2e2c37fa73d66 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 15 Jul 2020 00:04:31 +0200 Subject: [PATCH] LPC: Fix aligned page address write --- hal/lpc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hal/lpc.c b/hal/lpc.c index 805aaf49..a7156e7c 100644 --- a/hal/lpc.c +++ b/hal/lpc.c @@ -106,19 +106,19 @@ static uint8_t flash_page_cache[FLASH_PAGE_SIZE]; int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len) { - int w = 0; - int ret; int idx = 0; uint32_t page_address; uint32_t offset; int size; while (idx < len) { page_address = ((address + idx) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; - offset = address - page_address; + if(address > page_address) + offset = address - page_address; + else + offset = 0; size = FLASH_PAGE_SIZE - offset; if (size > (len - idx)) size = len - idx; - if (size > 0) { memcpy(flash_page_cache, (void *)page_address, FLASH_PAGE_SIZE); memcpy(flash_page_cache + offset, data + idx, size);