Electronics > Microcontrollers

STM32F4 saving data to internal flash (at runtime)

(1/2) > >>

roli:
I am building an application for this MCU that needs to persistently save some data - two or three string arrays (about 1k or less) at runtime (because the values are not known at compile time). I know that the micro has 11 flash sectors of different sizes. And I've seen the flash header that the STM provides. It has the erase/write functions that I need. And now for the actual question: How do I reserve the needed space (I'm guessing the whole sector?) so the compiler won't save any code there? And how do you actually read that data from memory - or is it as simple as using the actual sector base address? I am guessing that everything depends on the actual toolkit being used - I am using the lite (codesize limited) version of IAR Workbench.

andyturk:
The compiler doesn't determine the actual location of anything--that's the linker's job. So if you want to reserve space somewhere, you'll need to modify the linker file. I'm not sure how IAR does things, but with a GCC toolchain, you'll have a .ld file somewhere.

But since you're using a STM32F4, check out the "Backup SRAM" capability. There's 4K of RAM that's essentially non-volatile as long as the mcu has power on the VBAT pin. Writing to backup SRAM will be much faster and you won't have to worry about write endurance.

roli:
I completely forgot about the linker. That happens when you are used to other (non-C) high-level languages. You completely forget that the linker even exists. I found the linker options file (.icf if I understand this correctly) for the project but I have no idea how to set them - I've never actually dealt with linkers before.

As for the backup SRAM option. I've read about that but it really isn't the path I would like to take. It's still volatile and I don't like that. And flash would really be better since I mostly just need to read the data. I need to save/modify some data once a month or so. Not really something problematic.

leppie:
You might want to look at the bootloader examples. I guess the process will be similar.

casinada:
You might want to try the M3 series that comes with EEPROM that is as easy to write as to SRAM but is non volatile and the endurance is better than the Flash counterpart. :)
http://www.st.com/web/en/catalog/tools/PF259096
The discovery board is only $8
If you want to use your current kit you can buy some serial eeproms and save that data that way.
The Flash memory is conventionally used to hold the program and not the data.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod