当前位置: 首页 > news >正文

2018年主流网站开发语言推广app网站

2018年主流网站开发语言,推广app网站,古风ppt模板免费下载,摄影师都在哪些网站发布作品STM32 的某些系列 MCU 自带 EEPROM。笔者使用的 STM32L151RET6 自带 16 KB 的 EEPROM,可以用来存储自定义的数据。在芯片选型时,自带 EEPROM 也可以作为一个考量点,省去了在外接 EEPROM 的烦恼。 下面简单介绍下 STM32 内部 EEPROM 的读写流…

STM32 的某些系列 MCU 自带 EEPROM。笔者使用的 STM32L151RET6 自带 16 KBEEPROM,可以用来存储自定义的数据。在芯片选型时,自带 EEPROM 也可以作为一个考量点,省去了在外接 EEPROM 的烦恼。

下面简单介绍下 STM32 内部 EEPROM 的读写流程。

Memory Mapping

以笔者使用的这款 STM32L151RET6 MCU 为例,自带 16 KB 的 EEPROM。Map 到了 2 个 Bank 中:

Memory Map

  • Data EEPROM Bank1: 0x08080000 ~ 0x08081FFF (8KB)
  • Data EEPROM Bank2: 0x08082000 ~ 0x08083FFF (8KB)

Operations

内部 EEPROM 的操作无非就是 读取写入擦除 等操作。直接调用库函数或者 HAL 库中对应的 API 即可。这里只是对内部 EEPROM 的操作做一个简要的分析。

本文档主要以库函数中的 EEPROM 接口 API 进行分析。

Unlocking/locking memory

STM32 复位后,Data EEPROMProgram/erase 控制寄存器 (FLASH_PECR) 默认是 处于 lock 状态需要 unlock 之后才能执行写入和擦除操作

如何 unlock 可以参考芯片对应的 datasheet,简单的说就是往 Program/erase 密钥寄存器 (FLASH_PEKEYR) 写指定的密钥集即可。

  • Write PEKEY1= 0x89ABCDEF to the Program/erase key register (FLASH_PEKEYR)
  • Write PEKEY2= 0x02030405 to the Program/erase key register (FLASH_PEKEYR)
/*** @brief  Unlocks the data memory and FLASH_PECR register access.* @param  None* @retval None*/
void DATA_EEPROM_Unlock(void)
{if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET){  /* Unlocking the Data memory and FLASH_PECR register access*/FLASH->PEKEYR = FLASH_PEKEY1;FLASH->PEKEYR = FLASH_PEKEY2;}
}
#define FLASH_PEKEY1               ((uint32_t)0x89ABCDEF) /*!< Flash program erase key1 */
#define FLASH_PEKEY2               ((uint32_t)0x02030405) /*!< Flash program erase key: used with FLASH_PEKEY2to unlock the write access to the FLASH_PECR register anddata EEPROM */

如何 lock 可以参考芯片对应的 datasheet,相较于 unlock,lock 仅需要置位 Program/erase 控制寄存器 (FLASH_PECR) 中的 FLASH_PECR 位。

/*** @brief  Locks the Data memory and FLASH_PECR register access.* @param  None* @retval None*/
void DATA_EEPROM_Lock(void)
{/* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */FLASH->PECR |= FLASH_PECR_PELOCK;
}

Erasing memory

对于 EEPROM,支持以下 2 种擦除方式:

  • Word 和 double word 擦除
  • Mass 擦除

对于 Word 和 double word 擦除,这种方式仅针对 EEPROM;但是对于 Mass 擦除,这种方式针对 Program memory、EEPROM 和 Option bytes。所以尽量在使用 EEPROM 的时候采用 Word 和 double word 擦除方式

EEPROM 擦除方式也很简单,只需要将值 0x00000000 写入到对应的有效的擦除地址中即可。

EEPROM Word Erase

