cancel
Showing results for 
Search instead for 
Did you mean: 

freezing on stm32 for two second while erasing sector

Auysa.1
Associate

Hello all,

I would like to write data to eeprom of stm32f413zh with stm32cube ide. I use HAL library to do this. I am able to write to eeprom correctly. But while erase function is running, microprocessor freezes for a while(one or two second). I tried with some function but result was same. when i remove HAL erase function, freezing doesnt happen. What can reason be?

void Flash_WriteData(uint32_t addr)

{

     

  HAL_FLASH_Unlock();

  FLASH_EraseInitTypeDef f;

  uint8_t Size;

  f.TypeErase = FLASH_TYPEERASE_SECTORS;

   

  f.NbSectors = 1;

  f.Sector = FLASH_SECTOR_15;

  f.VoltageRange = FLASH_VOLTAGE_RANGE_3;

  Size = 1;    

  uint32_t PageError = 0;

  uint32_t data; 

  HAL_FLASHEx_Erase(&f, &PageError);

  HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD , addr, data);

  HAL_FLASH_Lock();

}

2 REPLIES 2

Doesn't the data sheet explicitly state the erase times of various size sectors?

During the time the flash is busy with write or erase transactions any time you try to secondarily access the flash bank will insert wait states until complete. This will include interrupt/nvic accesses to the vector table placed therein.

Use the SMALLER flash sectors for the EEPROM Emulation, or use the flash directly in a more intelligent way, via journalling and erasure to dead space at startup. Floorplan the use of flash so you can access the small sectors, and don't place code in them.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Auysa.1
Associate

Thanks for answer. According to data sheet of microcontroller, erase time is min 300 ms with smallest sector. I tried that and now it is better. as far as remember, on a document or forum site using last sectors is recommended to be more reliable of system. because of that i selected last sectors for EEPROM Emulation previously. 

''use the flash directly in a more intelligent way, via journalling and erasure to dead space at startup'' Can you reprahase this sentence? How can i apply this? as i use Hal libraries to do this, i have limited facility.