Add files via upload
This commit is contained in:
parent
a52d4c2120
commit
3dbe1f6065
21
eeprom.c
21
eeprom.c
|
@ -44,7 +44,9 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
|
||||
uint32_t EEPROMPageBackup[_EEPROM_FLASH_PAGE_SIZE/4];
|
||||
#endif
|
||||
|
||||
//##########################################################################################################
|
||||
//##########################################################################################################
|
||||
|
@ -85,6 +87,7 @@ bool EE_Write(uint16_t VirtualAddress, uint32_t Data)
|
|||
if(VirtualAddress >= (_EEPROM_FLASH_PAGE_SIZE/4))
|
||||
return false;
|
||||
|
||||
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
|
||||
if((*(__IO uint32_t*)((VirtualAddress*4)+_EEPROM_FLASH_PAGE_ADDRESS)) != 0xFFFFFFFF)
|
||||
{
|
||||
|
||||
|
@ -106,6 +109,7 @@ bool EE_Write(uint16_t VirtualAddress, uint32_t Data)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
HAL_FLASH_Unlock();
|
||||
if(Data!=0xFFFFFFFF)
|
||||
{
|
||||
|
@ -122,7 +126,6 @@ bool EE_Write(uint16_t VirtualAddress, uint32_t Data)
|
|||
}
|
||||
HAL_FLASH_Lock();
|
||||
return true;
|
||||
|
||||
}
|
||||
//##########################################################################################################
|
||||
bool EE_Reads(uint16_t StartVirtualAddress,uint16_t HowMuchToRead,uint32_t* Data)
|
||||
|
@ -141,6 +144,7 @@ bool EE_Writes(uint16_t StartVirtualAddress,uint16_t HowMuchToWrite,uint32_t* D
|
|||
{
|
||||
if((StartVirtualAddress+HowMuchToWrite) > (_EEPROM_FLASH_PAGE_SIZE/4))
|
||||
return false;
|
||||
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
|
||||
if( EE_Reads(0,(_EEPROM_FLASH_PAGE_SIZE/4),EEPROMPageBackup)==false)
|
||||
return false;
|
||||
for(uint16_t i=StartVirtualAddress ; i<HowMuchToWrite+StartVirtualAddress ; i++)
|
||||
|
@ -150,15 +154,28 @@ bool EE_Writes(uint16_t StartVirtualAddress,uint16_t HowMuchToWrite,uint32_t* D
|
|||
}
|
||||
if(EE_Format()==false)
|
||||
return false;
|
||||
#endif
|
||||
HAL_FLASH_Unlock();
|
||||
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
|
||||
for(uint16_t i=0 ; i<(_EEPROM_FLASH_PAGE_SIZE/4); i++)
|
||||
{
|
||||
{
|
||||
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,(i*4)+_EEPROM_FLASH_PAGE_ADDRESS,(uint64_t)EEPROMPageBackup[i])!=HAL_OK)
|
||||
{
|
||||
HAL_FLASH_Lock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
HAL_FLASH_Unlock();
|
||||
for(uint16_t i=0; i<HowMuchToWrite ; i++)
|
||||
{
|
||||
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,((i+StartVirtualAddress)*4)+_EEPROM_FLASH_PAGE_ADDRESS,(uint64_t)Data[i])!=HAL_OK)
|
||||
{
|
||||
HAL_FLASH_Lock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
HAL_FLASH_Lock();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __EEPROMCONFIG_H
|
||||
#define __EEPROMCONFIG_H
|
||||
|
||||
#define _EEPROM_AUTO_ERASE___NEED_MORE_RAM (0) // store old data
|
||||
|
||||
#define _EEPROM_F030x4_F030x6_F070x6_F030x8 (1)
|
||||
#define _EEPROM_F1_LOW_DESTINY (0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user