cancel
Showing results for 
Search instead for 
Did you mean: 

EDATA is partially erased when writing code using STM32CubeIDE.

Kiyama
Visitor

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();
  }

 

 

  1.  Initialize EDATA by skipping the added check process. It should finish normally and the LED should light up.
  2. Reset the code and run it while maintaining the debug state. I think this will also finish normally.
  3. Stop debugging, re-insert the USB cable, and run it in standalone mode. This should also end normally and the LED should light up.
  4. Run debugging again from CubeIDE. The added check process will cause an NMI interrupt and the LED will not light up.
  5. Stop debugging, re-insert the USB cable, and run it in standalone mode. The LED will not light up.

Please let me know if you have any good solutions!

Thanks,
Kiyama

0 REPLIES 0