BBC micro:bit C++ VS Code Extension
Build C++ programs for the BBC micro:bit with
CODAL, in VS Code
(web and desktop) without any additional compilers or toolchains.
The Clang compiler, LLD and the LLVM binutils have been built to WebAssembly,
and together with Arm Toolchain for Embedded's C and C++ libraries
and a prebuilt CODAL, this extension includes everything internally to compile
micro:bit C++ programmes.
🚧 Preview. It builds one fixed CODAL version in one fixed configuration.
See the limits.
How To Use This Extension
- Open a workspace that holds a
main.cpp
- Alternatively you can run the
BBC micro:bit C++: Create C++ Project
command to create it.
- Open the BBC micro:bit C++ icon in the Activity Bar, and press
Build micro:bit C++ project.
MICROBIT.hex and MICROBIT.map appear beside your sources, and the
compiler's output is in the BBC micro:bit C++ output channel.
- Press Flash C++ project hex to build again and write it to a connected
micro:bit V2, or copy
MICROBIT.hex onto the MICROBIT drive yourself.
- Open serial terminal shows what the program prints.
Every button is also a command, so BBC micro:bit C++: Build C++ Project and
BBC micro:bit C++: Flash C++ Project do the same from the Command Palette, which
opens with Ctrl/Cmd+Shift+P or F1.
The board
Connecting, flashing and the serial terminal are managed by the
BBC micro:bit Manager
extension, which is installed together with this one. It creates a micro:bit
item in the status bar, which lists this extension's commands too.
A build takes every .cpp, .cc and .cxx file under the workspace, and
every header, excluding what's listed in the bbcmicrobit-cpp.build.exclude
setting.
On a desktop computer, you normally have to install arm-none-eabi-gcc, CMake,
Ninja, and Python; then clone microbit-v2-samples, and use the build script.
This extension carries the compiler in
microbit-clang-wasm
and CODAL with its build recipe in
microbit-clang-wasm-codal,
currently using CODAL v0.3.5.
The recipe is captured from CODAL's own CMake build with the Clang toolchain,
so the flags and codal.json are the default ones that build uses.
Limits of this preview
- One CODAL version and one configuration.
codal.json cannot be changed
yet; the configuration is the microbit-v2-samples default, with the
SoftDevice present and the BLE stack off.
- micro:bit V2 only. CODAL builds for the V2's processor, so flashing
refuses a V1 rather than writing an image it cannot run.
- Errors are text in the output channel, not markers in the editor.
- Memory. The compiler needs a bit less than 1 GB of RAM when it compiles,
and keeps about half of that warm, so that later builds start and complete
faster.
On web close/reload the window to free up the memory back, and on desktop
you can close/reopen the window.
Licence
This extension is MIT, see LICENSE. The compiler, its libraries and
CODAL carry their own licences, and every notice ships inside the extension:
see LICENSES.md.