u8 Flash_Write_Byte(u8 data,u32 addr)
{
FLASH_EraseInitTypeDef Erase_Init;
u32 SectorError;
u8 sector = STMFLASH_GetFlashSector(addr + FLASH_BASE_ADDR);
u32 Bank = Flash_GetBank(sector);
HAL_FLASH_Unlock();
FLASH_WaitForLastOperation(50000);
Erase_Init.Banks = Bank;
Erase_Init.NbSectors = 1;
Erase_Init.Sector = sector;
Erase_Init.TypeErase = FLASH_TYPEERASE_SECTORS;
Erase_Init.VoltageRange = FLASH_VOLTAGE_RANGE_3;
//调试 一旦运行到此处 再往下走 就直接出错了 必须要重新下载程序才能运行
//0xFFFFFFFE 0000 MOVS r0,r0= FLASH_VOLTAGE_RANGE_3; 汇编窗口 就一直在这里
//请问下 这是怎么回事啊 ?
if(HAL_FLASHEx_Erase(&Erase_Init,&SectorError) != HAL_OK)
{
return 1;
}
FLASH_WaitForLastOperation(50000);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE ,(addr + FLASH_BASE_ADDR) , data);
FLASH_WaitForLastOperation(50000);
HAL_FLASH_Lock();
return 0;
}
一周热门 更多>