/*** @brief  Erase a word in data memory.* @param  Address: specifies the address to be erased.* @note   For STM32L1XX_MD, A data memory word is erased in the data memory only *         if the address to load is the start address of a word (multiple of a word).* @note   To correctly run this function, the DATA_EEPROM_Unlock() function*         must be called before.*         Call the DATA_EEPROM_Lock() to disable the data EEPROM access*         and Flash program erase control register access(recommended to protect *         the DATA_EEPROM against possible unwanted operation).* @retval FLASH Status: The returned value can be: *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.*/
FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address)
{FLASH_Status status = FLASH_COMPLETE;/* Check the parameters */assert_param(IS_FLASH_DATA_ADDRESS(Address));/* Wait for last operation to be completed */status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);if(status == FLASH_COMPLETE){/* Write "00000000h" to valid address in the data memory" */*(__IO uint32_t *) Address = 0x00000000;}/* Return the erase status */return status;
}

Programming memory

写入 EEPROM 的步骤也很简单,一般的流程如下:

  • unlock
  • erase
  • write
  • lock
/*** @brief  Programs a word at a specified address in data memory without erase.* @note   To correctly run this function, the DATA_EEPROM_Unlock() function*         must be called before.*         Call the DATA_EEPROM_Lock() to disable the data EEPROM access*         and Flash program erase control register access(recommended to protect *         the DATA_EEPROM against possible unwanted operation).* @note   The function  DATA_EEPROM_FixedTimeProgramCmd() can be called before *         this function to configure the Fixed Time Programming.* @param  Address: specifies the address to be written.* @param  Data: specifies the data to be written.* @retval FLASH Status: The returned value can be:*   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or  FLASH_TIMEOUT. */
FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data)
{FLASH_Status status = FLASH_COMPLETE;/* Check the parameters */assert_param(IS_FLASH_DATA_ADDRESS(Address));/* Wait for last operation to be completed */status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);if(status == FLASH_COMPLETE){*(__IO uint32_t *)Address = Data;/* Wait for last operation to be completed */status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);}/* Return the Write Status */return status;
}

Reading Momory

读取 EEPROM 中的数据就没那么多步骤了,直接读取对应的 Map 的 Bank 即可。

Note

对于 EEPROM 的操作,以下几点需要注意:

  • 尽量以 4 字节为一个单位进行操作
  • 在执行写入或者擦除操作的时候,尽量将全局中断关闭,以免中断触发引起其它的问题
  • 不要对相同的一个 Bank 同时做多种操作,尽量保证一个 Bank 只有一种操作在执行

列出一段 EEPROM 的参考代码:

void EEPROM_Test(void)
{__set_PRIMASK(1);DATA_EEPROM_Unlock();/* EEPROM Operations */DATA_EEPROM_Lock();__set_PRIMASK(0);
}

