Skip to content

add more hil tests#3557

Merged
hathach merged 8 commits intomasterfrom
hil-host-cdc
Mar 18, 2026
Merged

add more hil tests#3557
hathach merged 8 commits intomasterfrom
hil-host-cdc

Conversation

@hathach
Copy link
Copy Markdown
Owner

@hathach hathach commented Mar 17, 2026

Added new tests (test_host_cdc_msc_hid, test_device_midi_test, etc.) to verify enhanced CDC, MSC, LUN, MIDI, and HID features.

Copilot AI review requested due to automatic review settings March 17, 2026 07:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new HIL host-side CDC test to validate CDC enumeration + data path (via host cdc_msc_hid example), and updates HIL configuration / BSP helpers to better support the test environment.

Changes:

  • Add a new HIL test host/cdc_msc_hid that waits for CDC mount and performs a UART-console-driven CDC echo check.
  • Extend HIL board config (tinyusb.json) dev_attached entries with an is_cdc flag to identify CDC-capable attached devices.
  • Improve STM32H7 BSP support by implementing board_uart_read() and adding I2C retry logic for the STM32H743EVAL MFX bus access.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/hil/tinyusb.json Adds is_cdc metadata to attached-device entries for HIL host CDC testing.
test/hil/hil_test.py Introduces the new host/cdc_msc_hid HIL test and registers it in the host test list.
hw/bsp/stm32h7/family.c Implements board_uart_read() for UART-backed console input on STM32H7.
hw/bsp/stm32h7/boards/stm32h743eval/board.h Adds retry/delay logic for I2C mem read/write used by the MFX IO expander.
AGENTS.md Removes a stray blank line in documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

# reset device to catch mount messages
ret = globals()[f'reset_{flasher["name"].lower()}'](board)
assert ret.returncode == 0, 'Failed to reset device'

Comment on lines +427 to +492
ser.timeout = 0.1

# reset device to catch mount messages
ret = globals()[f'reset_{flasher["name"].lower()}'](board)
assert ret.returncode == 0, 'Failed to reset device'

# Wait for CDC mounted message
data = b''
timeout = ENUM_TIMEOUT
while timeout > 0:
new_data = ser.read(ser.in_waiting or 1)
if new_data:
data += new_data
if b'CDC Interface is mounted' in data:
break
time.sleep(0.1)
timeout -= 0.1
assert b'CDC Interface is mounted' in data, 'CDC device not mounted on host'

# Lookup serial chip name from vid_pid
vid_pid_name = {
'0403_6001': 'FTDI', '0403_6010': 'FTDI', '0403_6011': 'FTDI', '0403_6014': 'FTDI',
'10c4_ea60': 'CP210x', '10c4_ea70': 'CP210x',
'067b_2303': 'PL2303', '067b_23a3': 'PL2303',
'1a86_7523': 'CH340', '1a86_7522': 'CH340',
'1a86_55d3': 'CH9102', '1a86_55d4': 'CH9102',
}
dev = cdc_devs[0]
chip_name = vid_pid_name.get(dev['vid_pid'], dev['vid_pid'])
for l in data.decode('utf-8', errors='ignore').splitlines():
if 'CDC Interface is mounted' in l:
print(f'\r\n {chip_name}: {l} ', end='')

# CDC echo test via flasher serial
time.sleep(2)
ser.reset_input_buffer()

def rand_ascii(length):
return "".join(random.choices(string.ascii_letters + string.digits, k=length)).encode("ascii")

sizes = [8, 32, 64, 128]
for size in sizes:
test_data = rand_ascii(size)
ser.reset_input_buffer()

# Write byte-by-byte with delay to avoid UART overrun
for b in test_data:
ser.write(bytes([b]))
ser.flush()
time.sleep(0.001)

# Read echo back with timeout
echo = b''
t = 5.0
while t > 0 and len(echo) < size:
rd = ser.read(max(1, ser.in_waiting))
if rd:
echo += rd
time.sleep(0.05)
t -= 0.05
assert echo == test_data, (f'CDC echo wrong data ({size} bytes):\n'
f' expected: {test_data}\n received: {echo}')

