PlatformIO Community

Mbed for STM32 compiles toooooo long

Hello every one!

A very simple code (like ‘Hello world’) compiles three times longer for mbed framework with STM32 than the same code for the same board but with help of Arduino. If I include build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT then compilation of ‘Hello world’ with mbed takes more than 2 minutes at brand new Ryzen 7.

I think that there should be a way how to reduce the total amount of drivers and libs that are included into the compilation but can’t find the description for this (I guess that it was at Docs, but can’t find it now).

So, the problem is that everything is compiling and I don’t know how to reduce of this amount.

Is it just the first compile? (don’t make any changes to platformio.ini in between as that will trigger a full rebuild).

Clean compile takes around 2.5 minutes for “Hello World” with RTOS feature enabled.

Repeat build takes 40 seconds (and that is too much):

Processing nucleo_f103rb (platform: ststm32; board: nucleo_f103rb; framework: mbed)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f103rb.html
PLATFORM: ST STM32 5.6.0 > ST Nucleo F103RB
HARDWARE: STM32F103RBT6 72MHz, 20KB RAM, 128KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51304.190826 (5.13.4)
Collecting mbed sources…
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies…
No dependencies
Checking size .pio\build\nucleo_f103rb\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA: [===== ] 49.3% (used 10088 bytes from 20480 bytes)
PROGRAM: [===== ] 48.2% (used 63168 bytes from 131072 bytes)
[SUCCESS] Took 40.00 seconds

platformio.ini is also clean and clear:

[platformio]
default_envs = nucleo_f103rb
;[env:genericSTM32F103RB]
;platform = ststm32
;board = genericSTM32F103RB
;framework = mbed
;build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT

[env:nucleo_f103rb]
platform=ststm32
board=nucleo_f103rb
framework=mbed
build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT
monitor_speed = 115200
monitor_port = 10

The situation repeats at 3 computers with the same code.

I did some investigations.

The problem appears when I use PIO_FRAMEWORK_MBED_RTOS_PRESENT macros for the compiler. Than it includes a lot of not used stuff into cpp_properties.json like:
“C:/Users/Vladislav/.platformio/packages/framework-mbed/components/802.15.4_RF/atmel-rf-driver”,
“C:/Users/Vladislav/.platformio/packages/framework-mbed/features/cellular/framework/targets/TELIT/HE910”,
“C:/Users/Vladislav/.platformio/packages/framework-mbed/features/lwipstack/lwip”,

and following. So it compiles everything that is in the framework even if I don’t have this feature.

1 Like

It is possible to restrict mbed compilation features with help of usage of .mbedignore file.

According to this manual https://github.com/bravegnu/Handbook/blob/master/docs/advanced/mbedignore.md this file can contain infromation about the folders that should be excluded from the compilation process. And this file should be placed at any dir that bmed compiler is looking for sources.

I’ve place .mbedignore into root dir of my project. Then into src, lib, include dir of my project. Nothing helped. The file was ignored.

I searched the mbed framework and they used .mbedignore file broadly. For example, if they need to exclude test-dir or disable some competitive functions.

I’d like to keep .mbedignore together with my project files (due to syncronization purposes). And the question is - how to tell mbed compiler that it shoud use the file from my location?

1 Like

From what you said… since .mbedignore is specific to the mbed build command… I wonder if PlatformIO uses it? This comment suggests it is, and since you want to ignore core stuff, and it seems paths must be relative to the location of the ignore file, it probably needs to go in %userprofile%\.platformio\packages\framework-mbed to catch the stuff you want to ignore. If you want it in your project folder for synchronisation, perhaps make an extra_script that syncs the file? i.e. deletes it if it exists, and copies a new one into place?

Suggestion to put .mbedignore into every not required library core at Framework directory is ridiculous. I can fine tune a set of ‘features’ for one project and in a case when I have other project I need to remove all the files and repeat the work :slight_smile:

