diff --git a/source/Core/BSP/MHP30/configuration.h b/source/Core/BSP/MHP30/configuration.h index 7cb7e1bd..e42d23d6 100644 --- a/source/Core/BSP/MHP30/configuration.h +++ b/source/Core/BSP/MHP30/configuration.h @@ -176,3 +176,4 @@ #endif #define FLASH_LOGOADDR (0x08000000 + (62 * 1024)) +#define SETTINGS_START_PAGE (0x08000000 + (127 * 1024)) diff --git a/source/Core/BSP/MHP30/flash.c b/source/Core/BSP/MHP30/flash.c index 75352e7d..756e7fb4 100644 --- a/source/Core/BSP/MHP30/flash.c +++ b/source/Core/BSP/MHP30/flash.c @@ -10,9 +10,6 @@ #include "stm32f1xx_hal.h" #include "string.h" -#define SETTINGS_START_PAGE (0x08000000 + (127 * 1024)) - - void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { FLASH_EraseInitTypeDef pEraseInit; pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; diff --git a/source/Core/BSP/Miniware/configuration.h b/source/Core/BSP/Miniware/configuration.h index 896b9dba..a3c41f40 100644 --- a/source/Core/BSP/Miniware/configuration.h +++ b/source/Core/BSP/Miniware/configuration.h @@ -218,3 +218,4 @@ #endif #define FLASH_LOGOADDR (0x08000000 + (62 * 1024)) +#define SETTINGS_START_PAGE (0x08000000 + (63 * 1024)) diff --git a/source/Core/BSP/Miniware/flash.c b/source/Core/BSP/Miniware/flash.c index fd4b98bf..c6a8793e 100644 --- a/source/Core/BSP/Miniware/flash.c +++ b/source/Core/BSP/Miniware/flash.c @@ -10,8 +10,6 @@ #include "stm32f1xx_hal.h" #include "string.h" -#define SETTINGS_START_PAGE (0x08000000 + (63 * 1024)) - void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { FLASH_EraseInitTypeDef pEraseInit; pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; diff --git a/source/Core/BSP/Pinecil/configuration.h b/source/Core/BSP/Pinecil/configuration.h index bb418e1d..7fae28b4 100644 --- a/source/Core/BSP/Pinecil/configuration.h +++ b/source/Core/BSP/Pinecil/configuration.h @@ -166,5 +166,6 @@ #endif #define FLASH_LOGOADDR (0x08000000 + (126 * 1024)) +#define SETTINGS_START_PAGE (0x08000000 + (127 * 1024)) #define HAS_POWER_DEBUG_MENU diff --git a/source/Core/BSP/Pinecil/flash.c b/source/Core/BSP/Pinecil/flash.c index d66a3d1d..8c903628 100644 --- a/source/Core/BSP/Pinecil/flash.c +++ b/source/Core/BSP/Pinecil/flash.c @@ -10,7 +10,7 @@ #include "gd32vf103_libopt.h" #include "string.h" #define FMC_PAGE_SIZE ((uint16_t)0x400U) -#define SETTINGS_START_PAGE (0x08000000 + (127 * 1024)) + void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { /* unlock the flash program/erase controller */ diff --git a/source/Core/BSP/Pinecilv2/configuration.h b/source/Core/BSP/Pinecilv2/configuration.h index 1db58387..9796af61 100644 --- a/source/Core/BSP/Pinecilv2/configuration.h +++ b/source/Core/BSP/Pinecilv2/configuration.h @@ -168,3 +168,5 @@ #endif #define FLASH_LOGOADDR (0x23000000 + (1022 * 1024)) +#define FLASH_PAGE_SIZE (1024) +#define SETTINGS_START_PAGE (1023 * FLASH_PAGE_SIZE) // Hal auto offsets base addr diff --git a/source/Core/BSP/Pinecilv2/flash.c b/source/Core/BSP/Pinecilv2/flash.c index 071b8ce2..af298431 100644 --- a/source/Core/BSP/Pinecilv2/flash.c +++ b/source/Core/BSP/Pinecilv2/flash.c @@ -10,10 +10,6 @@ #include "hal_flash.h" #include "string.h" -#define FLASH_PAGE_SIZE (1024) - -#define SETTINGS_START_PAGE (1023 * FLASH_PAGE_SIZE) // Hal auto offsets base addr - 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); diff --git a/source/Core/BSP/Sequre_S60/configuration.h b/source/Core/BSP/Sequre_S60/configuration.h index d1c2eeb1..a624fc01 100644 --- a/source/Core/BSP/Sequre_S60/configuration.h +++ b/source/Core/BSP/Sequre_S60/configuration.h @@ -167,3 +167,4 @@ #endif #define FLASH_LOGOADDR (0x08000000 + (62 * 1024)) +#define SETTINGS_START_PAGE (0x08000000 + (63 * 1024)) diff --git a/source/Core/BSP/Sequre_S60/flash.c b/source/Core/BSP/Sequre_S60/flash.c index fd4b98bf..c6a8793e 100644 --- a/source/Core/BSP/Sequre_S60/flash.c +++ b/source/Core/BSP/Sequre_S60/flash.c @@ -10,8 +10,6 @@ #include "stm32f1xx_hal.h" #include "string.h" -#define SETTINGS_START_PAGE (0x08000000 + (63 * 1024)) - void flash_save_buffer(const uint8_t *buffer, const uint16_t length) { FLASH_EraseInitTypeDef pEraseInit; pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index 9a06592b..2d55db63 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -105,7 +105,11 @@ static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOp }; static_assert((sizeof(settingsConstants) / sizeof(SettingConstants)) == ((int)SettingsOptions::SettingsOptionsLength)); -void saveSettings() { flash_save_buffer((uint8_t *)&systemSettings, sizeof(systemSettingsType)); } +void saveSettings() { + if (memcmp((void *)SETTINGS_START_PAGE, (void *)&systemSettings, sizeof(systemSettingsType))) { + flash_save_buffer((uint8_t *)&systemSettings, sizeof(systemSettingsType)); + } +} bool loadSettings() { // We read the flash