In PlatformIO, build support for any framework / SDK is achieved by implement a “builder script”, which is a Python script using the underlying PlatformIO and SCons build system APIs to teach PlatformIO/SCons exactly what files to compile, how they’re compiled, and finally linked together and postprocessed.
That builder script is called from the platform (e.g., platform-ststm32, platform-nordicnrf52, …). For the mbed-os 5/6 framework, as is present at https://github.com/platformio/builder-framework-mbed, that’s currently about 800 lines of Python. That is quite a lot, something like the Arduino AVR builder script is only 190 lines. The mbed os build script does quite some work adapting it to PlatformIO, and that is with the help of importing the native mbed-os Python build packages.
Given that mbed 2 is so much older and 3 or 4 major versions behind the curent one, you will likely need a completely new builder script. Realistically, you can only write that if you have both superb knowledge of the PlatformIO / SCons internal (e.g., here) and the build system for mbed-os 2.
At which point one may also say, why do all this work and not directly use mbed-os’s native build system, or do the work and get it “up to date” on mbed os 6.
In any case, the mbed-os project was halted, killed by ARM almost a year ago.
So it’s quite a complex job (was hoping just unzipping the right commit’s sources would do). I know it’s going open source and yes mbed2 is old (but so is the application I build on it).
To my surprise, mbed-os6 in bare metal mode works (at least it’s testable on the device) after some not to big changes to my sources. Some serial port stuff. One major issue was getting *printf(0 functions to handle floats.
in the patformio.ini and it worked. Most fixes I found where for mbed-os’es mbed_app.json file which platformio mostly ignores (at least for the float/printf fixes).
Next up is getting debugging with cmis-dap to work.