Skip to content

Commit 8916c9d

Browse files
committed
feat(usbh_modem): support deinit function
1 parent aed8369 commit 8916c9d

File tree

18 files changed

+204
-27
lines changed

18 files changed

+204
-27
lines changed

.gitlab/ci/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,17 @@ build_components_usb_iot_usbh_cdc_test_apps:
16091609
variables:
16101610
EXAMPLE_DIR: components/usb/iot_usbh_cdc/test_apps
16111611

1612+
build_components_usb_iot_usbh_modem_test_apps:
1613+
extends:
1614+
- .build_examples_template
1615+
- .rules:build:components_usb_iot_usbh_modem_test
1616+
parallel:
1617+
matrix:
1618+
- IMAGE: espressif/idf:release-v4.4
1619+
- IMAGE: espressif/idf:release-v5.3
1620+
variables:
1621+
EXAMPLE_DIR: components/usb/iot_usbh_modem/test_apps
1622+
16121623
build_components_usb_usb_device_uac:
16131624
extends:
16141625
- .build_examples_template

.gitlab/ci/rules.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,21 @@
24572457
- <<: *if-dev-push
24582458
changes: *patterns-components_usb_iot_usbh_cdc
24592459

2460+
.rules:build:components_usb_iot_usbh_modem_test:
2461+
rules:
2462+
- <<: *if-protected
2463+
- <<: *if-label-build
2464+
- <<: *if-label-target_test
2465+
- <<: *if-trigger-job
2466+
- <<: *if-dev-push
2467+
changes: *patterns-build_system
2468+
- <<: *if-dev-push
2469+
changes: *patterns-components_usb_iot_usbh
2470+
- <<: *if-dev-push
2471+
changes: *patterns-components_usb_iot_usbh_cdc
2472+
- <<: *if-dev-push
2473+
changes: *patterns-components_usb_iot_usbh_modem
2474+
24602475
.rules:build:components_usb_usb_stream_test:
24612476
rules:
24622477
- <<: *if-protected

components/.build-rules.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ components/usb/iot_usbh/test_apps:
3939

4040
components/usb/iot_usbh_cdc/test_apps:
4141
enable:
42-
- if: IDF_TARGET in ["esp32s2","esp32s3"]
42+
- if: IDF_TARGET in ["esp32s2","esp32s3","esp32p4"]
43+
44+
components/usb/iot_usbh_modem/test_apps:
45+
enable:
46+
- if: IDF_TARGET in ["esp32s2","esp32s3","esp32p4"]
4347

4448
components/i2c_bus/test_apps:
4549
enable:

components/usb/iot_usbh_cdc/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## v1.0.4 - 2025-4-1
4+
5+
### Bug Fixes:
6+
7+
* Fix USB host interface release when URB is not cleared.
8+
39
## v1.0.3 - 2025-3-27
410

511
### Bug Fixes:

components/usb/iot_usbh_cdc/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.0.3"
1+
version: "1.0.4"
22
targets:
33
- esp32s2
44
- esp32s3

components/usb/iot_usbh_cdc/iot_usbh_cdc.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static size_t _get_ringbuf_len(RingbufHandle_t ringbuf_hdl)
8686

