2024-03-14 02:09 PM
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
Solved! Go to Solution.
2024-03-14 02:22 PM
> 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:
2024-03-14 02:22 PM
> 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:
2024-03-14 02:34 PM
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?
2024-03-14 02:49 PM
And ... this code
uint32_t bank32address = 0x08040000;
uint64_t data = 0x12345678;
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, bank32address, data);
status is HAL_ERROR
2024-03-14 02:57 PM
I wasn't doing Flash_Unlock() and Flash_Lock(). It's working now. Thank you!
2024-03-14 05:05 PM
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.