From a52d4c2120ce493409a9adc310e00ad35aa15381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nima=20Askari=20-----=20=D9=86=DB=8C=D9=85=D8=A7=20=D8=B9?= =?UTF-8?q?=D8=B3=DA=A9=D8=B1=DB=8C?= Date: Tue, 19 Feb 2019 12:28:20 +0330 Subject: [PATCH] Add F0 --- eeprom.c | 23 ++++++++++++++++++++--- eeprom.h | 13 +++++++------ eepromConfig.h | 9 +++++---- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/eeprom.c b/eeprom.c index e676de9..bbe0980 100644 --- a/eeprom.c +++ b/eeprom.c @@ -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; +} +//########################################################################################################## diff --git a/eeprom.h b/eeprom.h index 8da1a38..d2af508 100644 --- a/eeprom.h +++ b/eeprom.h @@ -2,15 +2,16 @@ #define __EEPROM_H #include -#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 diff --git a/eepromConfig.h b/eepromConfig.h index f3d4557..50e4d4a 100644 --- a/eepromConfig.h +++ b/eepromConfig.h @@ -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