0
\$\begingroup\$

Context:

  • I am using STM32CubeIDE 1.11.0 on Linux to program (via ST-Link V2) my STM32f103c8t6 bluepill, boot mode is 00 ("Main Flash Memory")
  • I have read the whole section about it in the manual, but the answer is not there or at least it is not there in any form I can understand
  • I need to store data into memory but I need to keep it after reset or power off. I was wondering if I could use flash memory to achieve this.

Boot modes

So, straight to the questions:

  1. If I keep using boot mode 00:

    1. Is my program stored in (and the unit booted from) "main flash memory"?
    2. Writing data in this memory section will make bad things happen, correct?
    3. Can I use "System memory" section of the flash since it's not being used to store my program?
  2. If I use Boot mode 01 "System memory":

    1. Will I be able to keep programming the unit via USB (ST-Link V2) and STM32CubeIDE?
    2. Now that "Main flash memory" is not used to boot from, am I able to write into it without any problems?
  3. If I use boot mode 11 "Embedded SRAM":

    1. Will I be able to keep programming the unit via USB (ST-Link V2) and STM32CubeIDE?
    2. Is my program now stored in SRAM leaving flash initially unused?
    3. If so, am I now able to write data into any address of the flash memory?

Thanks so much for your patience, I am quite new to this and non-native English speaker. If I missed information needed to answer please ask.

Kind regards.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

The main flash memory is flash where you can store program and data, and you must boot from there to start running your program.

The system flash memory runs the unerasable factory bootloader you can use to reprogram main flash memory. You can't use it for anything else.

You can boot from SRAM but then you need to load the program to SRAM before you can boot from SRAM. Your program will not be in SRAM if you turn power off and on again.

So in short, you must use main flash memory. You can freely use the rest of the flash as you wish if the program is smaller than the flash.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks so much for your answer and for editing my question for a better understanding. \$\endgroup\$
    – Santiago
    Commented Jan 27, 2023 at 22:13
  • 1
    \$\begingroup\$ @Santiago instead of thanking Justme for an answer: there's an upwards-pointing triangle next to the answer that is meant to say "the answer is useful". Click that! I've just done the same for this answer. Also, PS: I was the one editing your question, not justme :D \$\endgroup\$ Commented Jan 28, 2023 at 12:11
  • \$\begingroup\$ Yes, I already voted on both of your answers yesterday, but since I do not have enough reputation, my feedback is recorded but nod displayed until I get enough (15 I think?) reputation. Oh, thanks for that too then! I appreciate your help a lot \$\endgroup\$
    – Santiago
    Commented Jan 28, 2023 at 14:25
0
\$\begingroup\$

Yes, you can use flash to save data. You put that data, obviously, somewhere not occupied by program code :)

Question Answer
1.1. yes
1.2. If you overwrite your code, yes. If you write into positions not used for code, no
1.3. no (see justme's answer)
2.1. yes; that (usually) happens over SWD and has not much to do with the boot mode; however, that boot mode is specifically for loading program code into permanent memory (e.g. for factory flashing)
2.2. No you can't, because in this mode none of your own firmware is running.
3.1. see 2.1.
3.2. Your program needs to be in SRAM before you reboot. SRAM is volatile!
3.3. yes, but what's the point?
\$\endgroup\$
3
  • \$\begingroup\$ Thanks so much! One last question following up on point 1.2. My device has a main flash memory of 32kB. When uploading a code, I get some information in the console of which I extract: "Size : 3,27 KB ; "Address : 0x08000000" which according to the manual is the address where main flash memory begins. Does that mean that 3.27KB starting from 0x08000000 is occupied by the program and the rest (~29KB) is unused and available for my application data, writing it via DMA for example? \$\endgroup\$
    – Santiago
    Commented Jan 27, 2023 at 23:15
  • \$\begingroup\$ I can't tell you that, to be honest, without looking at the linker script that your toolchain uses - assuming you didn't write your own linker script, which is how you solve this: there you can define an area only used for your data, so when you compile and link together an image to be flaahed to your MCU, that is either left untouched it filled with data from some other file you define. \$\endgroup\$ Commented Jan 28, 2023 at 9:54
  • \$\begingroup\$ I understand, I guess I'll just try and see what happens. Of course I am not sure, but since it specifies the address and size, it probably saves everything together in one block leaving the rest of the memory available. Thanks for your answers! \$\endgroup\$
    – Santiago
    Commented Jan 28, 2023 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.