framework: idf5.1 (stable)
cpu: ESP32S3
vscode on windows 10
Trying usb_cdc_example to connect to an LTE modem and getting "Could not find required interface" error.
The vid, pid and interface extension are correct (0x2C7C, 0x6002, 3), and I have no idea what to look at/for to resolve my issue.
Help greatly appreciated please...
My code:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "esp_system.h"
#include "esp_log.h"
#include "esp_err.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "usb/usb_host.h"
#include "usb/cdc_acm_host.h"
#define EXAMPLE_USB_HOST_PRIORITY (20)
#define EXAMPLE_USB_DEVICE_VID (0x2C7C)
#define EXAMPLE_USB_DEVICE_PID (0x6002) // 0x303A:0x4001 (TinyUSB CDC device)
#define EXAMPLE_USB_DEVICE_DUAL_PID (0x4002) // 0x303A:0x4002 (TinyUSB Dual CDC device)
#define EXAMPLE_TX_STRING ("AT")
#define EXAMPLE_TX_TIMEOUT_MS (1000)
// outputs
const gpio_num_t VBAT = GPIO_NUM_12;
const gpio_num_t VBUS = GPIO_NUM_16;
const gpio_num_t PWRKEY = GPIO_NUM_14;
const gpio_num_t RSTKEY = GPIO_NUM_13;
// inputs
const gpio_num_t STAT = GPIO_NUM_8;
const gpio_num_t NET_STAT = GPIO_NUM_7;
const gpio_num_t SIM_DET = GPIO_NUM_48;
static const char *TAG = "USB-CDC";
static SemaphoreHandle_t device_disconnected_sem;
/**
* @brief Data received callback
*
* @param[in] data Pointer to received data
* @param[in] data_len Length of received data in bytes
* @param[in] arg Argument we passed to the device open function
* @return
* true: We have processed the received data
* false: We expect more data
*/
static bool handle_rx(const uint8_t *data, size_t data_len, void *arg)
{
ESP_LOGI(TAG, "Data received");
ESP_LOG_BUFFER_HEXDUMP(TAG, data, data_len, ESP_LOG_INFO);
return true;
}
/**
* @brief Device event callback
*
* Apart from handling device disconnection it doesn't do anything useful
*
* @param[in] event Device event type and data
* @param[in] user_ctx Argument we passed to the device open function
*/
static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx)
{
switch (event->type) {
case CDC_ACM_HOST_ERROR:
ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %i", event->data.error);
break;
case CDC_ACM_HOST_DEVICE_DISCONNECTED:
ESP_LOGI(TAG, "Device suddenly disconnected");
ESP_ERROR_CHECK(cdc_acm_host_close(event->data.cdc_hdl));
xSemaphoreGive(device_disconnected_sem);
break;
case CDC_ACM_HOST_SERIAL_STATE:
ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val);
break;
case CDC_ACM_HOST_NETWORK_CONNECTION:
default:
ESP_LOGW(TAG, "Unsupported CDC event: %i", event->type);
break;
}
}
/**
* @brief USB Host library handling task
*
* @param arg Unused
*/
static void usb_lib_task(void *arg)
{
while (1) {
// Start handling system events
uint32_t event_flags;
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
ESP_ERROR_CHECK(usb_host_device_free_all());
}
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE) {
ESP_LOGI(TAG, "USB: All devices freed");
// Continue handling USB events to allow device reconnection
}
}
}
esp_err_t config_lte_pins()
{
// inputs
esp_rom_gpio_pad_select_gpio(STAT);
gpio_set_direction(STAT, GPIO_MODE_INPUT);
gpio_pullup_en(STAT);
esp_rom_gpio_pad_select_gpio(SIM_DET);
gpio_set_direction(SIM_DET, GPIO_MODE_INPUT);
esp_rom_gpio_pad_select_gpio(NET_STAT);
gpio_set_direction(NET_STAT, GPIO_MODE_INPUT);
esp_rom_gpio_pad_select_gpio(SIM_DET);
gpio_set_direction(SIM_DET, GPIO_MODE_INPUT);
// outputs
esp_rom_gpio_pad_select_gpio(VBAT);
gpio_set_direction(VBAT, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(VBUS);
gpio_set_direction(VBUS, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(PWRKEY);
gpio_set_direction(PWRKEY, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(RSTKEY);
gpio_set_direction(RSTKEY, GPIO_MODE_OUTPUT);
return ESP_OK;
}
esp_err_t power_cycle_modem()
{
ESP_LOGW(TAG, "POWER CYCLE MODEM...");
// precondition signals
gpio_set_level(PWRKEY, 0); // HI
gpio_set_level(RSTKEY, 1); // LO
gpio_set_level(VBAT, 1); // power up LTE chip
gpio_set_level(VBUS, 1); // power up VBUS ref
vTaskDelay(50 / portTICK_PERIOD_MS); // 50ms wait VBAT stable
//RESET LTE chip
gpio_set_level(PWRKEY, 1); // LO
vTaskDelay(30 / portTICK_PERIOD_MS); // 30ms then RESET HI
gpio_set_level(RSTKEY, 0); // HI
vTaskDelay(470 / portTICK_PERIOD_MS); // 500ms total
gpio_set_level(PWRKEY, 0); // HI
ESP_LOGW(TAG, "wait STATUS loop...");
ESP_LOGI(TAG, "level: %d", gpio_get_level(STAT));
do
{
vTaskDelay(10 / portTICK_PERIOD_MS);
} while ( 1 == gpio_get_level(STAT) ); // this should occur at around 7.5 secs
ESP_LOGI(TAG, "level: %d", gpio_get_level(STAT));
vTaskDelay(pdMS_TO_TICKS(3000));
return ESP_OK;
}
/**
* @brief Main application
*
* Here we open a USB CDC device and send some data to it
*/
void app_main(void)
{
esp_err_t err;
device_disconnected_sem = xSemaphoreCreateBinary();
assert(device_disconnected_sem);
err = config_lte_pins();
err = power_cycle_modem();
// Install USB Host driver. Should only be called once in entire application
ESP_LOGI(TAG, "Installing USB Host");
const usb_host_config_t host_config = {
.skip_phy_setup = false,
.intr_flags = ESP_INTR_FLAG_LEVEL1,
};
ESP_ERROR_CHECK(usb_host_install(&host_config));
// Create a task that will handle USB library events
BaseType_t task_created = xTaskCreate(usb_lib_task, "usb_lib", 4096, xTaskGetCurrentTaskHandle(), EXAMPLE_USB_HOST_PRIORITY, NULL);
assert(task_created == pdTRUE);
ESP_LOGI(TAG, "Installing CDC-ACM driver");
ESP_ERROR_CHECK(cdc_acm_host_install(NULL));
const cdc_acm_host_device_config_t dev_config = {
.connection_timeout_ms = 5000,
.out_buffer_size = 512,
.in_buffer_size = 512,
.user_arg = NULL,
.event_cb = handle_event,
.data_cb = handle_rx
};
while (true) {
cdc_acm_dev_hdl_t cdc_dev = NULL;
// Open USB device from tusb_serial_device example example. Either single or dual port configuration.
ESP_LOGI(TAG, "Opening CDC ACM device 0x%04X:0x%04X...", EXAMPLE_USB_DEVICE_VID, EXAMPLE_USB_DEVICE_PID);
esp_err_t err = cdc_acm_host_open(EXAMPLE_USB_DEVICE_VID, EXAMPLE_USB_DEVICE_PID, 3, &dev_config, &cdc_dev);
cdc_acm_host_desc_print(cdc_dev);
vTaskDelay(pdMS_TO_TICKS(100));
// Test sending and receiving: responses are handled in handle_rx callback
ESP_ERROR_CHECK(cdc_acm_host_data_tx_blocking(cdc_dev, (const uint8_t *)EXAMPLE_TX_STRING, strlen(EXAMPLE_TX_STRING), EXAMPLE_TX_TIMEOUT_MS));
vTaskDelay(pdMS_TO_TICKS(100));
// Test Line Coding commands: Get current line coding, change it 9600 7N1 and read again
ESP_LOGI(TAG, "Setting up line coding");
cdc_acm_line_coding_t line_coding;
ESP_ERROR_CHECK(cdc_acm_host_line_coding_get(cdc_dev, &line_coding));
ESP_LOGI(TAG, "Line Get: Rate: %"PRIu32", Stop bits: %"PRIu8", Parity: %"PRIu8", Databits: %"PRIu8"",
line_coding.dwDTERate, line_coding.bCharFormat, line_coding.bParityType, line_coding.bDataBits);
// line_coding.dwDTERate = 9600;
// line_coding.bDataBits = 7;
// line_coding.bParityType = 1;
// line_coding.bCharFormat = 1;
line_coding.dwDTERate = 115200;
line_coding.bDataBits = 8;
line_coding.bParityType = 1;
line_coding.bCharFormat = 1;
ESP_ERROR_CHECK(cdc_acm_host_line_coding_set(cdc_dev, &line_coding));
ESP_LOGI(TAG, "Line Set: Rate: %"PRIu32", Stop bits: %"PRIu8", Parity: %"PRIu8", Databits: %"PRIu8"",
line_coding.dwDTERate, line_coding.bCharFormat, line_coding.bParityType, line_coding.bDataBits);
ESP_ERROR_CHECK(cdc_acm_host_line_coding_get(cdc_dev, &line_coding));
ESP_LOGI(TAG, "Line Get: Rate: %"PRIu32", Stop bits: %"PRIu8", Parity: %"PRIu8", Databits: %"PRIu8"",
line_coding.dwDTERate, line_coding.bCharFormat, line_coding.bParityType, line_coding.bDataBits);
ESP_ERROR_CHECK(cdc_acm_host_set_control_line_state(cdc_dev, true, false));
// We are done. Wait for device disconnection and start over
// ESP_LOGI(TAG, "Example finished successfully! You can reconnect the device to run again.");
// xSemaphoreTake(device_disconnected_sem, portMAX_DELAY);
}
}
Code: Select all
PS P:\projects\usb_cdc_example> C:\Espressif\python_env\idf5.1_py3.11_env\Scripts\python.exe C:\Espressif\frameworks\esp-idf-v5.1\tools\idf_monitor.py -p COM3 -b 115200 --toolchain-prefix xtensa-esp32s3-elf- --target esp32s3 p:\projects\usb_cdc_example\build\simple_cmux_client.elf
--- WARNING: GDB cannot open serial ports accessed as COMx
--- Using \\.\COM3 instead...
--- idf_monitor on \\.\COM3 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x2b (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x16e4
load:0x403c9700,len:0x4
load:0x403c9704,len:0xc00
load:0x403cc700,len:0x2eb0
entry 0x403c9908
I (27) boot: ESP-IDF v5.1-dirty 2nd stage bootloader
I (27) boot: compile time Oct 4 2023 14:19:10
I (27) boot: Multicore bootloader
I (30) boot: chip revision: v0.1
I (34) boot.esp32s3: Boot SPI Speed : 80MHz
I (39) boot.esp32s3: SPI Mode : DIO
I (44) boot.esp32s3: SPI Flash Size : 2MB
I (48) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (57) boot: ## Label Usage Type ST Offset Length
I (65) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (72) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (80) boot: 2 factory factory app 00 00 00010000 00100000
I (87) boot: End of partition table
I (91) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=0ecc0h ( 60608) map
I (111) esp_image: segment 1: paddr=0001ece8 vaddr=3fc92300 size=01330h ( 4912) load
I (112) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=2593ch (153916) map
I (144) esp_image: segment 3: paddr=00045964 vaddr=3fc93630 size=01614h ( 5652) load
I (146) esp_image: segment 4: paddr=00046f80 vaddr=40374000 size=0e298h ( 58008) load
I (169) boot: Loaded app from partition at offset 0x10000
I (169) boot: Disabling RNG early entropy source...
I (180) cpu_start: Multicore app
D (180) flash HPM: HPM with dummy, status is 3
I (181) cpu_start: Pro cpu up.
I (181) cpu_start: Starting app cpu, entry point is 0x40375304
0x40375304: call_start_cpu1 at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/port/cpu_start.c:154
I (0) cpu_start: App cpu up.
D (196) clk: RTC_SLOW_CLK calibration value: 3540467
I (208) cpu_start: Pro cpu start user code
I (208) cpu_start: cpu freq: 160000000 Hz
I (208) cpu_start: Application information:
I (211) cpu_start: Project name: simple_cmux_client
I (217) cpu_start: App version: 1
I (222) cpu_start: Compile time: Oct 4 2023 14:18:48
I (228) cpu_start: ELF file SHA256: 8994e322aa80dfe6...
I (234) cpu_start: ESP-IDF: v5.1-dirty
I (239) cpu_start: Min chip rev: v0.0
I (244) cpu_start: Max chip rev: v0.99
I (249) cpu_start: Chip rev: v0.1
D (253) memory_layout: Checking 5 reserved memory ranges:
D (259) memory_layout: Reserved memory range 0x3fc84000 - 0x3fc92300
D (265) memory_layout: Reserved memory range 0x3fc92300 - 0x3fc954b0
D (272) memory_layout: Reserved memory range 0x3fceee34 - 0x3fcf0000
D (278) memory_layout: Reserved memory range 0x40374000 - 0x40382300
0x40374000: _WindowOverflow4 at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:2013
D (284) memory_layout: Reserved memory range 0x600fe000 - 0x600fe010
D (291) memory_layout: Building list of available memory regions:
D (297) memory_layout: Available memory region 0x3fc954b0 - 0x3fca0000
D (304) memory_layout: Available memory region 0x3fca0000 - 0x3fcb0000
D (310) memory_layout: Available memory region 0x3fcb0000 - 0x3fcc0000
D (317) memory_layout: Available memory region 0x3fcc0000 - 0x3fcd0000
D (323) memory_layout: Available memory region 0x3fcd0000 - 0x3fce0000
D (330) memory_layout: Available memory region 0x3fce0000 - 0x3fce9710
D (337) memory_layout: Available memory region 0x3fce9710 - 0x3fceee34
D (343) memory_layout: Available memory region 0x3fcf0000 - 0x3fcf8000
D (350) memory_layout: Available memory region 0x600fe010 - 0x60100000
I (356) heap_init: Initializing. RAM available for dynamic allocation:
D (364) heap_init: New heap initialised at 0x3fc954b0
I (369) heap_init: At 3FC954B0 len 00054260 (336 KiB): DRAM
I (375) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
D (382) heap_init: New heap initialised at 0x3fcf0000
I (387) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
D (393) heap_init: New heap initialised at 0x600fe010
I (398) heap_init: At 600FE010 len 00001FF0 (7 KiB): RTCRAM
D (405) intr_alloc: Connected src 39 to int 2 (cpu 0)
D (410) spi_flash: trying chip: issi
D (413) spi_flash: trying chip: gd
I (417) spi_flash: detected chip: gd
I (421) spi_flash: flash io: dio
W (425) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
D (438) cpu_start: calling init function: 0x420132f8
0x420132f8: esp_ipc_init at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/esp_ipc.c:114
D (443) cpu_start: calling init function: 0x42001b90
0x42001b90: esp_init_app_elf_sha256 at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_app_format/esp_app_desc.c:69
D (448) cpu_start: calling init function: 0x42006984 on core: 0
0x42006984: __esp_system_init_fn_esp_timer_startup_init at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_timer/src/esp_timer.c:575
D (454) intr_alloc: Connected src 59 to int 3 (cpu 0)
D (459) cpu_start: calling init function: 0x420044ac on core: 0
0x420044ac: __esp_system_init_fn_esp_sleep_startup_init at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_hw_support/sleep_gpio.c:188
I (465) sleep: Configure to isolate all GPIO pins in sleep state
I (472) sleep: Enable automatic switching of GPIO sleep configuration
D (479) cpu_start: calling init function: 0x42002a80 on core: 0
0x42002a80: __esp_system_init_fn_init_components0 at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/startup.c:486
D (485) intr_alloc: Connected src 79 to int 9 (cpu 0)
I (490) app_start: Starting scheduler on CPU0
D (495) intr_alloc: Connected src 57 to int 12 (cpu 0)
D (495) intr_alloc: Connected src 80 to int 2 (cpu 1)
I (505) app_start: Starting scheduler on CPU1
D (505) intr_alloc: Connected src 58 to int 3 (cpu 1)
I (495) main_task: Started on CPU0
D (515) heap_init: New heap initialised at 0x3fce9710
D (515) intr_alloc: Connected src 52 to int 13 (cpu 0)
I (525) main_task: Calling app_main()
W (525) USB-CDC: POWER CYCLE MODEM...
W (1085) USB-CDC: wait STATUS loop...
I (1085) USB-CDC: level: 1
I (8105) USB-CDC: level: 0
I (11105) USB-CDC: Installing USB Host
D (11105) intr_alloc: Connected src 38 to int 17 (cpu 0)
I (11135) USB-CDC: Installing CDC-ACM driver
I (11135) USB-CDC: Opening CDC ACM device 0x2C7C:0x6002...
D (11135) cdc_acm: Checking list of opened USB devices
D (11135) cdc_acm: Checking list of connected USB devices
W (11145) cdc_acm: num_of_devices: 0
D (11195) cdc_acm: Checking list of connected USB devices
W (11195) cdc_acm: num_of_devices: 0
D (11245) cdc_acm: Checking list of connected USB devices
W (11245) cdc_acm: num_of_devices: 0
D (11295) cdc_acm: Checking list of connected USB devices
W (11295) cdc_acm: num_of_devices: 0
D (11345) cdc_acm: Checking list of connected USB devices
W (11345) cdc_acm: num_of_devices: 0
D (11395) cdc_acm: Checking list of connected USB devices
W (11395) cdc_acm: num_of_devices: 0
D (11445) HUB: Root port reset
D (11445) HUB: Stage done: START
D (11445) HUB: Stage done: GET_SHORT_DEV_DESC
D (11445) HUB: Stage done: CHECK_SHORT_DEV_DESC
D (11445) cdc_acm: Checking list of connected USB devices
W (11455) cdc_acm: num_of_devices: 0
D (11505) HUB: Stage done: SECOND_RESET
D (11505) HUB: Stage done: SET_ADDR
D (11505) HUB: Stage done: CHECK_ADDR
D (11505) cdc_acm: Checking list of connected USB devices
W (11505) cdc_acm: num_of_devices: 0
D (11515) HUB: Stage done: SET_ADDR_RECOVERY
D (11515) HUB: Stage done: GET_FULL_DEV_DESC
D (11515) HUB: Stage done: CHECK_FULL_DEV_DESC
D (11525) HUB: Stage done: GET_SHORT_CONFIG_DESC
D (11525) HUB: Stage done: CHECK_SHORT_CONFIG_DESC
D (11535) HUB: Stage done: GET_FULL_CONFIG_DESC
D (11535) HUB: Stage done: CHECK_FULL_CONFIG_DESC
D (11545) HUB: Stage done: SET_CONFIG
D (11545) HUB: Stage done: CHECK_CONFIG
D (11545) HUB: Stage done: GET_SHORT_LANGID_TABLE
D (11555) HUB: Stage done: CHECK_SHORT_LANGID_TABLE
D (11555) HUB: Stage done: GET_FULL_LANGID_TABLE
D (11565) HUB: Stage done: CHECK_FULL_LANGID_TABLE
D (11565) HUB: Stage done: GET_SHORT_MANU_STR_DESC
D (11575) HUB: Stage done: CHECK_SHORT_MANU_STR_DESC
D (11575) HUB: Stage done: GET_FULL_MANU_STR_DESC
D (11585) HUB: Stage done: CHECK_FULL_MANU_STR_DESC
D (11585) HUB: Stage done: GET_SHORT_PROD_STR_DESC
D (11595) HUB: Stage done: CHECK_SHORT_PROD_STR_DESC
D (11595) HUB: Stage done: GET_FULL_PROD_STR_DESC
D (11605) HUB: Stage done: CHECK_FULL_PROD_STR_DESC
D (11605) HUB: Stage done: GET_SHORT_SER_STR_DESC
D (11615) HUB: Stage done: CHECK_SHORT_SER_STR_DESC
D (11615) HUB: Stage done: GET_FULL_SER_STR_DESC
D (11625) HUB: Stage done: CHECK_FULL_SER_STR_DESC
D (11625) HUB: Stage done: CLEANUP
D (11635) USBH: Processing actions 0x100
D (11635) USBH: New device 1
D (11635) cdc_acm: New device connected
D (11645) cdc_acm: Checking list of connected USB devices
W (11645) cdc_acm: num_of_devices: 1
W (11655) cdc_acm: entering ::usb_host_device_open()...
W (11655) USB HOST: dev_addr: 0001
E (11665) cdc_acm: cdc_acm_host_open(772): Could not find required interface
assert failed: cdc_acm_host_desc_print cdc_acm_host.c:959 (cdc_hdl)
Backtrace: 0x4037584a:0x3fc98e70 0x40379c79:0x3fc98e90 0x40380195:0x3fc98eb0 0x42009e5d:0x3fc98fd0 0x42008a8d:0x3fc99000 0x42025163:0x3fc99060 0x4037c545:0x3fc99090
0x4037584a: panic_abort at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/panic.c:452
0x40379c79: esp_system_abort at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/port/esp_system_chip.c:84
0x40380195: __assert_func at C:/Espressif/frameworks/esp-idf-v5.1/components/newlib/assert.c:81
0x42009e5d: cdc_acm_host_desc_print at P:/projects/io/airkey/dev/simple_cmux_client/managed_components/espressif__usb_host_cdc_acm/cdc_acm_host.c:959 (discriminator 1)
0x42008a8d: app_main at P:/projects/io/airkey/dev/simple_cmux_client/main/usb_cdc_example_main.c:221
0x42025163: main_task at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/app_startup.c:208 (discriminator 13)
0x4037c545: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162