If you were building from scratch before 2021-12-15 then follow the Upgrade Instructions.
If you need instructions on how to debug on ESP32 or STM32 on device using JTAG then follow the On Device Debugging Instructions
We use the Micropython USER_C_MODULES extension mechanism for building a firmware with the microlite module and ulab included.
The tensorflow lite micro code is generated using the tensorflow/tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py python script.
Depending on the port it works in conjunction with the ./tensorflow/lite/micro/tools/make/Makefile to generate the source files for the tensorflow lite micro project suitable for inclusion in downstream projects.
Some ports like stm32 and rp2 have custom kernels that are provided in place of the reference kernels.
There is a per port script within the micropython-modules/microlite directory that will invoke this script with the correct options.
Running the applicable script will create a tflm subdirectory within micropython-modules/microlite and it is under this where all of the tensorflow c++ files are located.
Instructions for building ESP32S3 on MAC OS.
Remember to have built mpy-cross before building the board itself.
pip3 install Pillow pip3 install Wave
The esp-idf is provisioned through the micropython/tools/ci.sh script. We tie into the same tooling used by micropython to build esp32.
If you have the idf installed somewhere else you can use that instead. The shells running the build steps just need to have been configured by esp-idf/export.sh prior to running commands.
git submodule init
git submodule update --recursive
cd micropython
git submodule update --init lib/axtls
git submodule update --init lib/berkeley-db-1.xx
cd ..
echo "Regenerating microlite/tfm directory"
rm -rf ./micropython-modules/microlite/tflm
cd ./tensorflow
../micropython-modules/microlite/prepare-tflm-esp.sh
source ./esp-idf/export.sh
cd ./micropython
echo "make -C mpy-cross V=1 clean all"
make -C mpy-cross V=1 clean all
We should be able to support all micropython boards for the esp32 port. However, at the moment we have our own directory boards/esp32 which a further subdirectory for the boards we build.
Issues are welcome to request that we support new boards.
I'm considering implementing the building logic ontop of micropython's auto build logic which would allow a microlite build for all boards supported by the ports supported.
$ source ./esp-idf/export.sh
$ cd boards/esp32/MICROLITE
$ rm -rf build
$ idf.py build
After the successful build the build directory will contain:
- bootloader/bootloader.bin
- partition_table/partition-table.bin
- micropython.bin
These can then be flashed onto your board.
For CI we use the micropython/tools/ci.sh script to install the arm gcc toolchain. You probably want to have it installed somewhere permanently and have it available so that it will be used by the build steps below.
pip3 install Pillow pip3 install Wave
git submodule init
git submodule update --recursive
cd micropython
git submodule update --init lib/pico-sdk lib/tinyusb
cd ..
echo "Regenerating microlite/tfm directory"
rm -rf ./micropython-modules/microlite/tflm
cd ./tensorflow
../micropython-modules/microlite/prepare-tflm-rp2.sh
cd ./micropython
echo "make -C mpy-cross V=1 clean all"
make -C mpy-cross V=1 clean all
RP2 doesn't have the same external build configuration like esp32 and stm32 have so I have it implemented for all of the boards defined by micropython for rp2.
cd micropython
cmake -S ports/rp2 -B build-PICO -DPICO_BUILD_DOCS=0 -DMICROPY_BOARD=PICO \
-DUSER_C_MODULES=/home/runner/work/tensorflow-micropython-examples/tensorflow-micropython-examples/micropython-modules/micropython.cmake
cd build-PICO
make
The path needs to be absolute so you would change /home/runner/work/tensorflow-micropython-examples to be the prefix on your system where the project was cloned to.
The firmware files are located within micropython/build-PICO. The firmware.uf2 can be used to flash the board.
For CI we use the micropython/tools/ci.sh script to install the arm gcc toolchain. You probably want to have it installed somewhere permanently and have it available so that it will be used by the build steps below.
pip3 install Pillow pip3 install Wave
git submodule init
git submodule update --recursive
cd micropython
git submodule update --init lib/mynewt-nimble
cd ..
echo "Regenerating microlite/tfm directory"
rm -rf ./micropython-modules/microlite/tflm
cd ./tensorflow
../micropython-modules/microlite/prepare-tflm-stm32.sh
cd ./micropython
echo "make -C mpy-cross V=1 clean all"
make -C mpy-cross V=1 clean all
RP2 doesn't have the same external build configuration like esp32 and stm32 have so I have it implemented for all of the boards defined by micropython for rp2.
cd micropython-modules
ln -s ../micropython-ulab/code ulab
cd ..
echo "cd ./boards/stm32/NUCLEO_H743ZI2_MICROLITE"
cd ./boards/stm32/NUCLEO_H743ZI2_MICROLITE
echo "Building NUCLEO_H743ZI2_MICROLITE"
rm -rf build
make V=1
You can then flash the firmware with build/micropython.elf using the stm32cubeprogrammer.
The documentation here is mostly up to date but the latest is what is currently working for the github actions.