Hi from Mbed CE Project

Hello PlatformIO folks! I am Jamie Smith, a maintainer of Mbed OS Community Edition (Mbed CE for short). Me and the other maintainers are keeping Mbed OS alive after its end of support. We have a forked repo going and are trying to not just maintain the project, but improve it as well. Lots more information is available at our website, but basically this means better documentation, a new build system, better testing, bugfixes, and more supported devices. In particular, we now have official support for popular boards like Arduino Giga/Portenta, RPi Pico, and Teensy 4.0/4.1!

What I’d like to talk about today, though, is the prospect of integrating Mbed CE and PlatformIO. I’ve heard good things about you guys from some of my colleagues, and I would love a way to make Mbed OS easier to use for people who don’t want to install a toolchain and set up an IDE manually. And I know that ARM Mbed 6 is already supported on PlatformIO, so a good chunk of the needed work should already be done. However, Mbed CE replaced ARM Mbed 6’s strange homegrown Python build system with a more conventional CMake-based one. So, making Mbed CE work with PlatformIO might be a little bit tougher.

After reading through the PlatformIO documentation, I have a few questions that I’d love to get an answer to in order to see how we can proceed.

  1. What would be the recommended way to integrate the Mbed CE and PlatformIO build systems? Is there a way to make SCons call CMake? Or would it make more sense to prebuild Mbed OS as a static library and then distribute that?
    • I already wrote a script as part of a prototype Arduino core that dumps all of the include directories and compile flags from CMake, so a lot of this architecture could be reused if we go with the latter approach
  2. To make an Mbed CE platform available on PlatformIO, I believe I would need to pay $10/month for a Pro plan. Is that correct? Given that I’m an individual and not directly making money off of Mbed CE (though the project could one day accept donations), is there any risk of me needing an Enterprise plan?
  3. Would anyone from the PlatformIO side (either from the company or from the community) be able to assist me with this? Unless Mbed CE is integrated into PlatformIO, there will be no further updates or patches for Mbed OS ever, so fingers crossed that there is some interest!
1 Like

I suspect this is FAO @ivankravets .

The builder script for ESP-IDF is the only example of an SCons builder script interacting with CMake in PlatformIO that I know of.

ESP-IDF is also, next to mbed-os, the heaviest and slowest framework to compile. Most of the time, the build system logic is replicated in SCons or an adapter is written (as was with mbed-os 5 and 6 at https://github.com/platformio/builder-framework-mbed) to adapt their build system to SCons.

I have published multiple new platforms or modified platforms (platform-gd32, platform-ch32v, platform-raspberrypi) and did not need any paid PlatformIO support at all. Creating the platform is free, the core can freely install third-party platforms, and pushing packages (such as framework code, toolchains, upload tools, …) into the PIO registry is free.

1 Like

Hi @multiplemonomials, great job taking on this project! Maintaining something this large is definitely not easy. @maxgerhardt already gave a solid answer with great examples, but here’s a bit more info:

What would be the recommended way to integrate the Mbed CE and PlatformIO build systems? Is there a way to make SCons call CMake? Or would it make more sense to prebuild Mbed OS as a static library and then distribute that?

If your new build system is based on CMake then a wrapper is required. ESP-IDF and Zephyr are examples of such integrations. That wrapper basically runs CMake once to extract build info then replicates the build environment using SCons’ capabilities.

To make an Mbed CE platform available on PlatformIO, I believe I would need to pay $10/month for a Pro plan.

You don’t need to pay anything. You can just fork the ststm32 development platform, give it a clear name, add your changes, and write instructions so others know how to install it in PlatformIO. That’s it!

Would anyone from the PlatformIO side (either from the company or from the community) be able to assist me with this?

There are already lots of dev-platforms you can look at for reference. And if you run into trouble, feel free to ask for help on the community forum.

1 Like

For completeness: The Zephyr CMake-SCons-PlatformIO integration scripts can also be read at

https://github.com/platformio/zephyr/tree/v4.0-branch/scripts/platformio

to be seen in reference to the zephyr references in https://github.com/platformio/platform-ststm32/blob/develop/builder/main.py.

In comparison to those ~2000 line CMake integration scripts, replicating the build logic of for example the Arduino AVR core just takes 190 lines of very readable code.

1 Like

Hey, I’m back! After some off and on work, I have gotten an MVP-level integration between Mbed CE and PlatformIO working!

Mbed CE PR: github DOT com/mbed-ce/mbed-os/pull/494
platform-freescalekinetis PR: github DOT com/platformio/platform-freescalekinetis/pull/14

(forum does not like me posting links)

With these changes, if you apply the platformio-core change locally to your platformio scripts, then you can build for K64F using Mbed CE:

[env:frdm_k64f]
platform = https://github.com/multiplemonomials/platform-freescalekinetis.git#dev/add-mbed-ce-support
board = frdm_k64f
framework = mbed-ce

; Override mbed-ce package with correct repo
platform_packages =
  framework-mbed-ce @ https://github.com/mbed-ce/mbed-os.git#dev/platformio

PlatformIO core change:

@maxgerhardt I’d love if you could check this out and let me know if it’s working OK! What would be the next steps to get Mbed CE added as an official platform?

I’ve left some comments for consideration. If you need core changes, those would have to be reviewed and merged ofc by ivankravets.

Usually the step after that would be to pio pkg publish (docs) the framework-mbed-ce package first, wait for approval so that the platform can reference the PIO registry package version, then PR your platform-freescalekinetis back into the upstream platform-freescalekinetis repo (and possible other repos like platform-ststm32, etc.).

OK I did that, and I submitted the package for publishing on Monday. Still haven’t heard anything back yet about it being accepted.

Yay it finally went through! PlatformIO Registry

1 Like

Update: Made a similar PR for platform-ststm32: Add Mbed CE support for STM32 parts by multiplemonomials Ā· Pull Request #863 Ā· platformio/platform-ststm32 Ā· GitHub

Also, I realized that the framework-mbed-ce version I submitted had a dumb mistake which caused it to not work on Linux/Mac (hardcoded a path with backslashes). So I just uploaded version 6.99.2 which fixes this. (We will eventually be doing ā€œrealā€ versions but not yet).

1 Like

@valeros Have you had a chance to look at the PRs I submitted to the platform repositories?

Hi Jamie,

Thanks a lot for your work on Mbed CE and the PRs. Could we ask you to create an installation guide in the Mbed CE docs and point the platform to:

[env:stm32-mbed-ce]  
platform = https://github.com/multiplemonomials/platform-ststm32.git  

We will track how many users make use of the mbed-ce-project/framework-mbed-ce package. If we see sufficient interest in PlatformIO/Mbed CE, we will review and merge the PRs. Since the PRs affect many files, someone will need to maintain these changes in the long term. Adding extra work without a clear demand doesn’t make sense.

For context, we previously added support for Simba and similar frameworks, and maintaining them over the years has not been easy.

Thanks for your understanding!

OK, sounds good. I created this doc page: Setting Up Mbed CE with PlatformIO - Mbed CE, and I will make a formal announcement to our users once I fix one or two more issues.

By the way, I did want to let you guys know, when I tested Mbed CE on freescalekinetis FRDM-K64F, I found that debugging was broken with the default configuration. Seems like it’s using an old version of PyOCD that has issues, and if I explictly install the latest version, it hits an error like ā€œpyocd-gdbserver: command not foundā€. I think this means that something, somewhere needs to be updated to use the right command for latest pyocd, but not totally sure. Would appreciate if you could take a look!

The tool-pyocd pacakge could definitely use an update, also requested in Update tool-pyocd package.