From d05da61270943f83ecedb5acdee88fae9dbbd4ac Mon Sep 17 00:00:00 2001 From: Gustavo Romero Date: Tue, 30 Mar 2021 17:04:22 +0000 Subject: [PATCH] =?UTF-8?q?[=C2=B5TVM]=20apps:=20Fix=20Zephyr=20code=20exa?= =?UTF-8?q?mple=20for=20STM32F746=20boards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit c39a6e25d "Clean up uTVM demo runtime, add ONNX model test and tutorial (#7557)" changed the location of the Zephyr code example to apps/ so this commit updates the tutorial examples under tutorials/micro to reflect the new location where src/main.c resides. Since commit c39a6e25d also split Zephyr configuration per boards, under project's boards/, this commit also adds a proper config for the STM32F746 Discovery board and fixes a nit in the comment in boards/nucleo_f746zg.conf. It also removes CONFIG_MAIN_STACK_SIZE=50 for disco and nucleo boards since the MCUs for both boads are Cortex-m7 based, not Contex-m33. For the new boards/stm32f746g_disco.conf CONFIG_TEST_RANDOM_GENERATOR=y is set, otherwise when CONFIG_ENTROPY_GENERATOR=y linking will fail with the following error: rand32.h:33: undefined reference to `z_impl_sys_rand32_get' Finally, the size of 'uart_data' temporary buffer is reduced a bit (to 8 bytes) to free some additional bytes in SRAM, since most MCUs have a 1-byte FIFO, like it happens with Cortex-M-based MCUs. Signed-off-by: Gustavo Romero --- .../demo_runtime/boards/nucleo_f746zg.conf | 2 +- .../demo_runtime/boards/stm32f746g_disco.conf | 28 +++++++++++++++++++ apps/microtvm/zephyr/demo_runtime/src/main.c | 6 +--- tests/lint/check_file_type.py | 1 + tutorials/micro/micro_tflite.py | 2 +- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 apps/microtvm/zephyr/demo_runtime/boards/stm32f746g_disco.conf diff --git a/apps/microtvm/zephyr/demo_runtime/boards/nucleo_f746zg.conf b/apps/microtvm/zephyr/demo_runtime/boards/nucleo_f746zg.conf index 253ba43d8b36..eba023294894 100644 --- a/apps/microtvm/zephyr/demo_runtime/boards/nucleo_f746zg.conf +++ b/apps/microtvm/zephyr/demo_runtime/boards/nucleo_f746zg.conf @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. # -# This file is specific to the nRF5340 DK board. +# This file is specific to the STM32F746 Nucleo board. # For intrinsics used by generated optimized operators. CONFIG_CMSIS_DSP=y diff --git a/apps/microtvm/zephyr/demo_runtime/boards/stm32f746g_disco.conf b/apps/microtvm/zephyr/demo_runtime/boards/stm32f746g_disco.conf new file mode 100644 index 000000000000..505f1babc3f4 --- /dev/null +++ b/apps/microtvm/zephyr/demo_runtime/boards/stm32f746g_disco.conf @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# This file is specific to the STM32F746G Discovery board. + +# For intrinsics used by generated optimized operators. +CONFIG_CMSIS_DSP=y + +# For random number generation. +CONFIG_ENTROPY_GENERATOR=y +CONFIG_TEST_RANDOM_GENERATOR=y + +# For debugging. +CONFIG_LED=n diff --git a/apps/microtvm/zephyr/demo_runtime/src/main.c b/apps/microtvm/zephyr/demo_runtime/src/main.c index fc94e65d740a..c63d0922bd65 100644 --- a/apps/microtvm/zephyr/demo_runtime/src/main.c +++ b/apps/microtvm/zephyr/demo_runtime/src/main.c @@ -214,15 +214,11 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) { } // Ring buffer used to store data read from the UART on rx interrupt. -#if BOARD == qemu_x86 #define RING_BUF_SIZE_BYTES 4 * 1024 -#else -#define RING_BUF_SIZE_BYTES 1 * 1024 -#endif RING_BUF_DECLARE(uart_rx_rbuf, RING_BUF_SIZE_BYTES); // Small buffer used to read data from the UART into the ring buffer. -static uint8_t uart_data[32]; +static uint8_t uart_data[8]; // UART interrupt callback. void uart_irq_cb(const struct device* dev, void* user_data) { diff --git a/tests/lint/check_file_type.py b/tests/lint/check_file_type.py index 8d8b34322de3..ce20d7838b61 100644 --- a/tests/lint/check_file_type.py +++ b/tests/lint/check_file_type.py @@ -134,6 +134,7 @@ "apps/microtvm/zephyr/demo_runtime/boards/nrf5340dk_nrf5340_cpuapp.conf", "apps/microtvm/zephyr/demo_runtime/boards/nucleo_f746zg.conf", "apps/microtvm/zephyr/demo_runtime/boards/qemu_x86.conf", + "apps/microtvm/zephyr/demo_runtime/boards/stm32f746g_disco.conf", "apps/microtvm/zephyr/demo_runtime/qemu-hack/qemu-system-i386", # microTVM Virtual Machines "apps/microtvm/reference-vm/zephyr/Vagrantfile", diff --git a/tutorials/micro/micro_tflite.py b/tutorials/micro/micro_tflite.py index f59b1c3723a8..279756b9ca43 100644 --- a/tutorials/micro/micro_tflite.py +++ b/tutorials/micro/micro_tflite.py @@ -224,7 +224,7 @@ # from tvm.micro.contrib import zephyr # # repo_root = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], encoding='utf-8').strip() -# project_dir = f"{repo_root}/tests/micro/qemu/zephyr-runtime" +# project_dir = os.path.join(repo_root, "apps", "microtvm", "zephyr", "demo_runtime") # compiler = zephyr.ZephyrCompiler( # project_dir=project_dir, # board=BOARD if "stm32f746" in str(TARGET) else "qemu_x86",