mehrdadh commented on code in PR #13518:
URL: https://github.com/apache/tvm/pull/13518#discussion_r1037390304


##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -560,17 +580,21 @@ def _get_board_from_makefile(self, makefile_path: 
pathlib.Path) -> str:
     FLASH_MAX_RETRIES = 5
 
     def flash(self, options):
+        import serial.tools.list_ports

Review Comment:
   done. We should fix this issue. It's only because we are running microtvm 
tutorials in GPU where the dependencies are not installed



##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -524,26 +531,39 @@ def _parse_connected_boards(self, tabular_str):
                 device[col_name] = str_row[column.start() : 
column.end()].strip()
             yield device
 
-    def _auto_detect_port(self, arduino_cli_cmd: str, board: str) -> str:
-        list_cmd = [self._get_arduino_cli_cmd(arduino_cli_cmd), "board", 
"list"]
-        list_cmd_output = subprocess.run(
-            list_cmd, check=True, stdout=subprocess.PIPE
-        ).stdout.decode("utf-8")
-
-        desired_fqbn = self._get_fqbn(board)
-        for device in self._parse_connected_boards(list_cmd_output):
-            if device["fqbn"] == desired_fqbn:
-                return device["port"]
+    def _auto_detect_port(self, arduino_cli_cmd: str, board: str, 
serial_number) -> str:
+        if not serial_number:
+            # If serial_number is not set, it is assumed only one board
+            # with this type is connected to this host machine.
+            list_cmd = [self._get_arduino_cli_cmd(arduino_cli_cmd), "board", 
"list"]
+            list_cmd_output = subprocess.run(
+                list_cmd, check=True, stdout=subprocess.PIPE
+            ).stdout.decode("utf-8")
+
+            desired_fqbn = self._get_fqbn(board)
+            for device in self._parse_connected_boards(list_cmd_output):
+                if device["fqbn"] == desired_fqbn:
+                    device_port = device["port"]
+                    break
+        else:
+            com_ports = serial.tools.list_ports.comports()
+            for port in com_ports:
+                if port.serial_number == serial_number:
+                    device_port = port.device
 
+        if device_port:
+            return device_port
         # If no compatible boards, raise an error
         raise BoardAutodetectFailed()
 
-    def _get_arduino_port(self, arduino_cli_cmd: str, board: str, port: int):
+    def _get_arduino_port(self, arduino_cli_cmd: str, board: str, port: int, 
serial_number: str):
         if not self._port:
             if port:
                 self._port = port
             else:
-                self._port = self._auto_detect_port(arduino_cli_cmd, board)
+                self._port = self._auto_detect_port(
+                    arduino_cli_cmd, board, serial_number=serial_number

Review Comment:
   done



##########
python/tvm/micro/testing/pytest_plugin.py:
##########
@@ -60,6 +60,11 @@ def pytest_addoption(parser):
             "Also, it will enable debug level logging in project generation."
         ),
     )
+    parser.addoption(
+        "--serial",
+        default=None,
+        help="If set true, use the FVP emulator to run the test",

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to