cancel
Showing results for 
Search instead for 
Did you mean: 

Writing data to STM32G4 Flash

c_shearer_cooper
Associate III

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> 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

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

View solution in original post

5 REPLIES 5
TDK
Guru

> 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

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

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?

 

And ... this code

uint32_t bank32address = 0x08040000;

uint64_t data = 0x12345678;

status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, bank32address, data);

status is HAL_ERROR

I wasn't doing Flash_Unlock() and Flash_Lock().  It's working now.  Thank you!

 

Yes, as long as you don't overwrite or erase currently running code, you can erase/write wherever you want.

Note that erasing takes some time (tens of ms or so) and the system will stall if you are running code on the same bank as you are erasing.

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