STM32F413 flash erase doesn't work first time
Hi,
I am using STM32F413 Nucleo board. I am using MDK5 IDE and HAL libraries. I made an example for reading/writing internal flash based upon a cube project.
The idea is to erase interal flash and then to write some data to it. I alreay did some similar porjects but with F0 and F3 series so I am not newbie in that field.
However what I am seeing here is that the first time I load application to MCU and run it it won't erase flash. Then I break it, reset and re-run it and it will erase and program everything perfectly. And from this point on it will always work fine.
To sumarize. Flash erase is not working only the first time right after I load application into flash. Flash unlock returns HAL_OK while flash erase function returns HAL_ERROR. After I break it, press reset and run it again it will work without a problem (no HAL_ERROR for flash function).
I am visualizing data in Memory 1 window where I can see how data is changing.
So my code excerpt is as follows:
HAL_FLASH_Unlock();
EraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_3;
EraseInit.Sector = StartSector; //Specify start sector number
EraseInit.NbSectors = NumOfSectors; //Specify num of sectors
status = HAL_FLASHEx_Erase(&EraseInit, &SectorError) == HAL_OK;
...
// Do some data programing...
HAL_FLASH_Program(....)
...
HAL_FLASH_Lock();Again, it only happens first time right after I load application into MCU... after first reset/break it will always work ok.
Any idea? Could this be IDE problem?
Thank you in advance.
Nix
