Skip to main content
Explorer
March 14, 2024
Solved

Writing data to STM32G4 Flash

  • March 14, 2024
  • 1 reply
  • 4457 views

Sorry, my first time programming an STM32.  I have a bunch of data I need to store for a few hours, and the thought was to store it in Flash since there's a lot more of it (512k vs. 128k for regular RAM) but it looks to be pretty daunting. 

I've been reading a bunch of articles online, and they all seem to contradict each other, and they all say things like "all you do is write to the memory location, just like regular RAM" and then in the fine print it lists the 43 things you have to do first, - turn off IRQs, update control registers, etc., etc., etc.

Is there an example program for the STM32G474RE that shows a simple "write a bunch of data to Flash" and an equally simple "read a bunch of data from Flash"?

Thanks!

Chris

 

    This topic has been closed for replies.
    Best answer by TDK

    > Is there an example program for the STM32G474RE that shows a simple "write a bunch of data to Flash" and an equally simple "read a bunch of data from Flash"?

    Here's one:

    https://github.com/STMicroelectronics/STM32CubeG4/tree/master/Projects/NUCLEO-G474RE/Examples/FLASH/FLASH_EraseProgram

    1 reply

    TDKAnswer
    Super User
    March 14, 2024

    > Is there an example program for the STM32G474RE that shows a simple "write a bunch of data to Flash" and an equally simple "read a bunch of data from Flash"?

    Here's one:

    https://github.com/STMicroelectronics/STM32CubeG4/tree/master/Projects/NUCLEO-G474RE/Examples/FLASH/FLASH_EraseProgram

    Explorer
    March 14, 2024

    Brilliant, thank you!  If I'm reading the documentation right, the STM32 is in dual bank mode, am I allowed to read/write the Flash in bank 1 (where the program is) as long as I don't overwrite the program itself?

     

    Explorer
    March 14, 2024

    And ... this code

    uint32_t bank32address = 0x08040000;

    uint64_t data = 0x12345678;

    status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, bank32address, data);

    status is HAL_ERROR