I have an updatable project with stm32f407. Code produced by cubeMx. Updater code check new update from internet and if is avaliable write main program on 0x08020000(sector 5) and this updater code on 0x08000000(sector 0 and sector 2 size is less than 32kb)
I am writing a code(will be like main project on sector 5) can update the updater code on sector 0
My problem is when I erase sector 0 AC6 give an error for address wrapping and STM32 stop working. I think is because of sector 0 has a special situation. there is no problem with erase other sectors. Is there a anyway to erase sector0 with a embedded program? The problem begin after delete 1 sector. I dont know what to do. (sorry for my bad English)
for(data_sayac=0;data_sayac<=filelength/2;data_sayac+=2)
{
// UPDATEDATA_ADDRESS defined 0x08040000 (sector 6 where my new updater data copied from internet)
// UPDATEDATA_ADDRESS2 defined 0x08000000 (sector 0 where my new updater program copied from sector 6)
Data1=Flash_oku_halfword(UPDATEDATA_ADDRESS+data_sayac);
if(Flash_oku_halfword(UPDATEDATA_ADDRESS2+data_sayac)!=0xFFFF) // if sector is not empty erase first
{
HAL_FLASH_Unlock();
Get_Sector= FLASH_If_GetSectorNumber(UPDATEDATA_ADDRESS2+data_sayac); // get sector number by address
FLASH_Erase_Sector(Get_Sector,VOLTAGE_RANGE_3); //erase sector
}
Flash_yaz_halfword(UPDATEDATA_ADDRESS2+data_sayac,Data1); // write halfword
}