加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

stm32f103 flash读写函数

发布时间:2020-12-15 17:45:53 所属栏目:百科 来源:网络整理
导读:#include "main.h" #define PAGE_ADDR (0x08000000 + 64 * 1024) uint8 MemReadByte(uint16 *data,uint16 num) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? uint16 *temp_addr = (uint16 *)PAGE_ADDR; ? ? ? ?? ? ? ? ? while(num --) ? ? ? ? { ? ? ? ? ? ?
#include "main.h" #define PAGE_ADDR (0x08000000 + 64 * 1024) uint8 MemReadByte(uint16 *data,uint16 num) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? uint16 *temp_addr = (uint16 *)PAGE_ADDR; ? ? ? ?? ? ? ? ? while(num --) ? ? ? ? { ? ? ? ? ? ? ? ? *data ++ = *temp_addr ++; ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? return 1; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } uint8 MemWriteByte(uint16 *data,uint16 num) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? FLASH_Status temp_stat; ? ? ? ? uint32 temp_addr = PAGE_ADDR; ? ? ? ? ? ? ? ?? ? ? ? ? FLASH_Unlock(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Flash解锁,允许操作相关的寄存器 ? ? ? ? temp_stat = FLASH_ErasePage(PAGE_ADDR); ? ? ?// 擦出制定的页 ? ? ? ?? ? ? ? ? if(temp_stat != FLASH_COMPLETE) ? ? ? ? { ? ? ? ? ? ? ? ? FLASH_Lock(); ? ? ? ? ? ? ? ? return 0; ? ? ? ? } ? ? ? ?? ? ? ? ? while(num --) ? ? ? ? { ? ? ? ? ? ? ? ? temp_stat = FLASH_ProgramHalfWord(temp_addr,*data); ? ? ? ? ? ? ? ? if(temp_stat != FLASH_COMPLETE) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? FLASH_Lock(); ? ? ? ? ? ? ? ? ? ? ? ? return 0; ? ? ? ? ? ? ? ? } ? ? ? ?? ? ? ? ? ? ? ? ? temp_addr += 2; ? ? ? ? ? ? ? ? data++; ? ? ? ? } ? ? ? ?? ? ? ? ? FLASH_Lock(); ? ? ? ? ? ? ? ? return 1; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读