ser.close()


Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a3b2b42176

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

]

host_test = [
'host/cdc_msc_hid',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate host/cdc_msc_hid on boards with UART RX support

Adding host/cdc_msc_hid to the default host test list makes it run on every host: true board, but at least one configured board (stm32f723disco in test/hil/tinyusb.json) routes through hw/bsp/stm32f7/family.c where board_uart_read() is a stub that always returns 0; in that setup board_getchar() never receives injected bytes, so the new CDC echo assertion will fail deterministically. This should be opt-in per board (or conditioned on RX support) to avoid breaking HIL runs.

Useful? React with 👍 / 👎.

if (HAL_OK == HAL_I2C_Mem_Read(&i2c_handle, DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length, 10000)) {
return 0;
}
HAL_Delay(10);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid HAL_Delay retries during pre-scheduler init

Using HAL_Delay(10) in this retry loop can deadlock STM32H7 FreeRTOS startups: board_init() disables SysTick before calling board_init2() in hw/bsp/stm32h7/family.c, so if the first I2C access fails here, HAL_Delay() has no advancing tick source and blocks indefinitely instead of retrying. This retry path needs a delay mechanism that works before the scheduler/tick is running.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 17, 2026

Size Difference Report

Because TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds.

Note: If there is no change, only one value is shown.

Changes >1% in size

No entries.

Changes <1% in size

No entries.

No changes
file .text .rodata .data .bss size % diff
audio_device.c 2896 0 1260 1623 4514 +0.0%
cdc_device.c 1252 16 1106 682 1932 +0.0%
cdc_host.c 6617 487 15 1498 8327 +0.0%
dcd_ch32_usbfs.c 1473 0 0 2444 3917 +0.0%
dcd_ch32_usbhs.c 1469 0 0 448 1917 +0.0%
dcd_ci_fs.c 1925 0 0 1290 3215 +0.0%
dcd_ci_hs.c 1759 0 0 1344 2538 +0.0%
dcd_da146xx.c 3067 0 0 144 3211 +0.0%
dcd_dwc2.c 4176 25 0 265 4465 +0.0%
dcd_eptri.c 2271 0 0 259 2530 +0.0%
dcd_ft9xx.c 3276 0 0 172 3448 +0.0%
dcd_khci.c 1953 0 0 1290 3243 +0.0%
dcd_lpc17_40.c 1474 0 0 648 1798 +0.0%
dcd_lpc_ip3511.c 1463 0 0 264 1683 +0.0%
dcd_mm32f327x_otg.c 1478 0 0 1290 2768 +0.0%
dcd_msp430x5xx.c 1798 0 0 176 1974 +0.0%
dcd_musb.c 2445 0 0 160 2605 +0.0%
dcd_nrf5x.c 2918 0 0 292 3210 +0.0%
dcd_nuc120.c 1094 0 0 78 1172 +0.0%
dcd_nuc121.c 1168 0 0 101 1269 +0.0%
dcd_nuc505.c 0 0 1531 157 1688 +0.0%
dcd_rp2040.c 858 20 604 655 2137 +0.0%
dcd_rusb2.c 2919 0 0 156 3075 +0.0%
dcd_samd.c 1034 0 0 266 1300 +0.0%
dcd_samg.c 1320 0 0 72 1392 +0.0%
dcd_stm32_fsdev.c 2558 0 0 291 2849 +0.0%
dfu_device.c 777 28 712 140 916 +0.0%
dfu_rt_device.c 157 0 134 0 157 +0.0%
dwc2_common.c 602 30 0 0 618 +0.0%
ecm_rndis_device.c 1037 0 1 2858 3896 +0.0%
ehci.c 2763 0 0 6043 7597 +0.0%
fsdev_common.c 180 0 0 0 180 +0.0%
hcd_ch32_usbfs.c 2484 0 0 498 2982 +0.0%
hcd_ci_hs.c 184 0 0 0 184 +0.0%
hcd_dwc2.c 4994 33 1 513 5540 +0.0%
hcd_khci.c 2442 0 0 449 2891 +0.0%
hcd_musb.c 3073 0 0 157 3230 +0.0%
hcd_pio_usb.c 262 0 240 0 502 +0.0%
hcd_rp2040.c 976 73 416 384 1849 +0.0%
hcd_rusb2.c 2923 0 0 245 3168 +0.0%
hcd_samd.c 2220 0 0 324 2544 +0.0%
hcd_stm32_fsdev.c 3287 0 1 420 3708 +0.0%
hid_device.c 1125 44 997 119 1244 +0.0%
hid_host.c 1240 0 0 1251 2491 +0.0%
hub.c 1384 8 8 30 1418 +0.0%
midi_device.c 1150 0 1007 621 1770 +0.0%
midi_host.c 1341 7 7 3635 4979 +0.0%
msc_device.c 2525 108 2286 547 3071 +0.0%
msc_host.c 1587 0 0 394 1982 +0.0%
mtp_device.c 1696 22 735 588 2292 +0.0%
ncm_device.c 1538 28 718 5843 7395 +0.0%
ohci.c 1940 0 0 2414 4353 +0.0%
printer_device.c 830 0 706 564 1392 +0.0%
rp2040_usb.c 172 75 717 4 968 +0.0%
rusb2_common.c 160 0 16 0 176 +0.0%
tusb.c 451 0 383 3 453 +0.0%
tusb_fifo.c 842 0 480 0 837 +0.0%
typec_stm32.c 820 8 2 12 842 +0.0%
usbc.c 420 2 20 166 608 +0.0%
usbd.c 3225 57 88 275 3565 +0.0%
usbd_control.c 538 0 484 79 616 +0.0%
usbh.c 4649 55 99 961 5731 +0.0%
usbtmc_device.c 2196 24 68 316 2544 +0.0%
vendor_device.c 641 0 534 563 1202 +0.0%
video_device.c 4443 5 1235 479 4914 +0.0%
TOTAL 117935 1155 16611 46960 166982 +0.0%

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 17, 2026

MemBrowse Memory Report

Top 10 targets by memory change (%) (out of 2156 targets) View Project Dashboard →

target .text .rodata .data .bss total % diff
stm32h743eval/board_test 17,428 → 17,540 (+112) 18,160 → 18,272 (+112) +0.6%
stlinkv3mini/board_test 7,852 → 7,896 (+44) 8,384 → 8,428 (+44) +0.5%
stm32h743eval/msc_file_explorer 46,360 → 46,536 (+176) 3,020 → 3,056 (+36) 50,052 → 50,264 (+212) +0.4%
stm32h743eval/dfu 26,904 → 27,016 (+112) 28,340 → 28,452 (+112) +0.4%
stlinkv3mini/msc_file_explorer 36,896 → 37,004 (+108) 3,004 → 3,040 (+36) 40,388 → 40,532 (+144) +0.4%
stm32h743eval/hid_controller 31,744 → 31,856 (+112) 33,064 → 33,176 (+112) +0.3%
lpcxpresso1769/msc_file_explorer 31,156 → 31,260 (+104) 31,172 → 31,276 (+104) +0.3%
stm32h743eval/device_info 32,440 → 32,552 (+112) 33,860 → 33,972 (+112) +0.3%
stm32h743eval/bare_api 33,024 → 33,136 (+112) 34,536 → 34,648 (+112) +0.3%
stm32h743eval/midi_rx 33,664 → 33,776 (+112) 34,752 → 34,864 (+112) +0.3%

@hathach hathach changed the title add hil host cdc test add hil host cdc and msc test Mar 17, 2026
@hathach hathach changed the title add hil host cdc and msc test add more hil tests Mar 17, 2026
Use separate endpoint numbers (EP1 OUT, EP2 IN) on MCUs with shared
FIFO that cannot support the same endpoint number in both directions.
Also add missing static qualifier to print_musb_info().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hathach hathach merged commit 766ac4f into master Mar 18, 2026
311 checks passed
@hathach hathach deleted the hil-host-cdc branch March 18, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants