From 13f78e2e7716fda1c0ee1ef09a8bc76fde4f4c57 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 11 Nov 2024 16:07:33 +0700 Subject: [PATCH 01/15] add esp32p4 to hil --- .../boards/espressif_p4_function_ev/board.h | 4 ++++ hw/bsp/espressif/boards/family.c | 6 ++++++ test/hil/tinyusb.json | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/hw/bsp/espressif/boards/espressif_p4_function_ev/board.h b/hw/bsp/espressif/boards/espressif_p4_function_ev/board.h index 9c8aa409f..0022f0d2d 100644 --- a/hw/bsp/espressif/boards/espressif_p4_function_ev/board.h +++ b/hw/bsp/espressif/boards/espressif_p4_function_ev/board.h @@ -36,6 +36,10 @@ #define BUTTON_PIN 0 #define BUTTON_STATE_ACTIVE 0 +// For CI hardware test, to test both device and host on the same HS port with help of +#define HIL_DEVICE_HOST_MUX_PIN 47 +#define HIL_DEVICE_STATE 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/espressif/boards/family.c b/hw/bsp/espressif/boards/family.c index 0b1e8badb..729b3539d 100644 --- a/hw/bsp/espressif/boards/family.c +++ b/hw/bsp/espressif/boards/family.c @@ -105,6 +105,12 @@ void board_init(void) { usb_init(); #endif +#ifdef HIL_DEVICE_HOST_MUX_PIN + gpio_reset_pin(HIL_DEVICE_HOST_MUX_PIN); + gpio_set_direction(HIL_DEVICE_HOST_MUX_PIN, GPIO_MODE_OUTPUT); + gpio_set_level(HIL_DEVICE_HOST_MUX_PIN, CFG_TUD_ENABLED ? HIL_DEVICE_STATE : (1-HIL_DEVICE_STATE)); +#endif + #if CFG_TUH_ENABLED && CFG_TUH_MAX3421 max3421_init(); #endif diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index 2313f5d13..c92224e26 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -1,5 +1,18 @@ { "boards": [ + { + "name": "espressif_p4_function_ev", + "uid": "6055F9F98715", + "build" : { + "flags_on": ["", "CFG_TUD_DWC2_DMA"] + }, + "tests": { + "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"] + }, + "flasher": "esptool", + "flasher_sn": "4ea4f48f6bc3ee11bbb9d00f9e1b1c54", + "flasher_args": "-b 1500000" + }, { "name": "espressif_s3_devkitm", "uid": "84F703C084E4", From 57c8c223e5f873e8075eb807844140004c74472d Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 11 Nov 2024 16:42:08 +0700 Subject: [PATCH 02/15] correctly test dwc2 dma device for s3, disable for p4 (cache issue) and f407 fs (slave only) --- .../components/tinyusb_src/CMakeLists.txt | 5 + src/portable/synopsys/dwc2/dwc2_info.md | 116 +++++++++--------- src/portable/synopsys/dwc2/dwc2_info.py | 6 +- test/hil/tinyusb.json | 6 - 4 files changed, 66 insertions(+), 67 deletions(-) diff --git a/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt b/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt index e2250c4ca..900f620fd 100644 --- a/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt +++ b/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt @@ -60,6 +60,11 @@ if (DEFINED LOG) endif () endif() +if(DEFINED CFLAGS_CLI) + list(APPEND compile_definitions ${CFLAGS_CLI}) +endif() + + idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${tusb_src} REQUIRES src diff --git a/src/portable/synopsys/dwc2/dwc2_info.md b/src/portable/synopsys/dwc2/dwc2_info.md index 78c2c50f8..dec021f59 100644 --- a/src/portable/synopsys/dwc2/dwc2_info.md +++ b/src/portable/synopsys/dwc2/dwc2_info.md @@ -1,58 +1,58 @@ -| | BCM2711 (Pi4) | EFM32GG | ESP32-S2/S3 | ESP32-P4 | ST F207/F407/411/429 FS | ST F407/429 HS | ST F412/767 FS | ST F723/L4P5 FS | ST F723 HS | ST F769 | ST H743/H750 | ST L476 FS | ST U5A5 HS | GD32VF103 | XMC4500 | -|:---------------------------|:----------------|:-------------|:--------------|:-------------|:--------------------------|:-----------------|:-----------------|:------------------|:-------------|:-------------|:---------------|:-------------|:-------------|:------------|:-------------| -| GUID | 0x2708A000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00001200 | 0x00001100 | 0x00002000 | 0x00003000 | 0x00003100 | 0x00002100 | 0x00002300 | 0x00002000 | 0x00005000 | 0x00001000 | 0x00AEC000 | -| GSNPSID | 0x4F54280A | 0x4F54330A | 0x4F54400A | 0x4F54400A | 0x4F54281A | 0x4F54281A | 0x4F54320A | 0x4F54330A | 0x4F54330A | 0x4F54320A | 0x4F54330A | 0x4F54310A | 0x4F54411A | 0x00000000 | 0x4F54292A | -| - specs version | 2.80a | 3.30a | 4.00a | 4.00a | 2.81a | 2.81a | 3.20a | 3.30a | 3.30a | 3.20a | 3.30a | 3.10a | 4.11a | 0.00W | 2.92a | -| GHWCFG1 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | -| GHWCFG2 | 0x228DDD50 | 0x228F5910 | 0x224DD930 | 0x215FFFD0 | 0x229DCD20 | 0x229ED590 | 0x229ED520 | 0x229ED520 | 0x229FE1D0 | 0x229FE190 | 0x229FE190 | 0x229ED520 | 0x228FE052 | 0x00000000 | 0x228F5930 | -| - op_mode | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | noHNP noSRP | HNP SRP | HNP SRP | -| - arch | DMA internal | DMA internal | DMA internal | DMA internal | Slave only | DMA internal | Slave only | Slave only | DMA internal | DMA internal | DMA internal | Slave only | DMA internal | Slave only | DMA internal | -| - single_point | hub | hub | n/a | hub | n/a | hub | n/a | n/a | hub | hub | hub | n/a | hub | hub | n/a | -| - hs_phy_type | UTMI+ | n/a | n/a | UTMI+/ULPI | n/a | ULPI | n/a | n/a | UTMI+/ULPI | ULPI | ULPI | n/a | UTMI+ | n/a | n/a | -| - fs_phy_type | Dedicated | Dedicated | Dedicated | Shared ULPI | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | n/a | n/a | Dedicated | -| - num_dev_ep | 7 | 6 | 6 | 15 | 3 | 5 | 5 | 5 | 8 | 8 | 8 | 5 | 8 | 0 | 6 | -| - num_host_ch | 7 | 13 | 7 | 15 | 7 | 11 | 11 | 11 | 15 | 15 | 15 | 11 | 15 | 0 | 13 | -| - period_channel_support | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | -| - enable_dynamic_fifo | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | -| - mul_proc_intrpt | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | -| - reserved21 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - nptx_q_depth | 8 | 8 | 4 | 4 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 2 | 8 | -| - ptx_q_depth | 8 | 8 | 8 | 4 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 2 | 8 | -| - token_q_depth | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 0 | 8 | -| - otg_enable_ic_usb | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| GHWCFG3 | 0x0FF000E8 | 0x01F204E8 | 0x00C804B5 | 0x03805EB5 | 0x020001E8 | 0x03F403E8 | 0x0200D1E8 | 0x0200D1E8 | 0x03EED2E8 | 0x03EED2E8 | 0x03B8D2E8 | 0x0200D1E8 | 0x03B882E8 | 0x00000000 | 0x027A01E5 | -| - xfer_size_width | 8 | 8 | 5 | 5 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 0 | 5 | -| - packet_size_width | 6 | 6 | 3 | 3 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 0 | 6 | -| - otg_enable | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | -| - i2c_enable | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | -| - vendor_ctrl_itf | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | -| - optional_feature_removed | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - synch_reset | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - otg_adp_support | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | -| - otg_enable_hsic | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - battery_charger_support | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | -| - lpm_mode | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | -| - dfifo_depth | 4080 | 498 | 200 | 896 | 512 | 1012 | 512 | 512 | 1006 | 1006 | 952 | 512 | 952 | 0 | 634 | -| GHWCFG4 | 0x1FF00020 | 0x1BF08030 | 0xD3F0A030 | 0xDFF1A030 | 0x0FF08030 | 0x17F00030 | 0x17F08030 | 0x17F08030 | 0x23F00030 | 0x23F00030 | 0xE3F00030 | 0x17F08030 | 0xE2103E30 | 0x00000000 | 0xDBF08030 | -| - num_dev_period_in_ep | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - partial_powerdown | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | -| - ahb_freq_min | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | -| - hibernation | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - extended_hibernation | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - reserved8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - enhanced_lpm_support1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | -| - service_interval_flow | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | -| - ipg_isoc_support | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | -| - acg_support | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | -| - enhanced_lpm_support | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | -| - phy_data_width | 8 bit | 8/16 bit | 8/16 bit | 8/16 bit | 8/16 bit | 8 bit | 8/16 bit | 8/16 bit | 8 bit | 8 bit | 8 bit | 8/16 bit | 8 bit | 8 bit | 8/16 bit | -| - ctrl_ep_num | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| - iddg_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | -| - vbus_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | -| - a_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | -| - b_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | -| - session_end_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | -| - dedicated_fifos | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | -| - num_dev_in_eps | 7 | 6 | 4 | 7 | 3 | 5 | 5 | 5 | 8 | 8 | 8 | 5 | 8 | 0 | 6 | -| - dma_desc_enable | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | -| - dma_desc_dynamic | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | +| | BCM2711 (Pi4) | EFM32GG | ESP32-S2/S3 | ESP32-P4 | ST F207/F407/411/429 FS | ST F407/429 HS | ST F412/76x FS | ST F723/L4P5 FS | ST F723 HS | ST F76x HS | ST H743/H750 | ST L476 FS | ST U5A5 HS | XMC4500 | GD32VF103 | +|:---------------------------|:----------------|:-------------|:--------------|:-------------|:--------------------------|:-----------------|:-----------------|:------------------|:-------------|:-------------|:---------------|:-------------|:-------------|:-------------|:------------| +| GUID | 0x2708A000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00001200 | 0x00001100 | 0x00002000 | 0x00003000 | 0x00003100 | 0x00002100 | 0x00002300 | 0x00002000 | 0x00005000 | 0x00AEC000 | 0x00001000 | +| GSNPSID | 0x4F54280A | 0x4F54330A | 0x4F54400A | 0x4F54400A | 0x4F54281A | 0x4F54281A | 0x4F54320A | 0x4F54330A | 0x4F54330A | 0x4F54320A | 0x4F54330A | 0x4F54310A | 0x4F54411A | 0x4F54292A | 0x00000000 | +| - specs version | 2.80a | 3.30a | 4.00a | 4.00a | 2.81a | 2.81a | 3.20a | 3.30a | 3.30a | 3.20a | 3.30a | 3.10a | 4.11a | 2.92a | 0.00W | +| GHWCFG1 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | +| GHWCFG2 | 0x228DDD50 | 0x228F5910 | 0x224DD930 | 0x215FFFD0 | 0x229DCD20 | 0x229ED590 | 0x229ED520 | 0x229ED520 | 0x229FE1D0 | 0x229FE190 | 0x229FE190 | 0x229ED520 | 0x228FE052 | 0x228F5930 | 0x00000000 | +| - op_mode | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | HNP SRP | noHNP noSRP | HNP SRP | HNP SRP | +| - arch | DMA internal | DMA internal | DMA internal | DMA internal | Slave only | DMA internal | Slave only | Slave only | DMA internal | DMA internal | DMA internal | Slave only | DMA internal | DMA internal | Slave only | +| - single_point | hub | hub | n/a | hub | n/a | hub | n/a | n/a | hub | hub | hub | n/a | hub | n/a | hub | +| - hs_phy_type | UTMI+ | n/a | n/a | UTMI+/ULPI | n/a | ULPI | n/a | n/a | UTMI+/ULPI | ULPI | ULPI | n/a | UTMI+ | n/a | n/a | +| - fs_phy_type | Dedicated | Dedicated | Dedicated | Shared ULPI | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | Dedicated | n/a | Dedicated | n/a | +| - num_dev_ep | 7 | 6 | 6 | 15 | 3 | 5 | 5 | 5 | 8 | 8 | 8 | 5 | 8 | 6 | 0 | +| - num_host_ch | 7 | 13 | 7 | 15 | 7 | 11 | 11 | 11 | 15 | 15 | 15 | 11 | 15 | 13 | 0 | +| - period_channel_support | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | +| - enable_dynamic_fifo | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | +| - mul_proc_intrpt | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | +| - reserved21 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - nptx_q_depth | 8 | 8 | 4 | 4 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 2 | +| - ptx_q_depth | 8 | 8 | 8 | 4 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 2 | +| - token_q_depth | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 0 | +| - otg_enable_ic_usb | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| GHWCFG3 | 0x0FF000E8 | 0x01F204E8 | 0x00C804B5 | 0x03805EB5 | 0x020001E8 | 0x03F403E8 | 0x0200D1E8 | 0x0200D1E8 | 0x03EED2E8 | 0x03EED2E8 | 0x03B8D2E8 | 0x0200D1E8 | 0x03B882E8 | 0x027A01E5 | 0x00000000 | +| - xfer_size_width | 8 | 8 | 5 | 5 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 5 | 0 | +| - packet_size_width | 6 | 6 | 3 | 3 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 0 | +| - otg_enable | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | +| - i2c_enable | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | +| - vendor_ctrl_itf | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | +| - optional_feature_removed | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - synch_reset | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - otg_adp_support | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | +| - otg_enable_hsic | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - battery_charger_support | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | +| - lpm_mode | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | +| - dfifo_depth | 4080 | 498 | 200 | 896 | 512 | 1012 | 512 | 512 | 1006 | 1006 | 952 | 512 | 952 | 634 | 0 | +| GHWCFG4 | 0x1FF00020 | 0x1BF08030 | 0xD3F0A030 | 0xDFF1A030 | 0x0FF08030 | 0x17F00030 | 0x17F08030 | 0x17F08030 | 0x23F00030 | 0x23F00030 | 0xE3F00030 | 0x17F08030 | 0xE2103E30 | 0xDBF08030 | 0x00000000 | +| - num_dev_period_in_ep | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - partial_powerdown | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | +| - ahb_freq_min | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | +| - hibernation | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - extended_hibernation | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - reserved8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - enhanced_lpm_support1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | +| - service_interval_flow | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | +| - ipg_isoc_support | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | +| - acg_support | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | +| - enhanced_lpm_support | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | +| - phy_data_width | 8 bit | 8/16 bit | 8/16 bit | 8/16 bit | 8/16 bit | 8 bit | 8/16 bit | 8/16 bit | 8 bit | 8 bit | 8 bit | 8/16 bit | 8 bit | 8/16 bit | 8 bit | +| - ctrl_ep_num | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| - iddg_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | +| - vbus_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | +| - a_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | +| - b_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | +| - session_end_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | +| - dedicated_fifos | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | +| - num_dev_in_eps | 7 | 6 | 4 | 7 | 3 | 5 | 5 | 5 | 8 | 8 | 8 | 5 | 8 | 6 | 0 | +| - dma_desc_enable | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | +| - dma_desc_dynamic | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | diff --git a/src/portable/synopsys/dwc2/dwc2_info.py b/src/portable/synopsys/dwc2/dwc2_info.py index 5884cd455..25edcf22d 100755 --- a/src/portable/synopsys/dwc2/dwc2_info.py +++ b/src/portable/synopsys/dwc2/dwc2_info.py @@ -15,15 +15,15 @@ dwc2_reg_value = { 'ESP32-P4': [0, 0x4F54400A, 0, 0x215FFFD0, 0x03805EB5, 0xDFF1A030], 'ST F207/F407/411/429 FS': [0x1200, 0x4F54281A, 0, 0x229DCD20, 0x020001E8, 0x0FF08030], 'ST F407/429 HS': [0x1100, 0x4F54281A, 0, 0x229ED590, 0x03F403E8, 0x17F00030], - 'ST F412/767 FS': [0x2000, 0x4F54320A, 0, 0x229ED520, 0x0200D1E8, 0x17F08030], + 'ST F412/76x FS': [0x2000, 0x4F54320A, 0, 0x229ED520, 0x0200D1E8, 0x17F08030], 'ST F723/L4P5 FS': [0x3000, 0x4F54330A, 0, 0x229ED520, 0x0200D1E8, 0x17F08030], 'ST F723 HS': [0x3100, 0x4F54330A, 0, 0x229FE1D0, 0x03EED2E8, 0x23F00030], - 'ST F769': [0x2100, 0x4F54320A, 0, 0x229FE190, 0x03EED2E8, 0x23F00030], + 'ST F76x HS': [0x2100, 0x4F54320A, 0, 0x229FE190, 0x03EED2E8, 0x23F00030], 'ST H743/H750': [0x2300, 0x4F54330A, 0, 0x229FE190, 0x03B8D2E8, 0xE3F00030], 'ST L476 FS': [0x2000, 0x4F54310A, 0, 0x229ED520, 0x0200D1E8, 0x17F08030], 'ST U5A5 HS': [0x5000, 0x4F54411A, 0, 0x228FE052, 0x03B882E8, 0xE2103E30], + 'XMC4500': [0xAEC000, 0x4F54292A, 0, 0x228F5930, 0x027A01E5, 0xDBF08030], 'GD32VF103': [0x1000, 0, 0, 0, 0, 0], - 'XMC4500': [0xAEC000, 0x4F54292A, 0, 0x228F5930, 0x027A01E5, 0xDBF08030] } # Combine dwc2_info with dwc2_reg_list diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index c92224e26..f5a3f109e 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -3,9 +3,6 @@ { "name": "espressif_p4_function_ev", "uid": "6055F9F98715", - "build" : { - "flags_on": ["", "CFG_TUD_DWC2_DMA"] - }, "tests": { "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"] }, @@ -98,9 +95,6 @@ { "name": "stm32f407disco", "uid": "30001A000647313332353735", - "build" : { - "flags_on": ["", "CFG_TUD_DWC2_DMA"] - }, "flasher": "jlink", "flasher_sn": "000773661813", "flasher_args": "-device stm32f407vg" From d8970506a6999bb838fd61cdd1e97f57843d3f2d Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 11 Nov 2024 17:33:02 +0700 Subject: [PATCH 03/15] hil replace f407disco by h743nucleo --- test/hil/tinyusb.json | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index f5a3f109e..ea5345126 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -93,11 +93,14 @@ "flasher_args": "-device stm32f072rb" }, { - "name": "stm32f407disco", - "uid": "30001A000647313332353735", - "flasher": "jlink", - "flasher_sn": "000773661813", - "flasher_args": "-device stm32f407vg" + "name": "stm32h743nucleo", + "uid": "110018000951383432343236", + "build" : { + "flags_on": ["", "CFG_TUD_DWC2_DMA"] + }, + "flasher": "stlink", + "flasher_sn": "004C00343137510F39383538", + "flasher_args": "" }, { "name": "stm32g0b1nucleo", @@ -131,6 +134,13 @@ "flasher": "openocd_wch", "flasher_sn": "EBCA8F0670AF", "flasher_args": "" + }, + { + "name": "stm32f407disco", + "uid": "30001A000647313332353735", + "flasher": "jlink", + "flasher_sn": "000773661813", + "flasher_args": "-device stm32f407vg" } ] } From 3c564fd947bbaa9042930afc83ed1afd5a073242 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 11 Nov 2024 18:40:31 +0700 Subject: [PATCH 04/15] try adding host test for p4 --- test/hil/hil_test.py | 46 ++++++++++++++++++++++++++++++++++++------- test/hil/tinyusb.json | 8 ++++---- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 0d7cae77e..4a0510223 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -224,14 +224,13 @@ def flash_uniflash(board, firmware): # ------------------------------------------------------------- # Tests: dual # ------------------------------------------------------------- - def test_dual_host_info_to_device_cdc(board): uid = board['uid'] - declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dual_attached']] + declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] - port = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0) + port = get_serial_dev(board["flasher_sn"], None, None, 0) ser = open_serial_dev(port) - # read from cdc, first line should contain vid/pid and serial + # read from serial, first line should contain vid/pid and serial data = ser.read(1000) lines = data.decode('utf-8').splitlines() enum_dev_sn = [] @@ -251,6 +250,39 @@ def test_dual_host_info_to_device_cdc(board): return 0 +# ------------------------------------------------------------- +# Tests: host +# ------------------------------------------------------------- +def test_host_cdc_msc_hid(board): + uid = board['uid'] + declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] + + port = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0) + ser = open_serial_dev(port) + # read from serial, first line should contain vid/pid and serial + data = ser.read(1000) + lines = data.decode('utf-8').splitlines() + enum_dev_sn = [] + for l in lines: + vid_pid_sn = re.search(r'ID ([0-9a-fA-F]+):([0-9a-fA-F]+) SN (\w+)', l) + if vid_pid_sn: + print(f'\r\n {l} ', end='') + enum_dev_sn.append(f'{vid_pid_sn.group(1)}_{vid_pid_sn.group(2)}_{vid_pid_sn.group(3)}') + + if set(declared_devs) != set(enum_dev_sn): + # for pico/pico2 make this test optional + failed_msg = f'Enumerated devices {enum_dev_sn} not match with declared {declared_devs}' + if 'raspberry_pi_pico' in board['name']: + print(f'\r\n {failed_msg} {STATUS_FAILED} ', end='') + else: + assert False, failed_msg + return 0 + + +def test_host_cdc_msc_hid_freertos(board): + test_host_cdc_msc_hid(board) + + # ------------------------------------------------------------- # Tests: device # ------------------------------------------------------------- @@ -397,7 +429,7 @@ device_tests = [ 'device/hid_boot_interface', ] -dual_tests = [ +host_tests = [ 'dual/host_info_to_device_cdc', ] @@ -411,8 +443,8 @@ def test_board(board): if 'tests' in board: board_tests = board['tests'] - if 'dual_attached' in board_tests: - test_list += dual_tests + if 'dev_attached' in board_tests: + test_list += host_tests if 'only' in board_tests: test_list = board_tests['only'] if 'skip' in board_tests: diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index ea5345126..1b0b7c99a 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -4,7 +4,7 @@ "name": "espressif_p4_function_ev", "uid": "6055F9F98715", "tests": { - "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"] + "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos", "host/cdc_msc_hid_freertos"] }, "flasher": "esptool", "flasher_sn": "4ea4f48f6bc3ee11bbb9d00f9e1b1c54", @@ -44,7 +44,7 @@ "flasher_sn": "123456", "flasher_args": "-device ATSAMD51J19", "tests": { - "dual_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002130"}] + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002130"}] } }, { @@ -72,7 +72,7 @@ "flasher_sn": "E6614103E72C1D2F", "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"", "tests": { - "dual_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002470"}] + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002470"}] } }, { @@ -82,7 +82,7 @@ "flasher_sn": "E6633861A3978538", "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2350.cfg -c \"adapter speed 5000\"", "tests": { - "dual_attached": [{"vid_pid": "1a86_55d4", "serial": "533D004242"}] + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "533D004242"}] } }, { From 65e741937a4a6e5849f76fa94eca3daec63dbb4a Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 11 Nov 2024 21:40:03 +0700 Subject: [PATCH 05/15] fix build filter for esp32 --- tools/build_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_utils.py b/tools/build_utils.py index b4a1dc096..2998f940d 100755 --- a/tools/build_utils.py +++ b/tools/build_utils.py @@ -40,7 +40,7 @@ def skip_example(example, board): for line in mk_contents.splitlines(): match = re.search(r'set\(IDF_TARGET\s+"([^"]+)"\)', line) if match: - mcu = match.group(1) + mcu = match.group(1).upper() break else: for token in mk_contents.split(): From e391e33492b0051d4961909d0763f44918ab8048 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 12 Nov 2024 19:00:00 +0700 Subject: [PATCH 06/15] update host/device_info to build with freertos for espressif board. Add hil test for host/device_info --- examples/host/device_info/only.txt | 3 + examples/host/device_info/src/CMakeLists.txt | 4 + examples/host/device_info/src/main.c | 155 +++++++++++++++---- examples/host/device_info/src/tusb_config.h | 5 + test/hil/hil_test.py | 71 ++++----- test/hil/tinyusb.json | 3 +- tools/build.py | 1 + 7 files changed, 173 insertions(+), 69 deletions(-) create mode 100644 examples/host/device_info/src/CMakeLists.txt diff --git a/examples/host/device_info/only.txt b/examples/host/device_info/only.txt index f06d4df00..b6f87f423 100644 --- a/examples/host/device_info/only.txt +++ b/examples/host/device_info/only.txt @@ -1,3 +1,6 @@ +mcu:ESP32S2 +mcu:ESP32S3 +mcu:ESP32P4 mcu:KINETIS_KL mcu:LPC175X_6X mcu:LPC177X_8X diff --git a/examples/host/device_info/src/CMakeLists.txt b/examples/host/device_info/src/CMakeLists.txt new file mode 100644 index 000000000..1908a32c3 --- /dev/null +++ b/examples/host/device_info/src/CMakeLists.txt @@ -0,0 +1,4 @@ +# This file is for ESP-IDF only +idf_component_register(SRCS "main.c" + INCLUDE_DIRS "." + REQUIRES boards tinyusb_src) diff --git a/examples/host/device_info/src/main.c b/examples/host/device_info/src/main.c index 0ff4f32e9..6591a0198 100644 --- a/examples/host/device_info/src/main.c +++ b/examples/host/device_info/src/main.c @@ -24,7 +24,7 @@ */ /* Host example will get device descriptors of attached devices and print it out via uart/rtt (logger) as follows: - * Device 1: ID 046d:c52f + * Device 1: ID 046d:c52f SN 11223344 Device Descriptor: bLength 18 bDescriptorType 1 @@ -56,15 +56,20 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ -void led_blinking_task(void); + +static uint32_t blink_interval_ms = 1000; + +void led_blinking_task(void* param); static void print_utf16(uint16_t* temp_buf, size_t buf_len); -/*------------- MAIN -------------*/ -int main(void) { - board_init(); - - printf("TinyUSB Device Info Example\r\n"); +#if CFG_TUSB_OS == OPT_OS_FREERTOS +void init_freertos_task(void); +#endif +//-------------------------------------------------------------------- +// Main +//-------------------------------------------------------------------- +void init_tinyusb(void) { // init host stack on configured roothub port tusb_rhport_init_t host_init = { .role = TUSB_ROLE_HOST, @@ -75,14 +80,22 @@ int main(void) { if (board_init_after_tusb) { board_init_after_tusb(); } +} +int main(void) { + board_init(); + printf("TinyUSB Device Info Example\r\n"); + +#if CFG_TUSB_OS == OPT_OS_FREERTOS + init_freertos_task(); +#else + init_tinyusb(); while (1) { - // tinyusb host task - tuh_task(); + tuh_task(); // tinyusb host task led_blinking_task(); } - return 0; +#endif } /*------------- TinyUSB Callbacks -------------*/ @@ -97,9 +110,20 @@ void tuh_mount_cb(uint8_t daddr) { return; } + uint16_t serial[64]; uint16_t buf[256]; - printf("Device %u: ID %04x:%04x\r\n", daddr, desc_device.idVendor, desc_device.idProduct); + printf("Device %u: ID %04x:%04x SN ", daddr, desc_device.idVendor, desc_device.idProduct); + xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, serial, sizeof(serial)); + if (XFER_RESULT_SUCCESS != xfer_result) { + serial[0] = 'n'; + serial[1] = '/'; + serial[2] = 'a'; + serial[3] = 0; + } + print_utf16(serial, TU_ARRAY_SIZE(serial)); + printf("\r\n"); + printf("Device Descriptor:\r\n"); printf(" bLength %u\r\n", desc_device.bLength); printf(" bDescriptorType %u\r\n", desc_device.bDescriptorType); @@ -129,37 +153,17 @@ void tuh_mount_cb(uint8_t daddr) { printf("\r\n"); printf(" iSerialNumber %u ", desc_device.iSerialNumber); - xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, buf, sizeof(buf)); - if (XFER_RESULT_SUCCESS == xfer_result) { - print_utf16(buf, TU_ARRAY_SIZE(buf)); - } + printf((char*)serial); // serial is already to UTF-8 printf("\r\n"); printf(" bNumConfigurations %u\r\n", desc_device.bNumConfigurations); } -/// Invoked when device is unmounted (bus reset/unplugged) +// Invoked when device is unmounted (bus reset/unplugged) void tuh_umount_cb(uint8_t daddr) { printf("Device removed, address = %d\r\n", daddr); } -//--------------------------------------------------------------------+ -// Blinking Task -//--------------------------------------------------------------------+ -void led_blinking_task(void) { - const uint32_t interval_ms = 1000; - static uint32_t start_ms = 0; - - static bool led_state = false; - - // Blink every interval ms - if (board_millis() - start_ms < interval_ms) return; // not enough time - start_ms += interval_ms; - - board_led_write(led_state); - led_state = 1 - led_state; // toggle -} - //--------------------------------------------------------------------+ // String Descriptor Helper //--------------------------------------------------------------------+ @@ -212,3 +216,88 @@ static void print_utf16(uint16_t* temp_buf, size_t buf_len) { printf("%s", (char*) temp_buf); } + +//--------------------------------------------------------------------+ +// Blinking Task +//--------------------------------------------------------------------+ +void led_blinking_task(void* param) { + (void) param; + static uint32_t start_ms = 0; + static bool led_state = false; + + while (1) { +#if CFG_TUSB_OS == OPT_OS_FREERTOS + if (blink_interval_ms == 0) { + vTaskSuspend(NULL); + } else { + vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS); + } +#else + if (blink_interval_ms == 0) { + return; + } + if (board_millis() - start_ms < blink_interval_ms) { + return; // not enough time + } +#endif + + start_ms += blink_interval_ms; + board_led_write(led_state); + led_state = 1 - led_state; // toggle + } +} + +//--------------------------------------------------------------------+ +// FreeRTOS +//--------------------------------------------------------------------+ +#if CFG_TUSB_OS == OPT_OS_FREERTOS + +#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE + +#if TUSB_MCU_VENDOR_ESPRESSIF + #define USB_STACK_SIZE 4096 +#else + // Increase stack size when debug log is enabled + #define USB_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1) +#endif + + +// static task +#if configSUPPORT_STATIC_ALLOCATION +StackType_t blinky_stack[BLINKY_STACK_SIZE]; +StaticTask_t blinky_taskdef; + +StackType_t usb_stack[USB_STACK_SIZE]; +StaticTask_t usb_taskdef; +#endif + +#if TUSB_MCU_VENDOR_ESPRESSIF +void app_main(void) { + main(); +} +#endif + +void usb_host_task(void *param) { + (void) param; + init_tinyusb(); + while (1) { + tuh_task(); + } +} + +void init_freertos_task(void) { +#if configSUPPORT_STATIC_ALLOCATION + xTaskCreateStatic(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, blinky_stack, &blinky_taskdef); + xTaskCreateStatic(usb_host_task, "usbh", USB_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_stack, &usb_taskdef); +#else + xTaskCreate(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, NULL); + xTaskCreate(usb_host_task, "usbh", USB_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL); +#endif + + // skip starting scheduler (and return) for ESP32-S2 or ESP32-S3 +#if !TUSB_MCU_VENDOR_ESPRESSIF + vTaskStartScheduler(); +#endif +} + +#endif diff --git a/examples/host/device_info/src/tusb_config.h b/examples/host/device_info/src/tusb_config.h index 2e9731eaf..5190b5b1f 100644 --- a/examples/host/device_info/src/tusb_config.h +++ b/examples/host/device_info/src/tusb_config.h @@ -39,6 +39,11 @@ #error CFG_TUSB_MCU must be defined #endif +// Espressif IDF requires "freertos/" prefix in include path +#if TUSB_MCU_VENDOR_ESPRESSIF +#define CFG_TUSB_OS_INC_PATH freertos/ +#endif + #ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE #endif diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 4a0510223..91fe6b67c 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -50,6 +50,7 @@ verbose = False # Path # ------------------------------------------------------------- OPENCOD_ADI_PATH = f'{os.getenv("HOME")}/app/openocd_adi' +TINYUSB_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # get usb serial by id def get_serial_dev(id, vendor_str, product_str, ifnum): @@ -83,7 +84,7 @@ def open_serial_dev(port): # slight delay since kernel may occupy the port briefly time.sleep(0.5) timeout = timeout - 0.5 - ser = serial.Serial(port, timeout=5) + ser = serial.Serial(port, baudrate=115200, timeout=5) break except serial.SerialException: pass @@ -212,6 +213,7 @@ def flash_esptool(board, firmware): flash_args = f.read().strip().replace('\n', ' ') command = (f'esptool.py --chip {idf_target} -p {port} {board["flasher_args"]} ' f'--before=default_reset --after=hard_reset write_flash {flash_args}') + # command = f'echo abc' ret = run_cmd(command, cwd=fw_dir) return ret @@ -228,35 +230,6 @@ def test_dual_host_info_to_device_cdc(board): uid = board['uid'] declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] - port = get_serial_dev(board["flasher_sn"], None, None, 0) - ser = open_serial_dev(port) - # read from serial, first line should contain vid/pid and serial - data = ser.read(1000) - lines = data.decode('utf-8').splitlines() - enum_dev_sn = [] - for l in lines: - vid_pid_sn = re.search(r'ID ([0-9a-fA-F]+):([0-9a-fA-F]+) SN (\w+)', l) - if vid_pid_sn: - print(f'\r\n {l} ', end='') - enum_dev_sn.append(f'{vid_pid_sn.group(1)}_{vid_pid_sn.group(2)}_{vid_pid_sn.group(3)}') - - if set(declared_devs) != set(enum_dev_sn): - # for pico/pico2 make this test optional - failed_msg = f'Enumerated devices {enum_dev_sn} not match with declared {declared_devs}' - if 'raspberry_pi_pico' in board['name']: - print(f'\r\n {failed_msg} {STATUS_FAILED} ', end='') - else: - assert False, failed_msg - return 0 - - -# ------------------------------------------------------------- -# Tests: host -# ------------------------------------------------------------- -def test_host_cdc_msc_hid(board): - uid = board['uid'] - declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] - port = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0) ser = open_serial_dev(port) # read from serial, first line should contain vid/pid and serial @@ -279,8 +252,36 @@ def test_host_cdc_msc_hid(board): return 0 -def test_host_cdc_msc_hid_freertos(board): - test_host_cdc_msc_hid(board) +# ------------------------------------------------------------- +# Tests: host +# ------------------------------------------------------------- +def test_host_device_info(board): + uid = board['uid'] + declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] + + port = get_serial_dev(board["flasher_sn"], None, None, 0) + ser = open_serial_dev(port) + data = ser.read(1000) + if len(data) == 0: + assert False, 'No data from device' + + lines = data.decode('utf-8').splitlines() + enum_dev_sn = [] + for l in lines: + vid_pid_sn = re.search(r'ID ([0-9a-fA-F]+):([0-9a-fA-F]+) SN (\w+)', l) + if vid_pid_sn: + print(f'\r\n {l} ', end='') + enum_dev_sn.append(f'{vid_pid_sn.group(1)}_{vid_pid_sn.group(2)}_{vid_pid_sn.group(3)}') + + if set(declared_devs) != set(enum_dev_sn): + # for pico/pico2 make this test optional + failed_msg = f'Enumerated devices {enum_dev_sn} not match with declared {declared_devs}' + if 'raspberry_pi_pico' in board['name']: + print(f'\r\n {failed_msg} {STATUS_FAILED} ', end='') + else: + assert False, failed_msg + + return 0 # ------------------------------------------------------------- @@ -454,7 +455,7 @@ def test_board(board): print(f'{name:25} {skip:30} ... Skip') # board_test is added last to disable board's usb - test_list.append('device/board_test') + #test_list.append('device/board_test') err_count = 0 flags_on_list = [""] @@ -466,9 +467,9 @@ def test_board(board): if f1 != "": f1_str = '-' + f1.replace(' ', '-') for test in test_list: - fw_dir = f'cmake-build/cmake-build-{name}{f1_str}/{test}' + fw_dir = f'{TINYUSB_ROOT}/cmake-build/cmake-build-{name}{f1_str}/{test}' if not os.path.exists(fw_dir): - fw_dir = f'examples/cmake-build-{name}{f1_str}/{test}' + fw_dir = f'{TINYUSB_ROOT}/examples/cmake-build-{name}{f1_str}/{test}' fw_name = f'{fw_dir}/{os.path.basename(test)}' print(f'{name+f1_str:40} {test:30} ... ', end='') diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index 1b0b7c99a..2d61981f2 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -4,7 +4,8 @@ "name": "espressif_p4_function_ev", "uid": "6055F9F98715", "tests": { - "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos", "host/cdc_msc_hid_freertos"] + "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos", "host/device_info"], + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002427"}] }, "flasher": "esptool", "flasher_sn": "4ea4f48f6bc3ee11bbb9d00f9e1b1c54", diff --git a/tools/build.py b/tools/build.py index 91d4ebd30..48666adc4 100755 --- a/tools/build.py +++ b/tools/build.py @@ -68,6 +68,7 @@ def get_examples(family): if family == 'espressif': all_examples.append('device/board_test') all_examples.append('device/video_capture') + all_examples.append('host/device_info') all_examples.sort() return all_examples From 839ec1729252d81aa631ba7ea4653c5591f6fb6f Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 12 Nov 2024 22:03:13 +0700 Subject: [PATCH 07/15] fix example build --- examples/host/device_info/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/host/device_info/src/main.c b/examples/host/device_info/src/main.c index 6591a0198..8e0185878 100644 --- a/examples/host/device_info/src/main.c +++ b/examples/host/device_info/src/main.c @@ -92,7 +92,7 @@ int main(void) { init_tinyusb(); while (1) { tuh_task(); // tinyusb host task - led_blinking_task(); + led_blinking_task(NULL); } return 0; #endif From aeae2966a2afa669068e54eef7c4dd2dceffaa0d Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 13:08:30 +0700 Subject: [PATCH 08/15] hil add stm32f723disco, add test flags for device/host/dual --- examples/device/cdc_msc/CMakeLists.txt | 2 +- examples/host/device_info/src/main.c | 20 +-- .../stm32f7/boards/stm32f723disco/board.cmake | 6 +- hw/bsp/stm32f7/boards/stm32f723disco/board.mk | 5 +- hw/bsp/stm32f7/family.c | 29 ++-- src/portable/synopsys/dwc2/hcd_dwc2.c | 6 +- test/hil/hil_test.py | 151 ++++++++++++------ test/hil/tinyusb.json | 69 ++++++-- 8 files changed, 202 insertions(+), 86 deletions(-) diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 9415f8c68..c2f9cb095 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.17) -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +#set_property(GLOBAL PROPERTY USE_FOLDERS ON) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) diff --git a/examples/host/device_info/src/main.c b/examples/host/device_info/src/main.c index 8e0185878..70304e449 100644 --- a/examples/host/device_info/src/main.c +++ b/examples/host/device_info/src/main.c @@ -56,8 +56,12 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ - -static uint32_t blink_interval_ms = 1000; +enum { + BLINK_NOT_MOUNTED = 250, + BLINK_MOUNTED = 1000, + BLINK_SUSPENDED = 2500, +}; +static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; void led_blinking_task(void* param); static void print_utf16(uint16_t* temp_buf, size_t buf_len); @@ -102,6 +106,8 @@ int main(void) { // Invoked when device is mounted (configured) void tuh_mount_cb(uint8_t daddr) { + blink_interval_ms = BLINK_MOUNTED; + // Get Device Descriptor tusb_desc_device_t desc_device; uint8_t xfer_result = tuh_descriptor_get_device_sync(daddr, &desc_device, 18); @@ -161,6 +167,7 @@ void tuh_mount_cb(uint8_t daddr) { // Invoked when device is unmounted (bus reset/unplugged) void tuh_umount_cb(uint8_t daddr) { + blink_interval_ms = BLINK_NOT_MOUNTED; printf("Device removed, address = %d\r\n", daddr); } @@ -227,15 +234,8 @@ void led_blinking_task(void* param) { while (1) { #if CFG_TUSB_OS == OPT_OS_FREERTOS - if (blink_interval_ms == 0) { - vTaskSuspend(NULL); - } else { - vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS); - } + vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS); #else - if (blink_interval_ms == 0) { - return; - } if (board_millis() - start_ms < blink_interval_ms) { return; // not enough time } diff --git a/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake b/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake index 5655c217e..eb3ed407b 100644 --- a/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake +++ b/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake @@ -5,12 +5,12 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F723xE_FLASH.ld) set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED) -# device default to PORT 1 High Speed +# For Hardware test: device default to PORT 0, Host to port 1 if (NOT DEFINED RHPORT_DEVICE) - set(RHPORT_DEVICE 1) + set(RHPORT_DEVICE 0) endif() if (NOT DEFINED RHPORT_HOST) - set(RHPORT_HOST 0) + set(RHPORT_HOST 1) endif() function(update_board TARGET) diff --git a/hw/bsp/stm32f7/boards/stm32f723disco/board.mk b/hw/bsp/stm32f7/boards/stm32f723disco/board.mk index eb6799eb0..9b8e7a969 100644 --- a/hw/bsp/stm32f7/boards/stm32f723disco/board.mk +++ b/hw/bsp/stm32f7/boards/stm32f723disco/board.mk @@ -1,8 +1,9 @@ MCU_VARIANT = stm32f723xx +# For Hardware test: device default to PORT 0, Host to port 1 RHPORT_SPEED = OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED -RHPORT_DEVICE ?= 1 -RHPORT_HOST ?= 0 +RHPORT_DEVICE ?= 0 +RHPORT_HOST ?= 1 CFLAGS += \ -DSTM32F723xx \ diff --git a/hw/bsp/stm32f7/family.c b/hw/bsp/stm32f7/family.c index 61beac47e..527fbfe5c 100644 --- a/hw/bsp/stm32f7/family.c +++ b/hw/bsp/stm32f7/family.c @@ -37,6 +37,25 @@ typedef struct { #include "board.h" +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM +//--------------------------------------------------------------------+ + +#ifdef UART_DEV +UART_HandleTypeDef UartHandle = { + .Instance = UART_DEV, + .Init = { + .BaudRate = CFG_BOARD_UART_BAUDRATE, + .WordLength = UART_WORDLENGTH_8B, + .StopBits = UART_STOPBITS_1, + .Parity = UART_PARITY_NONE, + .HwFlowCtl = UART_HWCONTROL_NONE, + .Mode = UART_MODE_TX_RX, + .OverSampling = UART_OVERSAMPLING_16, + } +}; +#endif + //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler //--------------------------------------------------------------------+ @@ -54,8 +73,6 @@ void OTG_HS_IRQHandler(void) { // MACRO TYPEDEF CONSTANT ENUM //--------------------------------------------------------------------+ -UART_HandleTypeDef UartHandle; - void board_init(void) { board_clock_init(); @@ -89,14 +106,6 @@ void board_init(void) { #endif #ifdef UART_DEV - UartHandle.Instance = UART_DEV; - UartHandle.Init.BaudRate = CFG_BOARD_UART_BAUDRATE; - UartHandle.Init.WordLength = UART_WORDLENGTH_8B; - UartHandle.Init.StopBits = UART_STOPBITS_1; - UartHandle.Init.Parity = UART_PARITY_NONE; - UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; - UartHandle.Init.Mode = UART_MODE_TX_RX; - UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; HAL_UART_Init(&UartHandle); #endif diff --git a/src/portable/synopsys/dwc2/hcd_dwc2.c b/src/portable/synopsys/dwc2/hcd_dwc2.c index f9fc5ca8e..53583426f 100644 --- a/src/portable/synopsys/dwc2/hcd_dwc2.c +++ b/src/portable/synopsys/dwc2/hcd_dwc2.c @@ -1181,8 +1181,7 @@ static bool handle_sof_irq(uint8_t rhport, bool in_isr) { } // Config HCFG FS/LS clock and HFIR for SOF interval according to link speed (value is in PHY clock unit) -static void port0_enable(dwc2_regs_t* dwc2) { - const tusb_speed_t speed = hprt_speed_get(dwc2); +static void port0_enable(dwc2_regs_t* dwc2, tusb_speed_t speed) { uint32_t hcfg = dwc2->hcfg & ~HCFG_FSLS_PHYCLK_SEL; const dwc2_gusbcfg_t gusbcfg_bm = dwc2->gusbcfg_bm; @@ -1252,7 +1251,8 @@ static void handle_hprt_irq(uint8_t rhport, bool in_isr) { if (hprt_bm.enable) { // Port enable - port0_enable(dwc2); + const tusb_speed_t speed = hprt_speed_get(dwc2); + port0_enable(dwc2, speed); } else { // TU_ASSERT(false, ); } diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 91fe6b67c..b395c28a4 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -46,6 +46,26 @@ STATUS_SKIPPED = "\033[33mSkipped\033[0m" verbose = False +WCH_RISCV_CONTENT = """ +adapter driver wlinke +adapter speed 6000 +transport select sdi + +wlink_set_address 0x00000000 +set _CHIPNAME wch_riscv +sdi newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00001 + +set _TARGETNAME $_CHIPNAME.cpu + +target create $_TARGETNAME.0 wch_riscv -chain-position $_TARGETNAME +$_TARGETNAME.0 configure -work-area-phys 0x20000000 -work-area-size 10000 -work-area-backup 1 +set _FLASHNAME $_CHIPNAME.flash + +flash bank $_FLASHNAME wch_riscv 0x00000000 0 0 0 $_TARGETNAME.0 + +echo "Ready for Remote Connections" +""" + # ------------------------------------------------------------- # Path # ------------------------------------------------------------- @@ -147,63 +167,87 @@ def flash_jlink(board, firmware): return ret -def flash_stlink(board, firmware): - ret = run_cmd(f'STM32_Programmer_CLI --connect port=swd sn={board["flasher_sn"]} --write {firmware}.elf --go') +def reset_jlink(board): + script = ['halt', 'r', 'go', 'exit'] + f_jlink = f'{board["name"]}_reset.jlink' + if not os.path.exists(f_jlink): + with open(f_jlink, 'w') as f: + f.writelines(f'{s}\n' for s in script) + ret = run_cmd(f'JLinkExe -USB {board["flasher_sn"]} {board["flasher_args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile {f_jlink}') return ret +def flash_stlink(board, firmware): + return run_cmd(f'STM32_Programmer_CLI --connect port=swd sn={board["flasher_sn"]} --write {firmware}.elf --go') + + +def reset_stlink(board): + return run_cmd(f'STM32_Programmer_CLI --connect port=swd sn={board["flasher_sn"]} --rst --go') + def flash_stflash(board, firmware): ret = run_cmd(f'st-flash --serial {board["flasher_sn"]} write {firmware}.bin 0x8000000') return ret +def reset_stflash(board): + return subprocess.CompletedProcess(args=['dummy'], returncode=0) + + def flash_openocd(board, firmware): ret = run_cmd(f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware}.elf reset exit"') return ret +def reset_openocd(board): + ret = run_cmd(f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "reset exit"') + return ret + + def flash_openocd_wch(board, firmware): - # Content of the wch-riscv.cfg file - cfg_content = """ -adapter driver wlinke -adapter speed 6000 -transport select sdi - -wlink_set_address 0x00000000 -set _CHIPNAME wch_riscv -sdi newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00001 - -set _TARGETNAME $_CHIPNAME.cpu - -target create $_TARGETNAME.0 wch_riscv -chain-position $_TARGETNAME -$_TARGETNAME.0 configure -work-area-phys 0x20000000 -work-area-size 10000 -work-area-backup 1 -set _FLASHNAME $_CHIPNAME.flash - -flash bank $_FLASHNAME wch_riscv 0x00000000 0 0 0 $_TARGETNAME.0 - -echo "Ready for Remote Connections" -""" f_wch = f"wch-riscv_{board['uid']}.cfg" if not os.path.exists(f_wch): with open(f_wch, 'w') as file: - file.write(cfg_content) + file.write(WCH_RISCV_CONTENT) ret = run_cmd(f'openocd_wch -c "adapter serial {board["flasher_sn"]}" -f {f_wch} ' f'-c "program {firmware}.elf reset exit"') return ret +def reset_openocd_wch(board): + f_wch = f"wch-riscv_{board['uid']}.cfg" + if not os.path.exists(f_wch): + with open(f_wch, 'w') as file: + file.write(WCH_RISCV_CONTENT) + + ret = run_cmd(f'openocd_wch -c "adapter serial {board["flasher_sn"]}" -f {f_wch} -c "program reset exit"') + return ret + + def flash_openocd_adi(board, firmware): ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {board["flasher_sn"]}" -s {OPENCOD_ADI_PATH}/tcl ' f'{board["flasher_args"]} -c "program {firmware}.elf reset exit"') return ret + +def reset_openocd_adi(board): + ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {board["flasher_sn"]}" -s {OPENCOD_ADI_PATH}/tcl ' + f'{board["flasher_args"]} -c "program reset exit"') + return ret + + def flash_wlink_rs(board, firmware): # wlink use index for probe selection and lacking usb serial support ret = run_cmd(f'wlink flash {firmware}.elf') return ret +def reset_wlink_rs(board): + # wlink use index for probe selection and lacking usb serial support + ret = run_cmd(f'wlink reset') + return ret + + def flash_esptool(board, firmware): port = get_serial_dev(board["flasher_sn"], None, None, 0) fw_dir = os.path.dirname(f'{firmware}.bin') @@ -213,28 +257,39 @@ def flash_esptool(board, firmware): flash_args = f.read().strip().replace('\n', ' ') command = (f'esptool.py --chip {idf_target} -p {port} {board["flasher_args"]} ' f'--before=default_reset --after=hard_reset write_flash {flash_args}') - # command = f'echo abc' ret = run_cmd(command, cwd=fw_dir) return ret +def reset_esptool(board): + return subprocess.CompletedProcess(args=['dummy'], returncode=0) + + def flash_uniflash(board, firmware): ret = run_cmd(f'dslite.sh {board["flasher_args"]} -f {firmware}.hex') return ret +def reset_uniflash(board): + return subprocess.CompletedProcess(args=['dummy'], returncode=0) + + # ------------------------------------------------------------- # Tests: dual # ------------------------------------------------------------- def test_dual_host_info_to_device_cdc(board): uid = board['uid'] declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] - port = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0) ser = open_serial_dev(port) - # read from serial, first line should contain vid/pid and serial + + # read from cdc, first line should contain vid/pid and serial data = ser.read(1000) + ser.close() + if len(data) == 0: + assert False, 'No data from device' lines = data.decode('utf-8').splitlines() + enum_dev_sn = [] for l in lines: vid_pid_sn = re.search(r'ID ([0-9a-fA-F]+):([0-9a-fA-F]+) SN (\w+)', l) @@ -243,12 +298,8 @@ def test_dual_host_info_to_device_cdc(board): enum_dev_sn.append(f'{vid_pid_sn.group(1)}_{vid_pid_sn.group(2)}_{vid_pid_sn.group(3)}') if set(declared_devs) != set(enum_dev_sn): - # for pico/pico2 make this test optional - failed_msg = f'Enumerated devices {enum_dev_sn} not match with declared {declared_devs}' - if 'raspberry_pi_pico' in board['name']: - print(f'\r\n {failed_msg} {STATUS_FAILED} ', end='') - else: - assert False, failed_msg + failed_msg = f'Expected {declared_devs}, Enumerated {enum_dev_sn}' + assert False, failed_msg return 0 @@ -256,12 +307,17 @@ def test_dual_host_info_to_device_cdc(board): # Tests: host # ------------------------------------------------------------- def test_host_device_info(board): - uid = board['uid'] declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] port = get_serial_dev(board["flasher_sn"], None, None, 0) ser = open_serial_dev(port) + + # reset device since we can miss the first line + ret = globals()[f'reset_{board["flasher"].lower()}'](board) + assert ret.returncode == 0, 'Failed to reset device' + data = ser.read(1000) + ser.close() if len(data) == 0: assert False, 'No data from device' @@ -274,12 +330,8 @@ def test_host_device_info(board): enum_dev_sn.append(f'{vid_pid_sn.group(1)}_{vid_pid_sn.group(2)}_{vid_pid_sn.group(3)}') if set(declared_devs) != set(enum_dev_sn): - # for pico/pico2 make this test optional - failed_msg = f'Enumerated devices {enum_dev_sn} not match with declared {declared_devs}' - if 'raspberry_pi_pico' in board['name']: - print(f'\r\n {failed_msg} {STATUS_FAILED} ', end='') - else: - assert False, failed_msg + failed_msg = f'Expected {declared_devs}, Enumerated {enum_dev_sn}' + assert False, failed_msg return 0 @@ -323,7 +375,8 @@ def test_device_cdc_msc(board): str = b"test_str" ser.write(str) ser.flush() - assert ser.read(len(str)) == str, 'CDC wrong data' + rd_str = ser.read(len(str)) + assert rd_str == str, f'CDC wrong data: expected: {str} was {rd_str}' # Block test data = read_disk_file(uid,0,'README.TXT') @@ -430,10 +483,14 @@ device_tests = [ 'device/hid_boot_interface', ] -host_tests = [ +dual_tests = [ 'dual/host_info_to_device_cdc', ] +host_test = [ + 'host/device_info', +] + def test_board(board): name = board['name'] @@ -444,8 +501,12 @@ def test_board(board): if 'tests' in board: board_tests = board['tests'] - if 'dev_attached' in board_tests: - test_list += host_tests + if 'device' in board_tests and board_tests['device'] == True: + test_list += list(device_tests) + if 'dual' in board_tests and board_tests['dual'] == True: + test_list += dual_tests + if 'host' in board_tests and board_tests['host'] == True: + test_list += host_test if 'only' in board_tests: test_list = board_tests['only'] if 'skip' in board_tests: @@ -455,7 +516,7 @@ def test_board(board): print(f'{name:25} {skip:30} ... Skip') # board_test is added last to disable board's usb - #test_list.append('device/board_test') + test_list.append('device/board_test') err_count = 0 flags_on_list = [""] @@ -473,7 +534,7 @@ def test_board(board): fw_name = f'{fw_dir}/{os.path.basename(test)}' print(f'{name+f1_str:40} {test:30} ... ', end='') - if not os.path.exists(fw_dir): + if not os.path.exists(fw_dir) or not (os.path.exists(f'{fw_name}.elf') or os.path.exists(f'{fw_name}.bin')): print('Skip (no binary)') continue diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index 2d61981f2..f3ef9dcf7 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -27,6 +27,9 @@ { "name": "feather_nrf52840_express", "uid": "1F0479CD0F764471", + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "jlink", "flasher_sn": "000682804350", "flasher_args": "-device nrf52840_xxaa" @@ -34,6 +37,9 @@ { "name": "max32666fthr", "uid": "0C81464124010B20FF0A08CC2C", + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "openocd_adi", "flasher_sn": "E6614C311B597D32", "flasher_args": "-f interface/cmsis-dap.cfg -f target/max32665.cfg" @@ -41,16 +47,20 @@ { "name": "metro_m4_express", "uid": "9995AD485337433231202020FF100A34", + "tests": { + "device": true, "host": false, "dual": true, + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002130"}] + }, "flasher": "jlink", "flasher_sn": "123456", - "flasher_args": "-device ATSAMD51J19", - "tests": { - "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002130"}] - } + "flasher_args": "-device ATSAMD51J19" }, { "name": "lpcxpresso11u37", "uid": "17121919", + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "jlink", "flasher_sn": "000724441579", "flasher_args": "-device LPC11U37/401" @@ -59,6 +69,7 @@ "name": "ra4m1_ek", "uid": "152E163038303131393346E46F26574B", "tests": { + "device": true, "host": false, "dual": false, "skip": ["device/cdc_msc", "device/cdc_msc_freertos"] }, "comment": "MSC is slow to enumerated #2602", @@ -69,22 +80,24 @@ { "name": "raspberry_pi_pico", "uid": "E6614C311B764A37", + "tests": { + "device": true, "host": false, "dual": false, + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002470"}] + }, "flasher": "openocd", "flasher_sn": "E6614103E72C1D2F", - "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"", - "tests": { - "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002470"}] - } + "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"" }, { "name": "raspberry_pi_pico2", "uid": "560AE75E1C7152C9", + "tests": { + "device": true, "host": false, "dual": false, + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "533D004242"}] + }, "flasher": "openocd", "flasher_sn": "E6633861A3978538", - "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2350.cfg -c \"adapter speed 5000\"", - "tests": { - "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "533D004242"}] - } + "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2350.cfg -c \"adapter speed 5000\"" }, { "name": "stm32f072disco", @@ -93,12 +106,29 @@ "flasher_sn": "779541626", "flasher_args": "-device stm32f072rb" }, + { + "name": "stm32f723disco", + "uid": "460029001951373031313335", + "build" : { + "flags_on": ["", "CFG_TUD_DWC2_DMA"] + }, + "tests": { + "device": true, "host": true, "dual": false, + "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2003414"}] + }, + "flasher": "jlink", + "flasher_sn": "000776606156", + "flasher_args": "-device stm32f723ie" + }, { "name": "stm32h743nucleo", "uid": "110018000951383432343236", "build" : { "flags_on": ["", "CFG_TUD_DWC2_DMA"] }, + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "stlink", "flasher_sn": "004C00343137510F39383538", "flasher_args": "" @@ -106,6 +136,9 @@ { "name": "stm32g0b1nucleo", "uid": "4D0038000450434E37343120", + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "openocd", "flasher_sn": "066FFF495087534867063844", "flasher_args": "-f interface/stlink.cfg -f target/stm32g0x.cfg" @@ -118,6 +151,9 @@ "build" : { "flags_on": ["", "CFG_TUD_DWC2_DMA"] }, + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "jlink", "flasher_sn": "000778170924", "flasher_args": "-device stm32f769ni" @@ -125,6 +161,9 @@ { "name": "mimxrt1015_evk", "uid": "DC28F865D2111D228D00B0543A70463C", + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "jlink", "flasher_sn": "000726284213", "flasher_args": "-device MIMXRT1015DAF5A" @@ -132,6 +171,9 @@ { "name": "nanoch32v203", "uid": "CDAB277B0FBC03E339E339E3", + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "openocd_wch", "flasher_sn": "EBCA8F0670AF", "flasher_args": "" @@ -139,6 +181,9 @@ { "name": "stm32f407disco", "uid": "30001A000647313332353735", + "tests": { + "device": true, "host": false, "dual": false + }, "flasher": "jlink", "flasher_sn": "000773661813", "flasher_args": "-device stm32f407vg" From 42ead3a8e06bc48d6ddbdcbd0f8e018a00e7de32 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 13:37:29 +0700 Subject: [PATCH 09/15] hil cleanup flahser --- .idea/cmake.xml | 13 +++- test/hil/hfp.json | 33 +++++++--- test/hil/hil_test.py | 59 +++++++++++------- test/hil/tinyusb.json | 136 ++++++++++++++++++++++++++---------------- 4 files changed, 158 insertions(+), 83 deletions(-) diff --git a/.idea/cmake.xml b/.idea/cmake.xml index 625bfa916..1210c49e7 100644 --- a/.idea/cmake.xml +++ b/.idea/cmake.xml @@ -54,7 +54,14 @@ - + + + + + + + + @@ -92,9 +99,9 @@ - + - + diff --git a/test/hil/hfp.json b/test/hil/hfp.json index e79a3cfc9..8ba7a8f44 100644 --- a/test/hil/hfp.json +++ b/test/hil/hfp.json @@ -3,23 +3,38 @@ { "name": "stm32l412nucleo", "uid": "41003B000E504E5457323020", - "flasher": "jlink", - "flasher_sn": "774470029", - "flasher_args": "-device STM32L412KB" + "tests": { + "device": true, "host": false, "dual": false + }, + "flasher": { + "name": "jlink", + "uid": "774470029", + "args": "-device STM32L412KB" + } }, { "name": "stm32f746disco", "uid": "210041000C51343237303334", - "flasher": "jlink", - "flasher_sn": "770935966", - "flasher_args": "-device STM32F746NG" + "tests": { + "device": true, "host": false, "dual": false + }, + "flasher": { + "name": "jlink", + "uid": "770935966", + "args": "-device STM32F746NG" + } }, { "name": "lpcxpresso43s67", "uid": "08F000044528BAAA8D858F58C50700F5", - "flasher": "jlink", - "flasher_sn": "728973776", - "flasher_args": "-device LPC43S67_M4" + "tests": { + "device": true, "host": false, "dual": false + }, + "flasher": { + "name": "jlink", + "uid": "728973776", + "args": "-device LPC43S67_M4" + } } ] } diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index b395c28a4..e7f1953b1 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -158,119 +158,137 @@ def run_cmd(cmd, cwd=None): def flash_jlink(board, firmware): + flasher = board['flasher'] script = ['halt', 'r', f'loadfile {firmware}.elf', 'r', 'go', 'exit'] f_jlink = f'{board["name"]}_{os.path.basename(firmware)}.jlink' with open(f_jlink, 'w') as f: f.writelines(f'{s}\n' for s in script) - ret = run_cmd(f'JLinkExe -USB {board["flasher_sn"]} {board["flasher_args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile {f_jlink}') + ret = run_cmd(f'JLinkExe -USB {flasher["uid"]} {flasher["args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile {f_jlink}') os.remove(f_jlink) return ret def reset_jlink(board): + flasher = board['flasher'] script = ['halt', 'r', 'go', 'exit'] f_jlink = f'{board["name"]}_reset.jlink' if not os.path.exists(f_jlink): with open(f_jlink, 'w') as f: f.writelines(f'{s}\n' for s in script) - ret = run_cmd(f'JLinkExe -USB {board["flasher_sn"]} {board["flasher_args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile {f_jlink}') + ret = run_cmd(f'JLinkExe -USB {flasher["uid"]} {flasher["args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile {f_jlink}') return ret def flash_stlink(board, firmware): - return run_cmd(f'STM32_Programmer_CLI --connect port=swd sn={board["flasher_sn"]} --write {firmware}.elf --go') + flasher = board['flasher'] + return run_cmd(f'STM32_Programmer_CLI --connect port=swd sn={flasher["uid"]} --write {firmware}.elf --go') def reset_stlink(board): - return run_cmd(f'STM32_Programmer_CLI --connect port=swd sn={board["flasher_sn"]} --rst --go') + flasher = board['flasher'] + return run_cmd(f'STM32_Programmer_CLI --connect port=swd sn={flasher["uid"]} --rst --go') def flash_stflash(board, firmware): - ret = run_cmd(f'st-flash --serial {board["flasher_sn"]} write {firmware}.bin 0x8000000') + flasher = board['flasher'] + ret = run_cmd(f'st-flash --serial {flasher["uid"]} write {firmware}.bin 0x8000000') return ret def reset_stflash(board): + flasher = board['flasher'] return subprocess.CompletedProcess(args=['dummy'], returncode=0) def flash_openocd(board, firmware): - ret = run_cmd(f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware}.elf reset exit"') + flasher = board['flasher'] + ret = run_cmd(f'openocd -c "adapter serial {flasher["uid"]}" {flasher["args"]} -c "program {firmware}.elf reset exit"') return ret def reset_openocd(board): - ret = run_cmd(f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "reset exit"') + flasher = board['flasher'] + ret = run_cmd(f'openocd -c "adapter serial {flasher["uid"]}" {flasher["args"]} -c "reset exit"') return ret def flash_openocd_wch(board, firmware): + flasher = board['flasher'] f_wch = f"wch-riscv_{board['uid']}.cfg" if not os.path.exists(f_wch): with open(f_wch, 'w') as file: file.write(WCH_RISCV_CONTENT) - ret = run_cmd(f'openocd_wch -c "adapter serial {board["flasher_sn"]}" -f {f_wch} ' + ret = run_cmd(f'openocd_wch -c "adapter serial {flasher["uid"]}" -f {f_wch} ' f'-c "program {firmware}.elf reset exit"') return ret def reset_openocd_wch(board): + flasher = board['flasher'] f_wch = f"wch-riscv_{board['uid']}.cfg" if not os.path.exists(f_wch): with open(f_wch, 'w') as file: file.write(WCH_RISCV_CONTENT) - ret = run_cmd(f'openocd_wch -c "adapter serial {board["flasher_sn"]}" -f {f_wch} -c "program reset exit"') + ret = run_cmd(f'openocd_wch -c "adapter serial {flasher["uid"]}" -f {f_wch} -c "program reset exit"') return ret def flash_openocd_adi(board, firmware): - ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {board["flasher_sn"]}" -s {OPENCOD_ADI_PATH}/tcl ' - f'{board["flasher_args"]} -c "program {firmware}.elf reset exit"') + flasher = board['flasher'] + ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {flasher["uid"]}" -s {OPENCOD_ADI_PATH}/tcl ' + f'{flasher["args"]} -c "program {firmware}.elf reset exit"') return ret def reset_openocd_adi(board): - ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {board["flasher_sn"]}" -s {OPENCOD_ADI_PATH}/tcl ' - f'{board["flasher_args"]} -c "program reset exit"') + flasher = board['flasher'] + ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {flasher["uid"]}" -s {OPENCOD_ADI_PATH}/tcl ' + f'{flasher["args"]} -c "program reset exit"') return ret def flash_wlink_rs(board, firmware): + flasher = board['flasher'] # wlink use index for probe selection and lacking usb serial support ret = run_cmd(f'wlink flash {firmware}.elf') return ret def reset_wlink_rs(board): + flasher = board['flasher'] # wlink use index for probe selection and lacking usb serial support ret = run_cmd(f'wlink reset') return ret def flash_esptool(board, firmware): - port = get_serial_dev(board["flasher_sn"], None, None, 0) + flasher = board['flasher'] + port = get_serial_dev(flasher["uid"], None, None, 0) fw_dir = os.path.dirname(f'{firmware}.bin') with open(f'{fw_dir}/config.env') as f: idf_target = json.load(f)['IDF_TARGET'] with open(f'{fw_dir}/flash_args') as f: flash_args = f.read().strip().replace('\n', ' ') - command = (f'esptool.py --chip {idf_target} -p {port} {board["flasher_args"]} ' + command = (f'esptool.py --chip {idf_target} -p {port} {flasher["args"]} ' f'--before=default_reset --after=hard_reset write_flash {flash_args}') ret = run_cmd(command, cwd=fw_dir) return ret def reset_esptool(board): + flasher = board['flasher'] return subprocess.CompletedProcess(args=['dummy'], returncode=0) def flash_uniflash(board, firmware): - ret = run_cmd(f'dslite.sh {board["flasher_args"]} -f {firmware}.hex') + flasher = board['flasher'] + ret = run_cmd(f'dslite.sh {flasher["args"]} -f {firmware}.hex') return ret def reset_uniflash(board): + flasher = board['flasher'] return subprocess.CompletedProcess(args=['dummy'], returncode=0) @@ -307,13 +325,14 @@ def test_dual_host_info_to_device_cdc(board): # Tests: host # ------------------------------------------------------------- def test_host_device_info(board): + flasher = board['flasher'] declared_devs = [f'{d["vid_pid"]}_{d["serial"]}' for d in board['tests']['dev_attached']] - port = get_serial_dev(board["flasher_sn"], None, None, 0) + port = get_serial_dev(flasher["uid"], None, None, 0) ser = open_serial_dev(port) # reset device since we can miss the first line - ret = globals()[f'reset_{board["flasher"].lower()}'](board) + ret = globals()[f'reset_{flasher["name"].lower()}'](board) assert ret.returncode == 0, 'Failed to reset device' data = ser.read(1000) @@ -494,7 +513,7 @@ host_test = [ def test_board(board): name = board['name'] - flasher = board['flasher'].lower() + flasher = board['flasher'] # default to all tests test_list = list(device_tests) @@ -540,7 +559,7 @@ def test_board(board): # flash firmware. It may fail randomly, retry a few times for i in range(3): - ret = globals()[f'flash_{flasher}'](board, fw_name) + ret = globals()[f'flash_{flasher["name"].lower()}'](board, fw_name) if ret.returncode == 0: break else: diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index f3ef9dcf7..4d450cc5a 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -7,9 +7,11 @@ "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos", "host/device_info"], "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002427"}] }, - "flasher": "esptool", - "flasher_sn": "4ea4f48f6bc3ee11bbb9d00f9e1b1c54", - "flasher_args": "-b 1500000" + "flasher": { + "name": "esptool", + "uid": "4ea4f48f6bc3ee11bbb9d00f9e1b1c54", + "args": "-b 1500000" + } }, { "name": "espressif_s3_devkitm", @@ -20,9 +22,11 @@ "tests": { "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"] }, - "flasher": "esptool", - "flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1", - "flasher_args": "-b 1500000" + "flasher": { + "name": "esptool", + "uid": "3ea619acd1cdeb11a0a0b806e93fd3f1", + "args": "-b 1500000" + } }, { "name": "feather_nrf52840_express", @@ -30,9 +34,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "jlink", - "flasher_sn": "000682804350", - "flasher_args": "-device nrf52840_xxaa" + "flasher": { + "name": "jlink", + "uid": "000682804350", + "args": "-device nrf52840_xxaa" + } }, { "name": "max32666fthr", @@ -40,9 +46,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "openocd_adi", - "flasher_sn": "E6614C311B597D32", - "flasher_args": "-f interface/cmsis-dap.cfg -f target/max32665.cfg" + "flasher": { + "name": "openocd_adi", + "uid": "E6614C311B597D32", + "args": "-f interface/cmsis-dap.cfg -f target/max32665.cfg" + } }, { "name": "metro_m4_express", @@ -51,9 +59,11 @@ "device": true, "host": false, "dual": true, "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002130"}] }, - "flasher": "jlink", - "flasher_sn": "123456", - "flasher_args": "-device ATSAMD51J19" + "flasher": { + "name": "jlink", + "uid": "123456", + "args": "-device ATSAMD51J19" + } }, { "name": "lpcxpresso11u37", @@ -61,9 +71,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "jlink", - "flasher_sn": "000724441579", - "flasher_args": "-device LPC11U37/401" + "flasher": { + "name": "jlink", + "uid": "000724441579", + "args": "-device LPC11U37/401" + } }, { "name": "ra4m1_ek", @@ -73,9 +85,11 @@ "skip": ["device/cdc_msc", "device/cdc_msc_freertos"] }, "comment": "MSC is slow to enumerated #2602", - "flasher": "jlink", - "flasher_sn": "000831174392", - "flasher_args": "-device R7FA4M1AB" + "flasher": { + "name": "jlink", + "uid": "000831174392", + "args": "-device R7FA4M1AB" + } }, { "name": "raspberry_pi_pico", @@ -84,9 +98,11 @@ "device": true, "host": false, "dual": false, "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002470"}] }, - "flasher": "openocd", - "flasher_sn": "E6614103E72C1D2F", - "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"" + "flasher": { + "name": "openocd", + "uid": "E6614103E72C1D2F", + "args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"" + } }, { "name": "raspberry_pi_pico2", @@ -95,16 +111,20 @@ "device": true, "host": false, "dual": false, "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "533D004242"}] }, - "flasher": "openocd", - "flasher_sn": "E6633861A3978538", - "flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2350.cfg -c \"adapter speed 5000\"" + "flasher": { + "name": "openocd", + "uid": "E6633861A3978538", + "args": "-f interface/cmsis-dap.cfg -f target/rp2350.cfg -c \"adapter speed 5000\"" + } }, { "name": "stm32f072disco", "uid": "3A001A001357364230353532", - "flasher": "jlink", - "flasher_sn": "779541626", - "flasher_args": "-device stm32f072rb" + "name": "jlink", + "flasher": { + "uid": "779541626", + "args": "-device stm32f072rb" + } }, { "name": "stm32f723disco", @@ -116,9 +136,11 @@ "device": true, "host": true, "dual": false, "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2003414"}] }, - "flasher": "jlink", - "flasher_sn": "000776606156", - "flasher_args": "-device stm32f723ie" + "flasher": { + "name": "jlink", + "uid": "000776606156", + "args": "-device stm32f723ie" + } }, { "name": "stm32h743nucleo", @@ -129,9 +151,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "stlink", - "flasher_sn": "004C00343137510F39383538", - "flasher_args": "" + "flasher": { + "name": "stlink", + "uid": "004C00343137510F39383538", + "args": "" + } }, { "name": "stm32g0b1nucleo", @@ -139,9 +163,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "openocd", - "flasher_sn": "066FFF495087534867063844", - "flasher_args": "-f interface/stlink.cfg -f target/stm32g0x.cfg" + "flasher": { + "name": "openocd", + "uid": "066FFF495087534867063844", + "args": "-f interface/stlink.cfg -f target/stm32g0x.cfg" + } } ], "boards-skip": [ @@ -154,9 +180,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "jlink", - "flasher_sn": "000778170924", - "flasher_args": "-device stm32f769ni" + "flasher": { + "name": "jlink", + "uid": "000778170924", + "args": "-device stm32f769ni" + } }, { "name": "mimxrt1015_evk", @@ -164,9 +192,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "jlink", - "flasher_sn": "000726284213", - "flasher_args": "-device MIMXRT1015DAF5A" + "flasher": { + "name": "jlink", + "uid": "000726284213", + "args": "-device MIMXRT1015DAF5A" + } }, { "name": "nanoch32v203", @@ -174,9 +204,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "openocd_wch", - "flasher_sn": "EBCA8F0670AF", - "flasher_args": "" + "flasher": { + "name": "openocd_wch", + "uid": "EBCA8F0670AF", + "args": "" + } }, { "name": "stm32f407disco", @@ -184,9 +216,11 @@ "tests": { "device": true, "host": false, "dual": false }, - "flasher": "jlink", - "flasher_sn": "000773661813", - "flasher_args": "-device stm32f407vg" + "flasher": { + "name": "jlink", + "uid": "000773661813", + "args": "-device stm32f407vg" + } } ] } From 6776c7171e3176026faadea4a721fd96bc1e41f2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 15:06:39 +0700 Subject: [PATCH 10/15] fix hil set matrix --- test/hil/hil_ci_set_matrix.py | 3 ++- test/hil/tinyusb.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/hil/hil_ci_set_matrix.py b/test/hil/hil_ci_set_matrix.py index 192174e16..67ce2abb8 100644 --- a/test/hil/hil_ci_set_matrix.py +++ b/test/hil/hil_ci_set_matrix.py @@ -22,7 +22,8 @@ def main(): } for board in config['boards']: name = board['name'] - if board['flasher'] == 'esptool': + flasher = board['flasher'] + if flasher['name'] == 'esptool': toolchain = 'esp-idf' else: toolchain = 'arm-gcc' diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index 4d450cc5a..32f4a06de 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -120,8 +120,8 @@ { "name": "stm32f072disco", "uid": "3A001A001357364230353532", - "name": "jlink", "flasher": { + "name": "jlink", "uid": "779541626", "args": "-device stm32f072rb" } From 9ff02daa565ae6bc12d47dd7d1ce7a23036c9e55 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 16:20:41 +0700 Subject: [PATCH 11/15] improve hil for dual cdc, close cdc once done --- test/hil/hil_test.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index e7f1953b1..9d6078ba0 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -365,24 +365,24 @@ def test_device_board_test(board): def test_device_cdc_dual_ports(board): uid = board['uid'] - port1 = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0) - port2 = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 2) + port = [ + get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0), + get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 2) + ] + ser = [open_serial_dev(p) for p in port] - ser1 = open_serial_dev(port1) - ser2 = open_serial_dev(port2) - - # Echo test - str1 = b"test_no1" - ser1.write(str1) - ser1.flush() - assert ser1.read(len(str1)) == str1.lower(), 'Port1 wrong data' - assert ser2.read(len(str1)) == str1.upper(), 'Port2 wrong data' - - str2 = b"test_no2" - ser2.write(str2) - ser2.flush() - assert ser1.read(len(str2)) == str2.lower(), 'Port1 wrong data' - assert ser2.read(len(str2)) == str2.upper(), 'Port2 wrong data' + str_test = [ b"test_no1", b"test_no2" ] + # Echo test write to each port and read back + for i in range(len(str_test)): + s = str_test[i] + l = len(s) + ser[i].write(s) + ser[i].flush() + rd = [ ser[i].read(l) for i in range(len(ser)) ] + assert rd[0] == s.lower(), f'Port1 wrong data: expected {s.lower()} was {rd[0]}' + assert rd[1] == s.upper(), f'Port2 wrong data: expected {s.upper()} was {rd[1]}' + ser[0].close() + ser[1].close() def test_device_cdc_msc(board): @@ -395,6 +395,7 @@ def test_device_cdc_msc(board): ser.write(str) ser.flush() rd_str = ser.read(len(str)) + ser.close() assert rd_str == str, f'CDC wrong data: expected: {str} was {rd_str}' # Block test From 3ee3658dad4bd44be325ee18229dfc62a2ffa057 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 17:01:54 +0700 Subject: [PATCH 12/15] skip max3421e metro m4 for now, due to cdc output too fast. --- test/hil/hil_test.py | 2 +- test/hil/tinyusb.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 9d6078ba0..daa9868d9 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -517,7 +517,7 @@ def test_board(board): flasher = board['flasher'] # default to all tests - test_list = list(device_tests) + test_list = [] if 'tests' in board: board_tests = board['tests'] diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index 32f4a06de..c15daf1d9 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -56,7 +56,7 @@ "name": "metro_m4_express", "uid": "9995AD485337433231202020FF100A34", "tests": { - "device": true, "host": false, "dual": true, + "device": true, "host": false, "dual": false, "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002130"}] }, "flasher": { From 202aaa49ad5187e238a5cc4218ea58c8ad1e3c9b Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 17:34:22 +0700 Subject: [PATCH 13/15] change test order (no cdc or msc back to back). --- test/hil/hil_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index daa9868d9..eec7ec2be 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -494,12 +494,13 @@ def test_device_hid_composite_freertos(id): # Main # ------------------------------------------------------------- # device tests +# note don't test 2 examples with cdc or 2 msc next to each other device_tests = [ 'device/cdc_dual_ports', - 'device/cdc_msc', 'device/dfu', - 'device/cdc_msc_freertos', # don't test 2 cdc_msc next to each other + 'device/cdc_msc', 'device/dfu_runtime', + 'device/cdc_msc_freertos', 'device/hid_boot_interface', ] From 98bc480f7320f0272a185c64f2a1d518357ea800 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 18:23:58 +0700 Subject: [PATCH 14/15] retry test up to 2 times, somehow open serial failed randomly with rp2040 --- test/hil/hil_test.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index eec7ec2be..63902f515 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -201,13 +201,15 @@ def reset_stflash(board): def flash_openocd(board, firmware): flasher = board['flasher'] - ret = run_cmd(f'openocd -c "adapter serial {flasher["uid"]}" {flasher["args"]} -c "program {firmware}.elf reset exit"') + ret = run_cmd(f'openocd -c "tcl_port disabled" -c "gdb_port disabled" -c "adapter serial {flasher["uid"]}" ' + f'{flasher["args"]} -c init -c halt -c "program {firmware}.elf verify" -c reset -c exit') return ret def reset_openocd(board): flasher = board['flasher'] - ret = run_cmd(f'openocd -c "adapter serial {flasher["uid"]}" {flasher["args"]} -c "reset exit"') + ret = run_cmd(f'openocd -c "tcl_port disabled" -c "gdb_port disabled" -c "adapter serial {flasher["uid"]}" ' + f'{flasher["args"]} -c "reset exit"') return ret @@ -560,25 +562,31 @@ def test_board(board): continue # flash firmware. It may fail randomly, retry a few times - for i in range(3): + max_rety = 2 + for i in range(max_rety): ret = globals()[f'flash_{flasher["name"].lower()}'](board, fw_name) if ret.returncode == 0: - break + try: + globals()[f'test_{test.replace("/", "_")}'](board) + print('OK') + break + except Exception as e: + if i == max_rety - 1: + err_count += 1 + print(STATUS_FAILED) + print(f' {e}') + else: + print() + print(f' Test failed: {e}, retry {i+1}') + time.sleep(1) else: print(f'Flashing failed, retry {i+1}') time.sleep(1) - if ret.returncode == 0: - try: - ret = globals()[f'test_{test.replace("/", "_")}'](board) - print('OK') - except Exception as e: - err_count += 1 - print(STATUS_FAILED) - print(f' {e}') - else: + if ret.returncode != 0: err_count += 1 print(f'Flash {STATUS_FAILED}') + return err_count From 401a704804da3a039c98870783d895dc2a1646f7 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Nov 2024 19:32:57 +0700 Subject: [PATCH 15/15] clean up --- test/hil/hil_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 63902f515..f125c0d28 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -393,12 +393,12 @@ def test_device_cdc_msc(board): port = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0) ser = open_serial_dev(port) - str = b"test_str" - ser.write(str) + test_str = b"test_str" + ser.write(test_str) ser.flush() - rd_str = ser.read(len(str)) + rd_str = ser.read(len(test_str)) ser.close() - assert rd_str == str, f'CDC wrong data: expected: {str} was {rd_str}' + assert rd_str == test_str, f'CDC wrong data: expected: {test_str} was {rd_str}' # Block test data = read_disk_file(uid,0,'README.TXT')