diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 3e0c257..6168c44 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -20,6 +20,7 @@ jobs: - "examples/picosdk-blink" - "examples/picosdk-pioasm-blink" - "examples/picosdk-pioasm-blink-auto" + - "examples/mbed-ce-hello-world" runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/boards/rpipico.json b/boards/rpipico.json index fd43e88..59fd526 100644 --- a/boards/rpipico.json +++ b/boards/rpipico.json @@ -31,7 +31,8 @@ }, "frameworks": [ "arduino", - "picosdk" + "picosdk", + "mbed-ce" ], "name": "Pico", "upload": { diff --git a/builder/frameworks/mbed-ce.py b/builder/frameworks/mbed-ce.py new file mode 100644 index 0000000..9cfc181 --- /dev/null +++ b/builder/frameworks/mbed-ce.py @@ -0,0 +1,26 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Mbed OS Community Edition +https://mbed-ce.dev/ +""" + +from os.path import join + +from SCons.Script import Import, SConscript + +Import("env") + +SConscript( + join(env.PioPlatform().get_package_dir("framework-mbed-ce"), "tools", "python", "mbed_platformio", "build_mbed_ce.py")) \ No newline at end of file diff --git a/examples/mbed-ce-hello-world/.gitignore b/examples/mbed-ce-hello-world/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/examples/mbed-ce-hello-world/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/examples/mbed-ce-hello-world/mbed_app.json5 b/examples/mbed-ce-hello-world/mbed_app.json5 new file mode 100644 index 0000000..3733bca --- /dev/null +++ b/examples/mbed-ce-hello-world/mbed_app.json5 @@ -0,0 +1,15 @@ + +{ + "target_overrides": { + "*": { + "platform.stdio-baud-rate": 9600, + "platform.stdio-buffered-serial": 1, + + // Uncomment to use mbed-baremetal instead of mbed-os + // "target.application-profile": "bare-metal" + } + }, + "link_libraries": [ + "mbed-storage-sd" + ] +} diff --git a/examples/mbed-ce-hello-world/platformio.ini b/examples/mbed-ce-hello-world/platformio.ini new file mode 100644 index 0000000..13f9de6 --- /dev/null +++ b/examples/mbed-ce-hello-world/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env] +platform = raspberrypi +framework = mbed-ce + +[env:rpipico] +board = rpipico \ No newline at end of file diff --git a/examples/mbed-ce-hello-world/src/main.cpp b/examples/mbed-ce-hello-world/src/main.cpp new file mode 100644 index 0000000..c33f4da --- /dev/null +++ b/examples/mbed-ce-hello-world/src/main.cpp @@ -0,0 +1,14 @@ +#include "mbed.h" + +int main() +{ + while(true) + { + printf("Hello world from Mbed CE!\n"); + ThisThread::sleep_for(1s); + } + + // main() is expected to loop forever. + // If main() actually returns the processor will halt + return 0; +} \ No newline at end of file diff --git a/platform.json b/platform.json index 343511c..83e21d8 100644 --- a/platform.json +++ b/platform.json @@ -27,6 +27,13 @@ "picosdk": { "package": "framework-picosdk", "script": "builder/frameworks/picosdk.py" + }, + "mbed-ce": { + "package": "framework-mbed-ce", + "script": "builder/frameworks/mbed-ce.py", + "description": "Community edition of Mbed OS, an open-source operating system designed for the Internet of Things.", + "homepage": "https://mbed-ce.dev", + "title": "Mbed CE" } }, "packages": { @@ -65,6 +72,12 @@ "owner": "platformio", "version": "https://github.com/maxgerhardt/pico-sdk.git#4315984000afe20ac82c78c597a3c4a591f524b0" }, + "framework-mbed-ce": { + "type": "framework", + "optional": true, + "owner": "mbed-ce-project", + "version": ">=6.99.4" + }, "tool-picotool-rp2040-earlephilhower": { "type": "uploader", "optional": false, @@ -94,6 +107,16 @@ "optional": true, "owner": "earlephilhower", "version": "~5.100300.0" + }, + "tool-ninja": { + "optional": true, + "owner": "platformio", + "version": ">=1.7.0" + }, + "tool-cmake": { + "optional": true, + "owner": "platformio", + "version": ">=3.21.0" } } } diff --git a/platform.py b/platform.py index d21fe97..9230af8 100644 --- a/platform.py +++ b/platform.py @@ -166,6 +166,14 @@ def configure_default_packages(self, variables, targets): sys.stderr.write( "Error! Unknown build.core value '%s'. Don't know which Arduino core package to use." % build_core) sys.exit(-1) + elif "mbed-ce" in frameworks: + # Mbed CE only supports ARM cores and needs CMake and Ninja. + # Note: Currently unable to link via the earlephilhower toolchain as that seems to have retargetable locking + # turned on in Newlib, which Mbed does not currently support. + self.packages["toolchain-rp2040-earlephilhower"]["optional"] = True + self.packages.pop("toolchain-rp2040-earlephilhower", None) + self.packages["tool-cmake"]["optional"] = False + self.packages["tool-ninja"]["optional"] = False else: # this is a pico-sdk or baremetal project. if it's for a rp2350-riscv, we need the RISC-V toolchain. if chip == "rp2350-riscv":