diff --git a/include/eeprom.h b/include/eeprom.h index 8648f394982f04e99d2655ed38289c85023e6851..efa2aa9dd45b150cb46ba4fd3eb74b3f3aeda22c 100755 --- a/include/eeprom.h +++ b/include/eeprom.h @@ -53,11 +53,11 @@ /* Pages 0 and 1 base and end addresses */ #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000)) #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1))) -#define PAGE0_ID 0x08000800 +#define PAGE0_ID 0x08000400 #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0400)) #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 2*PAGE_SIZE - 1)) -#define PAGE1_ID 0x08001000 +#define PAGE1_ID 0x08000800 /* Used Flash pages for EEPROM emulation */ #define PAGE0 ((uint16_t)0x0000) diff --git a/src/eeprom.c b/src/eeprom.c index 984ffc6507b7767b5a5d33d66c209d6e1d27b699..8efce0397bb00ac88edde214c480776c7bcaf8d7 100755 --- a/src/eeprom.c +++ b/src/eeprom.c @@ -637,7 +637,7 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) HAL_StatusTypeDef flashstatus = HAL_OK; uint32_t newpageaddress = EEPROM_START_ADDRESS; uint32_t oldpageid = 0; - uint16_t validpage = PAGE0, varidx = 0; + uint16_t validpage = PAGE0, varidx = 0, address=0; uint16_t eepromstatus = 0, readstatus = 0; uint32_t page_error = 0; FLASH_EraseInitTypeDef s_eraseinit; @@ -685,15 +685,16 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) /* Transfer process: transfer variables from old to the new active page */ for (varidx = 0; varidx < EEPROM_NUM_VAR; varidx++) { - if (eeprom_data[varidx] != VirtAddress) /* Check each variable except the one passed as parameter */ + address=((__IO uint16_t*)oldpageid)[1+varidx*2]; + if (address != VirtAddress) /* Check each variable except the one passed as parameter */ { /* Read the other last variable updates */ - readstatus = EE_ReadVariable(eeprom_data[varidx], &DataVar); + readstatus = EE_ReadVariable(address, &DataVar); /* In case variable corresponding to the virtual address was found */ if (readstatus != 0x1) { /* Transfer the variable to the new active page */ - eepromstatus = EE_VerifyPageFullWriteVariable(eeprom_data[varidx], DataVar); + eepromstatus = EE_VerifyPageFullWriteVariable(address, DataVar); /* If program operation was failed, a Flash error code is returned */ if (eepromstatus != HAL_OK) {