Build and flash MicroPython

micro:bit V1

This applies to MicroPython for the micro:bit V1, the source of which can be found here: bbcmicrobit/micropython.

Dependencies

The yotta tool is used to build MicroPython, but before that takes place additional files have to be generated by the Makefile in preparation for the build, and additional data is added to the hex file after.

Clone the repository and change directory to it:

$ git clone https://github.com/bbcmicrobit/micropython

$ cd micropython

Configure yotta to use the micro:bit target:

yt target bbc-microbit-classic-gcc-nosd@https://github.com/lancaster-university/yotta-target-bbc-microbit-classic-gcc-nosd

Run yotta update to fetch remote assets:

yt up

Start the build using the makefile:

make all

The resulting firmware.hex can be found in the build/ directory which can then be copied to the micro:bit.

Preparing firmware and a Python program

Using tools/makecombinedhex.py you can combine the MicroPython firmware with a Python script and produce a hex file ready for uploading to the micro:bit.:

./makecombinedhex.py <firmware.hex> <script.py> [-o <combined.hex>]
# Output goes to stdout if no filename is given.

Using tools/hexlify.py you can turn a Python script into Intel HEX format to be concatenated at the end of the MicroPython firmware.hex. A simple header is added to the script.:

./hexlifyscript.py <script.py>

It also accepts data on standard input.

micro:bit V2

This applies to MicroPython for the micro:bit V2, the source of which can be found here: microbit-foundation/micropython-microbit-v2.

The repository also contains a history of MicroPython firmware builds.

Dependencies

Clone the repository and change directory to it:

$ git clone https://github.com/microbit-foundation/micropython-microbit-v2
$ cd micropython-microbit-v2

Update the submodules:

$ git submodule update --init

Then build the MicroPython cross-compiler:

$ make -C lib/micropython/mpy-cross

After setting up, go to the src/ directory and build:

$ cd src

$ make

The resulting firmware will be MICROBIT.hex in the src/ directory which can be copied to the micro:bit.