当前位置:网站首页>STM32F105RBT6 内部flash调试
STM32F105RBT6 内部flash调试
2022-07-25 18:00:00 【smile_5me】
flash.h
#ifndef _FLASH_H_
#define _FLASH_H_
#include "stm32f10x_flash.h"
#define StartServerManageFlashAddress ((u32)0x0801FC00)
#define SECTOR_SIZE 1024
#define FLASH_SIZE 128
void FLASH_WriteMoreData(uint32_t startAddress,uint16_t *writeData,uint16_t countToWrite);
uint16_t FLASH_ReadHalfWord(uint32_t address);
void FLASH_ReadMoreData(uint32_t startAddress,uint16_t *readData,uint16_t countToRead);
void write_to_flash(u16 *buff, u16 count_len);
void read_from_flash(u16 *buff, u16 count_len);
#endifflash.c
#include "flash.h"
//从指定地址开始写入多个数据
void FLASH_WriteMoreData(uint32_t startAddress,uint16_t *writeData,uint16_t countToWrite)
{
uint32_t offsetAddress=startAddress - FLASH_BASE;
uint32_t sectorPosition=offsetAddress/SECTOR_SIZE;
uint32_t sectorStartAddress=sectorPosition*SECTOR_SIZE+FLASH_BASE;
uint16_t dataIndex;
if(startAddress<FLASH_BASE||((startAddress+countToWrite*2)>=(FLASH_BASE + SECTOR_SIZE * FLASH_SIZE)))
{
return;//非法地址
}
FLASH_Unlock(); //解锁写保护
FLASH_ErasePage(sectorStartAddress);//擦除这个扇区
for(dataIndex=0;dataIndex<countToWrite;dataIndex++)
{
FLASH_ProgramHalfWord(startAddress+dataIndex*2,writeData[dataIndex]);
}
FLASH_Lock();//上锁写保护
}
//读取指定地址的半字(16位数据)
uint16_t FLASH_ReadHalfWord(uint32_t address)
{
return *(__IO uint16_t*)address;
}
//从指定地址开始读取多个数据
void FLASH_ReadMoreData(uint32_t startAddress,uint16_t *readData,uint16_t countToRead)
{
uint16_t dataIndex;
for(dataIndex=0;dataIndex<countToRead;dataIndex++)
{
readData[dataIndex]=FLASH_ReadHalfWord(startAddress+dataIndex*2);
}
}
void write_to_flash(u16 *buff,u16 count_len)
{
//u16 buff[1200];
//u16 count_len = 2272 / 2;
FLASH_WriteMoreData(StartServerManageFlashAddress,buff,count_len);
}
void read_from_flash(u16 *buff,u16 count_len)
{
//u16 buff[1200];
//u16 count_len = 2272 / 2;
FLASH_ReadMoreData(StartServerManageFlashAddress,buff,count_len);
}
使用的话就是直接使用wirte_to_flash来写或者是read_to_flash来读,亲测有效。
这篇博客里的代码是参考其他博主的,但是由于我后面没记录下博主的网址,所以就没注明,若是原创博主麻烦可以跟我私信,后面我会加上来自哪里的,感谢。
边栏推荐
猜你喜欢

更新|3DCAT实时云渲染 v2.1.2版本全新发布

Introduction to cloud XR and development opportunities of cloud XR in 5g Era

Redis source code and design analysis -- 15. RDB persistence mechanism

Idea integrates common functions of SVN code management

2022/7/23

Ch582 ble 5.0 uses Le coded broadcast and connection

Tme2022 campus recruitment background development / operation development / business operation and maintenance / application development written examination (I) a little self analysis of programming q

Redistemplate solves the problem of oversold inventory in the seckill system with high speed - redis transaction + optimistic lock mechanism

Hcip first day experiment

如何选择数字孪生可视化平台
随机推荐
Why the future of digitalization depends on 3D real-time rendering
Idea essential plug-ins
Mongodb cluster and sharding
mysql case when
推荐一个沁恒的蓝牙的参考博客
SVN客户端(TortoiseSVN)安装及使用说明
专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
go channel简单笔记
Nineteen year old summary
绘制pdf表格 (一) 通过itext实现在pdf中绘制excel表格样式并且实现下载(支持中文字体)
Function name pointer and function pointer
2022/7/23
SDLC 软件开发生命周期及模型
Brief introduction of bubble sort and quick sort
食品安全 | 八问八答带你重新认识小龙虾!这样吃才对!
OSPF --- open shortest priority path protocol
go语言context控制函数执行超时返回
MATLAB中join函数使用
Auditing相关注解
Redis source code and design analysis -- 16. AOF persistence mechanism