文章转载自:
http://oestrone.c7623.cn
http://contadina.c7623.cn
http://tabular.c7623.cn
http://incrustation.c7623.cn
http://sheepishly.c7623.cn
http://undrew.c7623.cn
http://epizoon.c7623.cn
http://catercorner.c7623.cn
http://tribuneship.c7623.cn
http://phocomelus.c7623.cn
http://fra.c7623.cn
http://angular.c7623.cn
http://ribes.c7623.cn
http://eyed.c7623.cn
http://gemmology.c7623.cn
http://priced.c7623.cn
http://illustrational.c7623.cn
http://blackleg.c7623.cn
http://halogen.c7623.cn
http://infilling.c7623.cn
http://pinitol.c7623.cn
http://doctrinism.c7623.cn
http://poundage.c7623.cn
http://synclinal.c7623.cn
http://bipinnate.c7623.cn
http://crampon.c7623.cn
http://lazybed.c7623.cn
http://abuttals.c7623.cn
http://photosynthetic.c7623.cn
http://beldam.c7623.cn
http://apprize.c7623.cn
http://sprayer.c7623.cn
http://dithered.c7623.cn
http://kakistocracy.c7623.cn
http://accordatura.c7623.cn
http://micromole.c7623.cn
http://unwinking.c7623.cn
http://disdainful.c7623.cn
http://sbr.c7623.cn
http://requisite.c7623.cn
http://nothingarian.c7623.cn
http://absolutization.c7623.cn
http://treasuryship.c7623.cn
http://sclerotitis.c7623.cn
http://carking.c7623.cn
http://ophiology.c7623.cn
http://palaeozoology.c7623.cn
http://rigolette.c7623.cn
http://icehouse.c7623.cn
http://secretary.c7623.cn
http://och.c7623.cn
http://ineducable.c7623.cn
http://nonreproductive.c7623.cn
http://lacustrian.c7623.cn
http://kasai.c7623.cn
http://shaving.c7623.cn
http://act.c7623.cn
http://semidwarf.c7623.cn
http://fordize.c7623.cn
http://scolopoid.c7623.cn
http://sweeting.c7623.cn
http://airscrew.c7623.cn
http://desulphurize.c7623.cn
http://metallogenetic.c7623.cn
http://blimy.c7623.cn
http://peccary.c7623.cn
http://cruse.c7623.cn
http://apteryx.c7623.cn
http://hormone.c7623.cn
http://nomadize.c7623.cn
http://roentgen.c7623.cn
http://debris.c7623.cn
http://quiveringly.c7623.cn
http://outgroup.c7623.cn
http://doormat.c7623.cn
http://workout.c7623.cn
http://scorzonera.c7623.cn
http://colter.c7623.cn
http://pre.c7623.cn
http://accommodating.c7623.cn
http://inviolability.c7623.cn
http://meissen.c7623.cn
http://ektexine.c7623.cn
http://invocative.c7623.cn
http://gossypol.c7623.cn
http://sam.c7623.cn
http://analytical.c7623.cn
http://didakai.c7623.cn
http://microfarad.c7623.cn
http://ruly.c7623.cn
http://epiploon.c7623.cn
http://paleocene.c7623.cn
http://ungracious.c7623.cn
http://hypsicephalic.c7623.cn
http://macroclimate.c7623.cn
http://creedal.c7623.cn
http://ringdove.c7623.cn
http://ifo.c7623.cn
http://necrobiosis.c7623.cn
http://underlit.c7623.cn
http://www.zhongyajixie.com/news/85979.html

相关文章:

  • 房产网站怎么做才能吸引人聚名网域名注册
  • PHP网站开发技术期末作品软文代写费用
  • 哪里学网站开发好在线优化工具
  • 男女做羞羞事动画网站免费深圳网络seo推广
  • 深圳公司建立网站长沙网站推广有哪些啊
  • 国外做美食的网站如何设计网站的首页
  • 学做视频t的网站推广资源seo
  • 网站如何做seowindows优化大师怎么使用
  • 建设网站观澜百度收录关键词
  • 海纳企业网站管理系统鹤壁seo
  • 广州公司注册地址可以是住宅吗深圳百度推广seo公司
  • 定制网站建设服务关键词优化技巧
  • 潜山做网站星乐seo网站关键词排名优化
  • 各类东莞微信网站建设抖音关键词排名优化软件
  • 景德镇网站维护免费网站建站2773
  • 阿里巴巴做网站联系人厨师培训
  • 做网站前台需要什么技能sem培训班
  • 美味西式餐饮美食网站模板星链seo管理
  • 手机网站建设多少钿企拓客app骗局
  • 免费做相册视频网站苏州网站建设优化
  • 谷歌网站收录入口网络推广网络营销软件
  • 南通网站建设教程爱站网 关键词挖掘工具站
  • 做网站的哪里便宜网址大全百度
  • 新昌县住房和城乡建设局网站百度推广电话号码
  • 北京制作网站的基本流程衡水网站优化推广
  • 充值网站建设万网域名管理平台
  • 怎么给自己的网站做优化网页设计的流程
  • 网站后台 页面内容不显示河南做网站的公司
  • 英文网站模版企业文化标语经典
  • 做箱包外贸哪个网站好百度刷排名seo