2025-02-07 1:39 AM - last edited on 2025-02-07 1:42 AM by mƎALLEm
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
Solved! Go to Solution.
2025-02-16 7:17 PM
Self resolved.
The cause of the defect was due to the MCU going into a free-run state when the debugger was connected, erasing and reprogramming the FLASH memory.
As a result, all memory contents that had been written immediately before were lost, and since the debugger was reset during the reprogramming process, the second half of the FLASH memory was left in an ERASE state.
The problem was solved by inserting an appropriate weight after initializing the MCU to prevent the FLASH erase from being executed in the free-run state.
Thank you.
2025-02-16 7:17 PM
Self resolved.
The cause of the defect was due to the MCU going into a free-run state when the debugger was connected, erasing and reprogramming the FLASH memory.
As a result, all memory contents that had been written immediately before were lost, and since the debugger was reset during the reprogramming process, the second half of the FLASH memory was left in an ERASE state.
The problem was solved by inserting an appropriate weight after initializing the MCU to prevent the FLASH erase from being executed in the free-run state.
Thank you.