From 77930a386cebbce02b13f6914ef4d24e59686d59 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 22 Oct 2022 11:23:12 +1100 Subject: [PATCH] flash api simpler Update flash.c --- source/Core/BSP/BSP_Flash.h | 2 +- source/Core/BSP/MHP30/flash.c | 5 ++--- source/Core/BSP/Miniware/flash.c | 6 +++--- source/Core/BSP/Pinecil/flash.c | 3 +-- source/Core/BSP/Pinecilv2/flash.c | 3 +-- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/source/Core/BSP/BSP_Flash.h b/source/Core/BSP/BSP_Flash.h index 0ed5f045..c1c68b5d 100644 --- a/source/Core/BSP/BSP_Flash.h +++ b/source/Core/BSP/BSP_Flash.h @@ -17,7 +17,7 @@ extern "C" { */ // Erase the flash, then save the buffer. Returns 1 if worked -uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length); +void flash_save_buffer(const uint8_t *buffer, const uint16_t length); void flash_read_buffer(uint8_t *buffer, const uint16_t length); #ifdef __cplusplus diff --git a/source/Core/BSP/MHP30/flash.c b/source/Core/BSP/MHP30/flash.c index dee6138e..75352e7d 100644 --- a/source/Core/BSP/MHP30/flash.c +++ b/source/Core/BSP/MHP30/flash.c @@ -13,7 +13,7 @@ #define SETTINGS_START_PAGE (0x08000000 + (127 * 1024)) -uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) { +void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { FLASH_EraseInitTypeDef pEraseInit; pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; pEraseInit.Banks = FLASH_BANK_1; @@ -33,10 +33,9 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) { HAL_FLASH_Unlock(); for (uint16_t i = 0; i < (length / 2); i++) { resetWatchdog(); - HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE+ (i*sizeof(uint32_t)), data[i]); + HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE+ (i*sizeof(uint16_t)), data[i]); } HAL_FLASH_Lock(); - return 1; } void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, (uint8_t*)SETTINGS_START_PAGE, length); } diff --git a/source/Core/BSP/Miniware/flash.c b/source/Core/BSP/Miniware/flash.c index 17eeb1da..fd4b98bf 100644 --- a/source/Core/BSP/Miniware/flash.c +++ b/source/Core/BSP/Miniware/flash.c @@ -12,7 +12,7 @@ #define SETTINGS_START_PAGE (0x08000000 + (63 * 1024)) -uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) { +void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { FLASH_EraseInitTypeDef pEraseInit; pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; pEraseInit.Banks = FLASH_BANK_1; @@ -32,10 +32,10 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) { HAL_FLASH_Unlock(); for (uint16_t i = 0; i < (length / 2); i++) { resetWatchdog(); - HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE+ (i*sizeof(uint32_t)), data[i]); + HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE+ (i*sizeof(uint16_t)), data[i]); } HAL_FLASH_Lock(); - return 1; + } void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, (uint8_t*)SETTINGS_START_PAGE, length); } diff --git a/source/Core/BSP/Pinecil/flash.c b/source/Core/BSP/Pinecil/flash.c index a6daa859..d66a3d1d 100644 --- a/source/Core/BSP/Pinecil/flash.c +++ b/source/Core/BSP/Pinecil/flash.c @@ -11,7 +11,7 @@ #include "string.h" #define FMC_PAGE_SIZE ((uint16_t)0x400U) #define SETTINGS_START_PAGE (0x08000000 + (127 * 1024)) -uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) { +void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { /* unlock the flash program/erase controller */ fmc_unlock(); @@ -32,7 +32,6 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) { resetWatchdog(); } fmc_lock(); - return 1; } void flash_read_buffer(uint8_t *buffer, const uint16_t length) { diff --git a/source/Core/BSP/Pinecilv2/flash.c b/source/Core/BSP/Pinecilv2/flash.c index 38337001..071b8ce2 100644 --- a/source/Core/BSP/Pinecilv2/flash.c +++ b/source/Core/BSP/Pinecilv2/flash.c @@ -14,10 +14,9 @@ #define SETTINGS_START_PAGE (1023 * FLASH_PAGE_SIZE) // Hal auto offsets base addr -uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) { +void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { BL_Err_Type err = flash_erase(SETTINGS_START_PAGE, FLASH_PAGE_SIZE); err = flash_write(SETTINGS_START_PAGE, buffer, length); - return err != SUCCESS; } void flash_read_buffer(uint8_t *buffer, const uint16_t length) { flash_read(SETTINGS_START_PAGE, buffer, length); }