Flash Erase not Working (STM32G491RC)
I'm trying to write some data to a address in the flash memory of the above mentioned chip. However the Erase doesn't seem to work.
void writeToFlash(uint32_t address, uint64_t data, uint64_t data2){
// Unlock the Flash Program controller
HAL_FLASH_Unlock();
// Setting Up the Erase
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = 2;
EraseInitStruct.Page = 127;
EraseInitStruct.NbPages = 1; // simple function only sending 8 Bytes at the time.
uint32_t pageError;
//Erasing specific part of memory
HAL_FLASHEx_Erase(&EraseInitStruct, &pageError);
//Programming the flash, last adress of the second Bank!
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address + 0x08, data2);
//Locking the flash back up
HAL_FLASH_Lock();
}
In the main I'm calling the following:
writeToFlash(0x0807FFF0, 0x00FFFFFF9A6410AC, 0x00000000016410AC);
The reason I'm specifying the bank and page number is because I (think I,) know where the data needs to be erased.
And when do a full chip erase via STM32Cube Programmer, the writing to the flash works. But when I try to do it with some data storage already in the memory. It doesn't. Please help, I've been struggling now for a couple of days.
