Skip to content

Commit 6d32256

Browse files
committed
HIL add timeout for opening mtp device
1 parent 2693958 commit 6d32256

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,18 @@ jobs:
199199
runs-on: [self-hosted, X64, hathach, hardware-in-the-loop]
200200
steps:
201201
- name: Clean workspace
202+
if: github.run_attempt == '1'
202203
run: |
203204
echo "Cleaning up for the first run"
204205
rm -rf "${{ github.workspace }}"
205206
mkdir -p "${{ github.workspace }}"
206207
207208
- name: Checkout TinyUSB
209+
if: github.run_attempt == '1'
208210
uses: actions/checkout@v4
209211

210212
- name: Download Artifacts
213+
if: github.run_attempt == '1'
211214
uses: actions/download-artifact@v4
212215
with:
213216
path: cmake-build

docs/reference/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ By default log message is printed via on-board UART which is slow and take lots
178178
* Pros: work with most if not all MCUs
179179
* Software viewer is JLink RTT Viewer/Client/Logger which is bundled with JLink driver package.
180180

181-
* ``LOGGER=swo``\ : Use dedicated SWO pin of ARM Cortex SWD debug header.
181+
* ``LOGGER=swo`` : Use dedicated SWO pin of ARM Cortex SWD debug header.
182182

183183
* Cons: only work with ARM Cortex MCUs minus M0
184184
* Pros: should be compatible with more debugger that support SWO.

examples/device/mtp/src/usb_descriptors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ char const *string_desc_arr[] =
143143
"TinyUsb", // 1: Manufacturer
144144
"TinyUsb Device", // 2: Product
145145
NULL, // 3: Serials will use unique ID if possible
146-
"TinyUSBB MTP", // 4: MTP Interface
146+
"TinyUSB MTP", // 4: MTP Interface
147147
};
148148

149149
static uint16_t _desc_str[32 + 1];

test/hil/hil_test.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import ctypes
4343
from pymtp import MTP
4444

45-
mtp = MTP()
46-
4745
ENUM_TIMEOUT = 30
4846

4947
STATUS_OK = "\033[32mOK\033[0m"
@@ -140,6 +138,19 @@ def read_disk_file(uid, lun, fname):
140138
return None
141139

142140

141+
def open_mtp_dev(uid):
142+
mtp = MTP()
143+
timeout = ENUM_TIMEOUT
144+
while timeout > 0:
145+
for raw in mtp.detect_devices():
146+
mtp.device = mtp.mtp.LIBMTP_Open_Raw_Device(ctypes.byref(raw))
147+
if mtp.device and mtp.get_serialnumber().decode('utf-8') == uid:
148+
return mtp
149+
time.sleep(1)
150+
timeout -= 1
151+
return None
152+
153+
143154
# -------------------------------------------------------------
144155
# Flashing firmware
145156
# -------------------------------------------------------------
@@ -505,19 +516,14 @@ def test_device_mtp(board):
505516
_null = os.open(os.devnull, os.O_WRONLY)
506517
os.dup2(_null, fd)
507518

508-
for raw in mtp.detect_devices():
509-
mtp.device = mtp.mtp.LIBMTP_Open_Raw_Device(ctypes.byref(raw))
510-
if mtp.device and mtp.get_serialnumber().decode('utf-8') == uid:
511-
break
512-
else:
513-
mtp.device = None
519+
mtp = open_mtp_dev(uid)
514520

515521
# --- AFTER: restore stderr ---
516522
os.dup2(_saved, fd)
517523
os.close(_null)
518524
os.close(_saved)
519525

520-
if mtp.device is None:
526+
if mtp is None or mtp.device is None:
521527
assert False, 'MTP device not found'
522528

523529
assert b"TinyUSB" == mtp.get_manufacturer(), 'MTP wrong manufacturer'

0 commit comments

Comments
 (0)