Home

Awesome

Example micro:bit V2 project for Mbed OS

Table of contents

Features

This is a basic Mbed OS project for micro:bit V2.

Requirements

Building This Project

Available Targets

This project contains multiple Mbed OS "targets" for different versions of the micro:bit V2 board and for the Nordic nRF52833 DK development board.

Other targets are available for micro:bit V2 prototype boards, and their names can be found in the mbed_app.json file. These are essentially the same as the nrf52_microbit_v2 target, but for code to support multiple boards it is useful to have different target names to be able to do conditional compilation of pins, I2C addresses, etc, as shown in the sensors.cpp example code.

Even older prototype targets can be found in the mbedos-softdevice branch.

The version of the micro:bit V2 board can be seen on the silkscreen at the back, near the right side of the edge connector.

Interface MCU

The micro:bit V2.2 contains an nRF52 microcontroller as the Interface MCU and Mbed OS targets has been created to be able to create Mbed OS project for these microcontrollers as well.

Initialise the Project

Note that for the mbed target ... line you should select the right target for your board.

git clone https://github.com/microbit-foundation/mbedos-microbit-v2-starter.git
cd mbedos-microbit-v2-starter
mbed config root .
mbed target nrf52_microbit_v2
mbed toolchain GCC_ARM
mbed deploy

If it fails to install some of the Python dependencies on the last command (mbed deploy) you can try to install them manually.

Run this command in the Python environment that has mbed-cli installed:

pip install -r mbed-os/requirements.txt

Warning: Do not use mbed new . as it can update MbedOS to the latest version, and this is often unwanted.

Build

mbed compile

Or if you want to manually add the flags previously configured in the project on the "Initialise" section:

mbed compile -m nrf52_microbit_v2 -t GCC_ARM

Build output can be found in: ./BUILD/NRF52_MICROBIT_V2/GCC_ARM/mbedos-microbit-v2-starter.hex

If mbed cannot find the tools directory in mbed-os, then you may have to delete the mbed cache by removing ~/.mbed/.

Mbed OS Version

This repo is currently configured Mbed OS to version 6.13.0.

The branch mbedos-softdevice (commit 9e185e9388cdd634ac4cc38f92a0bbf73af9c5b3) is configured to v5.12.4, as this is the last Mbed OS version to support the Nordic Soft Device BLE stack before it was switched to the Cordio BLE stack.

Mbed OS RTOS

This section needs to be updated to work with the Mbed OS v6 bare metal profile.

mbed_app.json:

{
    "requires": [
        "bare-metal",
        "drivers-usb",
        "events"
    ],
    "target_overrides": {
        "*": {
            "target.c_lib": "small"
        }
    }
}

Using NFC

The Mbed board target created for the micro:bit configures the NFC pins as GPIO as they are exposed via the Edge Connector to be used as normal GPIOs.

To change this and use them for NFC you can perform the following changes:

License

All files specific to this project are Apache License Version 2.0. Please see the LICENSE file.

Some files originated from the Mbed OS project, their copyright and license has been preserved in each file header.

Code of Conduct

Trust, partnership, simplicity and passion are our core values we live and breathe in our daily work life and within our projects. Our open-source projects are no exception. We have an active community which spans the globe and we welcome and encourage participation and contributions to our projects by everyone. We work to foster a positive, open, inclusive and supportive environment and trust that our community respects the micro:bit code of conduct.

Please see our code of conduct which outlines our expectations for all those that participate in our community and details on how to report any concerns and what would happen should breaches occur.