Add files via upload

This commit is contained in:
Nima Askari ----- نیما عسکری 2019-02-19 13:18:02 +03:30 committed by GitHub
parent a52d4c2120
commit 3dbe1f6065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -44,7 +44,9 @@
#endif #endif
#endif #endif
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
uint32_t EEPROMPageBackup[_EEPROM_FLASH_PAGE_SIZE/4]; 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)) if(VirtualAddress >= (_EEPROM_FLASH_PAGE_SIZE/4))
return false; return false;
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
if((*(__IO uint32_t*)((VirtualAddress*4)+_EEPROM_FLASH_PAGE_ADDRESS)) != 0xFFFFFFFF) 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(); HAL_FLASH_Unlock();
if(Data!=0xFFFFFFFF) if(Data!=0xFFFFFFFF)
{ {
@ -122,7 +126,6 @@ bool EE_Write(uint16_t VirtualAddress, uint32_t Data)
} }
HAL_FLASH_Lock(); HAL_FLASH_Lock();
return true; return true;
} }
//########################################################################################################## //##########################################################################################################
bool EE_Reads(uint16_t StartVirtualAddress,uint16_t HowMuchToRead,uint32_t* Data) 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)) if((StartVirtualAddress+HowMuchToWrite) > (_EEPROM_FLASH_PAGE_SIZE/4))
return false; return false;
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
if( EE_Reads(0,(_EEPROM_FLASH_PAGE_SIZE/4),EEPROMPageBackup)==false) if( EE_Reads(0,(_EEPROM_FLASH_PAGE_SIZE/4),EEPROMPageBackup)==false)
return false; return false;
for(uint16_t i=StartVirtualAddress ; i<HowMuchToWrite+StartVirtualAddress ; i++) for(uint16_t i=StartVirtualAddress ; i<HowMuchToWrite+StartVirtualAddress ; i++)
@ -150,7 +154,9 @@ bool EE_Writes(uint16_t StartVirtualAddress,uint16_t HowMuchToWrite,uint32_t* D
} }
if(EE_Format()==false) if(EE_Format()==false)
return false; return false;
#endif
HAL_FLASH_Unlock(); HAL_FLASH_Unlock();
#if (_EEPROM_AUTO_ERASE___NEED_MORE_RAM==1)
for(uint16_t i=0 ; i<(_EEPROM_FLASH_PAGE_SIZE/4); i++) 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) if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,(i*4)+_EEPROM_FLASH_PAGE_ADDRESS,(uint64_t)EEPROMPageBackup[i])!=HAL_OK)
@ -159,6 +165,17 @@ bool EE_Writes(uint16_t StartVirtualAddress,uint16_t HowMuchToWrite,uint32_t* D
return false; 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(); HAL_FLASH_Lock();
return true; return true;
} }

View File

@ -1,6 +1,7 @@
#ifndef __EEPROMCONFIG_H #ifndef __EEPROMCONFIG_H
#define __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_F030x4_F030x6_F070x6_F030x8 (1)
#define _EEPROM_F1_LOW_DESTINY (0) #define _EEPROM_F1_LOW_DESTINY (0)