Skip to content

in usb_rndis_4g_module sample, how to deinit? (AEGHB-1228) #582

@aiotfactory

Description

@aiotfactory

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

5.4.2

Espressif SoC revision.

esp32s3

Operating System used.

Windows

How did you build your project?

Command line with Make

If you are using Windows, please specify command line type.

None

Development Kit.

customized board

Power Supply used.

USB

What is the expected behavior?

The code below is from an example, but it lacks the deinit (cleanup) part. I've tried implementing deinit myself, but the system always crashes. Please provide code that safely deinitializes the USB functionality.

/* Initialize default TCP/IP stack */
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());

esp_event_handler_register(IOT_ETH_EVENT, ESP_EVENT_ANY_ID, iot_event_handle, NULL);

// install usbh cdc driver
usbh_cdc_driver_config_t config = {
    .task_stack_size = 1024 * 4,
    .task_priority = 5,
    .task_coreid = 0,
    .skip_init_usb_host_driver = false,
};
ESP_ERROR_CHECK(usbh_cdc_driver_install(&config));

iot_usbh_rndis_config_t rndis_cfg = {
    .auto_detect = true,
    .auto_detect_timeout = pdMS_TO_TICKS(1000),
};

iot_eth_driver_t *rndis_handle = NULL;
esp_err_t ret = iot_eth_new_usb_rndis(&rndis_cfg, &rndis_handle);
if (ret != ESP_OK || rndis_handle == NULL) {
    ESP_LOGE(TAG, "Failed to create USB RNDIS driver");
    return;
}

iot_eth_config_t eth_cfg = {
    .driver = rndis_handle,
    .stack_input = NULL,
    .user_data = NULL,
};

iot_eth_handle_t eth_handle = NULL;
ret = iot_eth_install(&eth_cfg, &eth_handle);
if (ret != ESP_OK) {
    ESP_LOGE(TAG, "Failed to install USB RNDIS driver");
    return;
}

esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH();
esp_netif_t *eth_netif = esp_netif_new(&netif_cfg);

iot_eth_netif_glue_handle_t glue = iot_eth_new_netif_glue(eth_handle);
if (glue == NULL) {
    ESP_LOGE(TAG, "Failed to create netif glue");
    return;
}
esp_netif_attach(eth_netif, glue);

while (1) {
    ret = iot_eth_start(eth_handle);
    if (ret != ESP_OK) {
        ESP_LOGW(TAG, "Failed to start USB RNDIS driver, try again...");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        continue;
    }
    break;
}

What is the actual behavior?

as above

Steps to reproduce.

  1. Step
  2. Step
  3. Step
    ...

Debug Logs.


More Information.

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions