当前位置:网站首页>STM32 internal flash operation function
STM32 internal flash operation function
2022-07-18 05:16:00 【Summer night breeze_】
IAP The contents of the remote update series are as follows :
1. IAP Description of remote update mechanism
2. Bootload and App Code implementation of inter jump
3. STM32 Inside Flash Operation function of
STM32 Inside the operation Flash The function interface of
#include "inFlash.h"
#include "stm32f10x_flash.h"
/*! * work can : Write internal without checking Flash * param1: Initial address * param2: Data pointer to write * param3: The number of data to be written * return: No return value */
void InFlashWriteNoCheck(uint32_t writeAddr, uint16_t *pBuffer, uint16_t numToWrite)
{
uint16_t i;
for(i=0; i<numToWrite; i++)
{
FLASH_ProgramHalfWord(writeAddr, pBuffer[i]); // Write half word at the specified address
writeAddr += 2; // Address increase 2.
}
}
/*! * work can : Write data of the specified length from the specified address * param1: Initial address ( This address must be 2 Multiple !!) * param2: Data pointer to write * param3: Half word (16 position ) Count ( Is to write 16 Number of bit data .) * return: Successfully returns 0 * Failure to return -1 */
int InFlashWrite(uint32_t writeAddr, uint8_t *pBuffer, uint16_t numToWrite)
{
uint16_t i, temp = 0;
// First judge whether the address is legal
if(writeAddr<INFLASH_START_ADDR || (writeAddr>=(INFLASH_START_ADDR + INFLASH_TOTAL_SIZE * 1024)))
{
return -1;
}
FLASH_Unlock(); // Unlock
FLASH_SetLatency(FLASH_Latency_2); // Because the system clock is 72M So set the delay of two clock cycles
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR | FLASH_FLAG_EOP);
// Erase the entire page before writing it , And judge whether the erasure is successful
while(FLASH_ErasePage(writeAddr) != FLASH_COMPLETE);
// Write data , Small end storage , The high byte of data is stored in the high address
if(numToWrite == 1)
{
temp |= pBuffer[0];
while(FLASH_ProgramHalfWord(writeAddr, temp) != FLASH_COMPLETE); // Judge whether the writing is successful
}
else
{
for(i=0; i<numToWrite; i++) // Write in half word
{
temp = (pBuffer[2*i+1]<<8) | pBuffer[2*i]; //2 Bytes are integrated into 1 A half word
while(FLASH_ProgramHalfWord(writeAddr, temp) != FLASH_COMPLETE); // Judge whether the writing is successful
writeAddr += 2; // Add... To the address 2, Because every time I write 2 Bytes (1 A half word )
}
}
FLASH_Lock(); // locked
return 0;
}
/*! * work can : Read the half word of the specified address (16 Bit data ) * param1: Read the address ( This address must be 2 Multiple !!) * return: Data read */
uint16_t InFlashReadHalfWord(uint32_t faddr)
{
return *(uint16_t*)faddr;
}
/*! * work can : Read the data of the specified length from the specified address * param1: Initial address ( This address must be 2 Multiple !!) * param2: The address of the buffer to be saved * param3: Halfword to read (16 position ) Count ( Is to read 16 Number of bit data .) * return: No return value */
void InFlashRead(uint32_t readAddr, uint16_t *pBuffer, uint16_t numToRead)
{
uint16_t i;
for(i = 0; i < numToRead; i++)
{
pBuffer[i] = InFlashReadHalfWord(readAddr); // Read 2 Bytes .
readAddr += 2; // The offset 2 Bytes .
}
}
/*! * work can : Test functions , Go inside Flash Write a byte of data * param1: Initial address * param2: The data to be written * return: Successfully returns 0 */
int InFlashWriteChar(uint32_t writeAddr, uint8_t writeData)
{
return InFlashWrite(writeAddr, &writeData, 1); // Write a word
}
边栏推荐
- Niuke 2021 summer training 5-d-double strings
- Information system project managers must memorize the core examination points (III) 14 graphic tools of UML
- CRC16校验 C语言实现
- 零基础学lua第十五天---最后归纳下
- 小bai挑战学c语言第七天----枚举、结构体、共用体
- cJSON使用
- 对接企业微信,客户关系管理也可以很简单!
- Niuke 2021 summer training 3-b-black and white
- Chess all in one
- About solving the problem of token expiration
猜你喜欢
随机推荐
H5 cloud image background reading and writing CAD files - Online CAD, web CAD, web browsing and editing CAD
Niuke 2021 summer training 1-h-hash function
信息系统项目管理师必背核心考点(四)UML类与类之间的关系
(pc+wap) Zhimeng template waterproof building materials website
第九届蓝桥杯B组省赛。
Information system project managers must recite the core examination points (IV) the relationship between UML classes
Salesforce项目中使用ETL工具做数据迁移
实现两个元素并排显示 (含flex一些属性的讲解)
image 标签 中的 mode=“widthFix“ 属性
MATLAB初次学习
Salesforce中使用LWC本地开发
INSUFFICIENT_ACCESS_ON_ CROSS_REFERENCE_ENTITY APEX / SALESFORCE
Niuke 2021 summer training 3-e-math
Matlab_ Figure is displayed on the top during debugging
An example of how to render objects and arrays on the page by rendering the data obtained in the background
Super Ping tool
CAS Compare and Swap 比较后交换
微信小程序从入门到学会第九天———-小程序的系统操作
电商平台后台管理系统--->系统详细设计(用户登录、商品管理模块)
电商平台后台管理系统--->系统详细设计(订单管理模块)








