当前位置:网站首页>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来读,亲测有效。
这篇博客里的代码是参考其他博主的,但是由于我后面没记录下博主的网址,所以就没注明,若是原创博主麻烦可以跟我私信,后面我会加上来自哪里的,感谢。
边栏推荐
- 为什么数字化未来取决于3D实时渲染
- Oracle导入出错:IMP-00038: 无法转换为环境字符集句柄
- Mock service Moco series (I) - introduction, first demo, get request, post request
- Food safety | eight questions and eight answers take you to know crayfish again! This is the right way to eat!
- Dating activity records
- I'm also drunk. Eureka delayed registration and this pit!
- Which real-time gold trading platform is reliable and safe?
- "Deprecated gradle features were used in this build, making it incompatible with gradle 6.0" problem solving
- 专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
- WPF 实现用户头像选择器
猜你喜欢
P2P 之 UDP穿透NAT的原理与实现

「数字安全」警惕 NFT的七大骗局

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

2022/7/23

Good news! Ruiyun technology was awarded the member unit of 5g integrated application special committee of "sailing on the sea"

Take you to a preliminary understanding of multiparty secure computing (MPC)

What are the advantages of real-time cloud rendering

OSPF---开放式最短优先路径协议

Auditing相关注解

Calculation date or date formatting
随机推荐
Calculation date or date formatting
Redis source code and design analysis -- 15. RDB persistence mechanism
越来越成熟的Rust,都应用了哪些场景呢?
Hcip first day experiment
推荐一个沁恒的蓝牙的参考博客
Landmark buildings around the world
Redis source code and design analysis -- 18. Analysis of redis network connection Library
云流化和云桌面有什么关系
期货开户哪家最好最安全
实时云渲染有哪些优势
Which real-time gold trading platform is reliable and safe?
Hit the test site directly: summary of common agile knowledge points in PMP examination
喜讯!瑞云科技被授予“海上扬帆”5G融合应用专委会成员单位
十九岁的总结
Basic knowledge of software testing (mind mapping)
WPF implements user avatar selector
简述Synchronized以及锁升级
Cloud XR面临的问题以及Cloud XR主要应用场景
Automated test Po design model
PageHelper can also be combined with lambda expressions to achieve concise paging encapsulation