[mw_shl_code=c,true]void Write_Flash(void)
{
u8 i = 0,nPage = 0;
u32 Address = 0;
volatile FLASH_Status FLASHStatus = FLASH_COMPLETE;//擦除完成标志
FLASH_Unlock();//擦写Flash解锁
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPERR);//清除操作结束|编写错误|页写保护错误
nPage = (Write_End_Address - Write_Start_Address)/Flash_Page;//计算页数
for(i=0;(i<nPage)&&(FLASHStatus == FLASH_COMPLETE);i++)//循环擦除flash
FLASHStatus = FLASH_ErasePage(Write_Start_Address+(Flash_Page*i));
//FLASH_ProgramHalfWord();半字写入(16位)FLASH_ProgramWord();全字写入(32位)
Address = Write_Start_Address;
if(FLASHStatus == FLASH_COMPLETE)//写入X轴水平点
FLASHStatus = FLASH_ProgramWord(Address,0x12345678);
Address +=4;
if(FLASHStatus == FLASH_COMPLETE)//写入Y轴水平点
FLASHStatus = FLASH_ProgramWord(Address,0x23456789);
Address +=4;
if(FLASHStatus == FLASH_COMPLETE)//写入Z轴水平点
FLASHStatus = FLASH_ProgramWord(Address,0x34567890);
Address +=4;
if(FLASHStatus == FLASH_COMPLETE)//写入设备ID
FLASHStatus = FLASH_ProgramWord(Address,Device_ID);
FLASH_Lock();//锁定Flash
}
[/mw_shl_code]
在调用这个函数后,写入地址时就会进入内存溢出,看了一些都是说的没有对齐,请问这个怎么对齐,我全字写入也不行,直接写入固定数也不行,
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
//STM32F042F4内部16KFlash,
#define Flash_Page ((uint32_t)0x00000400)
//Page 15
#define Write_Start_Address ((uint32_t)0x08003C00)
#define Write_End_Address ((uint32_t)0x08004000)
一周热门 更多>