Scripting can be solution (with a help of a script place the ignore file into the right dir). But I believe that there should be an easier option. I can’t believe that no one works with mbed and PlatformIO and ignores such behaviour.

1 Like

You, you don’t put it in every folder you don’t need… reread the page you linked earlier, specifically where it says

Each line in the .mbedignore file is a file pattern used for matching files. Each matched file or directory is ignored while building.

i.e. you don’t place it in every library… you add a line for every library you want to ignore.

I don’t use mbed myself, so I don’t know how else you’d do it… but I do agree it isn’t the way I would have through you’d have to do things… I would have expected only the libraries you use to be included… but maybe that is a side effect of enabling the RTOS?

Unfortunately I used different types of putting excluded dir into .mbedignore:
mbed-os/features/net/*
mbed-os/uvisor-mbed-lib/*
mbed-os/frameworks/*
mbed-os/features/mbedtls/*
mbed-os/features/cellular/*
mbed-os/features/nfc/*
mbed-os/features/netsocket/*
features/netsocket/*
features/nfc/*
nfc/*
nfc*
.pio\build\genericSTM32F103RB\FrameworkMbed\features\nfc*
.pio/build/genericSTM32F103RB/FrameworkMbed/features/nfc/*
pio\build\genericSTM32F103RB\FrameworkMbed\features\nfc*
pio/build/genericSTM32F103RB/FrameworkMbed/features/nfc/*
build\genericSTM32F103RB\FrameworkMbed\features\nfc*
build/genericSTM32F103RB/FrameworkMbed/features/nfc/*
features/*
features*
build\genericSTM32F103RB\FrameworkMbed\features*
build/genericSTM32F103RB/FrameworkMbed/features/*

With no results at all. It seems that this file is ignored by the compiler that is used within PlarformIO and its mbed extender. And yes, all these amounts of libs in compilation is a reaction to RTOS enabled.

I’ve installed Mbed Studio (that is also based on VSCode as I can judge) and try to do the same there. It works well. I can disconnect not necessary libs.

But going further. In Mbed Studio I can work with RTOS features without compiling all the libraries and drivers that it has in general. In PIO it is not possible.

PS. I’m personally disappointed with support of STM32 in PIO. Arduino (STM32Duino) doesn’t have any API and description, their site is not operable, forum is not operable etc. Mbed support is very wierd upon to complete unusability.

Probably best to put a feature request / issue on the STM32 platformio platform github, and it should get added… as excessive compiles such as this are major blockers.

The STM32Duino forum not being operable is due to it not being run by STMicroelectronics, but instead coming from the rogerclarkmelbourne/Arduino_STM32, and bandwidth demands exceeding Roger’s hosting providers terms of usage…

Do they have a separate website? I thought they only had the wiki, shared the forum, and had their github repo and issue tracker?

Yes, that may be a good option. But I need to start developing in 1-2 weeks. So my process of selecting of framework and IDE took me almost a month.
STM32Duino (it is used in PlatformIO I’m almost sure that it is not Arduino_STM32) awesome good and there is FreeRTOS implementation for it. But I can’t use not documented code and don’t want to spend my time for reading of platform source code. I need to have a reliable framework that can be used straightforward without any tribal dances around installation, boards creation and so forth.

MBED is supported by the MCU manufacturer and it has documentation at their site + more or less live forum :slight_smile: But it is not usable under PIO due to the compilation issue (at the same time it works very well with Mbed Studio by STM, the studio is based not at VSCode as I wrote before but at some Eclipse branch that looks very similar to VSCode).

STM32Duino is the default, unless you use the board_build.core = maple option, at which point the Arduino_STM32 core is used. But that is beside the point… if Mbed Studio is working for you, excellent! :slight_smile: Please do still open an issue, and explain the problem so it can be resolved in the future.

Well done https://github.com/platformio/platform-ststm32/issues/288

1 Like

It seems that it the expected behaviour… :-\