ImageVerifierCode 换一换
格式:DOCX , 页数:24 ,大小:19.55KB ,
资源ID:17106583      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/17106583.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(stm32flasheeprom断电保护数值存储程序Word下载.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

stm32flasheeprom断电保护数值存储程序Word下载.docx

1、h2© COPYRIGHT 2009 STMicroelectronics/h2 */* Define to prevent recursive inclusion -*/#ifndef _EEPROM_H#define _EEPROM_H/* Includes -*/#include stm32f10x.h/* Exported constants -*/* Define the STM32F10Xxx Flash page size depending on the used STM32 device */#if defined (STM32F10X_LD) | defined

2、(STM32F10X_MD) #define PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */#elif defined (STM32F10X_HD) | defined (STM32F10X_CL) #define PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */#endif/* EEPROM start address in Flash */#define EEPROM_START_ADDRESS (uint32_t)0x08010000) /* EEPROM emulation sta

3、rt address: after 64KByte of used Flash memory */* Pages 0 and 1 base and end addresses */#define PAGE0_BASE_ADDRESS (uint32_t)(EEPROM_START_ADDRESS + 0x000)#define PAGE0_END_ADDRESS (uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)#define PAGE1_BASE_ADDRESS (uint32_t)(EEPROM_START_ADDRESS + PAGE_SI

4、ZE)#define PAGE1_END_ADDRESS (uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)/* Used Flash pages for EEPROM emulation */#define PAGE0 (uint16_t)0x0000)#define PAGE1 (uint16_t)0x0001)/* No valid page define */#define NO_VALID_PAGE (uint16_t)0x00AB)/* Page status definitions */#define ERASED (uin

5、t16_t)0xFFFF) /* PAGE is empty */#define RECEIVE_DATA (uint16_t)0xEEEE) /* PAGE is marked to receive data */#define VALID_PAGE (uint16_t)0x0000) /* PAGE containing valid data */* Valid pages in read and write defines */#define READ_FROM_VALID_PAGE (uint8_t)0x00)#define WRITE_IN_VALID_PAGE (uint8_t)0

6、x01)/* Page full define */#define PAGE_FULL (uint8_t)0x80)/* Variables number */#define NumbOfVar (uint8_t)0x03)/* Exported types -*/* Exported macro -*/* Exported functions - */uint16_t EE_Init(void);uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);uint16_t EE_WriteVariable(uint16_t V

7、irtAddress, uint16_t Data);#endif /* _EEPROM_H */* (C) COPYRIGHT 2009 STMicroelectronics *END OF FILE*/*eeprom.c*/ * file EEPROM_Emulation/src/eeprom.c * brief This file provides all the EEPROM emulation firmware functions. */ /* addtogroup EEPROM_Emulation * eeprom.h/* Private typedef -*/* Private

8、define -*/* Private macro -*/* Private variables -*/* Global variable used to store variable value in read sequence */uint16_t DataVar = 0;uint32_t CurWrAddress;/* Virtual address defined by the user: 0xFFFF value is prohibited */uint16_t VirtAddVarTabNumbOfVar;/* Private function prototypes -*/* Pr

9、ivate functions -*/static FLASH_Status EE_Format(void);static uint16_t EE_FindValidPage(uint8_t Operation);static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data);static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data);/初始化写地址,减少每次读写时查询时间uint16_t InitCurrWrAd

10、dress(void) FLASH_Status FlashStatus = FLASH_COMPLETE; uint16_t ValidPage = PAGE0; /uint32_t Address; uint32_t PageEndAddress; /* Get valid Page for write operation */ ValidPage = EE_FindValidPage(WRITE_IN_VALID_PAGE); /* Check if there is no valid page */ if (ValidPage = NO_VALID_PAGE) CurWrAddress

11、 = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE); return NO_VALID_PAGE; /* Get the valid Page start Address */ /Address = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE); /* Get the valid Page end Address */ PageEndAddress = (uint32_t)(EEPROM_START_ADDRESS -

12、 2) + (uint32_t)(1 + ValidPage) * PAGE_SIZE); /* Check each active page address starting from begining */ while (CurWrAddress format EEPROM */ /* Erase both Page0 and Page1 and set Page0 as valid page */ FlashStatus = EE_Format(); /* If erase/program operation was failed, a Flash error code is retur

13、ned */ break; case RECEIVE_DATA: if (PageStatus1 = VALID_PAGE) /* Page0 receive, Page1 valid */ /* Transfer data from Page1 to Page0 */ for (VarIdx = 0; VarIdx NumbOfVar; VarIdx+) if ( *(_IO uint16_t*)(PAGE0_BASE_ADDRESS + 6) = VirtAddVarTabVarIdx) x = VarIdx; if (VarIdx != x) /* Read the last varia

14、bles updates */ ReadStatus = EE_ReadVariable(VirtAddVarTabVarIdx, &DataVar); /* In case variable corresponding to the virtual address was found */ if (ReadStatus != 0x1) /* Transfer the variable to the Page0 */ EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTabVarIdx, DataVar); if (EepromStatus ! return EepromStatus; /* Mark Page0 as valid */ FlashStatus = FLASH_ProgramHalfWord(PAGE0_BASE_ADDRESS, VALID_PAGE); /* Erase Page1 */ FlashStatus = FLASH_ErasePage(PAGE1_BASE_ADDRESS); else if (PageStatus1 = ERASED) /* Page0 receive, Page1 erased */ FlashStatus = FLA

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1