At the end of 2020, I suddenly became interested in TinyML and bought a Nano 33 BLE Sense as recommended in the book.

Recently joined the Chinese community of Rust, see the teacher zhang’s public article number of the Rust ecological research report 2021 | the ocean [last] “mentioned in the embedded system TockOS, just have the board, as with Rust in the TockOS to point a light! No sooner said than done.

First, prepare the development environment. My current development environment is on MacOS and requires Python3, Rust, and Tockloader. The Tockloader tool can burn the kernel and applications to the board, and also has features useful for the Tock board, such as easy to manage serial connections, and via JTAG or USB (if the boot loader is installed). It is a Python program that can be installed using the Python Package Management tool (PIP) :

(Linux): pip3 install --upgrade tockloader --user
(MacOS): pip3 install --upgrade tockloader
Copy the code

Since I use USB to connect my computer to the board, I need to install the Bootloader. The Nano 33 comes pre-loaded with the BOSSA Bootloader used on various Arduino boards. Unfortunately, this boot loader is not well suited for Tock development. For Tock development, we need to replace the Bootloader with the Tock Bootloader. Tock Bootloader provides greater flexibility in reading and writing boards and is implemented on top of Tock itself. Now we will show you how to install Tock Bootloader. Our goal is to override Tock Bootloader over BOSSA Bootloader.

  • For the first step we will need the Bossac tool. This tool is required to use the existing boot loader that comes with the development board. This tool can be compiled from source:

    git clone https://github.com/arduino/BOSSA
    cd BOSSA
    make bossac
    Copy the code

    Then you need to add BOSSA/bin to your $PATH variable so that your system can find the bossac program.

  • Next, connect the board to the computer using USB, and then we will use BOSSA Bootloader to load a copy of Tock Bootloader. BOSSA Bootloader expects all application code (that is, not the Bootloader) to start at address 0x10000. That is, when the boot loader completes, it begins execution at address 0x10000.

  • Therefore, we will load a copy of the Tock boot loader to address 0x10000. This also means that we need a compiled version of the boot loader to run at address 0x10000. To load the first Tock Bootloader, make sure Nano 33 is in Bootloader mode by double-clicking the reset button on the board (the indicator light should be blinking) and then executing the following command:

    Bootloaders bossac - e - w/tock - bootloader. Nano33ble. V1.1.0.0 x10000. BinCopy the code
    tockloader
    flash -address 0x10000 /Users/zhanghe/code/tock/target/thumbv7em-none-eabi/release/nano33ble.bin
    Copy the code

    The.bin file above was compiled locally by me. Can clone https://github.com/tock/tock.git warehouse, inside there are compiled under the/boards/nano33ble bootstrap.

  • We can test the success of the previous step using the TockLoader. A simple test is to run:

    tockloader info
    Copy the code

    If you can see something like the following, then the TockLoader can communicate with the boot loader.

    [INFO   ] No device name specified. Using default name "tock".
    [INFO   ] Using "/dev/cu.usbmodem144101 - Nano 33 BLE - TockOS". Tockloader Version: 1.8.0 [STATUS] Showing all properties of the board... [INFO ] Waitingforthe bootloader to start Apps: [INFO ] No found apps. Attributes: 00: board = nano33ble 01: arch = cortex-m4 02: Appaddr = 0x50000 03:04:05:06:07:08:09:10:11:12:13:14:15: Bootloader version: 1.1.0 [INFO] Finishedin 1.893 seconds
    Copy the code

    At this point, the installation of the boot loader is almost complete.

Next, you can install the application using the TockLoader:

tockloader install blink
Copy the code

Select the application that installs the online warehouse TAB. In the next article, we’ll write our own lightening program using the libtock-RS library.