|
1 | 1 | .. _flashfirmware: |
2 | 2 |
|
3 | | -================= |
4 | | -Flashing Firmware |
5 | | -================= |
| 3 | +=========================== |
| 4 | +Build and flash MicroPython |
| 5 | +=========================== |
6 | 6 |
|
7 | | -Building firmware |
8 | | ------------------ |
9 | | -Use yotta to build. |
| 7 | +micro:bit V1 |
| 8 | +============ |
10 | 9 |
|
11 | | -Use target bbc-microbit-classic-gcc-nosd:: |
| 10 | +This applies to MicroPython for the micro:bit V1, the source of which can be |
| 11 | +found here: `bbcmicrobit/micropython <https://github.com/bbcmicrobit/micropython>`_. |
12 | 12 |
|
13 | | - yotta target bbc-microbit-classic-gcc-nosd |
| 13 | +Dependencies |
| 14 | +------------ |
| 15 | +- `cMake <https://cmake.org/>`_ |
| 16 | +- `Arm gcc <https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads>`_ |
| 17 | +- `git <https://git-scm.com/>`_ |
| 18 | +- `ninja <https://ninja-build.org/>`_ |
| 19 | +- `python <https://www.python.org/downloads/>`_ |
| 20 | +- `srecord <http://srecord.sourceforge.net/>`_ |
| 21 | +- `yotta <http://docs.yottabuild.org//>`_ |
14 | 22 |
|
15 | | -Run yotta update to fetch remote assets:: |
| 23 | +The `yotta |
| 24 | +<http://docs.yottabuild.org//>`_ tool is used to build MicroPython, but before |
| 25 | +that takes place additional files have to be generated by the Makefile in |
| 26 | +preparation for the build, and additional data is added to the hex file after. |
16 | 27 |
|
17 | | - yotta up |
| 28 | +Clone the repository and change directory to it:: |
18 | 29 |
|
19 | | -Start the build with either yotta:: |
| 30 | + $ git clone https://github.com/bbcmicrobit/micropython |
20 | 31 |
|
21 | | - yotta build |
| 32 | + $ cd micropython |
22 | 33 |
|
23 | | -...or use the Makefile:: |
| 34 | +Configure yotta to use the micro:bit target:: |
24 | 35 |
|
25 | | - make all |
| 36 | + yotta target bbc-microbit-classic-gcc-nosd@https://github.com/lancaster-university/yotta-target-bbc-microbit-classic-gcc-nosd |
26 | 37 |
|
27 | | -The result is a microbit-micropython hex file (i.e. ``microbit-micropython.hex``) |
28 | | -found in the build/bbc-microbit-classic-gcc-nosd/source from the root of the |
29 | | -repository. |
| 38 | +Run yotta update to fetch remote assets:: |
30 | 39 |
|
31 | | -The Makefile does some extra preprocessing of the source, which is needed only |
32 | | -if you add new interned strings to ``qstrdefsport.h``. The Makefile also puts |
33 | | -the resulting firmware at build/firmware.hex, and includes some convenience |
34 | | -targets. |
| 40 | + yotta up |
| 41 | + |
| 42 | +Start the build using the makefile:: |
| 43 | + |
| 44 | + make all |
| 45 | + |
| 46 | +The resulting ``firmware.hex`` can be found in the ``build/`` |
| 47 | +directory which can then be copied to the micro:bit. |
35 | 48 |
|
36 | 49 | Preparing firmware and a Python program |
37 | 50 | --------------------------------------- |
38 | 51 |
|
39 | | -A script in the following location, called using the following syntax, should |
40 | | -help:: |
| 52 | +Using ``tools/makecombinedhex.py`` you can combine the MicroPython firmware |
| 53 | +with a Python script and produce a hex file ready for uploading to the |
| 54 | +micro:bit.:: |
41 | 55 |
|
42 | | - tools/makecombinedhex.py <firmware.hex> <script.py> [-o <combined.hex>] |
| 56 | + ./makecombinedhex.py <firmware.hex> <script.py> [-o <combined.hex>] |
43 | 57 |
|
44 | 58 | The script will output to ``stdout`` if no output option (``-o``) is provided. |
45 | 59 |
|
46 | | -Flashing to the micro:bit |
47 | | -------------------------- |
| 60 | +Using ``tools/hexlify.py`` you can turn a Python script into Intel HEX format |
| 61 | +to be concatenated at the end of the MicroPython firmware.hex. A simple header |
| 62 | +is added to the script.:: |
| 63 | + |
| 64 | + ./hexlifyscript.py <script.py> |
| 65 | + |
| 66 | +It also accepts data on standard input. |
| 67 | + |
| 68 | + |
| 69 | +micro:bit V2 |
| 70 | +============ |
48 | 71 |
|
49 | | -The Microbit mounts itself as a mass storage device over USB. When it detects |
50 | | -that a .hex file has been uploaded to the internal mass storage device, it will |
51 | | -flash itself with the bytecode representation, and start running the program. |
| 72 | +This applies to MicroPython for the micro:bit V2, the source of which can be |
| 73 | +found here: `microbit-foundation/micropython-microbit-v2 <https://github.com/microbit-foundation/micropython-microbit-v2>`_. |
52 | 74 |
|
53 | | -This means that uploading a .hex file should result in the Microbit running your |
54 | | -code. |
| 75 | +The repository also contains a history of |
| 76 | +`MicroPython firmware builds <https://github.com/microbit-foundation/micropython-microbit-v2/actions>`_. |
55 | 77 |
|
| 78 | +Dependencies |
| 79 | +------------ |
56 | 80 |
|
| 81 | +- `Arm gcc <https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads>`_ |
| 82 | +- `gcc <http://gcc.gnu.org/install/>`_ |
| 83 | +- `cMake <https://cmake.org/>`_ |
| 84 | +- `git <https://git-scm.com/>`_ |
| 85 | +- `ninja <https://ninja-build.org/>`_ |
| 86 | +- `python <https://www.python.org/downloads/>`_ |
57 | 87 |
|
58 | | -**Installation Scenarios** |
| 88 | +Clone the repository and change directory to it:: |
| 89 | + |
| 90 | + $ git clone https://github.com/microbit-foundation/micropython-microbit-v2 |
| 91 | + $ cd micropython-microbit-v2 |
| 92 | + |
| 93 | +Update the submodules:: |
| 94 | + |
| 95 | + $ git submodule update --init |
| 96 | + |
| 97 | +Then build the MicroPython cross-compiler:: |
| 98 | + |
| 99 | + $ make -C lib/micropython/mpy-cross |
| 100 | + |
| 101 | +After setting up, go to the src/ directory and build:: |
| 102 | + |
| 103 | + $ cd src |
| 104 | + |
| 105 | + $ make |
| 106 | + |
| 107 | +The resulting firmware will be ``MICROBIT.hex`` in the ``src/`` |
| 108 | +directory which can be copied to the micro:bit. |
| 109 | + |
| 110 | + |
| 111 | +Flashing to the micro:bit |
| 112 | +========================= |
59 | 113 |
|
60 | | -* :ref:`Windows <microbit-windows>` |
61 | | -* :ref:`OS X <microbit-osx>` |
62 | | -* :ref:`Linux <microbit-linux>` |
63 | | -* :ref:`Debian and Ubuntu <microbit-debian-ubuntu>` |
64 | | -* :ref:`Red Hat Fedora/CentOS <microbit-redhat>` |
65 | | -* :ref:`Raspberry Pi <microbit-rpi>` |
| 114 | +The micro:bit mounts itself as a USB mass storage device named ``MICROBIT``. |
| 115 | +When it detects that a .hex file has been copied to the USB drive, it will |
| 116 | +flash itself, and start running the program. |
0 commit comments