Skip to main content
Visitor II
April 11, 2023
Question

Programming a Data in to Flash memory STM32G series

  • April 11, 2023
  • 3 replies
  • 2741 views

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();

    This topic has been closed for replies.

    3 replies

    ST Employee
    April 11, 2023

    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!

    Visitor II
    April 11, 2023

    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.

    Visitor II
    January 9, 2024

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

     

    Visitor II
    January 9, 2024