├── .gitmodules ├── .travis.yml ├── LICENSE ├── README.md ├── binaries └── magic_wand │ ├── zephyr.bin │ └── zephyr.elf └── renode ├── angle.data ├── circle.data ├── litex-vexriscv-tflite.repl ├── litex-vexriscv-tflite.resc └── litex-vexriscv-tflite.robot /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "litex-buildenv"] 2 | path = litex-buildenv 3 | url = https://github.com/antmicro/litex-buildenv 4 | [submodule "tensorflow"] 5 | path = tensorflow 6 | url = https://github.com/tensorflow/tensorflow 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: linux 2 | dist: bionic 3 | language: c++ 4 | 5 | git: 6 | submodules: false 7 | 8 | before_install: 9 | - export DEBIAN_FRONTEND=noninteractive 10 | 11 | install: 12 | - sudo apt-get update && sudo apt-get install -y --no-install-recommends git ninja-build gperf ccache dfu-util device-tree-compiler wget python3-pip python3-setuptools python3-tk python3-wheel python3 xz-utils file make gcc gcc-multilib locales tar curl unzip gnupg ca-certificates 13 | - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF 14 | - echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list 15 | - sudo apt update 16 | - sudo locale-gen "en_US.UTF-8" 17 | - export LANG="en_US.UTF-8" 18 | - wget -q https://cmake.org/files/v3.14/cmake-3.14.2-Linux-x86_64.tar.gz 19 | - tar -xf cmake-3.14.2-Linux-x86_64.tar.gz 20 | - export PATH=`realpath cmake-3.14.2-Linux-x86_64/bin`:$PATH 21 | - wget -q https://antmicro.com/projects/renode/builds/renode-latest.deb 22 | - sudo apt install ./renode-latest.deb 23 | 24 | script: 25 | - ROOT=`pwd` 26 | - sudo pip3 install psutil netifaces requests virtualenv 27 | - sudo pip3 install robotframework==3.1.2 28 | - wget -q https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.2/zephyr-sdk-0.11.2-setup.run 29 | - chmod +x zephyr-sdk-0.11.2-setup.run 30 | - ./zephyr-sdk-0.11.2-setup.run -- -d ${ROOT}/zephyr-sdk -y 31 | - export ZEPHYR_SDK_INSTALL_DIR=${ROOT}/zephyr-sdk 32 | - git config --global url.https://github.com/llvm-mirror/.insteadOf 'https://git.llvm.org/git/' 33 | - git submodule update --init --recursive 34 | - pushd tensorflow 35 | - make -f tensorflow/lite/micro/tools/make/Makefile TARGET=zephyr_vexriscv hello_world_bin -j$(nproc) 36 | - make -f tensorflow/lite/micro/tools/make/Makefile TARGET=zephyr_vexriscv magic_wand_bin -j$(nproc) 37 | - cd ${ROOT} 38 | - travis_wait renode-test renode/litex-vexriscv-tflite.robot 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.com/antmicro/litex-vexriscv-tensorflow-lite-demo.svg?branch=master)](https://travis-ci.com/antmicro/litex-vexriscv-tensorflow-lite-demo) 2 | 3 | # Tensorflow lite demo running in Zephyr on Litex/VexRiscv SoC 4 | 5 | This repository collects all the repositories required to build and run [Zephyr](https://www.zephyrproject.org/) [TensorFlow Lite Micro](https://www.tensorflow.org/lite/microcontrollers) demos on either: 6 | 7 | * a [Digilent Arty A7](https://reference.digilentinc.com/reference/programmable-logic/arty-a7/start) board 8 | * the open source [Renode simulation framework](http://renode.io/) (no hardware required) 9 | 10 | The hardware version of the `magic wand` demo also requires a [PmodACL](https://store.digilentinc.com/pmod-acl-3-axis-accelerometer/) to be connected to the `JD` port of the Arty A7 board. 11 | 12 | ## Prerequisites 13 | 14 | Clone the repository and submodules: 15 | ```bash 16 | git clone https://github.com/antmicro/litex-vexriscv-tensorflow-lite-demo 17 | cd litex-vexriscv-tensorflow-lite-demo 18 | DEMO_HOME=`pwd` 19 | git submodule update --init --recursive 20 | ``` 21 | 22 | Install prerequisites (tested on Ubuntu 18.04): 23 | ```bash 24 | sudo apt update 25 | sudo apt install cmake ninja-build gperf ccache dfu-util device-tree-compiler wget python python3-pip python3-setuptools python3-tk python3-wheel xz-utils file make gcc gcc-multilib locales tar curl unzip xxd 26 | ``` 27 | 28 | Install Zephyr prerequisites: 29 | ```bash 30 | # update cmake to required version 31 | sudo pip3 install cmake virtualenv 32 | # install Zephyr SDK 33 | wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.2/zephyr-sdk-0.11.2-setup.run 34 | chmod +x zephyr-sdk-0.11.2-setup.run 35 | sudo ./zephyr-sdk-0.11.2-setup.run -- -d /opt/zephyr-sdk 36 | ``` 37 | 38 | Export Zephyr configuration: 39 | ```bash 40 | export ZEPHYR_TOOLCHAIN_VARIANT=zephyr 41 | export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk 42 | ``` 43 | 44 | ## Building the demos 45 | 46 | ### Hello World demo 47 | 48 | Build the `Hello World` demo with: 49 | ```bash 50 | cd $DEMO_HOME/tensorflow 51 | make -f tensorflow/lite/micro/tools/make/Makefile TARGET=zephyr_vexriscv hello_world_bin 52 | ``` 53 | The resulting binaries can be found in the `tensorflow/lite/micro/tools/make/gen/zephyr_vexriscv_x86_64/hello_world/build/zephyr` folder. 54 | 55 | ### Magic Wand demo 56 | 57 | Build the `Magic Wand` demo with: 58 | ```bash 59 | cd $DEMO_HOME/tensorflow 60 | make -f tensorflow/lite/micro/tools/make/Makefile TARGET=zephyr_vexriscv magic_wand_bin 61 | ``` 62 | The resulting binaries can be found in the `tensorflow/lite/micro/tools/make/gen/zephyr_vexriscv_x86_64/magic_wand/build/zephyr` folder. 63 | 64 | ## Building the gateware 65 | 66 | Note: For this section, if you have not already updated your udev rules, follow the instructions at "[Download & setup udev rules](https://github.com/timvideos/litex-buildenv/wiki/HowTo-LCA2018-FPGA-Miniconf#download--setup-udev-rules)" -- you probably won't need to reboot. 67 | 68 | The FPGA bitstream (gateware) can be built using [Litex Build Environment](https://github.com/timvideos/litex-buildenv). 69 | Building the gateware currently requires Xilinx's FPGA tooling, Vivado, to be installed in the system. 70 | 71 | Build the gateware with: 72 | ```bash 73 | cd $DEMO_HOME/litex-buildenv 74 | 75 | # Some of LiteX Buildenv's scritps have problems when running in a git repository in detached state. 76 | # Let's create a fake branch to avoid build errors. 77 | git checkout -b tf_demo 78 | 79 | export CPU=vexriscv 80 | export CPU_VARIANT=full 81 | export PLATFORM=arty 82 | export FIRMWARE=zephyr 83 | export TARGET=tf 84 | 85 | ./scripts/download-env.sh 86 | source scripts/enter-env.sh 87 | 88 | make gateware 89 | ``` 90 | 91 | Once you have synthesized the gateware, load it onto the FPGA with: 92 | 93 | ```bash 94 | make gateware-load 95 | ``` 96 | 97 | With the FPGA programmed, you can load the Zephyr binary on the device using the flterm program provided inside the environment you just initialized above: 98 | 99 | ```bash 100 | cd $DEMO_HOME/tensorflow 101 | flterm --port=/dev/ttyUSB1 --kernel=tensorflow/lite/micro/tools/make/gen/zephyr_vexriscv_x86_64/magic_wand/build/zephyr/zephyr.bin --speed=115200 102 | ``` 103 | 104 | See the [Litex Build Environment Wiki](https://github.com/timvideos/litex-buildenv/wiki/Getting-Started) for more available options. 105 | 106 | ## Simulating in Renode 107 | 108 | The `renode` directory contains all necessary scripts and assets required to simulate the `Magic Wand` demo. 109 | 110 | Install Renode as [detailed in its README file](https://github.com/renode/renode/blob/master/README.rst#installation). 111 | 112 | Build the `Magic Wand` demo as described [in the section above](#magic-wand-demo) or use a prebuilt binary from the `binares/magic_wand` directory. 113 | 114 | Now you should have everything to run the simulation using the locally built binary: 115 | ```bash 116 | cd $DEMO_HOME/renode 117 | renode -e "s @litex-vexriscv-tflite.resc" 118 | ``` 119 | 120 | Or using the prebuilt one: 121 | ```bash 122 | cd $DEMO_HOME/renode 123 | renode -e "set zephyr_elf @../binaries/magic_wand/zephyr.elf; s @litex-vexriscv-tflite.resc" 124 | ``` 125 | 126 | You should see the following output on the UART (which will open as a separate terminal in Renode automatically): 127 | ``` 128 | *** Booting Zephyr OS build 0.6.0-86741-g626bb2c4d0bd *** 129 | 4 bytes lost due to alignment. To avoid this loss, please make sure the tensor_arena is 16 bytes aligned. 130 | Got accelerometer, label: accel-0 131 | 132 | RING: 133 | * 134 | * * 135 | * * 136 | * * 137 | * * 138 | * * 139 | * 140 | 141 | SLOPE: 142 | * 143 | * 144 | * 145 | * 146 | * 147 | * 148 | * 149 | * * * * * * * * 150 | 151 | RING: 152 | * 153 | * * 154 | * * 155 | * * 156 | * * 157 | * * 158 | * 159 | 160 | SLOPE: 161 | * 162 | * 163 | * 164 | * 165 | * 166 | * 167 | * 168 | * * * * * * * * 169 | ``` 170 | 171 | In order to exit Renode, type `quit` in Monitor (the window with the Renode logo and `(machine-0)` prompt). 172 | 173 | Refer to the [Renode documentation](https://renode.readthedocs.org) for details on how to use Renode to implement more complex usage scenarios, and use its advanced debug capabilities, or set up CI testing your ML-oriented system. If you need commercial support, please contact us at [support@renode.io](mailto:support@renode.io). 174 | -------------------------------------------------------------------------------- /binaries/magic_wand/zephyr.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/litex-vexriscv-tensorflow-lite-demo/3f1dac40935fb8b996e982163970ce347c1263a9/binaries/magic_wand/zephyr.bin -------------------------------------------------------------------------------- /binaries/magic_wand/zephyr.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/litex-vexriscv-tensorflow-lite-demo/3f1dac40935fb8b996e982163970ce347c1263a9/binaries/magic_wand/zephyr.elf -------------------------------------------------------------------------------- /renode/angle.data: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 0 0 0 3 | 0 0 0 4 | 0 0 0 5 | 0 0 0 6 | 0 0 0 7 | 0 0 0 8 | 0 0 0 9 | 0 0 0 10 | 0 0 0 11 | 0 0 0 12 | 0 0 0 13 | 0 0 0 14 | 0 0 0 15 | 0 0 0 16 | 0 0 0 17 | 0 0 0 18 | 0 0 0 19 | 0 0 0 20 | 0 0 0 21 | 0 0 0 22 | 0 0 0 23 | 0 0 0 24 | 0 0 0 25 | 0 0 0 26 | 0 0 0 27 | 0 0 0 28 | 0 0 0 29 | 0 0 0 30 | 0 0 0 31 | 0 0 0 32 | 0 0 0 33 | 0 0 0 34 | 0 0 0 35 | 0 0 0 36 | 0 0 0 37 | 0 0 0 38 | 0 0 0 39 | 0 0 0 40 | 0 0 0 41 | 0 0 0 42 | 0 0 0 43 | 0 0 0 44 | 0 0 0 45 | 0 0 0 46 | 0 0 0 47 | 0 0 0 48 | 0 0 0 49 | 0 0 0 50 | 0 0 0 51 | 0 0 0 52 | 0 0 0 53 | 0 0 0 54 | 0 0 0 55 | 0 0 0 56 | 0 0 0 57 | 0 0 0 58 | 0 0 0 59 | 0 0 0 60 | 0 0 0 61 | 0 0 0 62 | 0 0 0 63 | 0 0 0 64 | 0 0 0 65 | 0 0 0 66 | 0 0 0 67 | 0 0 0 68 | 0 0 0 69 | 0 0 0 70 | 0 0 0 71 | 0 0 0 72 | 0 0 0 73 | 0 0 0 74 | -766 132 709 75 | -751 249 659 76 | -714 314 630 77 | -709 244 623 78 | -707 230 659 79 | -704 202 748 80 | -714 219 728 81 | -722 239 710 82 | -744 116 612 83 | -753 -49 570 84 | -748 -279 527 85 | -668 -664 592 86 | -601 -635 609 87 | -509 -559 606 88 | -286 -162 536 89 | -255 -144 495 90 | -209 -85 495 91 | 6 416 698 92 | -33 304 1117 93 | -82 405 1480 94 | -198 1008 1908 95 | -229 990 1743 96 | -234 934 1453 97 | -126 838 896 98 | -78 792 911 99 | -27 741 918 100 | 114 734 960 101 | 135 613 959 102 | 152 426 1015 103 | 106 -116 1110 104 | 63 -314 1129 105 | -12 -486 1179 106 | -118 -656 1510 107 | -116 -558 1553 108 | -126 -361 1367 109 | -222 -76 922 110 | -210 -26 971 111 | -194 50 1053 112 | -178 72 1082 113 | -169 100 1073 114 | -162 133 1050 115 | -156 226 976 116 | -154 323 886 117 | -130 240 1154 118 | -116 124 916 119 | -132 124 937 120 | -153 115 981 121 | -184 94 962 122 | -177 85 1017 123 | -173 92 1027 124 | -168 158 1110 125 | -181 101 1030 126 | -180 139 1054 127 | -152 10 1044 128 | -169 74 1007 129 | -------------------------------------------------------------------------------- /renode/circle.data: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 0 0 0 3 | 0 0 0 4 | 0 0 0 5 | 0 0 0 6 | 0 0 0 7 | 0 0 0 8 | 0 0 0 9 | 0 0 0 10 | 0 0 0 11 | 0 0 0 12 | 0 0 0 13 | 0 0 0 14 | 0 0 0 15 | 0 0 0 16 | 0 0 0 17 | 0 0 0 18 | 0 0 0 19 | 0 0 0 20 | 0 0 0 21 | 0 0 0 22 | 0 0 0 23 | 0 0 0 24 | 0 0 0 25 | 0 0 0 26 | 0 0 0 27 | 0 0 0 28 | 0 0 0 29 | 0 0 0 30 | 0 0 0 31 | 0 0 0 32 | 0 0 0 33 | 0 0 0 34 | 0 0 0 35 | 0 0 0 36 | 0 0 0 37 | 0 0 0 38 | 0 0 0 39 | 0 0 0 40 | 0 0 0 41 | 0 0 0 42 | 0 0 0 43 | 0 0 0 44 | 0 0 0 45 | 0 0 0 46 | 0 0 0 47 | 0 0 0 48 | 0 0 0 49 | 0 0 0 50 | 0 0 0 51 | 0 0 0 52 | 0 0 0 53 | 0 0 0 54 | 0 0 0 55 | 0 0 0 56 | 0 0 0 57 | 0 0 0 58 | 0 0 0 59 | 0 0 0 60 | 0 0 0 61 | 0 0 0 62 | -665 228 827 63 | -680 339 716 64 | -680 564 812 65 | -679 552 818 66 | -665 528 751 67 | -658 432 618 68 | -655 445 592 69 | -667 484 556 70 | -684 590 510 71 | -674 672 475 72 | -660 786 390 73 | -562 1124 128 74 | -526 1140 111 75 | -486 1044 33 76 | -416 652 -134 77 | -390 534 -143 78 | -365 381 -117 79 | -314 60 94 80 | -322 7 190 81 | -338 -95 342 82 | -360 -106 842 83 | -351 -41 965 84 | -352 12 960 85 | -366 42 1124 86 | -322 56 1178 87 | -312 15 1338 88 | -254 10 1532 89 | -241 5 1590 90 | -227 60 1565 91 | -204 282 1560 92 | -180 262 1524 93 | -138 385 1522 94 | -84 596 1626 95 | -55 639 1604 96 | -19 771 1511 97 | 16 932 1132 98 | 15 924 1013 99 | 1 849 812 100 | -88 628 500 101 | -114 609 463 102 | -155 559 382 103 | -234 420 278 104 | -254 390 272 105 | -327 200 336 106 | -558 -556 630 107 | -640 -607 740 108 | -706 -430 868 109 | -778 42 1042 110 | -763 84 973 111 | -735 185 931 112 | -682 252 766 113 | -673 230 757 114 | -671 218 757 115 | -656 222 714 116 | -659 238 746 117 | -640 276 731 118 | -634 214 754 119 | -637 207 735 120 | -637 194 742 121 | -634 248 716 122 | -631 265 697 123 | -628 252 797 124 | -592 204 816 125 | -618 218 812 126 | -633 231 828 127 | -640 222 736 128 | -634 221 787 129 | -------------------------------------------------------------------------------- /renode/litex-vexriscv-tflite.repl: -------------------------------------------------------------------------------- 1 | ram: Memory.MappedMemory @ { 2 | sysbus 0x40000000; 3 | sysbus 0xc0000000 // shadow 4 | } 5 | size: 0x10000000 6 | 7 | cpu: CPU.VexRiscv @ sysbus 8 | cpuType: "rv32imac" 9 | 10 | uart: UART.LiteX_UART @ { 11 | sysbus 0x60001800; 12 | sysbus 0xE0001800 // shadow 13 | } 14 | -> cpu@2 15 | 16 | timer0: Timers.LiteX_Timer @ { 17 | sysbus 0x60002800; 18 | sysbus 0xE0002800 // shadow 19 | } 20 | frequency: 100000000 21 | -> cpu@1 22 | 23 | i2c: I2C.LiteX_I2C_Zephyr @ { 24 | sysbus 0x60003000; 25 | sysbus 0xE0003000 // shadow 26 | } 27 | 28 | adxl345: Sensors.ADXL345 @ i2c 0x1D 29 | 30 | -------------------------------------------------------------------------------- /renode/litex-vexriscv-tflite.resc: -------------------------------------------------------------------------------- 1 | using sysbus 2 | 3 | $zephyr_elf?=@../tensorflow/tensorflow/lite/micro/tools/make/gen/zephyr_vexriscv_x86_64/magic_wand/build/zephyr/zephyr.elf 4 | 5 | mach create 6 | machine LoadPlatformDescription $ORIGIN/litex-vexriscv-tflite.repl 7 | showAnalyzer uart 8 | logLevel 3 i2c 9 | 10 | macro reset 11 | """ 12 | sysbus LoadELF $zephyr_elf 13 | 14 | i2c.adxl345 MaxFifoDepth 1 15 | i2c.adxl345 FeedSample $ORIGIN/circle.data 16 | i2c.adxl345 FeedSample 0 15000 15000 128 17 | i2c.adxl345 FeedSample 0 0 0 128 18 | i2c.adxl345 FeedSample $ORIGIN/angle.data 19 | i2c.adxl345 FeedSample 0 15000 15000 128 20 | i2c.adxl345 FeedSample 0 0 0 128 21 | i2c.adxl345 FeedSample $ORIGIN/circle.data 22 | i2c.adxl345 FeedSample 0 15000 15000 128 23 | i2c.adxl345 FeedSample 0 0 0 128 24 | i2c.adxl345 FeedSample $ORIGIN/angle.data 25 | i2c.adxl345 FeedSample 0 15000 15000 128 26 | i2c.adxl345 FeedSample 0 0 0 128 27 | 28 | """ 29 | 30 | runMacro $reset 31 | -------------------------------------------------------------------------------- /renode/litex-vexriscv-tflite.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Suite Setup Setup 3 | Suite Teardown Teardown 4 | Test Setup Reset Emulation 5 | Resource ${RENODEKEYWORDS} 6 | 7 | *** Keywords *** 8 | Wait For Ring 9 | Wait For Line On Uart RING: 10 | # Passing whitespaces in arguments is a bit tricky. 11 | # Here we wait for the following pattern: 12 | # * 13 | # * * 14 | # * * 15 | # * * 16 | # * * 17 | # * * 18 | # * 19 | Wait For Line On Uart ${SPACE*10}* 20 | Wait For Line On Uart ${SPACE*7}*${SPACE*5}* 21 | Wait For Line On Uart ${SPACE*5}*${SPACE*9}* 22 | Wait For Line On Uart ${SPACE*4}*${SPACE*11}* 23 | Wait For Line On Uart ${SPACE*5}*${SPACE*9}* 24 | Wait For Line On Uart ${SPACE*7}*${SPACE*5}* 25 | Wait For Line On Uart ${SPACE*10}* 26 | 27 | Wait For Slope 28 | Wait For Line On Uart SLOPE: 29 | # Passing whitespaces in arguments is a bit tricky. 30 | # Here we wait for the following pattern: 31 | # * 32 | # * 33 | # * 34 | # * 35 | # * 36 | # * 37 | # * 38 | # * * * * * * * * 39 | Wait For Line On Uart ${SPACE*8}* 40 | Wait For Line On Uart ${SPACE*7}* 41 | Wait For Line On Uart ${SPACE*6}* 42 | Wait For Line On Uart ${SPACE*5}* 43 | Wait For Line On Uart ${SPACE*4}* 44 | Wait For Line On Uart ${SPACE*3}* 45 | Wait For Line On Uart ${SPACE*2}* 46 | Wait For Line On Uart ${SPACE}* * * * * * * * 47 | 48 | *** Test Cases *** 49 | Run Hello World Demo 50 | Execute Command using sysbus 51 | 52 | Execute Command mach create 53 | Execute Command machine LoadPlatformDescription @${CURDIR}/litex-vexriscv-tflite.repl 54 | 55 | Execute Command showAnalyzer uart Antmicro.Renode.Analyzers.LoggingUartAnalyzer 56 | 57 | Execute Command sysbus LoadELF @${CURDIR}/../tensorflow/tensorflow/lite/micro/tools/make/gen/zephyr_vexriscv_x86_64/hello_world/build/zephyr/zephyr.elf 58 | 59 | Create Terminal Tester sysbus.uart 60 | 61 | Start Emulation 62 | 63 | Wait For Line On Uart Booting Zephyr OS 64 | Wait For Line On Uart x_value 65 | Wait For Line On Uart y_value 66 | 67 | Run Magic Wand Demo 68 | Execute Command using sysbus 69 | 70 | Execute Command mach create 71 | Execute Command machine LoadPlatformDescription @${CURDIR}/litex-vexriscv-tflite.repl 72 | 73 | Execute Command showAnalyzer uart Antmicro.Renode.Analyzers.LoggingUartAnalyzer 74 | 75 | Execute Command sysbus LoadELF @${CURDIR}/../tensorflow/tensorflow/lite/micro/tools/make/gen/zephyr_vexriscv_x86_64/magic_wand/build/zephyr/zephyr.elf 76 | 77 | Execute Command i2c.adxl345 MaxFifoDepth 1 78 | Execute Command i2c.adxl345 FeedSample @${CURDIR}/circle.data 79 | Execute Command i2c.adxl345 FeedSample 0 15000 15000 128 80 | Execute Command i2c.adxl345 FeedSample 0 0 0 128 81 | Execute Command i2c.adxl345 FeedSample @${CURDIR}/angle.data 82 | Execute Command i2c.adxl345 FeedSample 0 15000 15000 128 83 | Execute Command i2c.adxl345 FeedSample 0 0 0 128 84 | 85 | Create Terminal Tester sysbus.uart timeout=480 86 | 87 | Start Emulation 88 | 89 | Wait For Line On Uart Booting Zephyr OS 90 | Wait For Line On Uart Got accelerometer 91 | 92 | Wait For Ring 93 | Wait For Slope 94 | 95 | --------------------------------------------------------------------------------