PlatformIO MBED Framework - feature libs not working

Hi all,

I’m new on this forum and in Visual Studio Code - PlatformIO.
I’m trying to build a project for my Nucleo devices (F446RE, F767ZI) and using MBED framework. But the this framework have additional libs which are found here:
.platformio\packages\framework-mbed\features\frameworks

One example of this libs is mbed-trace and mbed-client-cli.
First test I’ve tried the mbed-trace, but it was impossible to make it compile. After few hours of troubleshooting I’ve success to make PlatformIO to include the directory and try to compile it, but it fails.

This is my platformio.ini file:

[env]
framework = mbed
build_flags = 
lib_deps = 
extra_scripts = 
lib_extra_dirs = $PROJECT_CORE_DIR/packages/framework-mbed/features/frameworks
build_type = debug
lib_ldf_mode = deep+
lib_compat_mode = soft

[env:nucleo_f767zi]
platform = ststm32
board = nucleo_f767zi
upload_port = /dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_066EFF485151717867222456-if02
upload_protocol = stlink

[env:nucleo_f446re]
platform = ststm32
board = nucleo_f446re
upload_protocol = stlink
upload_port = COM3

And main.cpp:

#include "mbed.h"
#define TRACE_GROUP                 "main"
#include "mbed-trace/mbed_trace.h"
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO

The error of the compilation is:

Compiling .pio\build\nucleo_f446re\lib0ed\mbed-trace\mbed_trace.o
C:\Users\Adrian\.platformio\packages\framework-mbed\features\frameworks\mbed-trace\source\mbed_trace.c:19:9: note: #pragma message: MBED_TRACE_MAX_LEVEL is defined as
 #pragma message "MBED_TRACE_MAX_LEVEL is defined as " XSTR(MBED_TRACE_MAX_LEVEL)
         ^~~~~~~
In file included from C:\Users\Adrian\.platformio\packages\framework-mbed\features\frameworks\mbed-trace\source\mbed_trace.c:37:0:
C:\Users\Adrian\.platformio\packages\framework-mbed\features\frameworks\mbed-trace/mbed-trace/mbed_trace.h:122:26: error: operator '>=' has no left operand
 #if MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_DEBUG

But when PlatformIO is starting to compile is creating a directory under the project named .pio\build\nucleo_f446re where I found this file: mbed_config.h . In this file I’ve found this:

// PlatformIO Library Dependency Finder (LDF)
#define MBED_CONF_MBED_TRACE_ENABLE
#define MBED_TRACE_MAX_LEVEL
#define MBED_CONF_MBED_TRACE_FEA_IPV6
#define MEM_ALLOC malloc
#define MEM_FREE free

Which is breaking the compilation. I’ve tried with lib_ldf_mode = off, lib_ldf_mode = chain+, lib_compat_mode = off. Nothing.

Could you please advice me how can I use those libs under MBED without installing them from repositories? Because those from repositories most of the time are not updated, from what I’ve noticed.

Thank you!

Framework-internal forlders should be included automatically and that should not be necessary.

You should try the other route: No special platformio.ini configuration for that but use the mbed_app.json file. See docs and the mbed-trace libray for enabling it. For example this project uses an mbed_app.json (and disables mbed-trace)

Hi maxgerhardt.

In the end the issue was from the building options. I’ve reread few times the PlatformIO documentation and I’ve ended here:
https://docs.platformio.org/en/latest/frameworks/mbed.html?highlight=mbed#id10

PIO_FRAMEWORK_MBED_RTOS_PRESENT → Build the project with enabled rtos

Without this option is impossible to compile MBED OS with the additional features. Enabling this and remove the lib_extra_dirs option, the compiler was able to compile everything!

Hope it will help others with the same issue.

Kind regards,
Adrian