diff --git a/Core/Src/EEPROM.c b/Core/Src/EEPROM.c index a0857fe..485e7a7 100644 --- a/Core/Src/EEPROM.c +++ b/Core/Src/EEPROM.c @@ -5,6 +5,7 @@ #include "RobotFunctions.h" InfoBlock infoBlock; +extern IWDG_HandleTypeDef hiwdg; //*********************** EEPROM_INIT ********************************// MemoryStatus EEPROM_INIT() { @@ -152,6 +153,7 @@ MemoryStatus saveShot(unsigned char number, Shot *shot) { } MemoryStatus getShot(unsigned char number, Shot *shot) { + HAL_IWDG_Refresh(&hiwdg); if (FLASH_ReadBlock(START_ADR_SHOT, number, (uint8_t*) shot, SHOT_BLOCKSIZE) != EEPROM_OK) { return EEPROM_FAIL; @@ -172,6 +174,7 @@ MemoryStatus delShot(unsigned char number) { MemoryStatus saveProg(unsigned char number, Program *prog) { MemoryStatus result = EEPROM_OK; for (uint16_t i = 0; i < prog->header.shotCount; ++i) { + HAL_IWDG_Refresh(&hiwdg); Shot shot; MemoryStatus stat = getShot(prog->shots[i].id, &shot); if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) { @@ -217,6 +220,7 @@ MemoryStatus delProg(unsigned char number) { MemoryStatus saveMacro(unsigned char number, Macro *macro) { MemoryStatus result = EEPROM_OK; for (uint16_t i = 0; i < macro->header.programmCount; ++i) { + HAL_IWDG_Refresh(&hiwdg); Program prog; MemoryStatus stat = getProg(macro->programs[i].id, &prog); if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) { @@ -259,19 +263,23 @@ MemoryStatus delMacro(unsigned char number) { } MemoryStatus EEPROM_EARSE() { - uint16_t addr = 0; - uint16_t old_addr = 0; - do { - uint8_t Buf[255]; - memset(Buf, 0x00, sizeof(Buf)); - FLASH_WriteBlock(addr, 0, Buf, sizeof(Buf), sizeof(Buf)); - old_addr = addr; - addr += sizeof(Buf); - } while (old_addr <= addr); + uint16_t addr = 0; + const uint16_t EEPROM_MAX_ADDR = 1024*32; + do { + uint8_t Buf[64]; + HAL_IWDG_Refresh(&hiwdg); + memset(Buf, 0x00, sizeof(Buf)); + HAL_IWDG_Refresh(&hiwdg); - return EEPROM_OK; + FLASH_WriteBlock(addr, 0, Buf, sizeof(Buf), sizeof(Buf)); + + addr += sizeof(Buf); + } while (addr < EEPROM_MAX_ADDR); + + return EEPROM_OK; } + MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number, uint8_t *writeData, uint16_t dataSize, uint16_t blockSize) { HAL_StatusTypeDef result;