I´m trying to save some data to flash memory on my STM32F407 board. Before I can save them I need to erase memory sector. I choosed 16 Kbytes Sector1 starting with address 0x08004000 and choosed Voltage range 2.1-2.7 V. I'm using HAL library.
Program stops responding after FLASH->CR |= FLASH_CR_STRT; line inside HAL_FLASHEx_Erase() -> FLASH_Erase_Sector() function.
I'm pretty sure it's my fault but I can't find out what is wrong.
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.Sector = FLASH_SECTOR_1;
EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_2;
EraseInitStruct.NbSectors = 1;
uint32_t SectorError = 0;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
HAL_FLASH_Lock();
return;
}
uint16_t data = 300;
//----------------------------write data
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, start_address, data) != HAL_OK) {
HAL_FLASH_Lock();
return;
}
HAL_FLASH_Lock();
Did I choosed wrong voltage range or number of sectors?
Thanks for your answers.