新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2018-12-5
- 在线时间
- 45 小时
|
13金钱
目前做IAP升级,有时能正常flash写入并跳转。有时是flash写入异常,写入需要跨扇区,200k左右。有时发现写入进去了,但是跳转后程序始终也没有运行。很奇怪 请问有人遇到过类似情况吗?
STMFLASH_Write(0x08120000,(uint32_t *)(iap_data_in_sdram+131072),((erase_data_length-131072)/4));
void STMFLASH_Write(uint32_t WriteAddr,uint32_t *pBuffer,uint32_t NumToWrite)
{
FLASH_EraseInitTypeDef FlashEraseInit;
HAL_StatusTypeDef FlashStatus=HAL_OK;
uint32_t SectorError=0;
uint32_t addrx=0;
uint32_t endaddr=0;
if(WriteAddr<STM32_FLASH_BASE||WriteAddr%4)return;
HAL_FLASH_Unlock();
addrx=WriteAddr;
endaddr=WriteAddr+NumToWrite*4; //
if(addrx<0X1FF00000)
{
while(addrx<endaddr) //
{
if(STMFLASH_ReadWord(addrx)!=0XFFFFFFFF)//
{
FlashEraseInit.TypeErase=FLASH_TYPEERASE_SECTORS;
FlashEraseInit.Sector=STMFLASH_GetFlashSector(addrx);
FlashEraseInit.Banks=FLASH_BANK_2; //
FlashEraseInit.NbSectors=2;
FlashEraseInit.VoltageRange=FLASH_VOLTAGE_RANGE_3; //
if(HAL_FLASHEx_Erase(&FlashEraseInit,&SectorError)!=HAL_OK)
{
break;//·¢éú′íÎóáË
}
SCB_CleanInvalidateDCache(); //Çå3yÎTD§μÄD-Cache
}else addrx+=4;
FLASH_WaitForLastOperation(FLASH_WAITETIME,FLASH_BANK_2); //μè′yéÏ′Î2ù×÷íê3é
}
}
FlashStatus=FLASH_WaitForLastOperation(FLASH_WAITETIME,FLASH_BANK_2); //μè′yéÏ′Î2ù×÷íê3é
if(FlashStatus==HAL_OK)
{
while(WriteAddr<endaddr)//D′êy¾Y
{
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD,WriteAddr,(uint64_t)pBuffer)!=HAL_OK)//D′èëêy¾Y
{
break; //D′èëòì3£
}
WriteAddr+=32;
pBuffer+=8;
}
}
HAL_FLASH_Lock(); //éÏËø
}
|
|