Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/microtvm/arduino/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--- 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 directory contains code to interface microTVM with [Arduino](https://www.arduino.cc/).

This file was deleted.

59 changes: 59 additions & 0 deletions apps/microtvm/arduino/template_project/boards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"due": {
"package": "arduino",
"architecture": "sam",
"board": "arduino_due_x_dbg",
"model": "sam3x8e"
},
"feathers2": {
"package": "esp32",
"architecture": "esp32",
"board": "feathers2",
"model": "esp32",
"note": "Due to the way the Feather S2 bootloader works, compilation behaves fine but uploads cannot be done automatically."
},
"metrom4": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_metro_m4",
"model": "atsamd51"
},
"spresense": {
"package": "SPRESENSE",
"architecture": "spresense",
"board": "spresense",
"model": "cxd5602gg",
"note": "Spresense only works as of its v2.3.0 sdk."
},
"nano33ble": {
"package": "arduino",
"architecture": "mbed_nano",
"board": "nano33ble",
"model": "nrf52840"
},
"pybadge": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_pybadge_m4",
"model": "atsamd51"
},
"teensy40": {
"package": "teensy",
"architecture": "avr",
"board": "teensy40",
"model": "imxrt1060",
"note": "The Teensy boards are listed here for completeness, but they won't work until https://github.com/arduino/arduino-cli/issues/700 is finished."
},
"teensy41": {
"package": "teensy",
"architecture": "avr",
"board": "teensy41",
"model": "imxrt1060"
},
"wioterminal": {
"package": "Seeeduino",
"architecture": "samd",
"board": "seeed_wio_terminal",
"model": "atsamd51"
}
}
98 changes: 23 additions & 75 deletions apps/microtvm/arduino/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,77 +44,21 @@
IS_TEMPLATE = not (API_SERVER_DIR / MODEL_LIBRARY_FORMAT_RELPATH).exists()


BOARDS = API_SERVER_DIR / "boards.json"

# Data structure to hold the information microtvm_api_server.py needs
# to communicate with each of these boards.
try:
with open(BOARDS) as boards:
BOARD_PROPERTIES = json.load(boards)
except FileNotFoundError:
raise FileNotFoundError(f"Board file {{{BOARDS}}} does not exist.")


class BoardAutodetectFailed(Exception):
"""Raised when no attached hardware is found matching the requested board"""


# Data structure to hold the information microtvm_api_server.py needs
# to communicate with each of these boards. Currently just holds the
# components of each board's FQBN, but might be extended in the future
# to include the SRAM, PSRAM, flash, etc. on each board.
BOARD_PROPERTIES = {
"due": {
"package": "arduino",
"architecture": "sam",
"board": "arduino_due_x_dbg",
"model": "sam3x8e",
},
# Due to the way the Feather S2 bootloader works, compilation
# behaves fine but uploads cannot be done automatically
"feathers2": {
"package": "esp32",
"architecture": "esp32",
"board": "feathers2",
"model": "esp32",
},
"metrom4": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_metro_m4",
"model": "atsamd51",
},
# Spresense only works as of its v2.3.0 sdk
"spresense": {
"package": "SPRESENSE",
"architecture": "spresense",
"board": "spresense",
"model": "cxd5602gg",
},
"nano33ble": {
"package": "arduino",
"architecture": "mbed_nano",
"board": "nano33ble",
"model": "nrf52840",
},
"pybadge": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_pybadge_m4",
"model": "atsamd51",
},
# The Teensy boards are listed here for completeness, but they
# won't work until https://github.com/arduino/arduino-cli/issues/700
# is finished
"teensy40": {
"package": "teensy",
"architecture": "avr",
"board": "teensy40",
"model": "imxrt1060",
},
"teensy41": {
"package": "teensy",
"architecture": "avr",
"board": "teensy41",
"model": "imxrt1060",
},
"wioterminal": {
"package": "Seeeduino",
"architecture": "samd",
"board": "seeed_wio_terminal",
"model": "atsamd51",
},
}

