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

View File

@ -2,7 +2,7 @@
#include "eeprom.h"
#include "eepromConfig.h"
#ifdef _EEPROM_F1_LOW_DESTINY
#if ( _EEPROM_F1_LOW_DESTINY==1)
#define _EEPROM_FLASH_PAGE_SIZE 1024
/* Base address of the Flash sectors */
#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08000000) /* Base @ of Page 0, 1 Kbytes */
@ -13,7 +13,7 @@
#endif
#ifdef _EEPROM_F1_MEDIUM_DESTINY
#if (_EEPROM_F1_MEDIUM_DESTINY==1)
#define _EEPROM_FLASH_PAGE_SIZE 1024
/* Base address of the Flash sectors */
#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08000000) /* Base @ of Page 0, 1 Kbytes */
@ -24,7 +24,7 @@
#endif
#ifdef _EEPROM_F1_HIGH_DESTINY
#if (_EEPROM_F1_HIGH_DESTINY==1)
#define _EEPROM_FLASH_PAGE_SIZE 2048
/* Base address of the Flash sectors */
#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08000000) /* Base @ of Page 0, 2 Kbytes */
@ -34,6 +34,16 @@
#endif
#endif
#if (_EEPROM_F030x4_F030x6_F070x6_F030x8==1)
#define _EEPROM_FLASH_PAGE_SIZE 1024
/* Base address of the Flash sectors */
#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08000000) /* Base @ of Page 0, 2 Kbytes */
#define _EEPROM_FLASH_PAGE_ADDRESS (ADDR_FLASH_PAGE_0|(_EEPROM_FLASH_PAGE_SIZE*_EEPROM_USE_FLASH_PAGE))
#if (_EEPROM_USE_FLASH_PAGE>63)
#error "Please Enter currect value _EEPROM_USE_FLASH_PAGE (0 to 63)"
#endif
#endif
uint32_t EEPROMPageBackup[_EEPROM_FLASH_PAGE_SIZE/4];
//##########################################################################################################
@ -45,7 +55,9 @@ bool EE_Format(void)
HAL_FLASH_Unlock();
FLASH_EraseInitTypeDef flashErase;
flashErase.NbPages=1;
#if ( _EEPROM_F1_LOW_DESTINY==1 || _EEPROM_F1_MEDIUM_DESTINY==1 || _EEPROM_F1_HIGH_DESTINY==1 )
flashErase.Banks = FLASH_BANK_1;
#endif
flashErase.PageAddress = _EEPROM_FLASH_PAGE_ADDRESS;
flashErase.TypeErase = FLASH_TYPEERASE_PAGES;
if(HAL_FLASHEx_Erase(&flashErase,&error)==HAL_OK)
@ -151,3 +163,8 @@ bool EE_Writes(uint16_t StartVirtualAddress,uint16_t HowMuchToWrite,uint32_t* D
return true;
}
//##########################################################################################################
uint16_t EE_GetSize(void)
{
return _EEPROM_FLASH_PAGE_SIZE;
}
//##########################################################################################################

View File

@ -2,15 +2,16 @@
#define __EEPROM_H
#include <stdbool.h>
#include "stm32f1xx_hal.h"
#include "gpio.h"
//################################################################################################################
bool EE_Format(void);
bool EE_Read(uint16_t VirtualAddress, uint32_t* Data);
bool EE_Write(uint16_t VirtualAddress, uint32_t Data);
bool EE_Reads(uint16_t StartVirtualAddress,uint16_t HowMuchToRead,uint32_t* Data);
bool EE_Writes(uint16_t StartVirtualAddress,uint16_t HowMuchToWrite,uint32_t* Data);
bool EE_Format(void);
bool EE_Read(uint16_t VirtualAddress, uint32_t* Data);
bool EE_Write(uint16_t VirtualAddress, uint32_t Data);
bool EE_Reads(uint16_t StartVirtualAddress,uint16_t HowMuchToRead,uint32_t* Data);
bool EE_Writes(uint16_t StartVirtualAddress,uint16_t HowMuchToWrite,uint32_t* Data);
uint16_t EE_GetSize(void);
//################################################################################################################
#endif

View File

@ -2,10 +2,11 @@
#define __EEPROMCONFIG_H
//#define _EEPROM_F1_LOW_DESTINY
//#define _EEPROM_F1_MEDIUM_DESTINY
#define _EEPROM_F1_HIGH_DESTINY
#define _EEPROM_F030x4_F030x6_F070x6_F030x8 (1)
#define _EEPROM_F1_LOW_DESTINY (0)
#define _EEPROM_F1_MEDIUM_DESTINY (0)
#define _EEPROM_F1_HIGH_DESTINY (0)
#define _EEPROM_USE_FLASH_PAGE 127
#define _EEPROM_USE_FLASH_PAGE (31)
#endif