Skip to content

Commit f9d5802

Browse files
Merge branch 'fix/usb_non_periodic' into 'master'
fix(usb/host): Set SCHED_INFO for all channels Closes IDF-12035 See merge request espressif/esp-idf!36724
2 parents 5a0e161 + e80a84c commit f9d5802

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

components/hal/esp32p4/include/hal/usb_dwc_ll.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -764,6 +764,23 @@ static inline void usb_dwc_ll_hcintmsk_set_intr_mask(volatile usb_dwc_host_chan_
764764

765765
// ---------------------------- HCTSIZi Register -------------------------------
766766

767+
static inline void usb_dwc_ll_hctsiz_init(volatile usb_dwc_host_chan_regs_t *chan)
768+
{
769+
usb_dwc_hctsiz_reg_t hctsiz;
770+
hctsiz.val = chan->hctsiz_reg.val;
771+
hctsiz.dopng = 0; // Don't do ping
772+
hctsiz.pid = 0; // Set PID to DATA0
773+
/*
774+
* Set SCHED_INFO which occupies xfersize[7:0]
775+
*
776+
* Although the hardware documentation suggests that SCHED_INFO is only used for periodic channels,
777+
* empirical evidence shows that omitting this configuration on non-periodic channels can cause them to freeze.
778+
* Therefore, we set this field for all channels to ensure reliable operation.
779+
*/
780+
hctsiz.xfersize |= 0xFF;
781+
chan->hctsiz_reg.val = hctsiz.val;
782+
}
783+
767784
static inline void usb_dwc_ll_hctsiz_set_pid(volatile usb_dwc_host_chan_regs_t *chan, uint32_t data_pid)
768785
{
769786
if (data_pid == 0) {

components/hal/esp32s2/include/hal/usb_dwc_ll.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -763,6 +763,23 @@ static inline void usb_dwc_ll_hcintmsk_set_intr_mask(volatile usb_dwc_host_chan_
763763

764764
// ---------------------------- HCTSIZi Register -------------------------------
765765

766+
static inline void usb_dwc_ll_hctsiz_init(volatile usb_dwc_host_chan_regs_t *chan)
767+
{
768+
usb_dwc_hctsiz_reg_t hctsiz;
769+
hctsiz.val = chan->hctsiz_reg.val;
770+
hctsiz.dopng = 0; // Don't do ping
771+
hctsiz.pid = 0; // Set PID to DATA0
772+
/*
773+
* Set SCHED_INFO which occupies xfersize[7:0]
774+
*
775+
* Although the hardware documentation suggests that SCHED_INFO is only used for periodic channels,
776+
* empirical evidence shows that omitting this configuration on non-periodic channels can cause them to freeze.
777+
* Therefore, we set this field for all channels to ensure reliable operation.
778+
*/
779+
hctsiz.xfersize |= 0xFF;
780+
chan->hctsiz_reg.val = hctsiz.val;
781+
}
782+
766783
static inline void usb_dwc_ll_hctsiz_set_pid(volatile usb_dwc_host_chan_regs_t *chan, uint32_t data_pid)
767784
{
768785
if (data_pid == 0) {

components/hal/esp32s3/include/hal/usb_dwc_ll.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -763,6 +763,23 @@ static inline void usb_dwc_ll_hcintmsk_set_intr_mask(volatile usb_dwc_host_chan_
763763

764764
// ---------------------------- HCTSIZi Register -------------------------------
765765

766+
static inline void usb_dwc_ll_hctsiz_init(volatile usb_dwc_host_chan_regs_t *chan)
767+
{
768+
usb_dwc_hctsiz_reg_t hctsiz;
769+
hctsiz.val = chan->hctsiz_reg.val;
770+
hctsiz.dopng = 0; // Don't do ping
771+
hctsiz.pid = 0; // Set PID to DATA0
772+
/*
773+
* Set SCHED_INFO which occupies xfersize[7:0]
774+
*
775+
* Although the hardware documentation suggests that SCHED_INFO is only used for periodic channels,
776+
* empirical evidence shows that omitting this configuration on non-periodic channels can cause them to freeze.
777+
* Therefore, we set this field for all channels to ensure reliable operation.
778+
*/
779+
hctsiz.xfersize |= 0xFF;
780+
chan->hctsiz_reg.val = hctsiz.val;
781+
}
782+
766783
static inline void usb_dwc_ll_hctsiz_set_pid(volatile usb_dwc_host_chan_regs_t *chan, uint32_t data_pid)
767784
{
768785
if (data_pid == 0) {

components/hal/usb_dwc_hal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -311,7 +311,7 @@ bool usb_dwc_hal_chan_alloc(usb_dwc_hal_context_t *hal, usb_dwc_hal_chan_t *chan
311311
usb_dwc_ll_hcint_read_and_clear_intrs(chan_obj->regs); //Clear the interrupt bits for that channel
312312
usb_dwc_ll_haintmsk_en_chan_intr(hal->dev, 1 << chan_obj->flags.chan_idx);
313313
usb_dwc_ll_hcintmsk_set_intr_mask(chan_obj->regs, CHAN_INTRS_EN_MSK); //Unmask interrupts for this channel
314-
usb_dwc_ll_hctsiz_set_pid(chan_obj->regs, 0); //Set the initial PID to zero
314+
usb_dwc_ll_hctsiz_init(chan_obj->regs);
315315
return true;
316316
}
317317

0 commit comments

Comments
 (0)