cancel
Showing results for 
Search instead for 
Did you mean: 

Programming a Data in to Flash memory STM32G series

Karthik Kumar
Associate III

Hello Every one I am using NUCLEO-G0B1RE board when trying to store the data in to flash memory address its not updating after erasing but individually if I try only erase or only write data in to flash memory it is working

please suggest me below is my code

at run time i would like to erase and update the data suggest me if went wrong in the code

uint32_t BaseAddr = 0x08041000; //global variable.

uint64_t FlashData = 0xee;////global variable.

inside main function

HAL_FLASH_Unlock();

FLASH_PageErase(2,258);

HAL_FLASH_Lock();

HAL_Delay(100);

HAL_FLASH_Unlock();

HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, BaseAddr, FlashData);

HAL_FLASH_Lock();

4 REPLIES 4
Sarra.S
ST Employee

Hello @Karthik Kumar​,

So based on your code, you're trying to erase a page from flash memory and then write data to a specific address in the same page..

you are writing a double word, so your base address (0x08041000) have to be aligned with 8 bytes

The problem is either in the erase or the write operation!

So, verify the erase is successfully done before writing, using HAL_FLASH_GetFlagStatus() function.

for example to wait for the erase operation is complete before HAL_FLASH_Lock();

Verify the write operation by reading back from the address you wrote to, and compare it to the data you wrote.

Hope that helps!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @Sarra.S​ Thank youfor your Response, I got the issue after adding this HAL_FLASH_GetFlagStatus() function.

Please guide me I have shared screen shot below.

poojith7
Associate II

bro i am facing the same issue i am not even getting data if do them induadually also

 

poojith7
Associate II