2025-02-07 01:39 AM - last edited on 2025-02-07 01:42 AM by SofLit
Hellow!
I am trying to use “FLASH_EDATA_EraseProgram” with NUCREO-H563ZI.
When I execute the code, it works normally, but when I connect to the debugger again after closing the debugger, part of the EDATA is initialized.
When running in standalone mode, the EDATA is not initialized even if the power is turned on and off, so it looks like the debugger is deleting part of the EDATA. However, the starting address of the area to be deleted is not fixed, and it changes each time the EDATA is deleted and reprogrammed, and it is deleted until the end of the EDATA area.
The code below is for verification purposes, and is simply a copy of the check process before the original code's erase process.
int main(void)
{
...
/* Start option byte load operation after successful programming operation */
HAL_FLASH_OB_Launch();
/**** To check the values stored in the EDATA, insert Check_Flash_Content immediately before HAL_FLASHEx_Erase */
/**** First time, skip this process by “jump to the line”. Otherwise, an NMI interrupt will occur because the EDATA has not been initialized. */
if (Check_Flash_Content(EDATA_USER_START_ADDR, EDATA_USER_END_ADDR, FlashHalfWord) != 0)
{
Error_Handler();
}
/****/
/* Get the first sector of FLASH high-cycle data area */
FirstSector = GetSector_EDATA(EDATA_USER_START_ADDR);
/* Get the last sector of FLASH high-cycle data area */
EndSector = GetSector_EDATA(EDATA_USER_END_ADDR);
/* Get the number of sectors to erase */
NbOfSectors = EndSector - FirstSector + 1;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.Banks = GetBank_EDATA(EDATA_USER_START_ADDR);
EraseInitStruct.Sector = FirstSector;
EraseInitStruct.NbSectors = NbOfSectors;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK)
{
/*
Error occurred while sector erase.
User can add here some code to deal with this error.
SectorError will contain the faulty sector and then to know the code error on this sector,
user can call function 'HAL_FLASH_GetError()'
*/
/* Infinite loop */
Error_Handler();
}
Please let me know if you have any good solutions!
Thanks,
Kiyama