diff --git a/Core/Inc/git_rev.h b/Core/Inc/git_rev.h index 160db2f..0fe520d 100644 --- a/Core/Inc/git_rev.h +++ b/Core/Inc/git_rev.h @@ -7,6 +7,6 @@ // Auto generated header file containing the last git revision -#define GIT_HASH "5b2e03a" +#define GIT_HASH "df5aa6f" #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H \ No newline at end of file diff --git a/Middlewares/floatpump/Inc/Config_Store.h b/Middlewares/floatpump/Inc/Config_Store.h index 1822d6f..662fa47 100644 --- a/Middlewares/floatpump/Inc/Config_Store.h +++ b/Middlewares/floatpump/Inc/Config_Store.h @@ -14,18 +14,33 @@ namespace floatpump { public: Config_Store(); + const uint32_t startAddr = 0x08060000; + static uint32_t StoreInFlash(uint32_t StartAddress, uint32_t *Data, uint16_t nData) { uint16_t progr = 0; HAL_FLASH_Unlock(); FLASH_Erase_Sector(FLASH_SECTOR_7, VOLTAGE_RANGE_1); - while( progr < nData) { - if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, StartAddress, Data[progr]) == HAL_OK) { + while (progr < nData) { + if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, StartAddress, Data[progr]) == HAL_OK) { progr++; - StartAddress += 4; } else { + StartAddress += 4; + } else { return HAL_FLASH_GetError(); } } HAL_FLASH_Lock(); + return 0; + } + + static uint32_t ReadFromFlash(uint32_t StartAddress, uint32_t *Data, uint16_t nData) { + uint16_t progr = 0; + + while (progr < nData) { + Data[progr] = *(uint32_t *) StartAddress; + progr++; + StartAddress += 4; + } + return 0; } void saveToFlash() { @@ -41,13 +56,26 @@ namespace floatpump { data[8] = RefillBelow.getValue(); data[9] = RefillHysteresis.getValue(); - StoreInFlash(0x08060000, data, 10); + StoreInFlash(startAddr, data, 10); + return; }; void resetDefaults(); void loadFromFlash() { - this->RefillBelow.setValue(*(uint32_t *)0x08060000); + uint32_t data[10]; + ReadFromFlash(startAddr, data, 10); + TankCalibLow.setValue(data[0]); + TankCalibHigh.setValue(data[1]); + TankMinLevel.setValue(data[2]); + TankHysteresis.setValue(data[3]); + TankPumpInvert.setValue(data[4]); + RefillEnable.setValue(data[5]); + RefillBlockInvert.setValue(data[6]); + RefillBlockEnable.setValue(data[7]); + RefillBelow.setValue(data[8]); + RefillHysteresis.setValue(data[9]); + return; }; template