PROJECT_TYPES = ["example_project", "host_driven"]

PROJECT_OPTIONS = [
Expand All @@ -123,11 +67,6 @@ class BoardAutodetectFailed(Exception):
choices=list(BOARD_PROPERTIES),
help="Name of the Arduino board to build for",
),
server.ProjectOption(
"arduino_model",
choices=[board["model"] for _, board in BOARD_PROPERTIES.items()],
help="Name of the model for each Arduino board.",
),
server.ProjectOption("arduino_cli_cmd", help="Path to the arduino-cli tool."),
server.ProjectOption("port", help="Port to use for connecting to hardware"),
server.ProjectOption(
Expand Down Expand Up @@ -166,8 +105,9 @@ def _copy_project_files(self, api_server_dir, project_dir, project_type):
so this file is copied separately in generate_project.

"""
project_types_folder = api_server_dir.parents[0]
for item in (project_types_folder / project_type / "src").iterdir():
for item in (API_SERVER_DIR / "src" / project_type).iterdir():
if item.name == "project.ino":
continue
dest = project_dir / "src" / item.name
if item.is_dir():
shutil.copytree(item, dest)
Expand All @@ -176,7 +116,7 @@ def _copy_project_files(self, api_server_dir, project_dir, project_type):

# Arduino requires the .ino file have the same filename as its containing folder
shutil.copy2(
project_types_folder / project_type / "project.ino",
API_SERVER_DIR / "src" / project_type / "project.ino",
project_dir / f"{project_dir.stem}.ino",
)

Expand Down Expand Up @@ -344,12 +284,20 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec

# Copies files from the template folder to project_dir
shutil.copy2(API_SERVER_DIR / "microtvm_api_server.py", project_dir)
shutil.copy2(BOARDS, project_dir / BOARDS.name)
self._copy_project_files(API_SERVER_DIR, project_dir, options["project_type"])

# Copy standalone_crt into src folder
self._copy_standalone_crt(source_dir, standalone_crt_dir)
self._remove_unused_components(source_dir, options["project_type"])

# Populate crt-config.h
crt_config_dir = project_dir / "src" / "standalone_crt" / "crt_config"
crt_config_dir.mkdir()
shutil.copy2(
API_SERVER_DIR / "crt_config" / "crt_config.h", crt_config_dir / "crt_config.h"
)

# Unpack the MLF and copy the relevant files
metadata = self._disassemble_mlf(model_library_format_path, source_dir)
shutil.copy2(model_library_format_path, source_dir / "model")
Expand Down
2 changes: 1 addition & 1 deletion apps/microtvm/zephyr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
<!--- specific language governing permissions and limitations -->
<!--- under the License. -->

This directory code to interface microTVM with the [Zephyr RTOS](https://zephyrproject.org/).
This directory contains code to interface microTVM with the [Zephyr RTOS](https://zephyrproject.org/).

20 changes: 9 additions & 11 deletions tests/micro/arduino/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

import datetime
import pathlib

import json
import pytest

import tvm.target.target
from tvm.micro import project
from tvm import micro, relay
Expand All @@ -34,19 +35,16 @@
/ "template_project"
).resolve()

BOARDS = TEMPLATE_PROJECT_DIR / "boards.json"


def arduino_boards() -> dict:
"""Returns a dict mapping board to target model"""
template = project.TemplateProject.from_directory(TEMPLATE_PROJECT_DIR)
project_options = template.info()["project_options"]
for option in project_options:
if option["name"] == "arduino_board":
boards = option["choices"]
if option["name"] == "arduino_model":
models = option["choices"]

arduino_boards = {boards[i]: models[i] for i in range(len(boards))}
return arduino_boards
with open(BOARDS) as f:
board_properties = json.load(f)

boards_model = {board: info["model"] for board, info in board_properties.items()}
return boards_model


ARDUINO_BOARDS = arduino_boards()
Expand Down