Electronic – How much FLASH memory is free for a program

flashstm32f10x

I'm programming for a STM32F103C8T6 (aka blue pill), with the be datasheet here.

On page 14 it states:

2.3.2 Embedded Flash memory 64 or 128 Kbytes of embedded Flash is available for storing programs and data.

Now mine has 64 KB, however, does this mean I have 100% available, or is there some part reduced? And if so, how much? Or is there a way to find out when it will not 'fit' (like an error will show up?).

I use an STM32 ST-LINK V2, and afaik I'm not using any special bootloader, development environment is Workbench 4 STM / Eclipse, and using HAL/STMCube.

Currently I'm using only about 19KB but I'm not finished (and running my unit tests also within this code, although I can switch it off, which saves half).

Best Answer

In a typical microcontroller, you can program all of the flash with your code. You can check the TRM to be sure -- if it talks about a boot loader in the first sector or tells you there are parts of the flash you can't erase, then those parts are reserved. But normally you get it all.

Note that that doesn't mean 100% of the flash will be used for code! You'll have interrupt vector addresses at the start of the flash. Constants and initialization values for static variables will also be stored in the flash. Your linker should take care of this for you, probably using a linker script supplied by the manufacturer (ST). The linker should give an error if your program is too big to fit in flash.

Advanced programmers can write their own linker scripts and manually assign code and data to whatever parts of the flash they want. For example, a default linker script from a manufacturer will normally put the interrupt vectors at the start of flash (or RAM, if running out of RAM).

Related Topic