├── .github └── workflows │ ├── build_esp32.yml │ ├── build_esp32c3.yml │ ├── build_esp32s2.yml │ ├── build_esp32s3.yml │ ├── build_rp2.yml │ ├── build_stm32.yml │ └── build_unix.yml ├── .gitignore ├── .gitmodules ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── BUILD.md ├── CONTRIBUTING.md ├── DEBUGGING.md ├── LICENSE ├── MAC_ESP32S3_BUILD.md ├── README.md ├── UPGRADE.md ├── berkeley-db-1.xx.diff ├── boards ├── esp32 │ ├── MICROLITE │ │ ├── CMakeLists.txt │ │ ├── custom-partitions.csv │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ └── sdkconfig.partition │ ├── MICROLITE_C3 │ │ ├── CMakeLists.txt │ │ ├── custom-partitions.csv │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ └── sdkconfig.partition │ ├── MICROLITE_C3_USB │ │ ├── CMakeLists.txt │ │ ├── board.json │ │ ├── custom-partitions.csv │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ └── sdkconfig.partition │ ├── MICROLITE_S2_SPIRAM │ │ ├── CMakeLists.txt │ │ ├── deploy.md │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ └── sdkconfig.board │ ├── MICROLITE_S3 │ │ ├── CMakeLists.txt │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ ├── partitions-8MiB.csv │ │ ├── sdkconfig-8m.partition │ │ └── sdkconfig.board │ ├── MICROLITE_S3_SPIRAM │ │ ├── CMakeLists.txt │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ ├── partitions-8MiB.csv │ │ ├── sdkconfig-8m.partition │ │ └── sdkconfig.board │ ├── MICROLITE_S3_SPIRAM_CS_GPIO_20 │ │ ├── CMakeLists.txt │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ ├── partitions-8MiB.csv │ │ ├── sdkconfig-8m.partition │ │ └── sdkconfig.board │ ├── MICROLITE_S3_SPIRAM_OCTAL │ │ ├── CMakeLists.txt │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ ├── partitions-8MiB.csv │ │ ├── sdkconfig-8m.partition │ │ └── sdkconfig.board │ ├── MICROLITE_SPIRAM │ │ ├── CMakeLists.txt │ │ ├── custom-partitions.csv │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ └── sdkconfig.partition │ ├── MICROLITE_SPIRAM_16M │ │ ├── CMakeLists.txt │ │ ├── custom-partitions-16M.csv │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ ├── sdkconfig-16m.partition │ │ └── sdkconfig.16m │ └── MICROLITE_SPIRAM_CAM │ │ ├── CMakeLists.txt │ │ ├── main │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ ├── mpconfigboard.h │ │ ├── sdkconfig.esp32cam │ │ └── sdkconfig.partition ├── rp2 │ └── ADAFRUIT_FEATHER_RP2040_MICROLITE │ │ ├── CMakeLists.txt │ │ ├── board.json │ │ ├── main │ │ └── CMakeLists.txt │ │ ├── mpconfigboard.cmake │ │ └── mpconfigboard.h ├── stm32 │ ├── NUCLEO_H743ZI2_MICROLITE │ │ ├── Makefile │ │ ├── STM32H743x.svd │ │ ├── board_init.c │ │ ├── mpconfigboard.h │ │ ├── mpconfigboard.mk │ │ ├── openocd.cfg │ │ ├── pins.csv │ │ ├── stm32h7xx_hal_conf.h │ │ └── vs-code-preconfigure.sh │ └── SPARKFUN_THINGPLUS_MICROLITE │ │ ├── Makefile │ │ ├── bdev.c │ │ ├── board.json │ │ ├── board_init.c │ │ ├── mpconfigboard.h │ │ ├── mpconfigboard.mk │ │ ├── pins.csv │ │ └── stm32f4xx_hal_conf.h └── unix │ └── microlite-variant │ ├── mpconfigvariant.h │ └── mpconfigvariant.mk ├── build-tensorflow-lite-micro.sh ├── build-with-docker-idf.sh ├── build-with-unix-docker.sh ├── ci ├── build_micropython_esp32_microlite_spiram_16m.sh ├── build_micropython_stm32_microlite.sh ├── build_tensorflow_cortex_m_generic.sh └── setup_esp32.sh ├── custom-partitions.csv ├── docker ├── arm-build │ ├── Dockerfile │ └── build.sh ├── esp32-build │ └── README.md └── unix-build │ └── Dockerfile ├── examples ├── hello-world │ ├── README.md │ ├── hello_world.py │ ├── images │ │ └── model_architecture.png │ └── model.tflite ├── micro-speech │ ├── README.md │ ├── data │ │ ├── no-16khz-2sec.wav │ │ ├── no-8khz-2sec.wav │ │ ├── one_two_three-16khz-2sec.wav │ │ ├── one_two_three-8khz-2sec.wav │ │ ├── yes-16khz-2sec.wav │ │ └── yes-8khz-2sec.wav │ ├── esp32 │ │ ├── README.md │ │ ├── i2s_dump.py │ │ ├── main.py │ │ └── micro_speech.py │ ├── images │ │ └── model_architecture.png │ ├── lib │ │ ├── debug-spectrograms.py │ │ ├── mic_left_channel_16bits.wav │ │ ├── micro_speech.py │ │ ├── model.tflite │ │ ├── no-example.wav │ │ ├── test_micro_speech.py │ │ └── yes-example.wav │ ├── rp2 │ │ ├── README.md │ │ ├── images │ │ │ ├── feather-rp2040-pinout.png │ │ │ ├── rp2-micro-speech-board-setup.png │ │ │ └── rp2-running.png │ │ ├── main.py │ │ └── micro_speech.py │ └── unix │ │ ├── main.py │ │ ├── micro_speech.py │ │ ├── model.tflite │ │ ├── no_1000ms_sample_data.py │ │ └── yes_1000ms_sample_data.py └── person_detection │ ├── README.md │ ├── esp32-cam │ ├── imageTools │ │ ├── getImage.sh │ │ ├── readImage.py │ │ └── showGrayScaleImg.py │ └── person_detection_cam.py │ ├── images │ ├── model_architecture.png │ ├── model_properties.png │ ├── not_a_person.png │ └── person.png │ ├── no_person_image_data.dat │ ├── person_detect_model.tflite │ ├── person_detection.py │ ├── person_image_data.dat │ └── show-test-images.py ├── images ├── download-esp32-artifact.png ├── esp32-micro-speech-board-setup.png ├── esp32-micro-speech-inmp441-setup.png ├── esp32-to-esp-prog-pins.png ├── hello-world-output-chart.png ├── person-detection-esp32-running.png ├── recommended stm32 boards.png ├── rp2-hello-world.png ├── tensorflow-micropython-examples.png └── write-firmware.png ├── lib └── README.md ├── micropython-modules ├── audio_frontend │ ├── .gitignore │ ├── micropython.cmake │ ├── micropython.not-mk │ └── refresh-tensorflow-microfrontend.sh ├── microlite │ ├── assemble-unified-image-esp.sh │ ├── audio_frontend.c │ ├── bare-metal-gc-heap.c │ ├── micropython-error-reporter.cpp │ ├── micropython-error-reporter.h │ ├── micropython.cmake │ ├── micropython.mk │ ├── micropython_esp.cmake │ ├── mpy_heap_malloc.c │ ├── mpy_heap_new_delete.cpp │ ├── openmv-libtf-updated.cpp │ ├── openmv-libtf.cpp │ ├── openmv-libtf.h │ ├── prepare-tflm-esp.sh │ ├── prepare-tflm-rp2.sh │ ├── prepare-tflm-stm32.sh │ ├── prepare-tflm-unix.sh │ ├── python_ops_resolver.cc │ ├── python_ops_resolver.h │ ├── stm32lib │ │ ├── abs.c │ │ ├── bsearch.c │ │ ├── ctype_.c │ │ ├── ctype_.h │ │ ├── strtoll.c │ │ └── strtoull.c │ ├── tensorflow-microlite.c │ ├── tensorflow-microlite.h │ ├── xalloc.c │ └── xalloc.h ├── micropython-camera-driver │ ├── micropython.cmake │ ├── modcamera.c │ └── modcamera.h └── micropython.cmake ├── src └── micro-speech │ ├── i2s_read.py │ ├── i2s_save.py │ └── main.py └── update-microlite.sh /.github/workflows/build_esp32s2.yml: -------------------------------------------------------------------------------- 1 | 2 | name: ESP32 S2 3 | 4 | # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule 5 | on: 6 | push: 7 | pull_request: 8 | paths-ignore: 9 | - 'examples/**' 10 | - 'README.md' 11 | - 'ci/*unix*.sh' 12 | - '.github/workflows/build_unix.yml' 13 | 14 | jobs: 15 | tensorflow_micropython_esp32_s2_build: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v2 21 | - name: Prepare to Build Tensorflow Micropython Firmware for ESP32 22 | run: | 23 | git submodule init 24 | git submodule update --recursive 25 | cd micropython 26 | git submodule update --init lib/axtls 27 | git submodule update --init lib/berkeley-db-1.xx 28 | cd ports/esp32 29 | make BOARD= submodules 30 | cd ../../.. 31 | cd tflm_esp_kernels 32 | git submodule update --init components/esp32-camera 33 | git submodule update --init components/esp-nn 34 | - name: Get Cache Keys 35 | # later get this like this: git ls-remote --heads https://github.com/espressif/esp-idf 36 | # this commit is hard-coded in micropython/tools/ci.sh 37 | run: | 38 | IDF_COMMIT=5bb59b00e72f8f91eb24d8c65bf9a7ea2b8a4f5f 39 | echo "esp-idf-commit=$IDF_COMMIT" >> $GITHUB_ENV 40 | TFLM_COMMIT=$(git submodule status tensorflow | awk '{print ($1)}') 41 | echo "tflm-commit=$TFLM_COMMIT" >> $GITHUB_ENV 42 | # - name: Cache esp-idf 43 | # id: cache-esp-idf 44 | # uses: actions/cache@v2 45 | # env: 46 | # cache-name: cache-esp-idf 47 | # with: 48 | # path: ./esp-idf 49 | # key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.esp-idf-commit }} 50 | - name: Setup IDF 51 | # if: steps.cache-esp-idf.outputs.cache-hit != 'true' 52 | run: | 53 | source ./micropython/tools/ci.sh && ci_esp32_idf44_setup 54 | - name: Cache tflm 55 | id: cache-tflm 56 | uses: actions/cache@v2 57 | env: 58 | cache-name: cache-tflm 59 | with: 60 | path: ./micropython-modules/microlite/tflm 61 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.tflm-commit }} 62 | - name: Setup Build for Tensorflow 63 | if: steps.cache-tflm.outputs.cache-hit != 'true' 64 | run: | 65 | 66 | source ./esp-idf/export.sh 67 | 68 | pip3 install Pillow 69 | pip3 install Wave 70 | 71 | echo "Regenerating microlite/tfm directory" 72 | rm -rf ./micropython-modules/microlite/tflm 73 | 74 | cd ./tensorflow 75 | 76 | ../micropython-modules/microlite/prepare-tflm-esp.sh 77 | 78 | - name: Build micropython cross compiler 79 | run: | 80 | source ./esp-idf/export.sh 81 | cd ./micropython 82 | echo "make -C mpy-cross V=1 clean all" 83 | make -C mpy-cross V=1 clean all 84 | 85 | - name: Build ESP32 S2 with SPIRAM 86 | run: | 87 | 88 | source ./esp-idf/export.sh 89 | 90 | echo "cd ./boards/esp32/MICROLITE_S2_SPIRAM" 91 | cd ./boards/esp32/MICROLITE_S2_SPIRAM 92 | 93 | echo "Building ESP32 MICROLITE_S2_SPIRAM" 94 | rm -rf builds 95 | idf.py clean build 96 | 97 | ../../../micropython-modules/microlite/assemble-unified-image-esp.sh \ 98 | ../../../micropython/ports/esp32 99 | 100 | - name: Archive ESP32-MICROLITE_S2_SPIRAM firmware 101 | uses: actions/upload-artifact@v4 102 | with: 103 | name: microlite-esp32s2-spiram-firmware 104 | path: | 105 | boards/esp32/MICROLITE_S2_SPIRAM/build/firmware.bin 106 | 107 | -------------------------------------------------------------------------------- /.github/workflows/build_stm32.yml: -------------------------------------------------------------------------------- 1 | 2 | name: STM32 3 | 4 | # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule 5 | on: 6 | push: 7 | pull_request: 8 | paths-ignore: 9 | - 'examples/**' 10 | - 'README.md' 11 | - 'ci/*unix*.sh' 12 | - '.github/workflows/build_unix.yml' 13 | - '.github/workflows/build_esp32.yml' 14 | - '.github/workflows/build_esp32s3.yml' 15 | - '.github/workflows/build_rp2.yml' 16 | 17 | jobs: 18 | tensorflow_micropython_stm32_build: 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - name: Set up Python 3.8 23 | uses: actions/setup-python@v1 24 | with: 25 | python-version: 3.8 26 | - name: Install Pillow & Wave 27 | run: | 28 | pip install Pillow 29 | pip3 install Wave 30 | - name: Checkout repository 31 | uses: actions/checkout@v2 32 | - name: Prepare to Build Tensorflow Micropython Firmware for STM32 33 | run: | 34 | git submodule init 35 | git submodule update --recursive 36 | cd micropython 37 | git submodule update --init lib/mynewt-nimble 38 | cd .. 39 | - name: Get Cache Keys 40 | run: | 41 | TFLM_COMMIT=$(git submodule status tensorflow | awk '{print ($1)}') 42 | echo "tflm-commit=$TFLM_COMMIT" >> $GITHUB_ENV 43 | - name: Setup GCC ARM 44 | run: | 45 | source ./micropython/tools/ci.sh && ci_gcc_arm_setup 46 | # - name: Cache tflm 47 | # id: cache-tflm 48 | # uses: actions/cache@v2 49 | # env: 50 | # cache-name: cache-stm32-tflm 51 | # with: 52 | # path: ./micropython-modules/microlite/tflm 53 | # key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.tflm-commit }} 54 | - name: Setup Build for Tensorflow 55 | # if: steps.cache-tflm.outputs.cache-hit != 'true' 56 | run: | 57 | 58 | echo "Regenerating microlite/tfm directory" 59 | rm -rf ./micropython-modules/microlite/tflm 60 | 61 | cd ./tensorflow 62 | 63 | ../micropython-modules/microlite/prepare-tflm-stm32.sh 64 | 65 | - name: Build micropython cross compiler 66 | run: | 67 | cd ./micropython 68 | make -C ports/stm32 submodules 69 | echo "make -C mpy-cross V=1 clean all" 70 | make -C mpy-cross V=1 clean all 71 | 72 | cd ../micropython-modules 73 | ln -s ../micropython-ulab/code ulab 74 | cd .. 75 | - name: Build Nucleo H743ZI2 Microlite 76 | run: | 77 | echo "cd ./boards/stm32/NUCLEO_H743ZI2_MICROLITE" 78 | cd ./boards/stm32/NUCLEO_H743ZI2_MICROLITE 79 | 80 | echo "Building NUCLEO_H743ZI2_MICROLITE" 81 | rm -rf build 82 | make V=1 83 | 84 | find build -ls 85 | 86 | - name: Archive NUCLEO_H743ZI2_MICROLITE firmware 87 | uses: actions/upload-artifact@v4 88 | with: 89 | name: microlite-stm32-nucleo-h743zi2-firmware 90 | path: | 91 | boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.elf 92 | boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.dfu 93 | boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.hex 94 | - name: Build SPARKFUN_THINGPLUS_MICROLITE 95 | run: | 96 | echo "cd ./boards/stm32/SPARKFUN_THINGPLUS_MICROLITE" 97 | cd ./boards/stm32/SPARKFUN_THINGPLUS_MICROLITE 98 | 99 | echo "Building SPARKFUN_THINGPLUS_MICROLITE" 100 | rm -rf build 101 | make V=1 102 | 103 | find build -ls 104 | 105 | - name: Archive SPARKFUN_THINGPLUS_MICROLITE firmware 106 | uses: actions/upload-artifact@v4 107 | with: 108 | name: microlite-stm32-sparkfun-thingplus-firmware 109 | path: | 110 | boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/build/firmware.elf 111 | boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/build/firmware.dfu 112 | boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/build/firmware.hex 113 | -------------------------------------------------------------------------------- /.github/workflows/build_unix.yml: -------------------------------------------------------------------------------- 1 | name: UNIX 2 | 3 | # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule 4 | on: 5 | push: 6 | pull_request: 7 | paths-ignore: 8 | - 'examples/**' 9 | - 'README.md' 10 | - 'ci/*esp32*.sh' 11 | - '.github/workflows/build_esp32.yml' 12 | 13 | jobs: 14 | tensorflow_micropython_unix_build: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Set up Python 3.8 19 | uses: actions/setup-python@v1 20 | with: 21 | python-version: 3.8 22 | - name: Install Pillow & Wave 23 | run: | 24 | pip install Pillow 25 | pip3 install Wave 26 | - name: Checkout repository 27 | uses: actions/checkout@v2 28 | - name: Prepare to Build Tensorflow Micropython Firmware for UNIX 29 | run: | 30 | git submodule init 31 | git submodule update --recursive 32 | 33 | - name: Setup Build for Tensorflow 34 | run: | 35 | 36 | echo "Regenerating microlite/tfm directory" 37 | rm -rf ./micropython-modules/microlite/tflm 38 | 39 | cd ./tensorflow 40 | 41 | ../micropython-modules/microlite/prepare-tflm-unix.sh 42 | 43 | - name: Setup micropython modules 44 | run: | 45 | cd ./micropython-modules 46 | ln -s ../micropython-ulab/code ulab 47 | 48 | - name: Build micropython cross compiler 49 | run: | 50 | cd ./micropython 51 | echo "make -C mpy-cross V=1 clean all" 52 | make -C mpy-cross V=1 clean all 53 | - name: Prepare to Build Tensorflow Micropython Firmware for unix 54 | run: | 55 | cd micropython/ports/unix 56 | make submodules 57 | make deplibs 58 | 59 | make VARIANT_DIR=../../../boards/unix/microlite-variant VARIANT=microlite 60 | 61 | - name: Archive Unix MICROLITE micropython interpreter 62 | uses: actions/upload-artifact@v4 63 | with: 64 | name: microlite-unix-micropython 65 | path: | 66 | micropython/ports/unix/micropython 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | build 3 | lib/*.a 4 | micropython-modules/microlite/tflm 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "micropython"] 2 | path = micropython 3 | url = https://github.com/micropython/micropython.git 4 | [submodule "tensorflow"] 5 | path = tensorflow 6 | url = https://github.com/mocleiri/tflite-micro.git 7 | # branch = main 8 | [submodule "micropython-ulab"] 9 | path = micropython-ulab 10 | url = https://github.com/v923z/micropython-ulab.git 11 | # branch = master 12 | [submodule "tflm_esp_kernels"] 13 | path = tflm_esp_kernels 14 | url = https://github.com/espressif/tflite-micro-esp-examples.git 15 | # branch = master 16 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "stm32", 5 | "includePath": [ 6 | "${workspaceFolder}/micropython/**", 7 | "${workspaceFolder}/micropython-modules/**", 8 | "${workspaceFolder}/boards/**" 9 | ], 10 | "defines": [ 11 | "TF_LITE_STATIC_MEMORY=1", 12 | "FFCONF_H=\"lib/oofatfs/ffconf.h\"", 13 | "MICROPY_VFS_FAT=1", 14 | "MICROPY_PY_USSL=1", 15 | "MICROPY_SSL_MBEDTLS=1", 16 | "MICROPY_PY_LWIP=1", 17 | "MBEDTLS_CONFIG_FILE='\"mbedtls/mbedtls_config.h\"'", 18 | "MODULE_AUDIO_FRONTEND_ENABLED=1", 19 | "MODULE_MICROLITE_ENABLED=1 ", 20 | "MODULE_ULAB_ENABLED=1 ", 21 | "STM32H743xx", 22 | "USE_FULL_LL_DRIVER", 23 | "NDEBUG", 24 | "STM32_HAL_H='' ", 25 | "MBOOT_VTOR=0x08000000 ", 26 | "MICROPY_HW_VTOR=0x08000000 ", 27 | "MICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE", 28 | "MICROPY_MODULE_FROZEN_STR ", 29 | "MICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool ", 30 | "MICROPY_MODULE_FROZEN_MPY", 31 | "MICROPY_ROM_TEXT_COMPRESSION=1", 32 | "CMSIS_NN", 33 | "MODULE_CAMERA_ENABLED", 34 | "__ARM_FEATURE_DSP=1" 35 | ], 36 | "compilerPath": "/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc", 37 | "cStandard": "gnu99", 38 | "cppStandard": "c++11", 39 | "intelliSenseMode": "gcc-arm", 40 | "compilerArgs": [ 41 | "-Wall", 42 | "-Wpointer-arith", 43 | "-Werror", 44 | "-Wdouble-promotion", 45 | "-Wfloat-conversion", 46 | "-std=gnu99", 47 | "-nostdlib", 48 | "-Wno-error=float-conversion", 49 | "-Wno-error=nonnull", 50 | "-Wno-error=double-promotion", 51 | "-Wno-error=pointer-arith", 52 | "-Wno-error=unused-const-variable", 53 | "-Wno-error=discarded-qualifiers", 54 | "-Wno-error=unused-variable", 55 | "-Wno-error=int-conversion", 56 | "-Wno-error=incompatible-pointer-types", 57 | "-g3", 58 | "-fdata-sections", 59 | "-ffunction-sections", 60 | "-mthumb", 61 | " -mfpu=fpv5-d16", 62 | " -mfloat-abi=hard ", 63 | "-mtune=cortex-m7", 64 | " -mcpu=cortex-m7", 65 | "-O0", 66 | "-MD" 67 | ], 68 | "browse": { 69 | "path": [ 70 | "${workspaceFolder}/src", 71 | "${workspaceFolder}/lib", 72 | "${workspaceFolder}/micropython-modules", 73 | "${workspaceFolder}/micropython-modules/microlite/tflm", 74 | "${workspaceFolder}/micropython" 75 | ] 76 | } 77 | }, 78 | { 79 | "name": "Linux", 80 | "includePath": [ 81 | "${workspaceFolder}/**" 82 | ], 83 | "defines": [], 84 | "compilerPath": "/usr/bin/gcc", 85 | "cStandard": "gnu17", 86 | "cppStandard": "gnu++14", 87 | "intelliSenseMode": "gcc-x64", 88 | "browse": { 89 | "path": [ 90 | "${workspaceFolder}/src", 91 | "${workspaceFolder}/lib", 92 | "${workspaceFolder}/micropython-modules", 93 | "${workspaceFolder}/micropython", 94 | "${workspaceFolder}/tensorflow" 95 | ] 96 | }, 97 | "configurationProvider": "ms-vscode.makefile-tools" 98 | } 99 | 100 | 101 | ], 102 | "version": 4 103 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "cwd": "${workspaceFolder}", 9 | "executable": "boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.elf", 10 | "name": "Debug STM32H743ZI2", 11 | "armToolchainPath": "/opt/gcc-arm-none-eabi-10-2020-q4-major/bin", 12 | "request": "attach", 13 | "runToMain": true, 14 | "type": "cortex-debug", 15 | "servertype": "external", 16 | "device": "STM32H743ZI2Tx", 17 | "demangle": true, 18 | "svdFile": "boards/stm32/NUCLEO_H743ZI2_MICROLITE/STM32H743x.svd", 19 | "gdbTarget": "172.21.192.1:3333", 20 | "symbolLoadInfo": { 21 | "loadAll": true, 22 | "exceptionList": "" 23 | } 24 | }, 25 | { 26 | "name": "Debug ESP32 WROOM", 27 | "type": "cppdbg", 28 | "request": "launch", 29 | "program": "${workspaceFolder}/boards/esp32/MICROLITE/build/micropython.elf", 30 | "args": [], 31 | "miDebuggerPath": "/home/mike/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb", 32 | "miDebuggerServerAddress": "172.29.144.1:3333", 33 | "stopAtEntry": true, 34 | "stopAtConnect": false, 35 | "cwd": "${workspaceFolder}", 36 | "environment": [], 37 | "externalConsole": false, 38 | "MIMode": "gdb", 39 | // "autorun": [ 40 | // // "target remote 172.29.144.1:3333", 41 | // "set remote hardware-watchpoint-limit 2", 42 | // "mon reset halt", 43 | // "flushregs", 44 | // "thb app_main", 45 | // "c" 46 | // ] 47 | }, 48 | { 49 | "name": "Debug OpenOCD H743ZI2", 50 | "type": "cppdbg", 51 | "request": "launch", 52 | "program": "${workspaceFolder}/boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.elf", 53 | "args": [], 54 | "miDebuggerPath": "/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gdb", 55 | "miDebuggerServerAddress": "172.27.16.1:3333", 56 | "stopAtEntry": true, 57 | "stopAtConnect": true, 58 | "cwd": "${workspaceFolder}", 59 | "environment": [], 60 | "externalConsole": false, 61 | "MIMode": "gdb", 62 | }, 63 | { 64 | "name": "(gdb) Micropython - micro speech", 65 | "type": "cppdbg", 66 | "request": "launch", 67 | "program": "${workspaceFolder}/micropython/ports/unix/micropython", 68 | "args": ["${workspaceFolder}/examples/micro-speech/unix/main.py"], 69 | "stopAtEntry": true, 70 | "cwd": "${workspaceFolder}/examples/micro-speech/unix", 71 | "environment": [], 72 | "externalConsole": false, 73 | "symbolLoadInfo": { 74 | "loadAll": true, 75 | "exceptionList": "" 76 | }, 77 | "MIMode": "gdb", 78 | "setupCommands": [ 79 | { 80 | "description": "Enable pretty-printing for gdb", 81 | "text": "-enable-pretty-printing", 82 | "ignoreFailures": true 83 | } 84 | ] 85 | } 86 | ] 87 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.errorSquiggles": "Disabled", 3 | "files.associations": { 4 | "any": "c", 5 | "variant": "c", 6 | "*.inc": "cpp", 7 | "*.tcc": "cpp", 8 | "bitset": "cpp", 9 | "string": "cpp", 10 | "vector": "cpp", 11 | "string_view": "cpp", 12 | "iomanip": "cpp", 13 | "istream": "cpp", 14 | "limits": "cpp", 15 | "ostream": "cpp", 16 | "ratio": "cpp", 17 | "sstream": "cpp", 18 | "streambuf": "cpp", 19 | "functional": "cpp", 20 | "regex": "cpp", 21 | "stdint.h": "c", 22 | "stdint-intn.h": "c", 23 | "types.h": "c", 24 | "array": "cpp", 25 | "charconv": "cpp", 26 | "chrono": "cpp", 27 | "compare": "cpp", 28 | "memory_resource": "cpp", 29 | "ranges": "cpp", 30 | "scoped_allocator": "cpp", 31 | "tuple": "cpp", 32 | "type_traits": "cpp", 33 | "utility": "cpp", 34 | "arm_nnsupportfunctions.h": "c", 35 | "arm_nnfunctions.h": "c", 36 | "arm_nn_math_types.h": "c", 37 | "cmsis_compiler.h": "c", 38 | "cmsis_gcc.h": "c", 39 | "gchelper.h": "c", 40 | "stdio.h": "c", 41 | "features.h": "c", 42 | "_ansi.h": "c", 43 | "newlib.h": "c", 44 | "stm32f4xx_hal_conf_base.h": "c" 45 | }, 46 | "python.pythonPath": "/usr/bin/python3", 47 | "makefile.configurations": [ 48 | { 49 | "name": "H743 firmware", 50 | "makeArgs": ["MICROPY_TOP=/home/mike/git/tensorflow-micropython-examples/micropython", 51 | "BOARD_DIR=/home/mike/git/tensorflow-micropython-examples/boards/stm32/NUCLEO_H743ZI2_MICROLITE", 52 | "CROSS_COMPILE=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-", 53 | "V=2"] 54 | } 55 | ], 56 | "makefile.makefilePath": "./boards/stm32/NUCLEO_H743ZI2_MICROLITE/Makefile", 57 | "makefile.preConfigureScript": "./boards/stm32/NUCLEO_H743ZI2_MICROLITE/vs-code-preconfigure.sh", 58 | "makefile.launchConfigurations": [ 59 | { 60 | "cwd": "/home/mike/git/tensorflow-micropython-examples/boards/stm32/NUCLEO_H743ZI2_MICROLITE/build", 61 | "binaryPath": "/home/mike/git/tensorflow-micropython-examples/boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.elf", 62 | "binaryArgs": [] 63 | } 64 | ], 65 | "cortex-debug.variableUseNaturalFormat": false, 66 | "cmake.configureOnOpen": false 67 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Build Tensorflow - Unix", 6 | "type": "shell", 7 | "command": "make -f tensorflow/lite/micro/tools/make/Makefile BUILD_TYPE=debug clean all", 8 | "options": { 9 | "cwd": "${workspaceFolder}/tensorflow" 10 | }, 11 | "group": { 12 | "kind": "build", 13 | "isDefault": true 14 | }, 15 | "presentation": { 16 | "reveal": "always", 17 | "panel": "new" 18 | }, 19 | "problemMatcher": [ 20 | "$gcc" 21 | ] 22 | }, 23 | { 24 | "label": "Build Micropython - Unix", 25 | "type": "shell", 26 | "command": "make -f /home/mike/git/tensorflow-micropython-examples/micropython-modules/GNUmakefile-unix V=1", 27 | "options": { 28 | "cwd": "${workspaceFolder}/micropython/ports/unix" 29 | }, 30 | "group": { 31 | "kind": "build", 32 | "isDefault": true 33 | }, 34 | "presentation": { 35 | "reveal": "always", 36 | "panel": "new" 37 | }, 38 | "problemMatcher": [ 39 | "$gcc" 40 | ] 41 | }, 42 | { 43 | "label": "Build ESP32 MICROLITE", 44 | "type": "shell", 45 | "command": ". /home/mike/esp/esp-idf/export.sh && /home/mike/.espressif/python_env/idf4.3_py3.7_env/bin/python /home/mike/esp/esp-idf/tools/idf.py build", 46 | "options": { 47 | "cwd": "${workspaceFolder}/boards/esp32/MICROLITE" 48 | }, 49 | "group": { 50 | "kind": "build", 51 | "isDefault": true 52 | }, 53 | "presentation": { 54 | "reveal": "always", 55 | "panel": "new" 56 | }, 57 | "problemMatcher": [ 58 | "$gcc" 59 | ] 60 | }, 61 | { 62 | "label": "Clean Micropython - Unix", 63 | "type": "shell", 64 | "command": "make -f /home/mike/git/tensorflow-micropython-examples/micropython-modules/GNUmakefile-unix V=1 clean", 65 | "options": { 66 | "cwd": "${workspaceFolder}/micropython/ports/unix" 67 | }, 68 | "group": { 69 | "kind": "build", 70 | "isDefault": true 71 | }, 72 | "presentation": { 73 | "reveal": "always", 74 | "panel": "new" 75 | }, 76 | "problemMatcher": [ 77 | "$gcc" 78 | ] 79 | } 80 | ] 81 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | Contributions in any form are welcome. 4 | 5 | This is an integration project between tensorflow lite for micro-controllers, micropython, ulab and other tools 6 | that will help users experiment within TinyML. 7 | 8 | New boards, Documentation Improvements, Adding New examples, etc are all welcome. 9 | 10 | # New board requests 11 | 12 | Please file issues and new boards can be added to the nightly github actions build. Downloading is supported and this 13 | is the easiest way for new users to get started. To just download the firmware for their board and flash it. 14 | 15 | Please include a pointer to the board config used to build micropython as that will be the base used for adding the 16 | microlite and other modules to it. 17 | 18 | For example the ESP32 geneneric board config is located here: 19 | https://github.com/micropython/micropython/tree/master/ports/esp32/boards/GENERIC 20 | 21 | At the moment we only build some of the boards supported by Micropython. The current minimum requirements are 1 MB 22 | Flash Size. 23 | 24 | ![stm32 nucleo boards with > 1MB flash](images/recommended%20stm32%20boards.png) 25 | 26 | To run microspeech you need to have approximately 50 kb available ram within micropython. To run person detection you 27 | need approximately 440 kb memory plus space for the framebuffer. This is most likely only possible on boards 28 | supporting PS RAM. 29 | 30 | In the future it may be possible to strip down what is included to fit into a smaller flash size but its not working 31 | yet. Refer to https://github.com/mocleiri/tensorflow-micropython-examples/issues/53 32 | 33 | 34 | # Documentation Improvements 35 | 36 | Please file issues to discuss how to improve documentation. Or area's where its confusing or missing key steps. 37 | -------------------------------------------------------------------------------- /DEBUGGING.md: -------------------------------------------------------------------------------- 1 | # On Device Debugging 2 | 3 | These instructions are for how to debug the C/C++ code running Micropython and the microlite module on device. 4 | 5 | It doesn't help with debugging the micropython program itelf. Once https://github.com/mocleiri/tensorflow-micropython-examples/issues/10 6 | is implemented the program can be debugged using a regular python ide. 7 | 8 | # General Information 9 | 10 | This documentation was written for running Visual Studio Code inside of the windows subsystem for linux in Windows 10 11 | and having it communicate with something in Windows which is talking to the development board plugged in via USB. 12 | 13 | Identify the IP address for the windows side from the windows subsystem for linux. 14 | 15 | ``` 16 | cat /etc/resolv.conf 17 | 18 | # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf: 19 | # [network] 20 | # generateResolvConf = false 21 | nameserver 172.24.176.1 22 | ``` 23 | 24 | In this case you need to edit the VS Code launcher with **172.24.176.1** 25 | 26 | This IP changes each time your computer restarts. 27 | 28 | There are ways to configure visual studio code to be able to compile your code which are outside the scope of this 29 | documentation. 30 | 31 | Here you will have to go to the board directory and then build the firmware, flash your device with the latest and 32 | then you are at the point where these debugging instructions come in to run that firmware on the device step by step. 33 | 34 | # ESP32 35 | 36 | Using the ESP-PROG external JTAG board. 37 | 38 | https://docs.espressif.com/projects/espressif-esp-iot-solution/en/latest/hw-reference/ESP-Prog_guide.html 39 | 40 | ![esp32-to-esp-prog-pins.png](images/esp32-to-esp-prog-pins.png) 41 | Credit: Brian Lough https://www.youtube.com/watch?v=TivyIFF-dzw 42 | 43 | 44 | 1. Install esp-idf in windows. 45 | 2. Then run: openocd -f board/esp32-wrover-kit-3.3v.cfg -c “bindto 0.0.0.0” 46 | 3. Then disable the firewall in an admin windows powershell: ```Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"``` 47 | 48 | ```json 49 | { 50 | "name": "Debug ESP32 WROOM", 51 | "type": "cppdbg", 52 | "request": "launch", 53 | "program": "${workspaceFolder}/boards/esp32/MICROLITE/build/micropython.elf", 54 | "args": [], 55 | "miDebuggerPath": "<>/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb", 56 | "miDebuggerServerAddress": "<>:3333", 57 | "stopAtEntry": true, 58 | "stopAtConnect": false, 59 | "cwd": "${workspaceFolder}", 60 | "environment": [], 61 | "externalConsole": false, 62 | "MIMode": "gdb" 63 | } 64 | ``` 65 | 66 | # STM32 67 | 68 | Basics: 69 | 1. Run stlink gdb in windows 70 | 2. Find IP of windows subsystem for linux 71 | 3. connect to stlink gdb in windows through TCP using IP found above. 72 | 73 | If your board is restarting and you want to know the path to the failure then enable fault mode: 74 | 75 | ``` 76 | pyb.fault_debug(1) 77 | ``` 78 | 79 | This will hold the microcontroller at the point where there failure/reset occurred and let you see the stack trace. 80 | 81 | Details: 82 | 83 | Install the STM32CubeIDE. Within it there is an stlink gdb server. You can run this and it will connect to the board 84 | through st link in windows and then be available for remote connections from the windows subsystem for linux: 85 | ```shell 86 | 87 | c:\ST\STM32CubeIDE_1.7.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.0.202105311346\tools\bin>ST-LINK_gdbserver.exe -p 3333 -l 31 -cp c:\ST\STM32CubeIDE_1.7.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.0.202105311346\tools\bin -d -v 88 | ``` 89 | 90 | ```json 91 | { 92 | "cwd": "${workspaceFolder}", 93 | "executable": "boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.elf", 94 | "name": "Debug STM32H743ZI2", 95 | "armToolchainPath": "/opt/gcc-arm-none-eabi-10-2020-q4-major/bin", 96 | "request": "attach", 97 | "runToMain": true, 98 | "type": "cortex-debug", 99 | "servertype": "external", 100 | "device": "STM32H743ZI2Tx", 101 | "demangle": true, 102 | "svdFile": "boards/stm32/NUCLEO_H743ZI2_MICROLITE/STM32H743x.svd", 103 | "gdbTarget": "<< windows IP>>:3333", 104 | "symbolLoadInfo": { 105 | "loadAll": true, 106 | "exceptionList": "" 107 | } 108 | } 109 | ``` 110 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Michael O'Cleirigh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MAC_ESP32S3_BUILD.md: -------------------------------------------------------------------------------- 1 | # Build Tensorflow Micropython on MAC OS using Bash Terminal 2 | 3 | Tested on: macOS Monterey Version 12.1 4 | 5 | ## Prerequisites 6 | 7 | # Properly Installing ESP-IDF (Taken from: https://docs.espressif.com/projects/esp-idf/en/v3.3/get-started-cmake/macos-setup.html) 8 | 9 | sudo easy_install pip 10 | 11 | pip install --user pyserial 12 | 13 | brew install cmake ninja 14 | 15 | brew install ccache 16 | 17 | Download: https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz 18 | 19 | mkdir -p ~/esp 20 | cd ~/esp 21 | tar -xzf ~/Downloads/xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz 22 | 23 | # Make Toolchain Accessible from Bash Terminal 24 | 25 | Open your /bash.profile file by navigating to usr directory and pressing down the keys "Command, Shift, FullStop" it shoudl appear. 26 | 27 | Add to your profile: 28 | 29 | export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH 30 | alias get_esp32="export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH" 31 | 32 | # Git Clone ESP-IDF Version 4.4 33 | 34 | cd ~/esp 35 | git clone -b v4.4 --recursive https://github.com/espressif/esp-idf.git esp-idf 36 | 37 | # Update the Submodules 38 | 39 | cd esp-idf 40 | git submodule update --init 41 | 42 | # Reopen your /bash.profile and add the following: 43 | 44 | export IDF_PATH=~/esp/esp-idf 45 | export PATH="$IDF_PATH/tools:$PATH" 46 | 47 | # Install the required python packages 48 | 49 | python3 -m pip install --user -r $IDF_PATH/requirements.txt 50 | 51 | ## Download the Tensorflow Micropython Examples Repo 52 | 53 | git clone https://github.com/mocleiri/tensorflow-micropython-examples.git 54 | 55 | ## Building ESP32S3 56 | 57 | # Building the TensorFlow Firmware 58 | 59 | cd /tensorflow-micropython-examples 60 | 61 | git submodule init 62 | git submodule update --recursive 63 | cd micropython 64 | git submodule update --init lib/axtls 65 | git submodule update --init lib/berkeley-db-1.xx 66 | cd .. 67 | 68 | # Get Cache Keys 69 | 70 | IDF_COMMIT=142bb32c50fa9875b8b69fa539a2d59559460d72 71 | TFLM_COMMIT=$(git submodule status tensorflow | awk '{print ($1)}') 72 | 73 | # Setup IDF within Repo (Another Option) 74 | 75 | source ./micropython/tools/ci.sh && ci_esp32_idf44_setup 76 | 77 | source ./esp-idf/export.sh 78 | 79 | pip3 install Pillow 80 | pip3 install Wave 81 | 82 | rm -rf ./micropython-modules/microlite/tflm 83 | 84 | cd ./tensorflow 85 | 86 | ../micropython-modules/microlite/prepare-tflm-esp.sh 87 | 88 | cd .. 89 | 90 | # Build Micropython Cross-Compiler 91 | 92 | source ./esp-idf/export.sh 93 | cd ./micropython 94 | make -C mpy-cross V=1 clean all 95 | 96 | cd .. 97 | 98 | # Build Generic ESP32S3 8MB FLASH 99 | 100 | source ./esp-idf/export.sh 101 | 102 | (OR: get_esp32 103 | get_idf) 104 | 105 | cd ./boards/esp32/MICROLITE_S3 106 | 107 | rm -rf build 108 | idf.py clean build 109 | 110 | # To build other boards e.g. GENERIC_SPIRAM replace with Board definition 111 | 112 | cd ./boards/esp32/MICROLITE_S3_SPIRAM 113 | 114 | 115 | If succesful you should see a reult similar to this: 116 | 117 | /micropython.bin 118 | or run 'idf.py -p (PORT) flash' 119 | bootloader @0x000000 18640 ( 14128 remaining) 120 | partitions @0x008000 3072 ( 1024 remaining) 121 | application @0x010000 1191120 ( 840496 remaining) 122 | total 1256656 123 | -------------------------------------------------------------------------------- /UPGRADE.md: -------------------------------------------------------------------------------- 1 | # Upgrading building from scratch to latest 2 | 3 | The main item needed is to get the 3 submodules updated to the latest code. 4 | 5 | Espescially the current tensorflow directory which has been repointed at my fork until 6 | [tflite-micro#704](https://github.com/tensorflow/tflite-micro/pull/704) has been merged. 7 | 8 | Tensorflow uses *.cc for c++ files while Micropython expects them to be suffixed with *.cpp. 9 | 10 | The above pull request is upstreaming the --rename-cc-to-cpp switch and is almost complete. 11 | 12 | # Upgrade submodules 13 | 14 | ```shell 15 | $ git submodule update 16 | 17 | ``` 18 | 19 | This should trigger an update to the tensorflow, micropython and micropython-ulab submodules. 20 | 21 | But tensorflow and micropython have their own submodules. 22 | 23 | ```shell 24 | $ cd micropython 25 | $ git submodule update 26 | $ cd ../tensorflow 27 | $ git submodule update 28 | ``` 29 | 30 | You can verify that this worked by looking at the log of what is at the tip of the checked out branch for each 31 | and that the commit date is in December 2021. -------------------------------------------------------------------------------- /berkeley-db-1.xx.diff: -------------------------------------------------------------------------------- 1 | diff --git a/PORT/include/bsd-queue.h b/PORT/include/bsd-queue.h 2 | index f28ad5d..4ebd3f3 120000 3 | --- a/PORT/include/bsd-queue.h 4 | +++ b/PORT/include/bsd-queue.h 5 | @@ -1 +1 @@ 6 | -queue.h 7 | \ No newline at end of file 8 | +#include "queue.h" 9 | diff --git a/PORT/include/db.h b/PORT/include/db.h 10 | index 44c1ba4..9d62cba 120000 11 | --- a/PORT/include/db.h 12 | +++ b/PORT/include/db.h 13 | @@ -1 +1 @@ 14 | -../../include/db.h 15 | \ No newline at end of file 16 | +#include "../../include/db.h" 17 | diff --git a/PORT/include/filevtable.h b/PORT/include/filevtable.h 18 | index 25306d1..7f8b252 120000 19 | --- a/PORT/include/filevtable.h 20 | +++ b/PORT/include/filevtable.h 21 | @@ -1 +1 @@ 22 | -../../include/filevtable.h 23 | \ No newline at end of file 24 | +#include "../../include/filevtable.h" 25 | diff --git a/PORT/include/mpool.h b/PORT/include/mpool.h 26 | index 03f870c..4b685f6 120000 27 | --- a/PORT/include/mpool.h 28 | +++ b/PORT/include/mpool.h 29 | @@ -1 +1 @@ 30 | -../../include/mpool.h 31 | \ No newline at end of file 32 | +#include "../../include/mpool.h" 33 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE/custom-partitions.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $ESPIDF/components/partition_table/Kconfig.projbuild and the 3 | # offset of the factory/ota_0 partition is set in makeimg.py 4 | # I needed to increase the size of the app partition to fit the tensorflow microlite library 5 | # There is 1/2 as much data partition as with standard micropython on esp32 4MiB. 6 | # Name, Type, SubType, Offset, Size, Flags 7 | nvs, data, nvs, 0x9000, 0x6000, 8 | phy_init, data, phy, 0xf000, 0x1000, 9 | factory, app, factory, 0x10000, 0x280000, 10 | vfs, data, fat, 0x300000, 0x100000, 11 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set (IDF_TARGET esp32) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 6 | ${MICROPY_PORT_DIR}/boards/sdkconfig.240mhz 7 | ${MICROPY_BOARD_DIR}/sdkconfig.partition 8 | 9 | ) 10 | 11 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 12 | 13 | set(USER_C_MODULES 14 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 15 | ) 16 | 17 | if(NOT MICROPY_FROZEN_MANIFEST) 18 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 19 | endif() 20 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32 module (microlite)" 2 | #define MICROPY_HW_MCU_NAME "ESP32" 3 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE/sdkconfig.partition: -------------------------------------------------------------------------------- 1 | # MICROLITE 4M flash partition adjustment 2 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 3 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 4 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 5 | CONFIG_PARTITION_TABLE_CUSTOM=y 6 | # move back up from micropython/ports/esp32 to the main project source code 7 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE/custom-partitions.csv" 8 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3/custom-partitions.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $ESPIDF/components/partition_table/Kconfig.projbuild and the 3 | # offset of the factory/ota_0 partition is set in makeimg.py 4 | # I needed to increase the size of the app partition to fit the tensorflow microlite library 5 | # There is 1/2 as much data partition as with standard micropython on esp32 4MiB. 6 | # Name, Type, SubType, Offset, Size, Flags 7 | nvs, data, nvs, 0x9000, 0x6000, 8 | phy_init, data, phy, 0xf000, 0x1000, 9 | factory, app, factory, 0x10000, 0x280000, 10 | vfs, data, fat, 0x300000, 0x100000, 11 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set (IDF_TARGET esp32c3) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 6 | ${MICROPY_BOARD_DIR}/sdkconfig.partition 7 | 8 | ) 9 | 10 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 11 | 12 | set(USER_C_MODULES 13 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 14 | ) 15 | 16 | if(NOT MICROPY_FROZEN_MANIFEST) 17 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 18 | endif() 19 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | // This configuration is for a generic ESP32C3 board with 4MiB (or more) of flash. 2 | 3 | #define MICROPY_HW_BOARD_NAME "ESP32C3 module (microlite)" 4 | #define MICROPY_HW_MCU_NAME "ESP32C3" 5 | 6 | #define MICROPY_HW_ENABLE_SDCARD (0) 7 | #define MICROPY_PY_MACHINE_DAC (0) 8 | // TODO: early esp-idf's didn't support i2s. check if this still applies 9 | #define MICROPY_PY_MACHINE_I2S (0) 10 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3/sdkconfig.partition: -------------------------------------------------------------------------------- 1 | # MICROLITE 4M flash partition adjustment 2 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 3 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 4 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 5 | CONFIG_PARTITION_TABLE_CUSTOM=y 6 | # move back up from micropython/ports/esp32 to the main project source code 7 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_C3/custom-partitions.csv" 8 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3_USB/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3_USB/board.json: -------------------------------------------------------------------------------- 1 | { 2 | "deploy": [ 3 | "../deploy_c3.md" 4 | ], 5 | "docs": "", 6 | "features": [ 7 | "BLE", 8 | "WiFi" 9 | ], 10 | "id": "esp32c3-usb", 11 | "images": [ 12 | "esp32c3_devkitmini.jpg" 13 | ], 14 | "mcu": "esp32c3", 15 | "product": "ESP32-C3 with USB", 16 | "thumbnail": "", 17 | "url": "https://www.espressif.com/en/products/modules", 18 | "vendor": "Espressif" 19 | } 20 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3_USB/custom-partitions.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $ESPIDF/components/partition_table/Kconfig.projbuild and the 3 | # offset of the factory/ota_0 partition is set in makeimg.py 4 | # I needed to increase the size of the app partition to fit the tensorflow microlite library 5 | # There is 1/2 as much data partition as with standard micropython on esp32 4MiB. 6 | # Name, Type, SubType, Offset, Size, Flags 7 | nvs, data, nvs, 0x9000, 0x6000, 8 | phy_init, data, phy, 0xf000, 0x1000, 9 | factory, app, factory, 0x10000, 0x280000, 10 | vfs, data, fat, 0x300000, 0x100000, 11 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3_USB/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3_USB/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set (IDF_TARGET esp32c3) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 6 | ${MICROPY_BOARD_DIR}/sdkconfig.partition 7 | 8 | ) 9 | 10 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 11 | 12 | set(USER_C_MODULES 13 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 14 | ) 15 | 16 | if(NOT MICROPY_FROZEN_MANIFEST) 17 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 18 | endif() 19 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3_USB/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | // This configuration is for a generic ESP32C3 board with 4MiB (or more) of flash. 2 | 3 | #define MICROPY_HW_BOARD_NAME "ESP32C3 module (microlite)" 4 | #define MICROPY_HW_MCU_NAME "ESP32C3" 5 | 6 | #define MICROPY_HW_ENABLE_SDCARD (0) 7 | #define MICROPY_PY_MACHINE_DAC (0) 8 | #define MICROPY_PY_MACHINE_I2S (0) 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_C3_USB/sdkconfig.partition: -------------------------------------------------------------------------------- 1 | # -- from GENERIC_C3_USB start -- 2 | 3 | CONFIG_ESP32C3_REV_MIN_3=y 4 | CONFIG_ESP32C3_REV_MIN=3 5 | CONFIG_ESP32C3_BROWNOUT_DET=y 6 | CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_7= 7 | CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_4=y 8 | CONFIG_ESP32C3_BROWNOUT_DET_LVL=4 9 | CONFIG_ESP_CONSOLE_UART_DEFAULT= 10 | CONFIG_ESP_CONSOLE_USB_CDC= 11 | CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y 12 | 13 | # -- from GENERIC_C3_USB end -- 14 | 15 | # MICROLITE 4M flash partition adjustment 16 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 17 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 18 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 19 | CONFIG_PARTITION_TABLE_CUSTOM=y 20 | # move back up from micropython/ports/esp32 to the main project source code 21 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_C3_USB/custom-partitions.csv" 22 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S2_SPIRAM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S2_SPIRAM/deploy.md: -------------------------------------------------------------------------------- 1 | Program your board using the esptool.py program, found [here](https://github.com/espressif/esptool). 2 | 3 | To flash or erase your TinyS2, you have to first put it into download mode. 4 | To do this, follow these steps: 5 | 6 | - Press and hold the [BOOT] button 7 | - Press and release the [RESET] button 8 | - Release the [BOOT] button 9 | 10 | Now the board is in download mode and the native USB will have enumerated as a serial device. 11 | 12 | If you are putting MicroPython on your board for the first time then you should 13 | first erase the entire flash using: 14 | 15 | ### Linux 16 | ```bash 17 | esptool.py --chip esp32s2 --port /dev/ttyACM0 erase_flash 18 | ``` 19 | 20 | ### Mac 21 | ```bash 22 | esptool.py --chip esp32s2 --port /dev/cu.usbmodem01 erase_flash 23 | ``` 24 | 25 | #### Windows 26 | Change (X) to whatever COM port is being used by the board 27 | ```bash 28 | esptool --chip esp32s2 --port COM(X) erase_flash 29 | ``` 30 | 31 | Now download the version of the firmware you would like to install from the options below, 32 | then use the following command to program the firmware starting at address 0x1000, 33 | remembering to replace `tinys2-micropython-firmware-version.bin` with the name of the 34 | firmware you just downloaded: 35 | 36 | #### Linux 37 | ```bash 38 | esptool.py --chip esp32s2 --port /dev/ttyACM0 write_flash -z 0x1000 tinys2-micropython-firmware-version.bin 39 | ``` 40 | 41 | #### Mac 42 | ```bash 43 | esptool.py --chip esp32s2 --port /dev/cu.usbmodem01 write_flash -z 0x1000 tinys2-micropython-firmware-version.bin 44 | ``` 45 | 46 | #### Windows 47 | Change (X) to whatever COM port is being used by the board 48 | ```bash 49 | esptool --chip esp32s2 --port COM(X) write_flash -z 0x1000 tinys2-micropython-firmware-version.bin 50 | ``` 51 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S2_SPIRAM/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S2_SPIRAM/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set(IDF_TARGET esp32s2) 2 | set(SDKCONFIG_DEFAULTS 3 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 4 | ${MICROPY_PORT_DIR}/boards/sdkconfig.spiram_sx 5 | # ${MICROPY_PORT_DIR}/boards/sdkconfig.usb 6 | ${MICROPY_BOARD_DIR}/sdkconfig.board 7 | ) 8 | 9 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 10 | 11 | set(USER_C_MODULES 12 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 13 | ) 14 | 15 | if(NOT MICROPY_FROZEN_MANIFEST) 16 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 17 | endif() 18 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S2_SPIRAM/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32S2 Microlite" 2 | #define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2" 3 | 4 | #define MICROPY_PY_BLUETOOTH (0) 5 | #define MICROPY_HW_ENABLE_SDCARD (0) 6 | 7 | // these were from the um_tiny s2 double check if they match the ESP32S2DEVKITM1R 8 | // #define MICROPY_HW_I2C0_SCL (9) 9 | // #define MICROPY_HW_I2C0_SDA (8) 10 | 11 | // #define MICROPY_HW_SPI1_MOSI (35) 12 | // #define MICROPY_HW_SPI1_MISO (36) 13 | // #define MICROPY_HW_SPI1_SCK (37) 14 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S2_SPIRAM/sdkconfig.board: -------------------------------------------------------------------------------- 1 | CONFIG_FLASHMODE_QIO=y 2 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 3 | CONFIG_USB_AND_UART=y 4 | # LWIP 5 | # CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS2" 6 | # end of LWIP 7 | CONFIG_PARTITION_TABLE_CUSTOM=y 8 | # cwd is boards/esp32/MICROLITE_S2_SPIRAM 9 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../micropython/ports/esp32/partitions.csv" 10 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set(IDF_TARGET esp32s3) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 6 | ${MICROPY_PORT_DIR}/boards/sdkconfig.240mhz 7 | ${MICROPY_BOARD_DIR}/sdkconfig.board 8 | ${MICROPY_BOARD_DIR}/sdkconfig-8m.partition 9 | ) 10 | 11 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 12 | 13 | set(USER_C_MODULES 14 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 15 | ) 16 | 17 | if(NOT MICROPY_FROZEN_MANIFEST) 18 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 19 | endif() 20 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32S3 module (microlite)" 2 | #define MICROPY_HW_MCU_NAME "ESP32S3" 3 | 4 | #define MICROPY_PY_MACHINE_DAC (0) 5 | 6 | #define MICROPY_HW_I2C0_SCL (9) 7 | #define MICROPY_HW_I2C0_SDA (8) 8 | 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3/partitions-8MiB.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $IDF_PATH/components/partition_table/Kconfig.projbuild. 3 | # Name, Type, SubType, Offset, Size, Flags 4 | nvs, data, nvs, 0x9000, 0x6000, 5 | phy_init, data, phy, 0xf000, 0x1000, 6 | factory, app, factory, 0x10000, 0x1F0000, 7 | vfs, data, fat, 0x200000, 0x600000, 8 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3/sdkconfig-8m.partition: -------------------------------------------------------------------------------- 1 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 2 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 3 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | # move back up from micropython/ports/esp32 to the main project source code 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_S3/partitions-8MiB.csv" 7 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3/sdkconfig.board: -------------------------------------------------------------------------------- 1 | CONFIG_FLASHMODE_QIO=y 2 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 3 | CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y 4 | CONFIG_ESPTOOLPY_AFTER_NORESET=y 5 | 6 | CONFIG_SPIRAM_MEMTEST= 7 | 8 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB= 9 | CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB= 11 | CONFIG_PARTITION_TABLE_CUSTOM=y 12 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv" 13 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set(IDF_TARGET esp32s3) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 6 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 7 | ${MICROPY_PORT_DIR}/boards/sdkconfig.spiram_sx 8 | ${MICROPY_PORT_DIR}/boards/sdkconfig.240mhz 9 | ${MICROPY_BOARD_DIR}/sdkconfig.board 10 | ${MICROPY_BOARD_DIR}/sdkconfig-8m.partition 11 | ) 12 | 13 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 14 | 15 | set(USER_C_MODULES 16 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 17 | ) 18 | 19 | if(NOT MICROPY_FROZEN_MANIFEST) 20 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 21 | endif() 22 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32S3 module (microlite-spiram)" 2 | #define MICROPY_HW_MCU_NAME "ESP32S3" 3 | 4 | #define MICROPY_PY_MACHINE_DAC (0) 5 | 6 | #define MICROPY_HW_I2C0_SCL (9) 7 | #define MICROPY_HW_I2C0_SDA (8) 8 | 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM/partitions-8MiB.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $IDF_PATH/components/partition_table/Kconfig.projbuild. 3 | # Name, Type, SubType, Offset, Size, Flags 4 | nvs, data, nvs, 0x9000, 0x6000, 5 | phy_init, data, phy, 0xf000, 0x1000, 6 | factory, app, factory, 0x10000, 0x1F0000, 7 | vfs, data, fat, 0x200000, 0x600000, 8 | 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM/sdkconfig-8m.partition: -------------------------------------------------------------------------------- 1 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 2 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 3 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | # move back up from micropython/ports/esp32 to the main project source code 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_S3_SPIRAM/partitions-8MiB.csv" 7 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM/sdkconfig.board: -------------------------------------------------------------------------------- 1 | CONFIG_FLASHMODE_QIO=y 2 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 3 | CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y 4 | CONFIG_ESPTOOLPY_AFTER_NORESET=y 5 | 6 | CONFIG_SPIRAM_MEMTEST= 7 | 8 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB= 9 | CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB= 11 | CONFIG_PARTITION_TABLE_CUSTOM=y 12 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv" 13 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_CS_GPIO_20/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_CS_GPIO_20/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_CS_GPIO_20/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set(IDF_TARGET esp32s3) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 6 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 7 | ${MICROPY_PORT_DIR}/boards/sdkconfig.spiram_sx 8 | ${MICROPY_PORT_DIR}/boards/sdkconfig.240mhz 9 | ${MICROPY_BOARD_DIR}/sdkconfig.board 10 | ${MICROPY_BOARD_DIR}/sdkconfig-8m.partition 11 | ) 12 | 13 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 14 | 15 | set(USER_C_MODULES 16 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 17 | ) 18 | 19 | if(NOT MICROPY_FROZEN_MANIFEST) 20 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 21 | endif() 22 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_CS_GPIO_20/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32S3 module (microlite-spiram)" 2 | #define MICROPY_HW_MCU_NAME "ESP32S3" 3 | 4 | #define MICROPY_PY_MACHINE_DAC (0) 5 | 6 | #define MICROPY_HW_I2C0_SCL (9) 7 | #define MICROPY_HW_I2C0_SDA (8) 8 | 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_CS_GPIO_20/partitions-8MiB.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $IDF_PATH/components/partition_table/Kconfig.projbuild. 3 | # Name, Type, SubType, Offset, Size, Flags 4 | nvs, data, nvs, 0x9000, 0x6000, 5 | phy_init, data, phy, 0xf000, 0x1000, 6 | factory, app, factory, 0x10000, 0x1F0000, 7 | vfs, data, fat, 0x200000, 0x600000, 8 | 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_CS_GPIO_20/sdkconfig-8m.partition: -------------------------------------------------------------------------------- 1 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 2 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 3 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | # move back up from micropython/ports/esp32 to the main project source code 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_S3_SPIRAM/partitions-8MiB.csv" 7 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_CS_GPIO_20/sdkconfig.board: -------------------------------------------------------------------------------- 1 | CONFIG_FLASHMODE_QIO=y 2 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 3 | CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y 4 | CONFIG_ESPTOOLPY_AFTER_NORESET=y 5 | 6 | CONFIG_SPIRAM_MEMTEST= 7 | 8 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB= 9 | CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB= 11 | CONFIG_PARTITION_TABLE_CUSTOM=y 12 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv" 13 | 14 | # overrides 15 | CONFIG_DEFAULT_PSRAM_CS_IO=20 16 | 17 | # Customizations from issue #40 18 | 19 | # not using the cpu settings as we are setting the cpu to max via 20 | # the standard config. 21 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_80= 22 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160=y 23 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240= 24 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=160 25 | 26 | # Cache config 27 | 28 | CONFIG_ESP32S3_INSTRUCTION_CACHE_16KB=y 29 | CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB= 30 | CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE=0x4000 31 | CONFIG_ESP32S3_INSTRUCTION_CACHE_4WAYS= 32 | CONFIG_ESP32S3_INSTRUCTION_CACHE_8WAYS=y 33 | CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS=8 34 | CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_16B= 35 | CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_32B=y 36 | CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE=32 37 | CONFIG_ESP32S3_INSTRUCTION_CACHE_WRAP= 38 | CONFIG_ESP32S3_DATA_CACHE_16KB= 39 | CONFIG_ESP32S3_DATA_CACHE_32KB=y 40 | CONFIG_ESP32S3_DATA_CACHE_64KB= 41 | CONFIG_ESP32S3_DATA_CACHE_SIZE=0x8000 42 | CONFIG_ESP32S3_DATA_CACHE_4WAYS= 43 | CONFIG_ESP32S3_DATA_CACHE_8WAYS=y 44 | CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS=8 45 | CONFIG_ESP32S3_DATA_CACHE_LINE_16B= 46 | CONFIG_ESP32S3_DATA_CACHE_LINE_32B=y 47 | CONFIG_ESP32S3_DATA_CACHE_LINE_64B= 48 | CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE=32 49 | CONFIG_ESP32S3_DATA_CACHE_WRAP= 50 | 51 | # end of Cache config 52 | 53 | CONFIG_ESP32S3_SPIRAM_SUPPORT=y 54 | 55 | # SPI RAM config 56 | 57 | CONFIG_SPIRAM_MODE_QUAD=y 58 | CONFIG_SPIRAM_MODE_OCT= 59 | CONFIG_SPIRAM_TYPE_AUTO= 60 | CONFIG_SPIRAM_TYPE_ESPPSRAM16= 61 | CONFIG_SPIRAM_TYPE_ESPPSRAM32= 62 | CONFIG_SPIRAM_TYPE_ESPPSRAM64=y 63 | CONFIG_SPIRAM_SIZE=8388608 64 | 65 | # PSRAM Clock and CS IO for ESP32S3 66 | 67 | CONFIG_DEFAULT_PSRAM_CLK_IO=30 68 | CONFIG_DEFAULT_PSRAM_CS_IO=20 69 | 70 | # end of PSRAM Clock and CS IO for ESP32S3 71 | 72 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS= 73 | CONFIG_SPIRAM_RODATA= 74 | CONFIG_SPIRAM_SPEED_120M= 75 | CONFIG_SPIRAM_SPEED_80M=y 76 | CONFIG_SPIRAM_SPEED_40M= 77 | CONFIG_SPIRAM=y 78 | CONFIG_SPIRAM_BOOT_INIT=y 79 | CONFIG_SPIRAM_IGNORE_NOTFOUND=y 80 | CONFIG_SPIRAM_USE_MEMMAP= 81 | CONFIG_SPIRAM_USE_CAPS_ALLOC=y 82 | CONFIG_SPIRAM_USE_MALLOC= 83 | CONFIG_SPIRAM_MEMTEST= 84 | CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP= 85 | 86 | # end of SPI RAM config 87 | 88 | CONFIG_ESP32S3_TRAX= 89 | CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM=0x0 90 | CONFIG_ESP32S3_ULP_COPROC_ENABLED= 91 | CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=0 92 | CONFIG_ESP32S3_DEBUG_OCDAWARE=y 93 | CONFIG_ESP32S3_DEBUG_STUBS_ENABLE= 94 | CONFIG_ESP32S3_BROWNOUT_DET=y 95 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_7=y 96 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_6= 97 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_5= 98 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_4= 99 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_3= 100 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_2= 101 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_1= 102 | CONFIG_ESP32S3_BROWNOUT_DET_LVL=7 103 | CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC_FRC1=y 104 | CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC= 105 | CONFIG_ESP32S3_TIME_SYSCALL_USE_FRC1= 106 | CONFIG_ESP32S3_TIME_SYSCALL_USE_NONE= 107 | CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y 108 | CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS= 109 | CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC= 110 | CONFIG_ESP32S3_RTC_CLK_SRC_INT_8MD256= 111 | CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=1024 112 | CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000 113 | CONFIG_ESP32S3_NO_BLOBS= 114 | CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM= 115 | CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE= 116 | 117 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_OCTAL/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_OCTAL/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_OCTAL/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set(IDF_TARGET esp32s3) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 6 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 7 | ${MICROPY_PORT_DIR}/boards/sdkconfig.spiram_sx 8 | ${MICROPY_PORT_DIR}/boards/sdkconfig.240mhz 9 | ${MICROPY_BOARD_DIR}/sdkconfig.board 10 | ${MICROPY_BOARD_DIR}/sdkconfig-8m.partition 11 | ) 12 | 13 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 14 | 15 | set(USER_C_MODULES 16 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 17 | ) 18 | 19 | if(NOT MICROPY_FROZEN_MANIFEST) 20 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 21 | endif() 22 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_OCTAL/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32S3 module (microlite-spiram)" 2 | #define MICROPY_HW_MCU_NAME "ESP32S3" 3 | 4 | #define MICROPY_PY_MACHINE_DAC (0) 5 | 6 | #define MICROPY_HW_I2C0_SCL (9) 7 | #define MICROPY_HW_I2C0_SDA (8) 8 | 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_OCTAL/partitions-8MiB.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $IDF_PATH/components/partition_table/Kconfig.projbuild. 3 | # Name, Type, SubType, Offset, Size, Flags 4 | nvs, data, nvs, 0x9000, 0x6000, 5 | phy_init, data, phy, 0xf000, 0x1000, 6 | factory, app, factory, 0x10000, 0x1F0000, 7 | vfs, data, fat, 0x200000, 0x600000, 8 | 9 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_OCTAL/sdkconfig-8m.partition: -------------------------------------------------------------------------------- 1 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 2 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 3 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | # move back up from micropython/ports/esp32 to the main project source code 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_S3_SPIRAM/partitions-8MiB.csv" 7 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_S3_SPIRAM_OCTAL/sdkconfig.board: -------------------------------------------------------------------------------- 1 | CONFIG_FLASHMODE_QIO=y 2 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 3 | CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y 4 | CONFIG_ESPTOOLPY_AFTER_NORESET=y 5 | 6 | CONFIG_SPIRAM_MEMTEST= 7 | 8 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB= 9 | CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y 10 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB= 11 | CONFIG_PARTITION_TABLE_CUSTOM=y 12 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv" 13 | 14 | # overrides 15 | CONFIG_DEFAULT_PSRAM_CS_IO=26 16 | 17 | # Customizations from issue #40 18 | 19 | # not using the cpu settings as we are setting the cpu to max via 20 | # the standard config. 21 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_80= 22 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160=y 23 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240= 24 | # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=160 25 | 26 | # Cache config 27 | 28 | # 29 | CONFIG_ESP32S3_INSTRUCTION_CACHE_16KB=y 30 | # CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB is not set 31 | CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE=0x4000 32 | # CONFIG_ESP32S3_INSTRUCTION_CACHE_4WAYS is not set 33 | CONFIG_ESP32S3_INSTRUCTION_CACHE_8WAYS=y 34 | CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS=8 35 | # CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_16B is not set 36 | CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_32B=y 37 | CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE=32 38 | # CONFIG_ESP32S3_DATA_CACHE_16KB is not set 39 | CONFIG_ESP32S3_DATA_CACHE_32KB=y 40 | # CONFIG_ESP32S3_DATA_CACHE_64KB is not set 41 | CONFIG_ESP32S3_DATA_CACHE_SIZE=0x8000 42 | # CONFIG_ESP32S3_DATA_CACHE_4WAYS is not set 43 | CONFIG_ESP32S3_DATA_CACHE_8WAYS=y 44 | CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS=8 45 | # CONFIG_ESP32S3_DATA_CACHE_LINE_16B is not set 46 | CONFIG_ESP32S3_DATA_CACHE_LINE_32B=y 47 | # CONFIG_ESP32S3_DATA_CACHE_LINE_64B is not set 48 | CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE=32 49 | # end of Cache config 50 | 51 | 52 | # end of Cache config 53 | 54 | CONFIG_ESP32S3_SPIRAM_SUPPORT=y 55 | 56 | # SPI RAM config 57 | # 58 | # CONFIG_SPIRAM_MODE_QUAD is not set 59 | CONFIG_SPIRAM_MODE_OCT=y 60 | CONFIG_SPIRAM_TYPE_AUTO=y 61 | # CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set 62 | CONFIG_SPIRAM_SIZE=-1 63 | 64 | # PSRAM Clock and CS IO for ESP32S3 65 | # 66 | CONFIG_DEFAULT_PSRAM_CLK_IO=30 67 | CONFIG_DEFAULT_PSRAM_CS_IO=26 68 | # end of PSRAM Clock and CS IO for ESP32S3 69 | 70 | 71 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS= 72 | CONFIG_SPIRAM_RODATA= 73 | CONFIG_SPIRAM_SPEED_120M= 74 | CONFIG_SPIRAM_SPEED_80M=y 75 | CONFIG_SPIRAM_SPEED_40M= 76 | CONFIG_SPIRAM=y 77 | CONFIG_SPIRAM_BOOT_INIT=y 78 | CONFIG_SPIRAM_IGNORE_NOTFOUND=y 79 | CONFIG_SPIRAM_USE_MEMMAP= 80 | CONFIG_SPIRAM_USE_CAPS_ALLOC=y 81 | CONFIG_SPIRAM_USE_MALLOC= 82 | CONFIG_SPIRAM_MEMTEST= 83 | CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP= 84 | 85 | # end of SPI RAM config 86 | 87 | CONFIG_ESP32S3_TRAX= 88 | CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM=0x0 89 | CONFIG_ESP32S3_ULP_COPROC_ENABLED= 90 | CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=0 91 | CONFIG_ESP32S3_DEBUG_OCDAWARE=y 92 | CONFIG_ESP32S3_DEBUG_STUBS_ENABLE= 93 | CONFIG_ESP32S3_BROWNOUT_DET=y 94 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_7=y 95 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_6= 96 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_5= 97 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_4= 98 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_3= 99 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_2= 100 | CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_1= 101 | CONFIG_ESP32S3_BROWNOUT_DET_LVL=7 102 | CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC_FRC1=y 103 | CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC= 104 | CONFIG_ESP32S3_TIME_SYSCALL_USE_FRC1= 105 | CONFIG_ESP32S3_TIME_SYSCALL_USE_NONE= 106 | CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y 107 | CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS= 108 | CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC= 109 | CONFIG_ESP32S3_RTC_CLK_SRC_INT_8MD256= 110 | CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=1024 111 | CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000 112 | CONFIG_ESP32S3_NO_BLOBS= 113 | CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM= 114 | CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE= 115 | 116 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM/custom-partitions.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $ESPIDF/components/partition_table/Kconfig.projbuild and the 3 | # offset of the factory/ota_0 partition is set in makeimg.py 4 | # I needed to increase the size of the app partition to fit the tensorflow microlite library 5 | # There is 1/2 as much data partition as with standard micropython on esp32 4MiB. 6 | # Name, Type, SubType, Offset, Size, Flags 7 | nvs, data, nvs, 0x9000, 0x6000, 8 | phy_init, data, phy, 0xf000, 0x1000, 9 | factory, app, factory, 0x10000, 0x280000, 10 | vfs, data, fat, 0x300000, 0x100000, 11 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set (IDF_TARGET esp32) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 6 | ${MICROPY_PORT_DIR}/boards/sdkconfig.240mhz 7 | ${MICROPY_PORT_DIR}/boards/sdkconfig.spiram 8 | ${MICROPY_BOARD_DIR}/sdkconfig.partition 9 | 10 | ) 11 | 12 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 13 | 14 | set(USER_C_MODULES 15 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 16 | ) 17 | 18 | if(NOT MICROPY_FROZEN_MANIFEST) 19 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 20 | endif() 21 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32 module (microlite-spiram)" 2 | #define MICROPY_HW_MCU_NAME "ESP32" 3 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM/sdkconfig.partition: -------------------------------------------------------------------------------- 1 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 2 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 3 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | # move back up from micropython/ports/esp32 to the main project source code 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_SPIRAM/custom-partitions.csv" 7 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_16M/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 22 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 23 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 24 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 25 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 26 | endforeach() 27 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 28 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 29 | 30 | # Include main IDF cmake file and define the project. 31 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 32 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_16M/custom-partitions-16M.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $ESPIDF/components/partition_table/Kconfig.projbuild and the 3 | # offset of the factory/ota_0 partition is set in makeimg.py 4 | # I needed to increase the size of the app partition to fit the tensorflow microlite library 5 | # There is 1/2 as much data partition as with standard micropython on esp32 4MiB. 6 | # Name, Type, SubType, Offset, Size, Flags 7 | nvs, data, nvs, 0x9000, 0x6000, 8 | phy_init, data, phy, 0xf000, 0x1000, 9 | factory, app, factory, 0x10000, 0x280000, 10 | # should be 13 MB for filesystem. 11 | vfs, data, fat, 0x300000, 0xC65D40, 12 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_16M/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_16M/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set (IDF_TARGET esp32) 2 | 3 | set(SDKCONFIG_DEFAULTS 4 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 5 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 6 | ${MICROPY_PORT_DIR}/boards/sdkconfig.240mhz 7 | ${MICROPY_PORT_DIR}/boards/sdkconfig.spiram 8 | ${MICROPY_BOARD_DIR}/sdkconfig.16m 9 | ${MICROPY_BOARD_DIR}/sdkconfig-16m.partition 10 | 11 | ) 12 | 13 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 14 | 15 | set(USER_C_MODULES 16 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 17 | ) 18 | 19 | if(NOT MICROPY_FROZEN_MANIFEST) 20 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 21 | endif() 22 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_16M/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32 module (microlite-spiram-16m)" 2 | #define MICROPY_HW_MCU_NAME "ESP32" 3 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_16M/sdkconfig-16m.partition: -------------------------------------------------------------------------------- 1 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 2 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 3 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | # move back up from micropython/ports/esp32 to the main project source code 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE_SPIRAM_16M/custom-partitions-16M.csv" 7 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_16M/sdkconfig.16m: -------------------------------------------------------------------------------- 1 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=n 2 | CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y 3 | CONFIG_ESPTOOLPY_FLASHSIZE="16MB" -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_CAM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on ESP32. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the esp32 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | set(EXTRA_COMPONENT_DIRS ../../../tflm_esp_kernels/components/esp32-camera) 12 | 13 | message (STATUS "EXTRA_COMPONENT_DIRS=${EXTRA_COMPONENT_DIRS}") 14 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 15 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 16 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 17 | 18 | # Define the output sdkconfig so it goes in the build directory. 19 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 20 | 21 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 22 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 23 | 24 | # Concatenate all sdkconfig files into a combined one for the IDF to use. 25 | file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "") 26 | foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS}) 27 | file(READ ${SDKCONFIG_DEFAULT} CONTENTS) 28 | file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}") 29 | endforeach() 30 | configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY) 31 | set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) 32 | 33 | # Include main IDF cmake file and define the project. 34 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 35 | project(micropython) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_CAM/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython ESP32 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_CAM/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | set (IDF_TARGET esp32) 2 | 3 | # this option causes the camera module to build 4 | set(CAMERA_TYPE esp32) 5 | 6 | set(SDKCONFIG_DEFAULTS 7 | ${MICROPY_PORT_DIR}/boards/sdkconfig.base 8 | ${MICROPY_PORT_DIR}/boards/sdkconfig.ble 9 | ${MICROPY_BOARD_DIR}/sdkconfig.esp32cam 10 | ${MICROPY_BOARD_DIR}/sdkconfig.partition 11 | ) 12 | 13 | message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}") 14 | 15 | set(USER_C_MODULES 16 | ${PROJECT_DIR}/micropython-modules/micropython.cmake 17 | ) 18 | 19 | 20 | if(NOT MICROPY_FROZEN_MANIFEST) 21 | set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) 22 | endif() 23 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_CAM/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #define MICROPY_HW_BOARD_NAME "ESP32-cam module (microlite)" 2 | #define MICROPY_HW_MCU_NAME "ESP32" 3 | 4 | #define MICROPY_PY_BLUETOOTH (0) 5 | #define MODULE_CAMERA_ENABLED (1) 6 | 7 | // The offset only has an effect if a board has psram 8 | // it allows the start of the range allocated to 9 | #define MICROPY_ALLOCATE_HEAP_USING_MALLOC (1) 10 | #define MICROPY_HEAP_SIZE_REDUCTION (512 * 1024) 11 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_CAM/sdkconfig.esp32cam: -------------------------------------------------------------------------------- 1 | # MicroPython on ESP32, ESP IDF configuration with SPIRAM support 2 | # The following options override the defaults 3 | 4 | # Bootloader config 5 | # CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y 6 | 7 | # ESP32-specific 8 | CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y 9 | CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=n 10 | CONFIG_ESP32_XTAL_FREQ_AUTO=y 11 | CONFIG_ESP32_SPIRAM_SUPPORT=y 12 | 13 | # verbose logging for debugging 14 | # CONFIG_LOG_DEFAULT_LEVEL_NONE= 15 | # CONFIG_LOG_DEFAULT_LEVEL_ERROR= 16 | # CONFIG_LOG_DEFAULT_LEVEL_WARN= 17 | # CONFIG_LOG_DEFAULT_LEVEL_INFO= 18 | # CONFIG_LOG_DEFAULT_LEVEL_DEBUG= 19 | # CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y 20 | # CONFIG_LOG_DEFAULT_LEVEL=5 21 | 22 | # 23 | # SPI RAM config 24 | # 25 | CONFIG_SPIRAM_TYPE_AUTO=y 26 | # CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set 27 | # CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set 28 | # CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set 29 | CONFIG_SPIRAM_SIZE=-1 30 | # CONFIG_SPIRAM_SPEED_40M is not set 31 | CONFIG_SPIRAM_SPEED_80M=y 32 | CONFIG_SPIRAM=y 33 | CONFIG_SPIRAM_BOOT_INIT=y 34 | # CONFIG_SPIRAM_IGNORE_NOTFOUND is not set 35 | # CONFIG_SPIRAM_USE_MEMMAP is not set 36 | # CONFIG_SPIRAM_USE_CAPS_ALLOC is not set 37 | 38 | # Micropython default is to use CONFIG_SPIRAM_USE_MEMMAP where 39 | # the Micropython Heap is established based on memory address. 40 | # For examples using esp32-camera the code underneath needs to be able to use the 41 | # malloc with capabilities as it needs to be able to get dma memory 42 | # as well as allocate the framebuffer 43 | CONFIG_SPIRAM_USE_MALLOC=y 44 | CONFIG_SPIRAM_MEMTEST=y 45 | # CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384 46 | # CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is not set 47 | # CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768 48 | # CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set 49 | # CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY is not set 50 | CONFIG_SPIRAM_CACHE_WORKAROUND=y 51 | 52 | # FreeRTOS 53 | #CONFIG_FREERTOS_UNICORE=y 54 | CONFIG_SUPPORT_STATIC_ALLOCATION=y 55 | CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK=y 56 | 57 | # UDP 58 | CONFIG_PPP_SUPPORT=y 59 | CONFIG_PPP_PAP_SUPPORT=y 60 | CONFIG_PPP_CHAP_SUPPORT=y 61 | 62 | # ESP32-CAMERA 63 | CONFIG_OV2640_SUPPORT=y 64 | CONFIG_OV3660_SUPPORT=y 65 | -------------------------------------------------------------------------------- /boards/esp32/MICROLITE_SPIRAM_CAM/sdkconfig.partition: -------------------------------------------------------------------------------- 1 | #CONFIG_ESPTOOLPY_FLASHMODE_DIO=y 2 | #CONFIG_ESPTOOLPY_FLASHFREQ_40M=y 3 | #CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | # move back up from micropython/ports/esp32 to the main project source code 6 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../boards/esp32/MICROLITE/custom-partitions.csv" 7 | -------------------------------------------------------------------------------- /boards/rp2/ADAFRUIT_FEATHER_RP2040_MICROLITE/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level cmake file for building MicroPython on RP2040. 2 | # Nothing in here needs to be customised, it will work for any board. 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | 6 | # Set the location of MicroPython, the rp2 port, and the board directory. 7 | get_filename_component(PROJECT_DIR "../../.." ABSOLUTE) 8 | set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/rp2) 9 | get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE) 10 | 11 | message (STATUS "PROJECT_DIR=${PROJECT_DIR}") 12 | message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}") 13 | message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}") 14 | 15 | # Define the output sdkconfig so it goes in the build directory. 16 | set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) 17 | 18 | # Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options). 19 | include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) 20 | 21 | project(micropython) -------------------------------------------------------------------------------- /boards/rp2/ADAFRUIT_FEATHER_RP2040_MICROLITE/board.json: -------------------------------------------------------------------------------- 1 | { 2 | "deploy": [ 3 | "../deploy.md" 4 | ], 5 | "docs": "", 6 | "features": [ 7 | "Battery Charging", 8 | "Breadboard Friendly", 9 | "Feather", 10 | "RGB LED", 11 | "SPI Flash", 12 | "STEMMA QT/QWIIC", 13 | "USB-C" 14 | ], 15 | "images": [ 16 | "4884-06.jpg" 17 | ], 18 | "mcu": "rp2040", 19 | "product": "Feather RP2040", 20 | "thumbnail": "", 21 | "url": "https://www.adafruit.com/product/4884", 22 | "vendor": "Adafruit" 23 | } 24 | -------------------------------------------------------------------------------- /boards/rp2/ADAFRUIT_FEATHER_RP2040_MICROLITE/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include MicroPython RP2 component. 2 | 3 | get_filename_component(CURRENT_DIR "." ABSOLUTE) 4 | 5 | message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}") 6 | 7 | get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE) 8 | 9 | 10 | message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}") 11 | 12 | set(PROJECT_DIR ${MICROPY_DIR}/ports/rp2) 13 | include(${PROJECT_DIR}/main/CMakeLists.txt) -------------------------------------------------------------------------------- /boards/rp2/ADAFRUIT_FEATHER_RP2040_MICROLITE/mpconfigboard.cmake: -------------------------------------------------------------------------------- 1 | # cmake file for Adafruit Feather RP2040 2 | 3 | -------------------------------------------------------------------------------- /boards/rp2/ADAFRUIT_FEATHER_RP2040_MICROLITE/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | // https://www.adafruit.com/product/4884 2 | // https://learn.adafruit.com/adafruit-feather-rp2040-pico/pinouts 3 | 4 | #define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040 Microlite" 5 | #define MICROPY_HW_FLASH_STORAGE_BYTES (7 * 1024 * 1024) 6 | 7 | #define MICROPY_HW_USB_VID (0x239A) 8 | #define MICROPY_HW_USB_PID (0x80F2) 9 | 10 | // STEMMA QT / Qwiic on I2C1 11 | #define MICROPY_HW_I2C1_SCL (3) 12 | #define MICROPY_HW_I2C1_SDA (2) 13 | 14 | #define MICROPY_HW_SPI0_SCK (18) 15 | #define MICROPY_HW_SPI0_MOSI (19) 16 | #define MICROPY_HW_SPI0_MISO (20) 17 | 18 | // NeoPixel GPIO16, power not toggleable 19 | 20 | // Red user LED GPIO13 21 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for custom MicroPython stm32 board. 2 | 3 | ################################################################################ 4 | # Define your settings here. 5 | 6 | # The board name. 7 | BOARD ?= NUCLEO_H743ZI2_MICROLITE 8 | 9 | # Location of MicroPython repository. 10 | MICROPY_TOP ?= $(abspath ../../../micropython) 11 | 12 | ################################################################################ 13 | # Define your targets here. 14 | 15 | all: firmware 16 | 17 | ################################################################################ 18 | # Items below this line do not generally need to be changed. 19 | 20 | BOARD_DIR ?= $(abspath .) 21 | BUILD = $(BOARD_DIR)/build 22 | 23 | include $(MICROPY_TOP)/py/mkenv.mk 24 | include $(MICROPY_TOP)/py/mkrules.mk 25 | 26 | firmware: 27 | $(Q)$(MAKE) -C $(MICROPY_TOP)/ports/stm32 \ 28 | PROJECT_TOP=$(abspath ../..) \ 29 | BOARD=$(BOARD) \ 30 | BOARD_DIR=$(BOARD_DIR) \ 31 | BUILD=$(BUILD) 32 | 33 | 34 | deploy: 35 | $(PYTHON) $(MICROPY_TOP)/tools/pydfu.py -u $(BUILD)/firmware.dfu 36 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/board_init.c: -------------------------------------------------------------------------------- 1 | #include "boards/NUCLEO_H743ZI/board_init.c" 2 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | #include "boards/NUCLEO_H743ZI/mpconfigboard.h" 2 | 3 | #undef MICROPY_HW_BOARD_NAME 4 | #define MICROPY_HW_BOARD_NAME "NUCLEO_H743ZI2 MICROLITE" 5 | 6 | // The board has an external 32kHz crystal attached 7 | #undef MICROPY_HW_RTC_USE_LSE 8 | #define MICROPY_HW_RTC_USE_LSE (1) 9 | 10 | // There is no external HS crystal. 11 | // JP1 STLNK_RST will disable the incoming 8MHz clock 12 | // since it is derived from the STLINK's MCO output 13 | #undef MICROPY_HW_CLK_USE_BYPASS 14 | #define MICROPY_HW_CLK_USE_BYPASS (1) 15 | 16 | #undef MICROPY_HW_LED2 17 | #define MICROPY_HW_LED2 (pin_E1) // yellow 18 | 19 | // only when mboot is used 20 | // Define the user button for entering mboot 21 | #if defined(USE_MBOOT) 22 | #define MBOOT_BOOTPIN_PIN (pin_C13) 23 | #define MBOOT_BOOTPIN_PULL (MP_HAL_PIN_PULL_DOWN) 24 | #define MBOOT_BOOTPIN_ACTIVE (1) 25 | #endif 26 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | include boards/NUCLEO_H743ZI/mpconfigboard.mk 2 | 3 | USER_C_MODULES=../../../micropython-modules 4 | 5 | # when enabled this flag blows up the firware size and it won't fit 6 | # its a bit counter intuitive but keep this disabled to be able to git microlite into 7 | # flash 8 | MICROPY_ROM_TEXT_COMPRESSION = 0 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/openocd.cfg: -------------------------------------------------------------------------------- 1 | source [find board/st_nucleo_h743zi.cfg] 2 | 3 | reset_config srst_only srst_nogate connect_assert_srst 4 | 5 | $_CHIPNAME.cpu0 configure -event gdb-attach { 6 | echo "Debugger attaching: halting execution" 7 | gdb_breakpoint_override hard 8 | } 9 | 10 | $_CHIPNAME.cpu0 configure -event gdb-detach { 11 | echo "Debugger detaching: resuming execution" 12 | resume 13 | } 14 | 15 | # Due to the use of connect_assert_srst, running gdb requires 16 | # to reset halt just after openocd init. 17 | rename init old_init 18 | proc init {} { 19 | old_init 20 | reset halt 21 | } 22 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/pins.csv: -------------------------------------------------------------------------------- 1 | A0,PA3 2 | A1,PC0 3 | A2,PC3 4 | A3,PB1 5 | A4,PC2 6 | A5,PF10 7 | A6,PF4 8 | A7,PF5 9 | A8,PF6 10 | D0,PB7 11 | D1,PB6 12 | D2,PG14 13 | D3,PE13 14 | D4,PE14 15 | D5,PE11 16 | D6,PE9 17 | D7,PG12 18 | D8,PF3 19 | D9,PD15 20 | D10,PD14 21 | D11,PB5 22 | D12,PA6 23 | D13,PA7 24 | D14,PB9 25 | D15,PB8 26 | D16,PC6 27 | D17,PB15 28 | D18,PB13 29 | D19,PB12 30 | D20,PA15 31 | D21,PC7 32 | D22,PB5 33 | D23,PB3 34 | D24,PA4 35 | D25,PB4 36 | D26,PG6 37 | D27,PB2 38 | D28,PD13 39 | D29,PD12 40 | D30,PD11 41 | D31,PE2 42 | D32,PA0 43 | D33,PB0 44 | D34,PE0 45 | D35,PB11 46 | D36,PB10 47 | D37,PE15 48 | D38,PE6 49 | D39,PE12 50 | D40,PE10 51 | D41,PE7 52 | D42,PE8 53 | D43,PC8 54 | D44,PC9 55 | D45,PC10 56 | D46,PC11 57 | D47,PC12 58 | D48,PD2 59 | D49,PG2 60 | D50,PG3 61 | D51,PD7 62 | D52,PD6 63 | D53,PD5 64 | D54,PD4 65 | D55,PD3 66 | D56,PE2 67 | D57,PE4 68 | D58,PE5 69 | D59,PE6 70 | D60,PE3 71 | D61,PF8 72 | D62,PF7 73 | D63,PF9 74 | D64,PG1 75 | D65,PG0 76 | D66,PD1 77 | D67,PD0 78 | D68,PF0 79 | D69,PF1 80 | D70,PF2 81 | D71,PE9 82 | D72,PB2 83 | DAC1,PA4 84 | DAC2,PA5 85 | LED1,PB0 86 | LED2,PE1 87 | LED3,PB14 88 | SW,PC13 89 | I2C1_SDA,PB9 90 | I2C1_SCL,PB8 91 | I2C2_SDA,PF0 92 | I2C2_SCL,PF1 93 | I2C4_SCL,PF14 94 | I2C4_SDA,PF15 95 | SD_D0,PC8 96 | SD_D1,PC9 97 | SD_D2,PC10 98 | SD_D3,PC11 99 | SD_CMD,PD2 100 | SD_CK,PC12 101 | SD_SW,PG2 102 | OTG_FS_POWER,PD10 103 | OTG_FS_OVER_CURRENT,PG7 104 | USB_VBUS,PA9 105 | USB_ID,PA10 106 | USB_DM,PA11 107 | USB_DP,PA12 108 | UART2_TX,PD5 109 | UART2_RX,PD6 110 | UART2_RTS,PD4 111 | UART2_CTS,PD3 112 | UART3_TX,PD8 113 | UART3_RX,PD9 114 | UART5_TX,PB6 115 | UART5_RX,PB12 116 | UART6_TX,PC6 117 | UART6_RX,PC7 118 | UART7_TX,PF7 119 | UART7_RX,PF6 120 | UART8_TX,PE1 121 | UART8_RX,PE0 122 | ETH_MDC,PC1 123 | ETH_MDIO,PA2 124 | ETH_RMII_REF_CLK,PA1 125 | ETH_RMII_CRS_DV,PA7 126 | ETH_RMII_RXD0,PC4 127 | ETH_RMII_RXD1,PC5 128 | ETH_RMII_TX_EN,PG11 129 | ETH_RMII_TXD0,PG13 130 | ETH_RMII_TXD1,PB13 131 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/stm32h7xx_hal_conf.h: -------------------------------------------------------------------------------- 1 | #include "boards/NUCLEO_H743ZI/stm32h7xx_hal_conf.h" 2 | -------------------------------------------------------------------------------- /boards/stm32/NUCLEO_H743ZI2_MICROLITE/vs-code-preconfigure.sh: -------------------------------------------------------------------------------- 1 | echo "change cwd to: /home/mike/git/tensorflow-micropython-examples" 2 | cd /home/mike/git/tensorflow-micropython-examples 3 | 4 | source ~/.bashrc -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for custom MicroPython stm32 board. 2 | 3 | ################################################################################ 4 | # Define your settings here. 5 | 6 | # The board name. 7 | BOARD ?= SPARKFUN_THINGPLUS_STM32_MICROLITE 8 | 9 | # Location of MicroPython repository. 10 | MICROPY_TOP ?= $(abspath ../../../micropython) 11 | 12 | ################################################################################ 13 | # Define your targets here. 14 | 15 | all: firmware 16 | 17 | ################################################################################ 18 | # Items below this line do not generally need to be changed. 19 | 20 | BOARD_DIR ?= $(abspath .) 21 | BUILD = $(BOARD_DIR)/build 22 | 23 | include $(MICROPY_TOP)/py/mkenv.mk 24 | include $(MICROPY_TOP)/py/mkrules.mk 25 | 26 | firmware: 27 | $(Q)$(MAKE) -C $(MICROPY_TOP)/ports/stm32 \ 28 | PROJECT_TOP=$(abspath ../..) \ 29 | BOARD=$(BOARD) \ 30 | BOARD_DIR=$(BOARD_DIR) \ 31 | BUILD=$(BUILD) 32 | 33 | 34 | deploy: 35 | $(PYTHON) $(MICROPY_TOP)/tools/pydfu.py -u $(BUILD)/firmware.dfu 36 | -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/bdev.c: -------------------------------------------------------------------------------- 1 | #include "storage.h" 2 | 3 | #if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE 4 | 5 | // External SPI flash uses standard SPI interface 6 | 7 | STATIC const mp_soft_spi_obj_t soft_spi_bus = { 8 | .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY, 9 | .polarity = 0, 10 | .phase = 0, 11 | .sck = MICROPY_HW_SPIFLASH_SCK, 12 | .mosi = MICROPY_HW_SPIFLASH_MOSI, 13 | .miso = MICROPY_HW_SPIFLASH_MISO, 14 | }; 15 | 16 | STATIC mp_spiflash_cache_t spi_bdev_cache; 17 | 18 | const mp_spiflash_config_t spiflash_config = { 19 | .bus_kind = MP_SPIFLASH_BUS_SPI, 20 | .bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS, 21 | .bus.u_spi.data = (void*)&soft_spi_bus, 22 | .bus.u_spi.proto = &mp_soft_spi_proto, 23 | .cache = &spi_bdev_cache, 24 | }; 25 | 26 | spi_bdev_t spi_bdev; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/board.json: -------------------------------------------------------------------------------- 1 | { 2 | "deploy": [ 3 | "../deploy.md" 4 | ], 5 | "docs": "", 6 | "features": [], 7 | "images": [ 8 | "sparkfun_micromod_stm32.jpg" 9 | ], 10 | "mcu": "stm32f4", 11 | "product": "Micromod STM32", 12 | "thumbnail": "", 13 | "url": "", 14 | "vendor": "Sparkfun" 15 | } 16 | -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/board_init.c: -------------------------------------------------------------------------------- 1 | #include "py/mphal.h" 2 | 3 | void board_early_init(void) { 4 | 5 | #if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE 6 | // set external SPI flash CS pin high 7 | mp_hal_pin_output(MICROPY_HW_SPIFLASH_CS); 8 | mp_hal_pin_write(MICROPY_HW_SPIFLASH_CS, 1); 9 | #endif 10 | 11 | } 12 | -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/mpconfigboard.h: -------------------------------------------------------------------------------- 1 | // The Sparkfun MicroMod spec uses a zero-based peripheral numbering scheme. 2 | // In cases where the 0th peripheral is the default, the "0" is omitted from 3 | // the name (e.g. "I2C" instead of "I2C0"). 4 | // 5 | // Note: UART (UART0) is not present in the edge connector pinout because the 6 | // primary debug serial port is exposed as a virtual serial port over USB, 7 | // i.e. Serial.print() should print over USB VCP, not UART_TX1. 8 | // 9 | // For more details, see https://www.sparkfun.com/micromod#tech-specs 10 | 11 | #define MICROPY_HW_BOARD_NAME "SparkFun STM32 ThingPlus Microlite" 12 | #define MICROPY_HW_MCU_NAME "STM32F405RG" 13 | 14 | // 1 = use STM32 internal flash (1 MByte) 15 | // 0 = use onboard external SPI flash (16 MByte) 16 | #define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0) 17 | 18 | #define MICROPY_HW_HAS_FLASH (1) 19 | #define MICROPY_HW_ENABLE_RNG (1) 20 | #define MICROPY_HW_ENABLE_RTC (1) 21 | #define MICROPY_HW_ENABLE_DAC (1) 22 | #define MICROPY_HW_ENABLE_USB (1) 23 | 24 | // External SPI Flash config 25 | #if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE 26 | 27 | // 128 Mbit (16 MByte) external SPI flash 28 | #define MICROPY_HW_SPIFLASH_SIZE_BITS (128 * 1024 * 1024) 29 | 30 | #define MICROPY_HW_SPIFLASH_CS (pin_A15) 31 | #define MICROPY_HW_SPIFLASH_SCK (pin_B3) 32 | #define MICROPY_HW_SPIFLASH_MOSI (pin_B5) 33 | #define MICROPY_HW_SPIFLASH_MISO (pin_B4) 34 | 35 | #define MICROPY_BOARD_EARLY_INIT board_early_init 36 | void board_early_init(void); 37 | 38 | extern const struct _mp_spiflash_config_t spiflash_config; 39 | extern struct _spi_bdev_t spi_bdev; 40 | #define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1) 41 | #define MICROPY_HW_BDEV_IOCTL(op, arg) ( \ 42 | (op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_SIZE_BITS / 8 / FLASH_BLOCK_SIZE) : \ 43 | (op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \ 44 | spi_bdev_ioctl(&spi_bdev, (op), (arg)) \ 45 | ) 46 | #define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) spi_bdev_readblocks(&spi_bdev, (dest), (bl), (n)) 47 | #define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) spi_bdev_writeblocks(&spi_bdev, (src), (bl), (n)) 48 | #define MICROPY_HW_BDEV_SPIFLASH_EXTENDED (&spi_bdev) // for extended block protocol 49 | 50 | #endif // !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE 51 | 52 | // STM32 HSE config 53 | // The module has a 12 MHz crystal for the HSE oscillator. 54 | #define MICROPY_HW_CLK_PLLM (12) 55 | #define MICROPY_HW_CLK_PLLN (336) 56 | #define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2) 57 | #define MICROPY_HW_CLK_PLLQ (7) 58 | #define MICROPY_HW_CLK_LAST_FREQ (1) 59 | 60 | // STM32 LSE config 61 | // The module has a 32.768 kHz crystal for the LSE (RTC). 62 | #define MICROPY_HW_RTC_USE_LSE (1) 63 | #define MICROPY_HW_RTC_USE_US (0) 64 | #define MICROPY_HW_RTC_USE_CALOUT (1) 65 | 66 | // UART1 config (MicroMod UART1) 67 | #define MICROPY_HW_UART1_NAME "UART1" 68 | #define MICROPY_HW_UART1_TX (pin_A2) 69 | #define MICROPY_HW_UART1_RX (pin_A3) 70 | 71 | // CAN1 config (MicroMod CAN) 72 | #define MICROPY_HW_CAN1_NAME "CAN" 73 | #define MICROPY_HW_CAN1_TX (pin_B9) 74 | #define MICROPY_HW_CAN1_RX (pin_B8) 75 | 76 | // I2C1 config (MicroMod I2C) 77 | #define MICROPY_HW_I2C1_NAME "I2C" 78 | #define MICROPY_HW_I2C1_SCL (pin_B10) 79 | #define MICROPY_HW_I2C1_SDA (pin_B11) 80 | 81 | // I2C2 config (MicroMod I2C1) 82 | #define MICROPY_HW_I2C2_NAME "I2C1" 83 | #define MICROPY_HW_I2C2_SCL (pin_B6) 84 | #define MICROPY_HW_I2C2_SDA (pin_B7) 85 | 86 | // SPI1 config (MicroMod SPI) 87 | #define MICROPY_HW_SPI1_NAME "SPI" 88 | #define MICROPY_HW_SPI1_NSS (pin_C4) 89 | #define MICROPY_HW_SPI1_SCK (pin_A5) 90 | #define MICROPY_HW_SPI1_MISO (pin_A6) 91 | #define MICROPY_HW_SPI1_MOSI (pin_A7) 92 | 93 | // LED1 config 94 | // The module has a single blue status LED. 95 | #define MICROPY_HW_LED1 (pin_C1) 96 | #define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin)) 97 | #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) 98 | 99 | // USB device config 100 | #define MICROPY_HW_USB_FS (1) 101 | -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = f4 2 | CMSIS_MCU = STM32F405xx 3 | AF_FILE = boards/stm32f405_af.csv 4 | ifeq ($(USE_MBOOT),1) 5 | # When using Mboot all the text goes together after the filesystem 6 | LD_FILES = boards/stm32f405.ld boards/common_blifs.ld 7 | TEXT0_ADDR = 0x08020000 8 | else 9 | # When not using Mboot the ISR text goes first, then the rest after the filesystem 10 | LD_FILES = boards/stm32f405.ld boards/common_blifs.ld 11 | TEXT0_ADDR = 0x08000000 12 | TEXT1_ADDR = 0x08020000 13 | endif 14 | 15 | # MicroPython settings 16 | MICROPY_VFS_LFS2 = 1 17 | 18 | # when enabled this flag blows up the firware size and it won't fit 19 | # its a bit counter intuitive but keep this disabled to be able to git microlite into 20 | # flash 21 | MICROPY_ROM_TEXT_COMPRESSION = 0 22 | 23 | USER_C_MODULES=../../../micropython-modules 24 | -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/pins.csv: -------------------------------------------------------------------------------- 1 | G2,PA0 2 | BUS2,PA0 3 | BATT_SENSE,PA1 4 | UART_TX1,PA2 5 | UART_RX1,PA3 6 | AUD_LRCLK,PA4 7 | SPI_SCK,PA5 8 | SPI_MISO,PA6 9 | SPI_CIPO,PA6 10 | SPI_MOSI,PA7 11 | SPI_COPI,PA7 12 | G1,PA8 13 | BUS1,PA8 14 | USB_DN,PA11 15 | USB_DP,PA12 16 | SWDIO,PA13 17 | SWDCK,PA14 18 | STATUS_LED,PA15 19 | A1,PB0 20 | I2C_INT,PB1 21 | AUD_BCLK,PB3 22 | AUD_OUT,PB4 23 | AUD_IN,PB5 24 | I2C_SCL1,PB6 25 | I2C_SDA1,PB7 26 | CAN_RX,PB8 27 | CAN_TX,PB9 28 | I2C_SCL,PB10 29 | I2C_SDA,PB11 30 | USB_HOST_ID,PB12 31 | G11,PB12 32 | USB_HOST_VBUS,PB13 33 | G10,PB13 34 | USB_HOST_DN,PB14 35 | USB_HOST_DP,PB15 36 | D0,PC0 37 | D1,PC1 38 | G6,PC2 39 | BUS6,PC2 40 | SPI_FLASH_CS,PC3 41 | SPI_CS,PC4 42 | A0,PC5 43 | PWM0,PC6 44 | PWM1,PC7 45 | G3,PC8 46 | BUS3,PC8 47 | G4,PC9 48 | BUS4,PC9 49 | SPI_FLASH_SCK,PC10 50 | SPI_FLASH_MISO,PC11 51 | SPI_FLASH_MOSI,PC12 52 | G5,PC13 53 | BUS5,PC13 54 | OSC32_IN,PC14 55 | OSC32_OUT,PC15 56 | G0,PD2 57 | BUS0,PD2 58 | -------------------------------------------------------------------------------- /boards/stm32/SPARKFUN_THINGPLUS_MICROLITE/stm32f4xx_hal_conf.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the MicroPython project, http://micropython.org/ 2 | * The MIT License (MIT) 3 | * Copyright (c) 2019 Damien P. George 4 | */ 5 | #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H 6 | #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H 7 | 8 | #include "boards/stm32f4xx_hal_conf_base.h" 9 | 10 | // Oscillator values in Hz 11 | #define HSE_VALUE (12000000) 12 | #define LSE_VALUE (32768) 13 | #define EXTERNAL_CLOCK_VALUE (12288000) 14 | 15 | // Oscillator timeouts in ms 16 | #define HSE_STARTUP_TIMEOUT (100) 17 | #define LSE_STARTUP_TIMEOUT (5000) 18 | 19 | #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H 20 | -------------------------------------------------------------------------------- /boards/unix/microlite-variant/mpconfigvariant.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2019 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #define MICROPY_PY_BUILTINS_HELP (1) 28 | #define MICROPY_PY_BUILTINS_HELP_MODULES (1) 29 | -------------------------------------------------------------------------------- /boards/unix/microlite-variant/mpconfigvariant.mk: -------------------------------------------------------------------------------- 1 | # This is the default variant when you `make` the Unix port. 2 | 3 | PROG ?= micropython 4 | 5 | USER_C_MODULES=../../../micropython-modules 6 | 7 | MICROPY_PY_FFI=0 8 | 9 | LDFLAGS_EXTRA=-static 10 | 11 | CFLAGS_EXTRA=-Wno-error=unused-function -Wno-error=maybe-uninitialized 12 | 13 | -------------------------------------------------------------------------------- /build-tensorflow-lite-micro.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd tensorflow 4 | 5 | # These CFLAGS came from looking at what the Micropython c++ build was emitting. 6 | make -f tensorflow/lite/micro/tools/make/Makefile \ 7 | CXXFLAGS="-std=c++11 -DNDEBUG -fstrict-volatile-bitfields -mlongcalls -nostdlib -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -O3 -Werror -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DESP -Wno-return-type -Wno-strict-aliasing -Wno-ignored-qualifiers -Wno-return-type -Wno-strict-aliasing" \ 8 | TARGET_TOOLCHAIN_PREFIX=xtensa-esp32-elf- TARGET=esp TARGET_ARCH=xtensa-esp32 $@ 9 | 10 | #tensorflow/lite/micro/tools/make/gen/esp32_xtensawin/lib/libtensorflow-microlite.a 11 | -------------------------------------------------------------------------------- /build-with-docker-idf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DOCKER_IMAGE=$1 4 | 5 | if test -z "$DOCKER_IMAGE"; then 6 | DOCKER_IMAGE=espressif/idf:release-v4.2 7 | fi 8 | 9 | winpty docker run -i -t -v /$(pwd):/src $DOCKER_IMAGE bash 10 | 11 | -------------------------------------------------------------------------------- /build-with-unix-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DOCKER_IMAGE=$1 4 | 5 | if test -z "$DOCKER_IMAGE"; then 6 | # need to build the docker/unix-build image first 7 | DOCKER_IMAGE=unix-build 8 | fi 9 | 10 | winpty docker run -i -t -v /$(pwd):/src --entrypoint "bash" $DOCKER_IMAGE 11 | 12 | -------------------------------------------------------------------------------- /ci/build_micropython_esp32_microlite_spiram_16m.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The TensorFlow Micropython Examples rs. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ============================================================================== 15 | # 16 | # Tests the microcontroller code for esp32 platform 17 | 18 | set -e 19 | 20 | BASE_DIR=/opt/tflite-micro-micropython 21 | 22 | cd $BASE_DIR/micropython 23 | 24 | pwd 25 | 26 | echo "make -C mpy-cross V=1 clean all" 27 | make -C mpy-cross V=1 clean all 28 | 29 | echo "cd $BASE_DIR/boards/esp32/MICROLITE_SPIRAM_16M" 30 | cd $BASE_DIR/boards/esp32/MICROLITE_SPIRAM_16M 31 | 32 | pwd 33 | 34 | echo "Building MICROLITE_SPIRAM_16M" 35 | rm -rf build 36 | idf.py clean build 37 | -------------------------------------------------------------------------------- /ci/build_micropython_stm32_microlite.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The TensorFlow Micropython Examples rs. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ============================================================================== 15 | # 16 | # Tests the microcontroller code for stm32 platform 17 | 18 | set -e 19 | 20 | BASE_DIR=/opt/tflite-micro-micropython 21 | 22 | python3 ./tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \ 23 | --makefile_options="TARGET=cortex_m_generic TARGET_ARCH=project_generation OPTIMIZED_KERNEL_DIR=cmsis_nn" \ 24 | --examples micro_speech --rename-cc-to-cpp $BASE_DIR/micropython-modules/microlite/tflm 25 | 26 | cd $BASE_DIR/tensorflow 27 | 28 | # get the dependencies needed by 29 | make -f tensorflow/lite/micro/tools/make/Makefile third_party_downloads 30 | 31 | 32 | mkdir $BASE_DIR/c-modules 33 | 34 | cd $BASE_DIR/c-modules 35 | 36 | ln -s ../micropython-ulab/code ulab 37 | ln -s ../micropython-modules/microlite microlite 38 | 39 | cd $BASE_DIR/micropython/ports/stm32 40 | 41 | pwd 42 | 43 | make V=1 submodules 44 | 45 | 46 | cd $BASE_DIR/micropython 47 | 48 | echo "make -C mpy-cross V=1 clean all" 49 | make -C mpy-cross V=1 clean all 50 | 51 | 52 | echo "cd $BASE_DIR/boards/esp32/MICROLITE" 53 | cd $BASE_DIR/boards/stm32/NUCLEO_H743ZI2_MICROLITE 54 | 55 | pwd 56 | 57 | echo "Building NUCLEO_H743ZI2_MICROLITE" 58 | rm -rf build 59 | make V=1 60 | -------------------------------------------------------------------------------- /ci/setup_esp32.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function ci_setup_microlite { 4 | 5 | pip3 install Pillow 6 | pip3 install Wave 7 | 8 | } -------------------------------------------------------------------------------- /custom-partitions.csv: -------------------------------------------------------------------------------- 1 | # Notes: the offset of the partition table itself is set in 2 | # $ESPIDF/components/partition_table/Kconfig.projbuild and the 3 | # offset of the factory/ota_0 partition is set in makeimg.py 4 | # I needed to increase the size of the app partition to fit the tensorflow microlite library 5 | # There is 1/2 as much data partition as with standard micropython on esp32 4MiB. 6 | # Name, Type, SubType, Offset, Size, Flags 7 | nvs, data, nvs, 0x9000, 0x6000, 8 | phy_init, data, phy, 0xf000, 0x1000, 9 | factory, app, factory, 0x10000, 0x280000, 10 | vfs, data, fat, 0x300000, 0x100000, 11 | -------------------------------------------------------------------------------- /docker/arm-build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:unstable-slim 2 | 3 | RUN apt-get update && apt-get install -y python3 python3-pip 4 | 5 | RUN apt-get update && apt-get install -y vim wget unzip git 6 | 7 | RUN apt-get update && apt-get install -y curl 8 | 9 | RUN pip install Pillow 10 | 11 | #RUN cd /tmp && wget --no-verbose https://adafruit-circuit-python.s3.amazonaws.com/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 12 | #RUN tar -C /usr --strip-components=1 -xaf /tmp/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 13 | 14 | RUN pip install mbed-cli 15 | -------------------------------------------------------------------------------- /docker/arm-build/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker build -t arm-build . 3 | -------------------------------------------------------------------------------- /docker/esp32-build/README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED 2 | 3 | Please use the espressif/idf public image to build tensorflow and the custom micropython firmware. 4 | 5 | -------------------------------------------------------------------------------- /docker/unix-build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM madduci/docker-linux-cpp 2 | 3 | RUN apt-get update && apt-get install -y make pkg-config git && rm -rf /var/cache/apt/* && ln -s /usr/bin/g++-9 /usr/bin/g++ 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/hello-world/README.md: -------------------------------------------------------------------------------- 1 | # Tensorflow Lite for Microcontrollers Hello World Example 2 | 3 | The hello-world example generates an approximate sine wave 4 | https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world 5 | 6 | ![](../../images/hello-world-output-chart.png) 7 | 8 | You provide an x value and then the model predicts what the y value should be. The model in this case 9 | has been trained to return a sine wave shape. 10 | 11 | The C++ version shows how you can convert from float to int8 on the input tensor and int8 to float on 12 | the output tensor. At the moment there are equivelant methods but you need to invoke manually. 13 | I may be able to [automatically quantitize](https://github.com/mocleiri/tensorflow-micropython-examples/issues/6) because we can know the tensor type and the current 14 | micropython type. 15 | 16 | # Model Architecture 17 | 18 | ![](images/model_architecture.png) 19 | 20 | ## Unix Port 21 | 22 | Download the micropython binary from the latest unix port build: 23 | https://github.com/mocleiri/tensorflow-micropython-examples/actions/workflows/build_unix.yml 24 | (click on the most successful, then scroll down to download the build artifact) 25 | 26 | Run in the root of this project and invoke the hello_world.py script: 27 | ``` 28 | micropython examples/hello-world/hello_world.py 29 | time step,y 30 | 6.283185,-0.110136 31 | 12.566371,-0.110136 32 | 18.849556,-0.110136 33 | 25.132741,-0.127080 34 | 31.415927,-0.127080 35 | 37.699112,-0.127080 36 | 43.982297,-0.169440 37 | 50.265482,-0.169440 38 | 56.548668,-0.169440 39 | ... 40 | ``` 41 | 42 | If you cut and paste these values into google spreadsheets then you can make a chart like the one shown 43 | above. 44 | 45 | ## Esp32 Port 46 | Download the micropython firmware for your esp32 board: 47 | https://github.com/mocleiri/tensorflow-micropython-examples/actions/workflows/build_esp32.yml 48 | (click on the most successful, then scroll down to download the build artifact) 49 | 50 | From examples/hello-world copy the following to the root file system of your board: 51 | 1. model.tflite 52 | 2. hello_world.py 53 | 3. in main.py add an import hello_world 54 | 55 | ## RP2 Port 56 | 57 | Download the micropython firmware for your rp2 board: 58 | https://github.com/mocleiri/tensorflow-micropython-examples/actions/workflows/build_rp2.yml 59 | (click on the most successful, then scroll down to download the build artifact) 60 | 61 | From examples/hello-world copy the following to the root file system of your board: 62 | 1. model.tflite 63 | 2. hello_world.py 64 | 3. in main.py add an import hello_world 65 | 66 | ![](../../images/rp2-hello-world.png) 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /examples/hello-world/hello_world.py: -------------------------------------------------------------------------------- 1 | # Microlite implementation of the tensorflow hello-world example 2 | # https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/hello_world 3 | import microlite 4 | import io 5 | 6 | counter = 1 7 | 8 | kXrange = 2.0 * 3.14159265359 9 | steps = 1000 10 | current_input = None 11 | 12 | 13 | def input_callback (microlite_interpreter): 14 | 15 | global current_input 16 | 17 | inputTensor = microlite_interpreter.getInputTensor(0) 18 | 19 | # print (inputTensor) 20 | 21 | position = counter*1.0 22 | 23 | # print ("position %f" % position) 24 | 25 | x = position * kXrange/steps 26 | 27 | current_input = x 28 | # print ("x: %f, " % x) 29 | 30 | x_quantized = inputTensor.quantizeFloatToInt8(x) 31 | 32 | inputTensor.setValue(0, x_quantized) 33 | 34 | def output_callback (microlite_interpreter): 35 | global current_input 36 | # print ("output callback") 37 | 38 | outputTensor = microlite_interpreter.getOutputTensor(0) 39 | 40 | # print (outputTensor) 41 | 42 | y_quantized = outputTensor.getValue(0) 43 | 44 | y = outputTensor.quantizeInt8ToFloat(y_quantized) 45 | 46 | print ("%f,%f" % (current_input,y)) 47 | 48 | hello_world_model = bytearray(2488) 49 | 50 | model_file = io.open('model.tflite', 'rb') 51 | 52 | model_file.readinto(hello_world_model) 53 | 54 | model_file.close() 55 | 56 | interp = microlite.interpreter(hello_world_model,2048, input_callback, output_callback) 57 | 58 | print ("time step,y") 59 | for c in range(steps): 60 | interp.invoke() 61 | counter = counter + 1 62 | -------------------------------------------------------------------------------- /examples/hello-world/images/model_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/hello-world/images/model_architecture.png -------------------------------------------------------------------------------- /examples/hello-world/model.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/hello-world/model.tflite -------------------------------------------------------------------------------- /examples/micro-speech/README.md: -------------------------------------------------------------------------------- 1 | # Tensorflow Lite for Microcontrollers Micro Speech Example 2 | 3 | The micro-speech example runs an example trained on the [Speech Commands Version 2 Dataset](https://www.tensorflow.org/datasets/catalog/speech_commands). 4 | 5 | Scores above 200 are considered a match. 6 | 7 | # Model Architecture 8 | 9 | ![](images/model_architecture.png) 10 | 11 | It has been trained to detect four possible classes of output, each with a score: 12 | 13 | 14 | | Index | Category | 15 | | --- |----------| 16 | | 0 | Silence | 17 | | 1 | Unknown | 18 | | 2 | Yes | 19 | | 3 | No | 20 | 21 | scores over 200 are considered a match. 22 | 23 | # Audio Preprocessing 24 | 25 | ![spectrogram diagram](https://storage.googleapis.com/download.tensorflow.org/example_images/spectrogram_diagram.png) 26 | 27 | The microlite.audio_frontend type wraps the tensorflow lite experimental audio frontend which is used to create 28 | the spectogram data. 29 | 30 | The spectrogram data is what is fed into the input layer of the machine learning model. 31 | 32 | # Additional Classes 33 | 34 | The micro_speech.py file is a micropython script that handles some of the tasks that were done in c++ in the upstream 35 | example. 36 | 37 | The **FeatureData** class holds 49 **Slices**. Each slice is 30ms of the last second of audio that has been 38 | converted into a spectrogram. 39 | 40 | The FeatureData.segmentAudio takes an audio buffer and cuts it up into slices. 41 | 42 | When inferences runs several times a second it copies the spectrogram data for those 49 slices into the input 43 | tensor. 44 | 45 | Just like in the C++ reference implementation we only replace as many slices as are covered by the length of the audio 46 | buffer passed in. 47 | 48 | We are not repeatedly converting the 49 slices from audio to spectrogram; at any time we only create the new slices and 49 | then use that plus the previously converted data to feed the input tensor. 50 | 51 | In main.py the **Results** class is used to keep score for the previously matched values. The upstream example 52 | expects several inferences per second and reports a match if the last few matches have an averrage score over 200 in one 53 | category (yes, no, silence, unknown). 54 | 55 | The micropython implementation is able to work when we find a single score over 200. In which case we throw away the 56 | FeatureData slices and start frmo scratch again. 57 | 58 | The output tensor has 4 values which rank its prediction of the four classes: 59 | 60 | | Index | Category | 61 | | --- |----------| 62 | | 0 | Silence | 63 | | 1 | Unknown | 64 | | 2 | Yes | 65 | | 3 | No | 66 | 67 | # Working Examples 68 | 69 | [ESP32](esp32/README.md), [RP2040](rp2/README.md). 70 | 71 | # Tensorflow Micro C++ Micro_Speech Example 72 | 73 | This is the [tflite-micro c++ micro_speech example](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/micro_speech/README.md) in tensorflow micro 74 | 75 | -------------------------------------------------------------------------------- /examples/micro-speech/data/no-16khz-2sec.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/data/no-16khz-2sec.wav -------------------------------------------------------------------------------- /examples/micro-speech/data/no-8khz-2sec.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/data/no-8khz-2sec.wav -------------------------------------------------------------------------------- /examples/micro-speech/data/one_two_three-16khz-2sec.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/data/one_two_three-16khz-2sec.wav -------------------------------------------------------------------------------- /examples/micro-speech/data/one_two_three-8khz-2sec.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/data/one_two_three-8khz-2sec.wav -------------------------------------------------------------------------------- /examples/micro-speech/data/yes-16khz-2sec.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/data/yes-16khz-2sec.wav -------------------------------------------------------------------------------- /examples/micro-speech/data/yes-8khz-2sec.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/data/yes-8khz-2sec.wav -------------------------------------------------------------------------------- /examples/micro-speech/esp32/README.md: -------------------------------------------------------------------------------- 1 | # Demo 2 | 3 | [![Watch the micro speech video](https://img.youtube.com/vi/FBUwIvzNVd4/default.jpg)](https://youtu.be/FBUwIvzNVd4) 4 | 5 | # Setup 6 | 7 | Using a single INMP441 Microphone: 8 | 9 | | Wire | ESP32 Pin | INMP441 Pin | 10 | |----|----| --- | 11 | | RED | 3v3 | VDD | 12 | | WHITE | GND | GND | 13 | | YELLOW | D18 (GPIO 18) | WS| 14 | | GREEN | D19 (GPIO 19) | SCK | 15 | | PURPLE | D23 (GPIO 23) | SD | 16 | | BLUE | GND | L/R | 17 | 18 | The blue wire pulls L/R low and activates the left 19 | channel. 20 | 21 | ## ESP32 Pinout 22 | ![](../../../images/esp32-micro-speech-board-setup.png) 23 | 24 | ## INMP441 Pinout 25 | ![](../../../images/esp32-micro-speech-inmp441-setup.png) 26 | 27 | ## I2S Configuration Block 28 | 29 | ```python 30 | 31 | # Green Wire 32 | bck_pin = Pin(19) 33 | 34 | # Yellow Wire 35 | ws_pin = Pin(18) 36 | 37 | # Purple Wire 38 | sdin_pin = Pin(23) 39 | 40 | audio_in = I2S(0, 41 | sck=bck_pin, 42 | ws=ws_pin, 43 | sd=sdin_pin, 44 | mode=I2S.RX, 45 | bits=16, 46 | format=I2S.MONO, 47 | rate=16000, 48 | ibuf=16000 49 | ) 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /examples/micro-speech/images/model_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/images/model_architecture.png -------------------------------------------------------------------------------- /examples/micro-speech/lib/mic_left_channel_16bits.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/lib/mic_left_channel_16bits.wav -------------------------------------------------------------------------------- /examples/micro-speech/lib/micro_speech.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | import audio_frontend 4 | from ulab import numpy as np 5 | 6 | audio_frontend.configure() 7 | 8 | # The size of the input time series data we pass to the FFT to produce the 9 | # frequency information. This has to be a power of two, and since we're dealing 10 | # with 30ms of 16KHz inputs, which means 480 samples, this is the next value. 11 | kMaxAudioSampleSize = 512 12 | kAudioSampleFrequency = 16000 13 | 14 | kAudioOneMsSize = 16 15 | 16 | # The following values are derived from values used during model training. 17 | # If you change the way you preprocess the input, update all these constants. 18 | kFeatureSliceSize = 40 19 | kFeatureSliceCount = 49 20 | kFeatureElementCount = (kFeatureSliceSize * kFeatureSliceCount) 21 | kFeatureSliceStrideMs = 20 22 | kFeatureSliceDurationMs = 30 23 | 24 | stride_size = kFeatureSliceStrideMs * kAudioOneMsSize 25 | 26 | window_size = kFeatureSliceDurationMs * kAudioOneMsSize 27 | 28 | class Slice: 29 | 30 | def __init__(self, segment, start_index): 31 | # self.segment = segment 32 | if segment.size() != 480: 33 | raise ValueError ("Expected segment to be 480 bytes, was %d." % (segment.size())) 34 | 35 | self.spectrogram = audio_frontend.execute(segment) 36 | self.start_index = start_index 37 | 38 | def getSpectrogram(self): 39 | return self.spectrogram 40 | 41 | class FeatureData: 42 | 43 | def __init__(self, tf_interp): 44 | self.slices=[] 45 | self.totalSlices = 0 46 | self.tf_interp = tf_interp 47 | 48 | def addSlice(self, slice): 49 | 50 | self.totalSlices = self.totalSlices + 1 51 | 52 | self.slices.append(slice) 53 | 54 | if len (self.slices) > 49: 55 | self.slices.pop(0) 56 | 57 | 58 | # self.tf_interp.invoke() 59 | 60 | 61 | 62 | # print ("total slices = %d\n" % self.totalSlices) 63 | # print ("addSlice(): spectrogram length = %d\n" % spectrogram.size()) 64 | # print (spectrogram) 65 | 66 | 67 | def setInputTensorValues(self, inputTensor): 68 | 69 | # print (inputTensor) 70 | 71 | counter = 0 72 | 73 | for slice_index in range(len(self.slices)): 74 | 75 | slice = self.slices[slice_index] 76 | 77 | for spectrogram_index in range (slice.spectrogram.size()): 78 | 79 | inputTensor.setValue(counter, slice.spectrogram[spectrogram_index]) 80 | counter = counter + 1 81 | 82 | 83 | 84 | # set 1960 values on input tensor 85 | # print ("set %d values on input tensor\n" % (counter)) 86 | 87 | def segmentAudio(featureData, audio, trailing_10ms): 88 | # In this example we have an array of 1 second of audio data. 89 | # This is a 16,000 element array. 90 | # each micro second is 16 elements in this array. 91 | # the stride is how far over we adjust the start of the window on each step 92 | # in this example it is 20 ms (20x16=320). 93 | # The width of the window for which we capture the spectogram is 30ms (16x30=480). 94 | # this function will turn the input array into a dictionary of start time to wav data 95 | 96 | 97 | input_audio = np.concatenate((trailing_10ms, audio), axis=0) 98 | 99 | input_size = input_audio.size() 100 | 101 | total_segments = math.floor(input_size / stride_size) 102 | 103 | start_index = 0 104 | 105 | for segment_index in range (total_segments): 106 | 107 | end_index = min (start_index + window_size, input_size) 108 | 109 | # print ("segment_index=%d,start_index=%d, end_index=%d, size=%d\n" % (segment_index, start_index, end_index, end_index-start_index)) 110 | 111 | slice = Slice (input_audio[start_index:end_index], start_index) 112 | 113 | featureData.addSlice(slice) 114 | 115 | start_index = start_index + stride_size 116 | 117 | # return the trailing 10ms 118 | return np.array(input_audio[input_size-160:input_size], dtype=np.int16) 119 | 120 | 121 | -------------------------------------------------------------------------------- /examples/micro-speech/lib/model.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/lib/model.tflite -------------------------------------------------------------------------------- /examples/micro-speech/lib/no-example.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/lib/no-example.wav -------------------------------------------------------------------------------- /examples/micro-speech/lib/yes-example.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/lib/yes-example.wav -------------------------------------------------------------------------------- /examples/micro-speech/rp2/README.md: -------------------------------------------------------------------------------- 1 | # Demo 2 | 3 | [![Watch the micro speech video](https://img.youtube.com/vi/MK8A4Kt1haU/default.jpg)](https://youtu.be/MK8A4Kt1haU) 4 | 5 | 6 | # Setup 7 | 8 | Using a single INMP441 Microphone: 9 | 10 | | Wire | RP2 Pin | INMP441 Pin | 11 | |----|---------| --- | 12 | | RED | 3v3 | VDD | 13 | | WHITE | GND | GND | 14 | | YELLOW | GPIO 12 | WS| 15 | | GREEN | GPIO 11 | SCK | 16 | | PURPLE | GPIO 13 | SD | 17 | | BLUE | GND | L/R | 18 | 19 | The blue wire pulls L/R low and activates the left 20 | channel. 21 | 22 | ## Feather 2040 Pinout 23 | ![](images/feather-rp2040-pinout.png) 24 | 25 | ## Feather 2040 Wiring 26 | ![](images/rp2-micro-speech-board-setup.png) 27 | 28 | 29 | ## INMP441 Pinout 30 | ![](../../../images/esp32-micro-speech-inmp441-setup.png) 31 | 32 | ## I2S Configuration Block 33 | 34 | ```python 35 | 36 | # Green Wire 37 | bck_pin = Pin(11) 38 | 39 | # Yellow Wire 40 | ws_pin = Pin(12) 41 | 42 | # Purple Wire 43 | sdin_pin = Pin(13) 44 | 45 | audio_in = I2S( 46 | 0, 47 | sck=bck_pin, 48 | ws=ws_pin, 49 | sd=sdin_pin, 50 | mode=I2S.RX, 51 | bits=16, 52 | format=I2S.MONO, 53 | rate=16000, 54 | ibuf=9600 55 | ) 56 | ``` 57 | 58 | -------------------------------------------------------------------------------- /examples/micro-speech/rp2/images/feather-rp2040-pinout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/rp2/images/feather-rp2040-pinout.png -------------------------------------------------------------------------------- /examples/micro-speech/rp2/images/rp2-micro-speech-board-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/rp2/images/rp2-micro-speech-board-setup.png -------------------------------------------------------------------------------- /examples/micro-speech/rp2/images/rp2-running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/rp2/images/rp2-running.png -------------------------------------------------------------------------------- /examples/micro-speech/unix/main.py: -------------------------------------------------------------------------------- 1 | # 2 | # For microspeech in unix we need to use a wav sample to invoke the tensorflow model 3 | import micro_speech 4 | from ulab import numpy as np 5 | import microlite 6 | import io 7 | import no_1000ms_sample_data 8 | import yes_1000ms_sample_data 9 | 10 | micro_speech_model = bytearray(18712) 11 | 12 | model_file = io.open('model.tflite', 'rb') 13 | 14 | model_file.readinto(micro_speech_model) 15 | 16 | model_file.close() 17 | 18 | currentFeatureData = None 19 | 20 | def input_callback (microlite_interpreter): 21 | 22 | # print ("input callback") 23 | # can't print the tensor directly because it is not an mp_obj_t 24 | # we probably need to define a container object that will hold the TfLiteTensor pointer 25 | # we may be able to put the pointer directly as a field in the interpreter class 26 | # print (input_tensor) 27 | 28 | inputTensor = microlite_interpreter.getInputTensor(0) 29 | 30 | currentFeatureData.setInputTensorValues(inputTensor) 31 | 32 | 33 | 34 | kSilenceIndex = 0 35 | kUnknownIndex = 1 36 | kYesIndex = 2 37 | kNoIndex = 3 38 | 39 | resultLabel = {} 40 | 41 | resultLabel[0] = "Silence" 42 | resultLabel[1] = "Unknown" 43 | resultLabel[2] = "Understood Yes" 44 | resultLabel[3] = "Understood No" 45 | 46 | inferenceResult = {} 47 | 48 | def maxIndex (): 49 | 50 | maxValue = 0 51 | maxIndex = 0 52 | 53 | for index in range (4): 54 | value = inferenceResult[index] 55 | 56 | if (value > maxValue): 57 | maxValue = value 58 | maxIndex = index 59 | 60 | print ("maxIndex=%d,maxValue=%d\n" %(maxIndex, maxValue)) 61 | 62 | return maxIndex 63 | 64 | def output_callback (microlite_interpreter): 65 | # print ("output callback") 66 | 67 | outputTensor = microlite_interpreter.getOutputTensor(0) 68 | 69 | # we expect there to be a category 70 | 71 | for index in range (4): 72 | result = outputTensor.getValue(index) 73 | print ("results at %d = result = %d\n" % (index, result)) 74 | inferenceResult[index] = result 75 | 76 | 77 | af = microlite.audio_frontend() 78 | 79 | af.configure() 80 | 81 | 82 | interp = microlite.interpreter(micro_speech_model,20480, input_callback, output_callback) 83 | 84 | 85 | no_pcm_input = no_1000ms_sample_data.no_1000ms_array 86 | 87 | print ("Process 'No' input of length = %d\n" % (len (no_pcm_input))) 88 | 89 | noFeatureData = micro_speech.FeatureData(interp) 90 | 91 | trailing_10ms = np.zeros(160, dtype=np.int16) 92 | 93 | trailing_10ms = micro_speech.segmentAudio(noFeatureData, no_pcm_input, trailing_10ms) 94 | 95 | currentFeatureData = noFeatureData 96 | 97 | interp.invoke() 98 | 99 | foundIndex = maxIndex() 100 | 101 | if foundIndex != kNoIndex: 102 | raise ValueError("Error: Expected inference to match the 1 second no sample to no.\n") 103 | 104 | 105 | print (resultLabel[foundIndex]) 106 | 107 | print ("\n\n") 108 | 109 | yes_pcm_input = yes_1000ms_sample_data.yes_1000ms_array 110 | 111 | print ("Process 'Yes' input of length = %d\n" % (len (yes_pcm_input))) 112 | 113 | yesFeatureData = micro_speech.FeatureData(interp) 114 | 115 | trailing_10ms = np.zeros(160, dtype=np.int16) 116 | 117 | micro_speech.segmentAudio(yesFeatureData, yes_pcm_input, trailing_10ms) 118 | 119 | currentFeatureData = yesFeatureData 120 | 121 | interp.invoke() 122 | 123 | foundIndex = maxIndex() 124 | 125 | if foundIndex != kYesIndex: 126 | raise ValueError("Error: Expected inference to match the 1 second yes sample to yes.\n") 127 | 128 | 129 | print (resultLabel[foundIndex]) 130 | 131 | print ("\n\n") 132 | 133 | -------------------------------------------------------------------------------- /examples/micro-speech/unix/model.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/micro-speech/unix/model.tflite -------------------------------------------------------------------------------- /examples/person_detection/README.md: -------------------------------------------------------------------------------- 1 | Micropython implementation of the Person Detection Example 2 | 3 | # Model Architecture 4 | 5 | ![](images/model_architecture.png) 6 | 7 | # Model Properties 8 | ![](images/model_properties.png) 9 | 10 | # Upstream example 11 | https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/person_detection/README.md 12 | 13 | # Training the model 14 | 15 | https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/person_detection/training_a_model.md 16 | 17 | # Files 18 | 19 | ## person_detect_model.tflite 20 | 21 | I was able to restore the tflite model from the person_detection_int8 archive. It was a .cc file but I converted it back into a binary file and verified the architecture in netron. 22 | 23 | 24 | ## person_image_data.dat 25 | 26 | I was able to create this (96,96) binary file from the corresponding .cc file from the person_detection_int8 archive. 27 | 28 | ![person image](images/person.png) 29 | 30 | ## no_person_image_data.dat 31 | 32 | I was able to create this (96,96) binary file from the corresponding .cc file from the person_detection_int8 archive. 33 | 34 | ![not a person](images/not_a_person.png) 35 | 36 | ## show-test-images.py 37 | 38 | A script that runs in python3 to load and display the two test images. 39 | 40 | # Running in unix port 41 | 42 | Download the latest build of the micropython unix port: 43 | 1. Click on "Actions" tab. 44 | 2. Click on "Select Workflow" button. 45 | 3. Choose "UNIX" 46 | 4. Click on the commit message name for the most recent successful build 47 | 5. Click on microlite-unix-micropython in the "Artifacts" area to download a zip file containing the micropython command for unix. It can also run within the windows subsystem for linux. 48 | 49 | Run micropython /examples/person_detection/person_detection.py 50 | 51 | ``` 52 | ~/git/tensorflow-micropython-examples/examples/person_detection$ ./micropython ./person_detection.py 53 | interpreter_make_new: model size = 300568, tensor area = 139264 54 | Classify No Person Image 55 | setup 9612 bytes on the inputTensor. 56 | 'not a person' = -25, 'person' = 25 57 | Classify Person Image 58 | setup 9612 bytes on the inputTensor. 59 | 'not a person' = -113, 'person' = 113 60 | ``` 61 | 62 | # Running on ESP32 port without a camera 63 | 64 | **NOTE: The person detection model is 300 kb so you need to use a board with SPI RAM** 65 | 66 | 67 | Download the latest build of the micropython microlite spiram board for the esp32 port: 68 | 1. Click on "Actions" tab. 69 | 2. Click on "Select Workflow" button. 70 | 3. Choose "ESP32" 71 | 4. Click on the commit message name for the most recent successful build 72 | 5. Click on microlite-spiram-16m-esp32-firmware in the "Artifacts" area to download a zip file containing the 73 | esp32 firmware you can now flash. 74 | 75 | After flashing upload these files from here onto the board: 76 | 1. no_person_image_data.dat 77 | 2. person_image_data.dat 78 | 3. person_detect_model.tflite 79 | 4. person_detection.py 80 | 81 | Then import person_detection to run the example: 82 | ![ESP32 Running Person Detection](../../images/person-detection-esp32-running.png) 83 | 84 | # Running on an ESP32 With a Camera 85 | 86 | This has been tested using an ESP32-CAM-MB and an M5 Timer Camera using the 87 | [MICROLITE_SPIRAM_CAM](../../boards/esp32/MICROLITE_SPIRAM_CAM) Firmware. 88 | 89 | Flash that firmware and then copy the esp32-cam/person_detection_cam.py and person_detect_model.tflite 90 | model to the camera. 91 | 92 | Run import person_detection_cam to activate the demo program. The led will illuminate 93 | when it thinks a person is in frame. -------------------------------------------------------------------------------- /examples/person_detection/esp32-cam/imageTools/getImage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rshell cp /pyboard/camImage.raw . 3 | -------------------------------------------------------------------------------- /examples/person_detection/esp32-cam/imageTools/readImage.py: -------------------------------------------------------------------------------- 1 | # Reads a 96x96 pixel gray scale image from the camera in raw mode 2 | # This image can directly be passed into the input tensor of the 3 | # person detection model 4 | # The program is part of a course on AI and edge computing at the 5 | # University of Cape Coast, Ghana 6 | # Copyright (c) U. Raich [2022] 7 | # The program is released under the MIT License 8 | 9 | import sys 10 | import camera 11 | from utime import sleep_ms 12 | 13 | try: 14 | # this is for the esp32-cam-mb using ov2640 sensor 15 | camera.init(0,format=camera.GRAYSCALE,framesize=camera.FRAME_96X96) 16 | # switch to this for the m5 timer camera with ov3660 sensor 17 | # camera.init(0,format=camera.GRAYSCALE,framesize=camera.FRAME_96X96, 18 | # sioc=23,siod=25,xclk=27,vsync=22,href=26,pclk=21, 19 | # d0=32,d1=35,d2=34,d3=5,d4=39,d5=18,d6=36,d7=19, 20 | # reset=15) 21 | except: 22 | print("Error when initializing the camera") 23 | sys.exit() 24 | 25 | buf=camera.capture() 26 | print("type: ", type(buf), " Length: ",len(buf)) 27 | # save the raw image to a file 28 | print("Writing the data to camImage.raw") 29 | if len(buf) == 96*96: 30 | f = open("camImage.raw","w+b") 31 | f.write(buf) 32 | f.close() 33 | 34 | camera.deinit() 35 | -------------------------------------------------------------------------------- /examples/person_detection/esp32-cam/imageTools/showGrayScaleImg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from PIL import Image 3 | import io,sys 4 | 5 | if len(sys.argv) != 2: 6 | print("Usage %s filename"%sys.argv[0]) 7 | sys.exit() 8 | 9 | image_data_file = open (sys.argv[1], 'rb') 10 | image_data = bytearray(9612) 11 | image_data_file.readinto(image_data) 12 | image_data_file.close() 13 | image = Image.frombytes ('L', (96,96), bytes(image_data) ,'raw') 14 | image.show() 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/person_detection/esp32-cam/person_detection_cam.py: -------------------------------------------------------------------------------- 1 | # Run the person detection model 2 | # This version reads the images from the ov2640 camera on the esp32-cam board 3 | # with minor changes this also works for the m5 timer camera 4 | 5 | import sys 6 | import microlite 7 | import camera 8 | from machine import Pin,PWM 9 | 10 | # initialize the camera to read 96x96 pixel gray scale images 11 | 12 | try: 13 | 14 | # uncomment for esp32-cam-mb with ov2640 sensor 15 | camera.init(0,format=camera.GRAYSCALE,framesize=camera.FRAME_96X96) 16 | 17 | # uncomment for the m5 timer camera with ov3660 sensor 18 | # camera.init(0,format=camera.GRAYSCALE,framesize=camera.FRAME_96X96, 19 | # sioc=23,siod=25,xclk=27,vsync=22,href=26,pclk=21, 20 | # d0=32,d1=35,d2=34,d3=5,d4=39,d5=18,d6=36,d7=19, 21 | # reset=15) 22 | except: 23 | print("Error when initializing the camera") 24 | sys.exit() 25 | 26 | # initialize the flash-light LED, it is connected to GPIO 4 27 | flash_light = PWM(Pin(4)) 28 | # switch it off 29 | flash_light.duty(0) 30 | 31 | # change for m5 timer camera 32 | # # initialize the flash-light LED, it is connected to GPIO 4 33 | # flash_light = Pin(2,Pin.OUT) 34 | # switch it off 35 | # flash_light.off() 36 | 37 | mode = 1 38 | test_image = bytearray(9612) 39 | 40 | def handle_output(person): 41 | if person > 10: 42 | flash_light.duty(5) 43 | # if m5 timer camera 44 | # flash_light.on() 45 | else: 46 | flash_light.duty(0) 47 | # if m5 timer camera 48 | # flash_light.off() 49 | 50 | def input_callback (microlite_interpreter): 51 | inputTensor = microlite_interpreter.getInputTensor(0) 52 | for i in range (0, len(test_image)): 53 | inputTensor.setValue(i, test_image[i]) 54 | print ("setup %d bytes on the inputTensor." % (len(test_image))) 55 | 56 | def output_callback (microlite_interpreter): 57 | outputTensor = microlite_interpreter.getOutputTensor(0) 58 | not_a_person = outputTensor.getValue(0) 59 | person = outputTensor.getValue(1) 60 | print ("'not a person' = %d, 'person' = %d" % (not_a_person, person)) 61 | handle_output(person) 62 | 63 | # read the model 64 | person_detection_model_file = open ('person_detect_model.tflite', 'rb') 65 | person_detection_model = bytearray (300568) 66 | person_detection_model_file.readinto(person_detection_model) 67 | person_detection_model_file.close() 68 | 69 | # create the interpreter 70 | interp = microlite.interpreter(person_detection_model,136*1024, input_callback, output_callback) 71 | 72 | # Permanently read images from the camera and pass them into the model for 73 | # inference 74 | 75 | while True: 76 | test_image = camera.capture() 77 | interp.invoke() 78 | 79 | camera.deinit() 80 | -------------------------------------------------------------------------------- /examples/person_detection/images/model_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/person_detection/images/model_architecture.png -------------------------------------------------------------------------------- /examples/person_detection/images/model_properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/person_detection/images/model_properties.png -------------------------------------------------------------------------------- /examples/person_detection/images/not_a_person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/person_detection/images/not_a_person.png -------------------------------------------------------------------------------- /examples/person_detection/images/person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/person_detection/images/person.png -------------------------------------------------------------------------------- /examples/person_detection/no_person_image_data.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/person_detection/no_person_image_data.dat -------------------------------------------------------------------------------- /examples/person_detection/person_detect_model.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/person_detection/person_detect_model.tflite -------------------------------------------------------------------------------- /examples/person_detection/person_detection.py: -------------------------------------------------------------------------------- 1 | import microlite 2 | 3 | mode = 1 4 | 5 | test_image = bytearray(9612) 6 | 7 | 8 | 9 | def input_callback (microlite_interpreter): 10 | 11 | inputTensor = microlite_interpreter.getInputTensor(0) 12 | 13 | for i in range (0, len(test_image)): 14 | inputTensor.setValue(i, test_image[i]) 15 | 16 | print ("setup %d bytes on the inputTensor." % (len(test_image))) 17 | 18 | def output_callback (microlite_interpreter): 19 | 20 | outputTensor = microlite_interpreter.getOutputTensor(0) 21 | 22 | not_a_person = outputTensor.getValue(0) 23 | person = outputTensor.getValue(1) 24 | 25 | print ("'not a person' = %d, 'person' = %d" % (not_a_person, person)) 26 | 27 | 28 | person_detection_model_file = open ('person_detect_model.tflite', 'rb') 29 | 30 | person_detection_model = bytearray (300568) 31 | 32 | person_detection_model_file.readinto(person_detection_model) 33 | 34 | person_detection_model_file.close() 35 | 36 | interp = microlite.interpreter(person_detection_model,136*1024, input_callback, output_callback) 37 | 38 | print("Classify No Person Image") 39 | 40 | no_person_test_image_file = open ('no_person_image_data.dat', 'rb') 41 | 42 | no_person_test_image_file.readinto(test_image) 43 | 44 | no_person_test_image_file.close() 45 | 46 | interp.invoke() 47 | 48 | print("Classify Person Image") 49 | 50 | no_person_test_image_file = open ('person_image_data.dat', 'rb') 51 | 52 | no_person_test_image_file.readinto(test_image) 53 | 54 | no_person_test_image_file.close() 55 | 56 | interp.invoke() -------------------------------------------------------------------------------- /examples/person_detection/person_image_data.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/examples/person_detection/person_image_data.dat -------------------------------------------------------------------------------- /examples/person_detection/show-test-images.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import io 3 | 4 | image_data_file = open ('person_image_data.dat', 'rb') 5 | 6 | image_data = bytearray(9612) 7 | 8 | image_data_file.readinto(image_data) 9 | 10 | image_data_file.close() 11 | 12 | image = Image.frombytes ('L', (96,96), bytes(image_data) ,'raw') 13 | 14 | image.show() 15 | 16 | np_image_data_file = open ('no_person_image_data.dat', 'rb') 17 | 18 | np_image_data = bytearray(9612) 19 | 20 | np_image_data_file.readinto(np_image_data) 21 | 22 | np_image_data_file.close() 23 | 24 | np_image = Image.frombytes ('L', (96,96), bytes(np_image_data) ,'raw') 25 | 26 | np_image.show() 27 | -------------------------------------------------------------------------------- /images/download-esp32-artifact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/download-esp32-artifact.png -------------------------------------------------------------------------------- /images/esp32-micro-speech-board-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/esp32-micro-speech-board-setup.png -------------------------------------------------------------------------------- /images/esp32-micro-speech-inmp441-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/esp32-micro-speech-inmp441-setup.png -------------------------------------------------------------------------------- /images/esp32-to-esp-prog-pins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/esp32-to-esp-prog-pins.png -------------------------------------------------------------------------------- /images/hello-world-output-chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/hello-world-output-chart.png -------------------------------------------------------------------------------- /images/person-detection-esp32-running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/person-detection-esp32-running.png -------------------------------------------------------------------------------- /images/recommended stm32 boards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/recommended stm32 boards.png -------------------------------------------------------------------------------- /images/rp2-hello-world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/rp2-hello-world.png -------------------------------------------------------------------------------- /images/tensorflow-micropython-examples.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/tensorflow-micropython-examples.png -------------------------------------------------------------------------------- /images/write-firmware.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mocleiri/tensorflow-micropython-examples/44b7fbe5d0fd3c574ad9d546290a26e7012e12fc/images/write-firmware.png -------------------------------------------------------------------------------- /lib/README.md: -------------------------------------------------------------------------------- 1 | At the moment the libtensorflow-microlite.a library is built first and then placed into this directory. 2 | 3 | For esp32 and the unix port build it will pick up the library from here and link into the main firmware. 4 | -------------------------------------------------------------------------------- /micropython-modules/audio_frontend/.gitignore: -------------------------------------------------------------------------------- 1 | fft.cpp 2 | fft_util.cpp 3 | -------------------------------------------------------------------------------- /micropython-modules/audio_frontend/micropython.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Tensorflow Micropython Examples Project. 3 | # 4 | # The MIT License (MIT) 5 | # 6 | # Copyright (c) 2021 Michael O'Cleirigh 7 | # 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy 9 | # of this software and associated documentation files (the "Software"), to deal 10 | # in the Software without restriction, including without limitation the rights 11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | # copies of the Software, and to permit persons to whom the Software is 13 | # furnished to do so, subject to the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be included in 16 | # all copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | # THE SOFTWARE. 25 | #/ 26 | 27 | get_filename_component(TENSORFLOW_DIR ${PROJECT_DIR}/../../../tensorflow ABSOLUTE) 28 | 29 | add_library(audio_frontend INTERFACE) 30 | 31 | # file(GLOB_RECURSE ULAB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/*.c) 32 | 33 | target_sources(audio_frontend INTERFACE 34 | ${TENSORFLOW_DIR}/tensorflow/lite/micro/tools/make/downloads/kissfft/kiss_fft.c 35 | ${TENSORFLOW_DIR}/tensorflow/lite/micro/tools/make/downloads/kissfft/tools/kiss_fftr.c 36 | 37 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/filterbank.c 38 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c 39 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/frontend.c 40 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c 41 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/log_lut.c 42 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/log_scale.c 43 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.c 44 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c 45 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c 46 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c 47 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c 48 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/window.c 49 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/window_util.c 50 | 51 | ${CMAKE_CURRENT_LIST_DIR}/audio_frontend_module.c 52 | 53 | ${CMAKE_CURRENT_LIST_DIR}/fft.cpp 54 | ${CMAKE_CURRENT_LIST_DIR}/fft_util.cpp 55 | 56 | ) 57 | 58 | target_include_directories(audio_frontend INTERFACE 59 | ${CMAKE_CURRENT_LIST_DIR} 60 | ${TENSORFLOW_DIR} 61 | ${TENSORFLOW_DIR}/tensorflow/lite/micro/tools/make/downloads/kissfft 62 | ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib 63 | ) 64 | 65 | target_compile_definitions(audio_frontend INTERFACE 66 | MODULE_AUDIO_FRONTEND_ENABLED=1 67 | TF_LITE_STATIC_MEMORY=1 68 | ) 69 | 70 | target_compile_options(audio_frontend INTERFACE 71 | -Wno-error=float-conversion 72 | -Wno-error=nonnull 73 | -Wno-error=double-promotion 74 | -Wno-error=pointer-arith 75 | -Wno-error=unused-const-variable 76 | ) 77 | 78 | target_link_libraries(usermod INTERFACE audio_frontend) 79 | 80 | -------------------------------------------------------------------------------- /micropython-modules/audio_frontend/micropython.not-mk: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Tensorflow Micropython Examples Project. 3 | # 4 | # The MIT License (MIT) 5 | # 6 | # Copyright (c) 2021 Michael O'Cleirigh 7 | # 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy 9 | # of this software and associated documentation files (the "Software"), to deal 10 | # in the Software without restriction, including without limitation the rights 11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | # copies of the Software, and to permit persons to whom the Software is 13 | # furnished to do so, subject to the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be included in 16 | # all copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | # THE SOFTWARE. 25 | #/ 26 | AUDIO_FRONTEND_MOD_DIR := $(USERMOD_DIR) 27 | 28 | # current working directory seems to be micropython/ports/esp32 when this is run 29 | TENSORFLOW := ../../../tensorflow 30 | 31 | ULAB := ../../../micropython-ulab 32 | 33 | # Add all C files to SRC_USERMOD. 34 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/micro/tools/make/downloads/kissfft/kiss_fft.c 35 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/micro/tools/make/downloads/kissfft/tools/kiss_fftr.c 36 | 37 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/filterbank.c 38 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c 39 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/frontend.c 40 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c 41 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/log_lut.c 42 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/log_scale.c 43 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.c 44 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c 45 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c 46 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c 47 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c 48 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/window.c 49 | SRC_USERMOD += $(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib/window_util.c 50 | 51 | SRC_USERMOD += $(AUDIO_FRONTEND_MOD_DIR)/audio_frontend_module.c 52 | 53 | SRC_USERMOD_CXX += $(AUDIO_FRONTEND_MOD_DIR)/fft.cpp 54 | SRC_USERMOD_CXX += $(AUDIO_FRONTEND_MOD_DIR)/fft_util.cpp 55 | 56 | # needed with c++ 57 | #LDFLAGS_USERMOD += -lsupc++ 58 | 59 | CFLAGS_USERMOD += -I$(AUDIO_FRONTEND_MOD_DIR) 60 | CFLAGS_USERMOD += -I$(TENSORFLOW)/tensorflow/lite/micro/tools/make/downloads/kissfft 61 | CFLAGS_USERMOD += -I$(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib 62 | CFLAGS_USERMOD += -I$(ULAB)/code 63 | CFLAGS_USERMOD += -I$(MICROLITE_MOD_DIR)/../../tensorflow 64 | 65 | CFLAGS_USERMOD += -DTF_LITE_STATIC_MEMORY=1 66 | 67 | CFLAGS_USERMOD += -Wno-error=float-conversion 68 | CFLAGS_USERMOD += -Wno-error=nonnull 69 | CFLAGS_USERMOD += -Wno-error=double-promotion 70 | CFLAGS_USERMOD += -Wno-error=pointer-arith 71 | CFLAGS_USERMOD += -Wfloat-conversion 72 | 73 | CXXFLAGS_USERMOD += -I$(AUDIO_FRONTEND_MOD_DIR) 74 | CXXFLAGS_USERMOD += -I$(TENSORFLOW)/tensorflow/lite/micro/tools/make/downloads/kissfft 75 | CXXFLAGS_USERMOD += -I$(TENSORFLOW)/tensorflow/lite/experimental/microfrontend/lib 76 | CXXFLAGS_USERMOD += -I$(MICROLITE_MOD_DIR)/../../tensorflow 77 | 78 | CXXFLAGS_USERMOD += -DTF_LITE_STATIC_MEMORY=1 79 | 80 | CXXFLAGS_USERMOD += -Wfloat-conversion 81 | 82 | # unix port 83 | CFLAGS_USERMOD += -Wno-error=unused-const-variable 84 | 85 | override CFLAGS_EXTRA += -DMODULE_AUDIO_FRONTEND_ENABLED=1 86 | 87 | #PART_SRC=$(MFCC_MOD_DIR)/../../partitions-2MiB.csv 88 | -------------------------------------------------------------------------------- /micropython-modules/audio_frontend/refresh-tensorflow-microfrontend.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd ../../tensorflow 4 | 5 | # remove build details 6 | rm -rf tensorflow/lite/micro/tools/make/gen 7 | rm -rf tensorflow/lite/micro/tools/make/downloads 8 | 9 | # need to download the kissft dependency. 10 | make -f tensorflow/lite/micro/tools/make/Makefile generate_hello_world_make_project 11 | 12 | 13 | cd ../micropython-modules/audio_frontend 14 | 15 | # at the moment micropython esp32 port doesn't work with .cc extension c++ files only .cpp 16 | # so copy to rename the line ending 17 | cp ../../tensorflow/tensorflow/lite/experimental/microfrontend/lib/fft.cc fft.cpp 18 | cp ../../tensorflow/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc fft_util.cpp 19 | -------------------------------------------------------------------------------- /micropython-modules/microlite/assemble-unified-image-esp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BASE_DIR=$1 4 | 5 | if test -z "$BASE_DIR"; then 6 | echo "USAGE: " 7 | exit 1 8 | fi 9 | 10 | 11 | python3 ${BASE_DIR}/makeimg.py \ 12 | build/sdkconfig \ 13 | build/bootloader/bootloader.bin \ 14 | build/partition_table/partition-table.bin \ 15 | build/micropython.bin \ 16 | build/firmware.bin \ 17 | build/micropython.uf2 18 | -------------------------------------------------------------------------------- /micropython-modules/microlite/bare-metal-gc-heap.c: -------------------------------------------------------------------------------- 1 | #include "py/gc.h" 2 | #include "py/obj.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct _reent *_impure_ptr; 9 | 10 | /* func can be NULL, in which case no function information is given. */ 11 | void 12 | __assert_func (const char *file, int line, const char *func, const char *failedexpr) 13 | { 14 | printf( 15 | "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", 16 | failedexpr, file, line, 17 | func ? ", function: " : "", func ? func : ""); 18 | abort(); 19 | /* NOTREACHED */ 20 | } 21 | 22 | 23 | 24 | 25 | int fputs ( const char * str, FILE * stream ) { 26 | // ignore the stream and just write out 27 | // uses puts from shared/libc/printf.c 28 | return puts (str); 29 | 30 | } 31 | 32 | int fprintf(FILE* stream, const char *fmt, ...) { 33 | va_list ap; 34 | va_start(ap, fmt); 35 | int ret = mp_vprintf(&mp_plat_print, fmt, ap); 36 | va_end(ap); 37 | return ret; 38 | } 39 | 40 | 41 | // size_t fwrite (const void * __ptr, size_t __size, 42 | // size_t __n, FILE * __s); 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /micropython-modules/microlite/micropython-error-reporter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Tensorflow Micropython Examples Project. 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2021 Michael O'Cleirigh 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #include "micropython-error-reporter.h" 27 | 28 | #include 29 | 30 | namespace microlite { 31 | 32 | int MicropythonErrorReporter::Report(const char* format, ...) { 33 | 34 | va_list args; 35 | va_start(args, format); 36 | MicropythonErrorReporter::Report(format, args); 37 | va_end(args); 38 | 39 | return 0; 40 | 41 | } 42 | 43 | int MicropythonErrorReporter::Report(const char* format, va_list args) { 44 | 45 | static constexpr int kMaxLogLen = 256; 46 | char log_buffer[kMaxLogLen]; 47 | 48 | MicroVsnprintf(log_buffer, kMaxLogLen, format, args); 49 | 50 | mp_printf(MP_PYTHON_PRINTER, log_buffer); 51 | mp_printf(MP_PYTHON_PRINTER, "\n"); 52 | 53 | return 0; 54 | 55 | } 56 | 57 | } // end microlite 58 | -------------------------------------------------------------------------------- /micropython-modules/microlite/micropython-error-reporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Tensorflow Micropython Examples Project. 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2021 Michael O'Cleirigh 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPYTHON__ERROR_REPORTER_H_ 27 | #define MICROPYTHON__ERROR_REPORTER_H_ 28 | 29 | #include 30 | 31 | #include "tensorflow/lite/core/api/error_reporter.h" 32 | #include "tensorflow/lite/micro/compatibility.h" 33 | #include "tensorflow/lite/micro/micro_string.h" 34 | 35 | namespace microlite { 36 | 37 | class MicropythonErrorReporter : public tflite::ErrorReporter { 38 | public: 39 | ~MicropythonErrorReporter() override {} 40 | int Report(const char* format, va_list args) override; 41 | int Report(const char* format, ...); 42 | 43 | private: 44 | TF_LITE_REMOVE_VIRTUAL_DELETE 45 | }; 46 | 47 | } // namespace tflite 48 | 49 | extern "C" { 50 | // added the micropython functions used by MicropythonErrorReporter implementation here to prevent the c++ compiler 51 | // from mangling the names which then prevents the linker from working properly. 52 | #include "py/mpprint.h" 53 | int mp_printf(const mp_print_t *print, const char *fmt, ...); 54 | int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /micropython-modules/microlite/micropython_esp.cmake: -------------------------------------------------------------------------------- 1 | # File to contain all the source list for Espressif boards to build 2 | 3 | if(IDF_TARGET STREQUAL "esp32") 4 | set(MICROLITE_PLATFORM "ESP32") 5 | endif() 6 | 7 | if(IDF_TARGET STREQUAL "esp32s2") 8 | set(MICROLITE_PLATFORM "ESP32S2") 9 | endif() 10 | 11 | if(IDF_TARGET STREQUAL "esp32s3") 12 | set(MICROLITE_PLATFORM "ESP32S3") 13 | endif() 14 | 15 | if(IDF_TARGET STREQUAL "esp32c3") 16 | set(MICROLITE_PLATFORM "ESP32C3") 17 | endif() 18 | 19 | if (MICROLITE_PLATFORM STREQUAL "ESP32" OR 20 | MICROLITE_PLATFORM STREQUAL "ESP32S3" OR 21 | MICROLITE_PLATFORM STREQUAL "ESP32C3" OR 22 | MICROLITE_PLATFORM STREQUAL "ESP32S2") 23 | 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 25 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") 26 | set(ESP_NN_DIR "${CMAKE_CURRENT_LIST_DIR}/../../tflm_esp_kernels/components/esp-nn") 27 | set(ESP_NN_SRCS 28 | "${ESP_NN_DIR}/src/activation_functions/esp_nn_relu_ansi.c" 29 | "${ESP_NN_DIR}/src/basic_math/esp_nn_add_ansi.c" 30 | "${ESP_NN_DIR}/src/basic_math/esp_nn_mul_ansi.c" 31 | "${ESP_NN_DIR}/src/convolution/esp_nn_conv_ansi.c" 32 | "${ESP_NN_DIR}/src/convolution/esp_nn_conv_opt.c" 33 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_ansi.c" 34 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_opt.c" 35 | "${ESP_NN_DIR}/src/fully_connected/esp_nn_fully_connected_ansi.c" 36 | "${ESP_NN_DIR}/src/softmax/esp_nn_softmax_ansi.c" 37 | "${ESP_NN_DIR}/src/softmax/esp_nn_softmax_opt.c" 38 | "${ESP_NN_DIR}/src/pooling/esp_nn_avg_pool_ansi.c" 39 | "${ESP_NN_DIR}/src/pooling/esp_nn_max_pool_ansi.c" 40 | ) 41 | if(CONFIG_IDF_TARGET_ESP32S3) 42 | list(APPEND ESP_NN_SRCS 43 | "${ESP_NN_DIR}/src/common/esp_nn_common_functions_esp32s3.S" 44 | "${ESP_NN_DIR}/src/common/esp_nn_multiply_by_quantized_mult_esp32s3.S" 45 | "${ESP_NN_DIR}/src/common/esp_nn_multiply_by_quantized_mult_ver1_esp32s3.S" 46 | "${ESP_NN_DIR}/src/activation_functions/esp_nn_relu_s8_esp32s3.S" 47 | "${ESP_NN_DIR}/src/basic_math/esp_nn_add_s8_esp32s3.S" 48 | "${ESP_NN_DIR}/src/basic_math/esp_nn_mul_s8_esp32s3.S" 49 | "${ESP_NN_DIR}/src/convolution/esp_nn_conv_esp32s3.c" 50 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s8_esp32s3.c" 51 | "${ESP_NN_DIR}/src/convolution/esp_nn_conv_s16_mult8_esp32s3.S" 52 | "${ESP_NN_DIR}/src/convolution/esp_nn_conv_s8_mult8_1x1_esp32s3.S" 53 | "${ESP_NN_DIR}/src/convolution/esp_nn_conv_s16_mult4_1x1_esp32s3.S" 54 | "${ESP_NN_DIR}/src/convolution/esp_nn_conv_s8_filter_aligned_input_padded_esp32s3.S" 55 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s8_mult1_3x3_padded_esp32s3.S" 56 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s16_mult1_esp32s3.S" 57 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s16_mult1_3x3_esp32s3.S" 58 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s16_mult1_3x3_no_pad_esp32s3.S" 59 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s16_mult8_3x3_esp32s3.S" 60 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s16_mult4_esp32s3.S" 61 | "${ESP_NN_DIR}/src/convolution/esp_nn_depthwise_conv_s16_mult8_esp32s3.S" 62 | "${ESP_NN_DIR}/src/fully_connected/esp_nn_fully_connected_s8_esp32s3.S" 63 | "${ESP_NN_DIR}/src/pooling/esp_nn_max_pool_s8_esp32s3.S" 64 | "${ESP_NN_DIR}/src/pooling/esp_nn_avg_pool_s8_esp32s3.S") 65 | endif() 66 | set(ESP_NN_INC ${ESP_NN_DIR}/include ${ESP_NN_DIR}/src/common) 67 | endif() 68 | -------------------------------------------------------------------------------- /micropython-modules/microlite/mpy_heap_malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Implement Standard C memory allocation 3 | * using xalloc which uses the micropython heap. 4 | */ 5 | #include "py/mpconfig.h" 6 | #include "py/misc.h" 7 | #include "xalloc.h" 8 | 9 | void *malloc (size_t size) { 10 | byte *data = xalloc(size); 11 | 12 | return data; 13 | } 14 | 15 | void *calloc (size_t num, size_t size) { 16 | return xalloc (num*size); 17 | } 18 | 19 | void* realloc (void* ptr, size_t size) { 20 | return xrealloc (ptr, size); 21 | } 22 | void free (void* ptr) { 23 | xfree(ptr); 24 | 25 | } 26 | void __cxa_pure_virtual() 27 | { 28 | while (true) {} 29 | } -------------------------------------------------------------------------------- /micropython-modules/microlite/mpy_heap_new_delete.cpp: -------------------------------------------------------------------------------- 1 | // suggested in: https://alex-robenko.gitbook.io/bare_metal_cpp/compiler_output/abstract_classes 2 | // Implemented using xalloc functions from openmv. 3 | /* 4 | * 5 | */ 6 | #include 7 | 8 | #include "malloc.h" 9 | 10 | void * operator new(unsigned int n) 11 | { 12 | void * const p = malloc(n); 13 | // handle p == 0 14 | return p; 15 | } 16 | 17 | void operator delete(void *p) 18 | { 19 | free(p); 20 | } 21 | 22 | void operator delete(void *p, size_t size) 23 | { 24 | free(p); 25 | } 26 | -------------------------------------------------------------------------------- /micropython-modules/microlite/openmv-libtf.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the OpenMV project. 2 | * Copyright (c) 2013-2019 Ibrahim Abdelkader & Kwabena W. Agyeman 3 | * This work is licensed under the MIT license, see the file LICENSE for details. 4 | * 5 | * The C -> C++ micropython -> tensorflow micro c++ api bridging code originated with the OpenMV 6 | * project although it is now quite different. 7 | * 8 | */ 9 | 10 | #ifndef __OPENMV_LIBTF_H 11 | #define __OPENMV_LIBTF_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | 18 | #include "tensorflow/lite/c/common.h" 19 | 20 | #include "py/runtime.h" 21 | #include "py/mpprint.h" 22 | 23 | // Callback to populate the model input data byte array (laid out in [height][width][channel] order). 24 | typedef void (*libtf_interpreter_input_data_callback_t)(TfLiteTensor *input_tensor); // Actual is float32 (not optimal - network should be fixed). Input should be ([0:255]->[0.0f:+1.0f]). 25 | 26 | // Callback to use the model output data byte array (laid out in [height][width][channel] order). 27 | typedef void (*libtf_interpreter_output_data_callback_t)(TfLiteTensor *output_tensor); // Actual is float32 (not optimal - network should be fixed). Output is [0.0f:+1.0f]. 28 | 29 | int libtf_interpreter_init(microlite_interpreter_obj_t *microlite_interpreter); 30 | 31 | TfLiteTensor *libtf_interpreter_get_input_tensor(microlite_interpreter_obj_t *microlite_interpreter, mp_uint_t index); 32 | 33 | TfLiteTensor *libtf_interpreter_get_output_tensor(microlite_interpreter_obj_t *microlite_interpreter, mp_uint_t index); 34 | 35 | // get the input tensor 36 | mp_obj_t libtf_interpreter_get_input(microlite_interpreter_obj_t *microlite_interpreter, int index); 37 | 38 | int libtf_interpreter_outputs(microlite_interpreter_obj_t *microlite_interpreter); 39 | 40 | // Returns 0 on success and 1 on failure. 41 | // Errors are printed to stdout. 42 | int libtf_interpreter_invoke(microlite_interpreter_obj_t *interpreter); // Callback to use the model output data byte array. 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif // __OPENMV_LIBTF_H 49 | -------------------------------------------------------------------------------- /micropython-modules/microlite/prepare-tflm-esp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # needs to be run from the tensorflow top level directory 3 | 4 | rm -rf ./tensorflow/lite/micro/tools/make/downloads 5 | rm -rf ./tensorflow/lite/micro/tools/make/gen 6 | rm -rf ../micropython-modules/microlite/tflm 7 | 8 | python3 ./tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \ 9 | --examples micro_speech --rename_cc_to_cpp ../micropython-modules/microlite/tflm 10 | -------------------------------------------------------------------------------- /micropython-modules/microlite/prepare-tflm-rp2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # needs to be run from the tensorflow top level directory 3 | 4 | rm -rf ./tensorflow/lite/micro/tools/make/downloads 5 | rm -rf ./tensorflow/lite/micro/tools/make/gen 6 | rm -rf ../micropython-modules/microlite/tflm 7 | 8 | python3 ./tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \ 9 | --makefile_options="TARGET=cortex_m_generic OPTIMIZED_KERNEL_DIR=cmsis_nn TARGET_ARCH=cortex-m0" \ 10 | --examples micro_speech --rename_cc_to_cpp ../micropython-modules/microlite/tflm 11 | -------------------------------------------------------------------------------- /micropython-modules/microlite/prepare-tflm-stm32.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf ./tensorflow/lite/micro/tools/make/downloads 4 | rm -rf ./tensorflow/lite/micro/tools/make/gen 5 | rm -rf ../micropython-modules/microlite/tflm 6 | 7 | # add the following to makefile_options OPTIMIZED_KERNEL_DIR=cmsis_nn to build the optimized 8 | # kernels 9 | # however we need a lot more of the math library to support it. 10 | python3 ./tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \ 11 | --makefile_options="TARGET=cortex_m_generic OPTIMIZED_KERNEL_DIR=cmsis_nn TARGET_ARCH=cortex-m7" \ 12 | --examples micro_speech --rename_cc_to_cpp ../micropython-modules/microlite/tflm 13 | 14 | # we need to update the CMSIS-Core files to use the ones that were downloaded 15 | cp ../micropython-modules/microlite/tflm/third_party/cmsis/CMSIS/Core/Include/* ../micropython/lib/cmsis/inc -------------------------------------------------------------------------------- /micropython-modules/microlite/prepare-tflm-unix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # needs to be run from the tensorflow top level directory 3 | 4 | rm -rf ./tensorflow/lite/micro/tools/make/downloads 5 | rm -rf ./tensorflow/lite/micro/tools/make/gen 6 | rm -rf ../micropython-modules/microlite/tflm 7 | 8 | python3 ./tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \ 9 | --examples micro_speech --rename_cc_to_cpp ../micropython-modules/microlite/tflm 10 | -------------------------------------------------------------------------------- /micropython-modules/microlite/python_ops_resolver.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "python_ops_resolver.h" 17 | 18 | #include "tensorflow/lite/micro/kernels/micro_ops.h" 19 | 20 | namespace tflite { 21 | 22 | PythonOpsResolver::PythonOpsResolver() { 23 | // Please keep this list of Builtin Operators in alphabetical order. 24 | AddAbs(); 25 | AddAdd(); 26 | AddAddN(); 27 | AddArgMax(); 28 | AddArgMin(); 29 | AddAssignVariable(); 30 | AddAveragePool2D(); 31 | AddBatchToSpaceNd(); 32 | AddBroadcastArgs(); 33 | AddBroadcastTo(); 34 | AddCallOnce(); 35 | AddCast(); 36 | AddCeil(); 37 | AddCircularBuffer(); 38 | AddConcatenation(); 39 | AddConv2D(); 40 | AddCos(); 41 | AddCumSum(); 42 | AddDepthToSpace(); 43 | AddDepthwiseConv2D(); 44 | AddDequantize(); 45 | AddDetectionPostprocess(); 46 | AddDiv(); 47 | AddElu(); 48 | AddEqual(); 49 | AddEthosU(); 50 | AddExp(); 51 | AddExpandDims(); 52 | AddFill(); 53 | AddFloor(); 54 | AddFloorDiv(); 55 | AddFloorMod(); 56 | AddFullyConnected(); 57 | AddGather(); 58 | AddGatherNd(); 59 | AddGreater(); 60 | AddGreaterEqual(); 61 | AddHardSwish(); 62 | AddIf(); 63 | AddL2Normalization(); 64 | AddL2Pool2D(); 65 | AddLeakyRelu(); 66 | AddLess(); 67 | AddLessEqual(); 68 | AddLog(); 69 | AddLogicalAnd(); 70 | AddLogicalNot(); 71 | AddLogicalOr(); 72 | AddLogistic(); 73 | AddLogSoftmax(); 74 | AddMaxPool2D(); 75 | AddMaximum(); 76 | AddMean(); 77 | AddMinimum(); 78 | AddMirrorPad(); 79 | AddMul(); 80 | AddNeg(); 81 | AddNotEqual(); 82 | AddPack(); 83 | AddPad(); 84 | AddPadV2(); 85 | AddPrelu(); 86 | AddQuantize(); 87 | AddReadVariable(); 88 | AddReduceMax(); 89 | AddRelu(); 90 | AddRelu6(); 91 | AddReshape(); 92 | AddResizeBilinear(); 93 | AddResizeNearestNeighbor(); 94 | AddRound(); 95 | AddRsqrt(); 96 | AddSelectV2(); 97 | AddShape(); 98 | AddSin(); 99 | AddSlice(); 100 | AddSoftmax(); 101 | AddSpaceToBatchNd(); 102 | AddSpaceToDepth(); 103 | AddSplit(); 104 | AddSplitV(); 105 | AddSqrt(); 106 | AddSquare(); 107 | AddSquaredDifference(); 108 | AddSqueeze(); 109 | AddStridedSlice(); 110 | AddSub(); 111 | AddSum(); 112 | AddSvdf(); 113 | AddTanh(); 114 | AddTranspose(); 115 | AddTransposeConv(); 116 | AddUnidirectionalSequenceLSTM(); 117 | AddUnpack(); 118 | AddVarHandle(); 119 | AddWhile(); 120 | AddZerosLike(); 121 | } 122 | 123 | } // namespace tflite 124 | -------------------------------------------------------------------------------- /micropython-modules/microlite/python_ops_resolver.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_PYTHON_OPS_RESOLVER_H_ 16 | #define TENSORFLOW_LITE_MICRO_PYTHON_OPS_RESOLVER_H_ 17 | 18 | #include "tensorflow/lite/micro/compatibility.h" 19 | #include "tensorflow/lite/micro/micro_mutable_op_resolver.h" 20 | 21 | namespace tflite { 22 | 23 | // PythonOpsResolver is used to register all the Ops for the TFLM Python 24 | // interpreter. This is ok since code size is not a concern from Python and 25 | // the goal is to be able to run any model supported by TFLM in a flexible way 26 | class PythonOpsResolver : public MicroMutableOpResolver<200> { 27 | public: 28 | PythonOpsResolver(); 29 | 30 | private: 31 | TF_LITE_REMOVE_VIRTUAL_DELETE 32 | }; 33 | 34 | } // namespace tflite 35 | 36 | #endif // TENSORFLOW_LITE_MICRO_PYTHON_OPS_RESOLVER_H_ 37 | -------------------------------------------------------------------------------- /micropython-modules/microlite/stm32lib/abs.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---integer absolute value (magnitude) 4 | 5 | INDEX 6 | abs 7 | 8 | ANSI_SYNOPSIS 9 | #include 10 | int abs(int <[i]>); 11 | 12 | TRAD_SYNOPSIS 13 | #include 14 | int abs(<[i]>) 15 | int <[i]>; 16 | 17 | DESCRIPTION 18 | <> returns 19 | @tex 20 | $|x|$, 21 | @end tex 22 | the absolute value of <[i]> (also called the magnitude 23 | of <[i]>). That is, if <[i]> is negative, the result is the opposite 24 | of <[i]>, but if <[i]> is nonnegative the result is <[i]>. 25 | 26 | The similar function <> uses and returns <> rather than <> values. 27 | 28 | RETURNS 29 | The result is a nonnegative integer. 30 | 31 | PORTABILITY 32 | <> is ANSI. 33 | 34 | No supporting OS subroutines are required. 35 | */ 36 | 37 | #include 38 | 39 | int abs (int i) 40 | { 41 | return (i < 0) ? -i : i; 42 | } -------------------------------------------------------------------------------- /micropython-modules/microlite/stm32lib/bsearch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990 Regents of the University of California. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. [rescinded 22 July 1999] 14 | * 4. Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | /* 34 | * Perform a binary search. 35 | * 36 | * The code below is a bit sneaky. After a comparison fails, we 37 | * divide the work in half by moving either left or right. If lim 38 | * is odd, moving left simply involves halving lim: e.g., when lim 39 | * is 5 we look at item 2, so we change lim to 2 so that we will 40 | * look at items 0 & 1. If lim is even, the same applies. If lim 41 | * is odd, moving right again involes halving lim, this time moving 42 | * the base up one item past p: e.g., when lim is 5 we change base 43 | * to item 3 and make lim 2 so that we will look at items 3 and 4. 44 | * If lim is even, however, we have to shrink it by one before 45 | * halving: e.g., when lim is 4, we still looked at item 2, so we 46 | * have to make lim 3, then halve, obtaining 1, so that we will only 47 | * look at item 3. 48 | */ 49 | void * 50 | bsearch (const void *key, const void *base0, 51 | size_t nmemb, size_t size, 52 | int (*compar)(const void *, const void *)) 53 | { 54 | const char *base = (const char *) base0; 55 | int lim, cmp; 56 | const void *p; 57 | 58 | for (lim = nmemb; lim != 0; lim >>= 1) { 59 | p = base + (lim >> 1) * size; 60 | cmp = (*compar)(key, p); 61 | if (cmp == 0) 62 | return (void *)p; 63 | if (cmp > 0) { /* key > p: move right */ 64 | base = (const char *)p + size; 65 | lim--; 66 | } /* else move left */ 67 | } 68 | return (NULL); 69 | } -------------------------------------------------------------------------------- /micropython-modules/microlite/stm32lib/ctype_.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if (defined(__GNUC__) && !defined(__CHAR_UNSIGNED__) && !defined(COMPACT_CTYPE)) || defined (__CYGWIN__) 4 | #define ALLOW_NEGATIVE_CTYPE_INDEX 5 | #endif 6 | 7 | #ifdef ALLOW_NEGATIVE_CTYPE_INDEX 8 | 9 | #ifndef __CYGWIN__ 10 | extern const char _ctype_b[]; 11 | #else 12 | extern char _ctype_b[]; 13 | #endif 14 | # define DEFAULT_CTYPE_PTR ((char *) _ctype_b + 127) 15 | 16 | #else /* !ALLOW_NEGATIVE_CTYPE_INDEX */ 17 | 18 | /* _ctype_ is declared in . */ 19 | # define DEFAULT_CTYPE_PTR ((char *) _ctype_) 20 | 21 | #endif /* !ALLOW_NEGATIVE_CTYPE_INDEX */ 22 | -------------------------------------------------------------------------------- /micropython-modules/microlite/stm32lib/strtoull.c: -------------------------------------------------------------------------------- 1 | /* 2 | This code is based on strtoul.c which has the following copyright. 3 | It is used to convert a string into an unsigned long long. 4 | 5 | long long _strtoull_r (struct _reent *rptr, const char *s, 6 | char **ptr, int base); 7 | 8 | */ 9 | 10 | /* 11 | * Copyright (c) 1990 Regents of the University of California. 12 | * All rights reserved. 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. All advertising materials mentioning features or use of this software 23 | * must display the following acknowledgement: 24 | * This product includes software developed by the University of 25 | * California, Berkeley and its contributors. 26 | * 4. Neither the name of the University nor the names of its contributors 27 | * may be used to endorse or promote products derived from this software 28 | * without specific prior written permission. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 | * SUCH DAMAGE. 41 | */ 42 | 43 | 44 | #include <_ansi.h> 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | unsigned long long strtoull(const char *nptr, char **endptr, int base) 52 | { 53 | register const unsigned char *s = (const unsigned char *)nptr; 54 | register unsigned long long acc; 55 | register int c; 56 | register unsigned long long cutoff; 57 | register int neg = 0, any, cutlim; 58 | 59 | /* 60 | * See strtol for comments as to the logic used. 61 | */ 62 | do { 63 | c = *s++; 64 | } while (isspace(c)); 65 | if (c == '-') { 66 | neg = 1; 67 | c = *s++; 68 | } else if (c == '+') 69 | c = *s++; 70 | if ((base == 0 || base == 16) && 71 | c == '0' && (*s == 'x' || *s == 'X')) { 72 | c = s[1]; 73 | s += 2; 74 | base = 16; 75 | } 76 | if (base == 0) 77 | base = c == '0' ? 8 : 10; 78 | cutoff = (unsigned long long)ULONG_LONG_MAX / (unsigned long long)base; 79 | cutlim = (unsigned long long)ULONG_LONG_MAX % (unsigned long long)base; 80 | for (acc = 0, any = 0;; c = *s++) { 81 | if (isdigit(c)) 82 | c -= '0'; 83 | else if (isalpha(c)) 84 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; 85 | else 86 | break; 87 | if (c >= base) 88 | break; 89 | if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 90 | any = -1; 91 | else { 92 | any = 1; 93 | acc *= base; 94 | acc += c; 95 | } 96 | } 97 | if (any < 0) { 98 | acc = ULONG_LONG_MAX; 99 | } else if (neg) 100 | acc = -acc; 101 | if (endptr != 0) 102 | *endptr = (char *) (any ? (char *)s - 1 : nptr); 103 | return (acc); 104 | } 105 | -------------------------------------------------------------------------------- /micropython-modules/microlite/tensorflow-microlite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Tensorflow Micropython Examples Project. 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2021 Michael O'Cleirigh 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef HELLO_WORLD_MICRO_LITE_H_ 27 | #define HELLO_WORLD_MICRO_LITE_H_ 28 | 29 | 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #include 36 | 37 | #include "py/runtime.h" 38 | #include "py/obj.h" 39 | #include "py/objstr.h" 40 | #include "py/objarray.h" 41 | 42 | #include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" 43 | #include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h" 44 | 45 | // TODO #15 get this from the tensorflow submodule via a ci script 46 | #define TFLITE_MICRO_VERSION "e87305ee53c124188d0390b1ef8ec0555760d4d6" 47 | 48 | typedef struct _microlite_model_obj_t { 49 | mp_obj_base_t base; 50 | mp_obj_array_t *model_data; 51 | mp_obj_t tf_model; 52 | } microlite_model_obj_t; 53 | 54 | 55 | typedef struct _microlite_interpreter_obj_t { 56 | mp_obj_base_t base; 57 | mp_obj_array_t *model_data; 58 | mp_obj_array_t *tensor_area; 59 | mp_obj_t tf_interpreter; 60 | mp_obj_t tf_model; 61 | mp_obj_t tf_error_reporter; 62 | int16_t inference_count; 63 | mp_obj_t input_callback; 64 | mp_obj_t output_callback; 65 | } microlite_interpreter_obj_t; 66 | 67 | typedef struct _microlite_tensor_obj_t { 68 | mp_obj_base_t base; 69 | mp_obj_t tf_tensor; 70 | microlite_interpreter_obj_t *microlite_interpreter; 71 | } microlite_tensor_obj_t; 72 | 73 | typedef struct _microlite_audio_frontend_obj_t { 74 | mp_obj_base_t base; 75 | struct FrontendConfig *config; 76 | struct FrontendState *state; 77 | } microlite_audio_frontend_obj_t; 78 | 79 | mp_obj_t audio_frontend_execute (mp_obj_t self_in, mp_obj_t input); 80 | mp_obj_t audio_frontend_configure (mp_obj_t self_in); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /micropython-modules/microlite/xalloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * 4 | * Copyright (c) 2013-2021 Ibrahim Abdelkader 5 | * Copyright (c) 2013-2021 Kwabena W. Agyeman 6 | * 7 | * This work is licensed under the MIT license, see the file LICENSE for details. 8 | * 9 | * Memory allocation functions. 10 | * 11 | * Copied from github.com/openmv/openmv (master) commit: df6f77bd0646167837d0b40081b98ccca2b4591a 12 | * Commit Date: Tue Nov 9 16:55:44 2021 +0200 13 | * 14 | */ 15 | #include 16 | #include "py/runtime.h" 17 | #include "py/gc.h" 18 | #include "py/mphal.h" 19 | #include "xalloc.h" 20 | 21 | NORETURN static void xalloc_fail(size_t size) 22 | { 23 | mp_raise_msg_varg(&mp_type_MemoryError, 24 | MP_ERROR_TEXT("memory allocation failed, allocating %u bytes"), (uint)size); 25 | } 26 | 27 | // returns null pointer without error if size==0 28 | void *xalloc(size_t size) 29 | { 30 | void *mem = gc_alloc(size, false); 31 | if (size && (mem == NULL)) { 32 | xalloc_fail(size); 33 | } 34 | return mem; 35 | } 36 | 37 | // returns null pointer without error if size==0 38 | void *xalloc_try_alloc(size_t size) 39 | { 40 | return gc_alloc(size, false); 41 | } 42 | 43 | // returns null pointer without error if size==0 44 | void *xalloc0(size_t size) 45 | { 46 | void *mem = gc_alloc(size, false); 47 | if (size && (mem == NULL)) { 48 | xalloc_fail(size); 49 | } 50 | memset(mem, 0, size); 51 | return mem; 52 | } 53 | 54 | // returns without error if mem==null 55 | void xfree(void *mem) 56 | { 57 | gc_free(mem); 58 | } 59 | 60 | // returns null pointer without error if size==0 61 | // allocs if mem==null and size!=0 62 | // frees if mem!=null and size==0 63 | void *xrealloc(void *mem, size_t size) 64 | { 65 | mem = gc_realloc(mem, size, true); 66 | if (size && (mem == NULL)) { 67 | xalloc_fail(size); 68 | } 69 | return mem; 70 | } 71 | -------------------------------------------------------------------------------- /micropython-modules/microlite/xalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * 4 | * Copyright (c) 2013-2021 Ibrahim Abdelkader 5 | * Copyright (c) 2013-2021 Kwabena W. Agyeman 6 | * 7 | * This work is licensed under the MIT license, see the file LICENSE for details. 8 | * 9 | * Memory allocation functions. 10 | * 11 | * Copied from github.com/openmv/openmv (master) commit: df6f77bd0646167837d0b40081b98ccca2b4591a 12 | * Commit Date: Tue Nov 9 16:55:44 2021 +0200 13 | * 14 | */ 15 | #ifndef __XALLOC_H__ 16 | #define __XALLOC_H__ 17 | #include 18 | void *xalloc(size_t size); 19 | void *xalloc_try_alloc(size_t size); 20 | void *xalloc0(size_t size); 21 | void xfree(void *mem); 22 | void *xrealloc(void *mem, size_t size); 23 | #endif // __XALLOC_H__ 24 | -------------------------------------------------------------------------------- /micropython-modules/micropython-camera-driver/micropython.cmake: -------------------------------------------------------------------------------- 1 | # we have only integrated with esp32-camera so require 2 | if (CAMERA_TYPE STREQUAL "esp32") 3 | 4 | # Create an INTERFACE library for our C module. 5 | add_library(usermod_esp32camera INTERFACE) 6 | 7 | # Add our source files to the lib 8 | target_sources(usermod_esp32camera INTERFACE 9 | ${CMAKE_CURRENT_LIST_DIR}/modcamera.c 10 | ) 11 | 12 | get_filename_component(ESP32_CAMERA_DIR ${PROJECT_DIR}/../../../tflm_esp_kernels/components/esp32-camera ABSOLUTE) 13 | 14 | list(APPEND COMPONENTS esp32-camera) 15 | 16 | # Add the current directory as an include directory. 17 | target_include_directories(usermod_esp32camera INTERFACE 18 | ${CMAKE_CURRENT_LIST_DIR} 19 | ${ESP32_CAMERA_DIR}/driver/include 20 | ${ESP32_CAMERA_DIR}/driver/private_include 21 | ${ESP32_CAMERA_DIR}/conversions/include 22 | ${ESP32_CAMERA_DIR}/conversions/private_include 23 | ${ESP32_CAMERA_DIR}/sensors/private_include 24 | ) 25 | 26 | target_compile_definitions(usermod_esp32camera INTERFACE) 27 | 28 | # Link our INTERFACE library to the usermod target. 29 | target_link_libraries(usermod INTERFACE usermod_esp32camera) 30 | 31 | endif() -------------------------------------------------------------------------------- /micropython-modules/micropython-camera-driver/modcamera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2021] Mauro Riva 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef MICROPY_INCLUDED_ESP32_MODCAMERA_H 18 | #define MICROPY_INCLUDED_ESP32_MODCAMERA_H 19 | 20 | enum { OV2640, OV7725}; 21 | 22 | #define TAG "camera" 23 | 24 | //WROVER-KIT PIN Map 25 | #define CAM_PIN_PWDN 32 //power down is not used 26 | #define CAM_PIN_RESET -1 //software reset will be performed 27 | #define CAM_PIN_XCLK 0 28 | #define CAM_PIN_SIOD 26 // SDA 29 | #define CAM_PIN_SIOC 27 // SCL 30 | 31 | #define CAM_PIN_D7 35 32 | #define CAM_PIN_D6 34 33 | #define CAM_PIN_D5 39 34 | #define CAM_PIN_D4 36 35 | #define CAM_PIN_D3 21 36 | #define CAM_PIN_D2 19 37 | #define CAM_PIN_D1 18 38 | #define CAM_PIN_D0 5 39 | #define CAM_PIN_VSYNC 25 40 | #define CAM_PIN_HREF 23 41 | #define CAM_PIN_PCLK 22 42 | #define XCLK_FREQ_10MHz 10000000 43 | #define XCLK_FREQ_20MHz 20000000 44 | 45 | //White Balance 46 | #define WB_NONE 0 47 | #define WB_SUNNY 1 48 | #define WB_CLOUDY 2 49 | #define WB_OFFICE 3 50 | #define WB_HOME 4 51 | 52 | //Special Effect 53 | #define EFFECT_NONE 0 54 | #define EFFECT_NEG 1 55 | #define EFFECT_BW 2 56 | #define EFFECT_RED 3 57 | #define EFFECT_GREEN 4 58 | #define EFFECT_BLUE 5 59 | #define EFFECT_RETRO 6 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /micropython-modules/micropython.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Tensorflow Micropython Examples Project. 3 | # 4 | # The MIT License (MIT) 5 | # 6 | # Copyright (c) 2021 Michael O'Cleirigh 7 | # 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy 9 | # of this software and associated documentation files (the "Software"), to deal 10 | # in the Software without restriction, including without limitation the rights 11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | # copies of the Software, and to permit persons to whom the Software is 13 | # furnished to do so, subject to the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be included in 16 | # all copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | # THE SOFTWARE. 25 | # 26 | 27 | include(${CMAKE_CURRENT_LIST_DIR}/microlite/micropython.cmake) 28 | 29 | # disabled. will be incorporated into microlite in #36 30 | # include(${CMAKE_CURRENT_LIST_DIR}/audio_frontend/micropython.cmake) 31 | 32 | include(${CMAKE_CURRENT_LIST_DIR}/../micropython-ulab/code/micropython.cmake) 33 | 34 | # the camera driver 35 | include(${CMAKE_CURRENT_LIST_DIR}/micropython-camera-driver/micropython.cmake) 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/micro-speech/i2s_read.py: -------------------------------------------------------------------------------- 1 | from machine import I2S 2 | from machine import Pin 3 | 4 | bck_pin = Pin(18) # Bit clock output 5 | ws_pin = Pin(18) # Word clock output 6 | sdin_pin = Pin(5) # Serial data input 7 | 8 | audio_in = I2S(I2S.NUM0, # create I2S peripheral to read audio 9 | bck=bck_pin, ws=ws_pin, sdin=sdin_pin, # sample data from an INMP441 10 | standard=I2S.PHILIPS, mode=I2S.MASTER_RX, # microphone module 11 | dataformat=I2S.B32, 12 | channelformat=I2S.RIGHT_LEFT, 13 | samplerate=16000, 14 | dmacount=16,dmalen=256) 15 | 16 | samples = bytearray(2048) # bytearray to receive audio samples 17 | 18 | num_bytes_read = audio_in.readinto(samples) # read audio samples from microphone 19 | # note: blocks until sample array is full 20 | # - see optional timeout argument 21 | # to configure maximum blocking duration 22 | -------------------------------------------------------------------------------- /update-microlite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TF_LITE=tensorflow/tensorflow/lite 4 | TF_LITE_MICRO=$TF_LITE/micro 5 | 6 | cp $TF_LITE_MICRO/tools/make/gen/esp_xtensa-esp32_default/lib/libtensorflow-microlite.a lib/libtensorflow-microlite.a 7 | 8 | --------------------------------------------------------------------------------