8787
static esp_err_t _ringbuf_pop(RingbufHandle_t ringbuf_hdl, uint8_t *buf, size_t req_bytes, size_t *read_bytes, TickType_t ticks_to_wait)
8888
{
89-
uint8_t *buf_rcv = xRingbufferReceiveUpTo(ringbuf_hdl, read_bytes, pdMS_TO_TICKS(1000), req_bytes);
89+
uint8_t *buf_rcv = xRingbufferReceiveUpTo(ringbuf_hdl, read_bytes, ticks_to_wait, req_bytes);
9090
if (!buf_rcv) {
9191
return ESP_FAIL;
9292
}
@@ -524,7 +524,6 @@ static esp_err_t _cdc_reset_transfer_endpoint(usb_device_handle_t dev_hdl, usb_t
524524
{
525525
assert(dev_hdl);
526526
assert(transfer);
527-
528527
ESP_RETURN_ON_ERROR(usb_host_endpoint_halt(dev_hdl, transfer->bEndpointAddress), TAG,);
529528
ESP_RETURN_ON_ERROR(usb_host_endpoint_flush(dev_hdl, transfer->bEndpointAddress), TAG,);
530529
usb_host_endpoint_clear(dev_hdl, transfer->bEndpointAddress);
@@ -652,17 +651,24 @@ static esp_err_t _cdc_close(usbh_cdc_t *cdc)
652651
return ESP_ERR_INVALID_STATE;
653652
}
654653

654+
cdc->state = USBH_CDC_CLOSE;
655+
655656
// Cancel polling of BULK IN
656657
if (cdc->data.in_xfer) {
657658
ESP_ERROR_CHECK(_cdc_reset_transfer_endpoint(cdc->dev_hdl, cdc->data.in_xfer));
658659
}
659660

661+
if (cdc->data.out_xfer) {
662+
ESP_ERROR_CHECK(_cdc_reset_transfer_endpoint(cdc->dev_hdl, cdc->data.out_xfer));
663+
}
664+
665+
// wait for transfers to complete
666+
vTaskDelay(10 / portTICK_PERIOD_MS);
660667
// Release all interfaces
661-
ESP_ERROR_CHECK(usb_host_interface_release(p_usbh_cdc_obj->cdc_client_hdl, cdc->dev_hdl, cdc->data.intf_desc->bInterfaceNumber));
668+
ESP_ERROR_CHECK(usb_host_interface_release(p_usbh_cdc_obj->cdc_client_hdl, cdc->dev_hdl, cdc->intf_idx));
662669

663670
_cdc_transfers_free(cdc);
664671
usb_host_device_close(p_usbh_cdc_obj->cdc_client_hdl, cdc->dev_hdl);
665-
cdc->state = USBH_CDC_CLOSE;
666672

667673
_ring_buffer_flush(cdc->in_ringbuf_handle);
668674
_ring_buffer_flush(cdc->out_ringbuf_handle);
@@ -802,7 +808,7 @@ esp_err_t usbh_cdc_read_bytes(usbh_cdc_handle_t cdc_handle, const uint8_t *buf,
802808

803809
ret = _ringbuf_pop(cdc->in_ringbuf_handle, (uint8_t *)buf, data_len, length, ticks_to_wait);
804810
if (ret != ESP_OK) {
805-
ESP_LOGI(TAG, "cdc read failed");
811+
ESP_LOGE(TAG, "cdc read failed");
806812
*length = 0;
807813
return ret;
808814
}

components/usb/iot_usbh_modem/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog
22

3+
## v1.1.5 - 2024-4-1
4+
5+
* Support `modem_board_deinit()`.
6+
37
## v1.1.4 - 2024-3-20
48

59
* Support 4g module `YM310_X09`

components/usb/iot_usbh_modem/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.1.4"
1+
version: "1.1.5"
22
targets:
33
- esp32s2
44
- esp32s3

components/usb/iot_usbh_modem/include/usbh_modem_board.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -61,6 +61,15 @@ typedef struct {
6161
*/
6262
esp_err_t modem_board_init(modem_config_t *config);
6363

64+
/**
65+
* @brief Deinit all about the modem object
66+
*
67+
* @return
68+
* - ESP_ERR_INVALID_STATE
69+
* - ESP_OK
70+
*/
71+
esp_err_t modem_board_deinit(void);
72+
6473
/**
6574
* @brief Get the DNS information of modem ppp interface
6675
*

components/usb/iot_usbh_modem/private_include/esp_modem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ esp_err_t esp_modem_set_event_handler(esp_modem_dte_t *dte, esp_event_handler_t
224224
*
225225
* @param dte modem_dte_t type object
226226
* @param handler event handler to unregister
227+
* @param event_id event id to unregister
227228
* @return esp_err_t
228229
* - ESP_OK on success
229230
* - ESP_ERR_INVALID_ARG on invalid combination of event base and event id
230231
*/
231-
esp_err_t esp_modem_remove_event_handler(esp_modem_dte_t *dte, esp_event_handler_t handler);
232+
esp_err_t esp_modem_remove_event_handler(esp_modem_dte_t *dte, esp_event_handler_t handler, int32_t event_id);
232233

233234
esp_err_t esp_modem_post_event(esp_modem_dte_t *dte, int32_t event_id, void* event_data, size_t event_data_size, TickType_t ticks_to_wait);
234235

0 commit comments

Comments
 (0)