Arm Mbed and Pelion Device Management support forum

Mbed 5 + stm32f103c8t6 64kb very greedy of flash memory

Hello, I’m using mbed os 5 with platformio ide to program a stm32f103c8t6 with 64kb of flash memory (the same on bluepill board). If I compile by default take over 30k of flash (about 50.3%). Is it possible to use a lightweight version of framework? (I checked and I use -Os to comile the code).
Thanks in advance.

Hello Niccolò,

Yes, it is possible to use a lightweight version of framework called Mbed OS bare metal profile.

I have published some examples which could help you get started:

Bare metal on Bluepill

EDIT: After some modifications to the mbed_app.json the Bare metal with EventQueue on Bluepill seems to work. So here is the link again:

Bare metal with EventQueue on Bluepill

To further reduce the amount of used Flash memory the examples above feature the newlib-nano library (for instance printf does not work for float types). If you’d like to use the default one remove

            "target.c_lib"    : "small"

from the mbed_app.json project config file.

WARNING: The examples above are not intended to be compiled with the online compiler. Please have a look at Bluepill board support for Mbed OS 6 how to compile them offline with mbed-cli.

Best regards, Zoltan

Hello!
Thank you very much for your exhaustive reply!
Is it possible to integrate Mbed bare metal in platformio? Thanks very much!

I’m sorry Niccolò, I don’t have any experience with platformio. Perhaps someone else can hep you with that.

Best regards, Zoltan

Hi there,
that is probably a question for PlatformIO web but accoridng to PlatformIO documentation, it looks same, as Zoltan described.

However, it seems like the PlatformIO use bare metal in default.

PlatformIO allows compiling projects with or without Mbed OS. By default, project is built without the OS feature.

BR, Jan

Thank you all very much!
Yes I’m reading the documentation provided by @hudakz and one on platformio and it seems to be possible!
Best regards,
Niccolò

Hello,

After some modifications to the mbed_app.json the Bare metal with EventQueue on Bluepill seems to work too.

With the newlib-nano library the binary is smaller but printf does not work for float.
Below is a function I usually use instead. It has a smaller footprint and it rounds the result as needed:

void printf(float val, int fraDigs = 1, bool newline = false)
{
    char    sign = val < 0 ? '-' : '\0';
    val = val < 0 ? -val : val;
    int mult = 1;
    for (int i = 0; i < fraDigs; i++)
        mult *= 10;
    float   flt = val * mult;
    int     intPart = rintf(flt) / mult;
    int     d = val;
    mult = 1;
    for (int i = 0; i < fraDigs; i++)
        mult *= 10;
    flt = val * mult - d * mult;
    int fraPart = rintf(flt);
    if (fraDigs == 0)
        printf("%c%d", sign, intPart);
    else
        printf("%c%d.%01d", sign, intPart, fraPart);
    if (newline)
        printf("\r\n");
}

Best regards, Zoltan