资源简介
基于stm32 开发板的flash读写程序,可以保存用户数据,测试ok!
代码片段和文件信息
#include “ev_stm32_falsh.h“
uint16_t Flash_Write_Without_check(uint32_t iAddress uint8_t *buf uint16_t iNumByteToWrite)
{
uint16_t i = 0;
volatile FLASH_Status FLASHStatus = FLASH_COMPLETE;
while((i < iNumByteToWrite) && (FLASHStatus == FLASH_COMPLETE))
{
FLASHStatus = FLASH_ProgramHalfWord(iAddress *(uint16_t*)buf);
i = i+2;
iAddress = iAddress + 2;
buf = buf + 2;
}
return iNumByteToWrite;
}
int Flash_Write(uint32_t iAddress uint8_t *buf uint32_t iNbrToWrite)
{
uint32_t sectoraddress;
uint32_t iNumByteToWrite = iNbrToWrite;
uint16_t sectoroffset;
uint16_t sectorremainspace;
uint16_t i = 0;
uint8_t tmp[FLASH_PAGE_SIZE];
volatile FLASH_Status FLASHStatus = FLASH_COMPLETE;
FLASH_UnlockBank1();
sectoraddress = iAddress & (~(FLASH_PAGE_SIZE - 1 )) ;//扇区地址
sectoroffset = iAddress & (FLASH_PAGE_SIZE - 1); //在扇区内的偏移
sectorremainspace = FLASH_PAGE_SIZE - sectoroffset; //扇区剩余空间大小
if(iNumByteToWrite<=sectorremainspace) sectorremainspace = iNumByteToWrite;//不大于4096个字节
while( 1 ) {
Flash_Read(sectoraddress tmp FLASH_PAGE_SIZE); //读出整个扇区
for(i=0;i { //校验数据
if(tmp[sectoroffset+i]!=0XFF) break; //需要擦除
}
if(i FLASHStatus = FLASH_ErasePage(sectoraddress); //擦除这个扇区
if(FLASHStatus != FLASH_COMPLETE)
return -1;
for(i=0;i { //复制
tmp[i+sectoroffset]=buf[i];
}
Flash_Write_Without_check(sectoraddress tmp FLASH_PAGE_SIZE);//写入整个扇区
} else {
Flash_Write_Without_check(iAddressbufsectorremainspace);//写已经擦除了的直接写入扇区剩余区间.
}
if(iNumByteToWrite==sectorremainspace) //写入结束了
break;
else
{
sectoraddress += FLASH_PAGE_SIZE;
sectoroffset = 0;//偏移位置为0
buf += sectorremainspace; //指针偏移
iAddress += sectorremainspace;//写地址偏移
iNumByteToWrite -= sectorremainspace; //字节数递减
if(iNumByteToWrite>FLASH_PAGE_SIZE)
sectorremainspace=FLASH_PAGE_SIZE;//下一个扇区还是写不完
else
sectorremainspace = iNumByteToWrite; //下一个扇区可以写完了
}
}
FLASH_LockBank1();
return iNbrToWrite;
}
int Flash_Read(uint32_t iAddress uint8_t *buf uint32_t iNbrToRead)
{
int i = 0;
while(i < iNbrToRead ){
*(buf + i) = *(__IO uint8_t*) iAddress++;
i++;
}
return i;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2495 2014-09-26 10:50 application\ev_stm32_falsh.c
文件 878 2014-09-26 11:27 application\ev_stm32_falsh.h
文件 537 2014-09-26 11:00 application\startup.c
目录 0 2014-09-26 11:30 application
----------- --------- ---------- ----- ----
3910 4
- 上一篇:普通快速排序随机快速排序算法实验
- 下一篇:基于LQR的二级倒立摆模糊控制
相关资源
- STM32F103 TFT彩屏显示图片和汉字字符(
- STM32F103 TFT彩屏显示汉字字符(取摸
- STM32雕刻机、CNC源代码
- 中学Flash课件选择题模板
- flash、SRAM、EEPROM在AVR中的应用
- stm32f4探索者开发板原理图
- STM32Cube-USART
- STM32F10Xlib.h系列的固件库
- STM32F030-uCOSIII
- 开源三轴无刷云台算法STM32程序带注释
- STM32 d的图形GUI界面代码
- STM32驱动max30102和MLX90614程序
- stm32 IAP源码
- STM32F407 6288语音模块程序
- STM32-实时时钟和闹钟程序.pdf
- 声音定位系统
- Flash兔子跳铃铛
- STM32定时器
- 基于STM32图像采集程序
- STM32单片机WS2812B驱动程序灯效程序
- stm32串口调试助手
- STM32F103VET6最小系统板原理图
- FLASH套环游戏flash
- 嵌入式网络那些事-STM32物联实战 百度
- STM32F4 GPS NEO-M8N完整项目
-
Eclipse + CDT + YAGARTO + J-li
nk,STM32开源 - stm32 多通道ADC转换
- STM32F103读SHT31温湿度传感器代码,实测
- STM32 STM8的protel库文件 内含原理图sc
- STM32F411标准库模板例程,基于正点原
评论
共有 条评论