From dfd8098716f0b628ac45a02de367eb41c49debe4 Mon Sep 17 00:00:00 2001 From: "igor.masar" Date: Thu, 20 Feb 2025 13:41:34 +0100 Subject: [PATCH] fix(usb/hal/dwc): Correct host channel number calculation The hardware field `ghwcfg2.numhstchnl` is zero-based, meaning the actual number of available host channels is `numhstchnl + 1`. This off-by-one error caused the USB Host controller to report N-1 channels instead of N, leading to premature "No more HCD channels available" errors when connecting multiple devices. This issue affects ESP32-S2, ESP32-S3, and ESP32-P4. --- components/hal/esp32p4/include/hal/usb_dwc_ll.h | 2 +- components/hal/esp32s2/include/hal/usb_dwc_ll.h | 2 +- components/hal/esp32s3/include/hal/usb_dwc_ll.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/hal/esp32p4/include/hal/usb_dwc_ll.h b/components/hal/esp32p4/include/hal/usb_dwc_ll.h index 3afb678e78..3788f147f0 100644 --- a/components/hal/esp32p4/include/hal/usb_dwc_ll.h +++ b/components/hal/esp32p4/include/hal/usb_dwc_ll.h @@ -362,7 +362,7 @@ static inline unsigned usb_dwc_ll_ghwcfg_get_hsphy_type(usb_dwc_dev_t *hw) static inline unsigned usb_dwc_ll_ghwcfg_get_channel_num(usb_dwc_dev_t *hw) { - return hw->ghwcfg2_reg.numhstchnl; + return hw->ghwcfg2_reg.numhstchnl + 1; } // --------------------------- HPTXFSIZ Register ------------------------------- diff --git a/components/hal/esp32s2/include/hal/usb_dwc_ll.h b/components/hal/esp32s2/include/hal/usb_dwc_ll.h index 1497edd2ff..27859e5ef7 100644 --- a/components/hal/esp32s2/include/hal/usb_dwc_ll.h +++ b/components/hal/esp32s2/include/hal/usb_dwc_ll.h @@ -361,7 +361,7 @@ static inline unsigned usb_dwc_ll_ghwcfg_get_hsphy_type(usb_dwc_dev_t *hw) static inline unsigned usb_dwc_ll_ghwcfg_get_channel_num(usb_dwc_dev_t *hw) { - return hw->ghwcfg2_reg.numhstchnl; + return hw->ghwcfg2_reg.numhstchnl + 1; } // --------------------------- HPTXFSIZ Register ------------------------------- diff --git a/components/hal/esp32s3/include/hal/usb_dwc_ll.h b/components/hal/esp32s3/include/hal/usb_dwc_ll.h index 75ffe37665..fc5edff0bd 100644 --- a/components/hal/esp32s3/include/hal/usb_dwc_ll.h +++ b/components/hal/esp32s3/include/hal/usb_dwc_ll.h @@ -361,7 +361,7 @@ static inline unsigned usb_dwc_ll_ghwcfg_get_hsphy_type(usb_dwc_dev_t *hw) static inline unsigned usb_dwc_ll_ghwcfg_get_channel_num(usb_dwc_dev_t *hw) { - return hw->ghwcfg2_reg.numhstchnl; + return hw->ghwcfg2_reg.numhstchnl + 1; } // --------------------------- HPTXFSIZ Register -------------------------------