1
\$\begingroup\$

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).

\$\endgroup\$
1
  • \$\begingroup\$ Someone said that the C8 is a version the CB (which has 128 kB of flash) but upper 64 kB have failed the quality, reliability test. You can force the C8 to "128 kB mode" if you want but use at your own risk. \$\endgroup\$ – Long Pham Aug 7 '18 at 4:10
3
\$\begingroup\$

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).

\$\endgroup\$
3
  • \$\begingroup\$ Thanks, Eclipse will take care of the linker scripts I assume. And probably I get a warning (already confirmed by another answer too). \$\endgroup\$ – Michel Keijzers Aug 7 '18 at 8:48
  • 1
    \$\begingroup\$ The linker script is really part of the SDK, but it sounds like you've already got that installed, so you should be okay. \$\endgroup\$ – Adam Haun Aug 7 '18 at 14:49
  • 1
    \$\begingroup\$ Yes I guess so. it was probably installed with the Eclipse 'package' SW4STM32. At least, I can compile/upload/debug. \$\endgroup\$ – Michel Keijzers Aug 7 '18 at 14:51
2
\$\begingroup\$

The datasheet is describing a family of parts, not just one. Note that the first page lists the part names as:

STM32F103x8
STM32F103xB

The STM32F103C8T6 is a specific variant with a 48-pin LQFP package and 64 KB of flash, rated for an industrial temperature range. An example of another part covered by this datasheet might be the STM32F103VBH6, which has a 100-pin BGA package and 128 KB of flash.

Refer to page 108 of the datasheet ("Ordering information scheme") for more information on how to decode the part numbers.


Now, a practical note: many parts marked as "STM32F103C8T6" actually have 128 KB of flash available. (They are, in effect, …CBT6 parts remarked as …C8T6 for inventory reasons.) You shouldn't rely on the availability of this extra flash for a product, but it's a convenient bonus for development. :)

\$\endgroup\$
4
  • \$\begingroup\$ I don't see how this answers the question at all. \$\endgroup\$ – Jashaszun Aug 7 '18 at 0:17
  • \$\begingroup\$ @Jashaszun As I read it, the OP is confused by the language "64 or 128 KB" in the datasheet. \$\endgroup\$ – duskwuff -inactive- Aug 7 '18 at 0:19
  • 1
    \$\begingroup\$ They said that they know theirs has 64KB. They're just wondering how much of that 64KB they can use. \$\endgroup\$ – Jashaszun Aug 7 '18 at 0:24
  • \$\begingroup\$ @duskwuff I meant indeed how much of the 64 KB I can use, but opvoted for the last remark. \$\endgroup\$ – Michel Keijzers Aug 7 '18 at 8:46
2
\$\begingroup\$

That datasheet is for both STM32F103x8 and STM32F103xB.

You can see in "Table 63. Ordering information scheme" on page 108, that STM32F103x8 has 64 Kbytes flash, and STM32F103xB has 128 Kbytes flash.

The 'x' in the part number identifies the package.

So the STM32F103C8T6 is STM32F103 plus:

  • C = 48 pins
  • 8 = 64 Kbytes flash
  • T = LQFP package
  • 6 = Industrial temperature range, –40 to 85 °C

So yours has only 64 Kbytes, but you can use all of that. It is not a part with 128 Kbytes flash.

However, there are stories (eg. at stm32duino.com) of STMicro sometimes shipping parts with 128 Kbytes flash but with STM32F103x8 part number printed on the package, so you might be lucky.

\$\endgroup\$
2
\$\begingroup\$

is there a way to find out when it will not 'fit' ?

The IDE or compiler may show you memory (flash or RAM) overflow warning. I have tested with my F3 board.There was once I declared an big array for testing purpose, when I built the source, Eclipse threw me a RAM overflow error.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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