cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0. How to write/read in Flash Memory

EGonz.11
Associate

Hi,

This is to request clarification on doubts regarding the storage of data in the non-volatile memory of the STM32G030C6T6 micro controller ... from what I see in the micro controller's technical sheet, it does not have EEPROM memory, since FLASH memory is used both to save the code and to store data.

I have two routines to write and read respectively from FLASH; but they don't work, and I get an error in the statement: "HAL_FLASHEx_Erase (& EraseInitStruct, & SECTORError);"

Could you please help me to identify the error, or to know another way to record data in the non-volatile memory of the STM32G030C6T6

Below is attached the code used in both routines

Thank you so much

/* WRITE IN FLASH MEMORY */

void writeToFLASH (uint32_t address, uint32_t value){

  HAL_StatusTypeDef flash_ok;

  flash_ok = HAL_ERROR;

  while (flash_ok != HAL_OK){

   flash_ok = HAL_FLASH_Unlock();

//  flash_ok = HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);

   flash_ok = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, value);

   flash_ok = HAL_FLASH_Lock();

  }

}

/* READ FROM FLASH MEMORY */

uint32_t readFromFLASH (uint32_t address){

 return (*(__IO uint32_t *)address);

}

2 REPLIES 2

>> I get an error in the statement: "HAL_FLASHEx_Erase (& EraseInitStruct, & SECTORError);"

What does the error specifically say? That you haven't defined the variables/structures?

Usually one would have a structure/array of data to be saved into a flash sector, so the write/erase can be done efficiently.

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

And how is EraseInitStruct defined? You need to populate it with what you're trying to do.

If you feel a post has answered your question, please click "Accept as Solution".