From a2825da3f88a11f5346f17aa8793f8c155a5f692 Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sat, 11 Nov 2023 12:08:31 +0000 Subject: [PATCH 01/13] Fix USB Host issues --- src/USBHost/dbg.h | 2 +- src/targets/TARGET_STM/USBEndpoint_STM.cpp | 5 + src/targets/TARGET_STM/USBHALHost_STM.cpp | 132 ++++++++++++++++++++- 3 files changed, 136 insertions(+), 3 deletions(-) diff --git a/src/USBHost/dbg.h b/src/USBHost/dbg.h index dd15be7..fbfce5d 100644 --- a/src/USBHost/dbg.h +++ b/src/USBHost/dbg.h @@ -18,7 +18,7 @@ #define USB_DEBUG_H //Debug is disabled by default -#define DEBUG 0 /*INFO,ERR,WARN*/ +#define DEBUG 4 /*INFO,ERR,WARN*/ #define DEBUG_TRANSFER 0 #define DEBUG_EP_STATE 0 #define DEBUG_EVENT 0 diff --git a/src/targets/TARGET_STM/USBEndpoint_STM.cpp b/src/targets/TARGET_STM/USBEndpoint_STM.cpp index 3a6d880..47b00ee 100644 --- a/src/targets/TARGET_STM/USBEndpoint_STM.cpp +++ b/src/targets/TARGET_STM/USBEndpoint_STM.cpp @@ -178,7 +178,12 @@ USB_TYPE USBEndpoint::queueTransfer() } ep_queue.get(0); MBED_ASSERT(*addr == 0); +#if ARC_USB_FULL_SIZE + transfer_len = td_current->size; +#else transfer_len = td_current->size <= max_size ? td_current->size : max_size; +#endif + buf_start = (uint8_t *)td_current->currBufPtr; //Now add this free TD at this end of the queue diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index 1439c4d..7459ca8 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -91,6 +91,98 @@ uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chnum) // - URB_NOTREADY = a NAK, NYET, or not more than a couple of repeats of some of the errors that will // become URB_ERROR if they repeat several times in a row // +#if ARC_USB_FULL_SIZE +void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *pHcd, uint8_t uChannel, HCD_URBStateTypeDef urbState) +{ + USBHALHost_Private_t *pPriv = (USBHALHost_Private_t *)(pHcd->pData); + + HCTD *pTransferDescriptor = (HCTD *)pPriv->addr[uChannel]; + + + + if (pTransferDescriptor) + { + constexpr uint32_t uRetryCount = 10; + + uint32_t endpointType = pHcd->hc[uChannel].ep_type; + + if ((endpointType == EP_TYPE_INTR)) + { + // Disable the channel interupt and retransfer below + pTransferDescriptor->state = USB_TYPE_IDLE ; + HAL_HCD_DisableInt(pHcd, uChannel); + } + else if ((endpointType == EP_TYPE_BULK) || (endpointType == EP_TYPE_CTRL)) + { + switch(urbState) + { + case URB_NOTREADY: + { + // If we have transfered any data then disable retries + if(pHcd->hc[uChannel].xfer_count > 0) + pTransferDescriptor->retry = 0xffffffff; // Disable retries + else + { + // if the retry count is 0 then initialise downward counting retry + // otherwise decrement retry count + if(pTransferDescriptor->retry == 0) + pTransferDescriptor->retry = uRetryCount; + else + pTransferDescriptor->retry--; + } + + // If our retry count has got down to 0 or we are an Ack then submit request again + if((pTransferDescriptor->retry == 0) || (pTransferDescriptor->size==0)) + { + // initialise downward counting retry + pTransferDescriptor->retry = uRetryCount; + + // resubmit the request. + HAL_HCD_HC_SubmitRequest(pHcd, uChannel, pHcd->hc[uChannel].ep_is_in, endpointType, !pTransferDescriptor->setup, (uint8_t *) pTransferDescriptor->currBufPtr, pTransferDescriptor->size, 0); + HAL_HCD_EnableInt(pHcd, uChannel); + } + } + break; + + case URB_DONE: + { + // this will be handled below for USB_TYPE_IDLE + pTransferDescriptor->state = USB_TYPE_IDLE; + } + break; + + case URB_ERROR: + { + // While USB_TYPE_ERROR in the endpoint state is used to activate error recovery, this value is actually never used. + // Going here will lead to a timeout at a higher layer, because of ep_queue.get() timeout, which will activate error + // recovery indirectly. + pTransferDescriptor->state = USB_TYPE_ERROR; + } + break; + + default: + { + pTransferDescriptor->state = USB_TYPE_PROCESSING; + } + break; + } + } + + if (pTransferDescriptor->state == USB_TYPE_IDLE) + { + // Disable retrues + pTransferDescriptor->retry = 0xffffffff; // Disable retries + + // Update transfer descriptor buffer pointer + pTransferDescriptor->currBufPtr += HAL_HCD_HC_GetXferCount(pHcd, uChannel); + + // Call transferCompleted on correct object + void (USBHALHost::*func)(volatile uint32_t addr) = pPriv->transferCompleted; + (pPriv->inst->*func)(reinterpret_cast(pTransferDescriptor)); + } + } +} +#else void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state) { USBHALHost_Private_t *priv = (USBHALHost_Private_t *)(hhcd->pData); @@ -168,6 +260,7 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, } } } +#endif USBHALHost *USBHALHost::instHost; @@ -348,6 +441,41 @@ void USBHALHost::_usbisr(void) void USBHALHost::UsbIrqhandler() { - HAL_HCD_IRQHandler((HCD_HandleTypeDef *)usb_hcca); -} +#if ARC_USB_FULL_SIZE + // fix from Lix Paulian : https://community.st.com/t5/stm32-mcus-products/stm32f4-stm32f7-usb-host-core-interrupt-flood/td-p/436225/page/4 + + // Enable USB_OTG_HCINT_NAK interupts for CTRL and BULK on USB_OTG_GINTSTS_SOF (1ms) + uint32_t ch_num; + HCD_HandleTypeDef* hhcd = (HCD_HandleTypeDef *)usb_hcca; + + if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF) && hhcd->Init.dma_enable == 0) + { + for (ch_num = 0; ch_num < hhcd->Init.Host_channels; ch_num++) + { + // workaround the interrupts flood issue: re-enable NAK interrupt + USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINT_NAK; + } + } + + HAL_HCD_IRQHandler((HCD_HandleTypeDef *)usb_hcca); + + // Disable USB_OTG_HCINT_NAK interupts for CTRL and BULK on USB_OTG_GINTSTS_HCINT + if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT) && hhcd->Init.dma_enable == 0) + { + for (ch_num = 0; ch_num < hhcd->Init.Host_channels; ch_num++) + { + if (USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NAK) + { + if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) || (hhcd->hc[ch_num].ep_type == EP_TYPE_BULK)) + { + // workaround the interrupts flood issue: disable NAK interrupt + USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINT_NAK; + } + } + } + } +#else + HAL_HCD_IRQHandler((HCD_HandleTypeDef *)usb_hcca); #endif +} +#endif \ No newline at end of file From 8ced486b3e765c9ab7c0c9f304b8e92ed8794cf6 Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sat, 11 Nov 2023 12:14:37 +0000 Subject: [PATCH 02/13] Spelling --- src/targets/TARGET_STM/USBHALHost_STM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index 7459ca8..4bc8bfc 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -118,7 +118,7 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *pHcd, uint8_t uChann { case URB_NOTREADY: { - // If we have transfered any data then disable retries + // If we have transferred any data then disable retries if(pHcd->hc[uChannel].xfer_count > 0) pTransferDescriptor->retry = 0xffffffff; // Disable retries else From 04d067dad84b7ed3a765562bb226cbe3f260874a Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sat, 11 Nov 2023 12:15:48 +0000 Subject: [PATCH 03/13] Spelling --- src/targets/TARGET_STM/USBHALHost_STM.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index 4bc8bfc..97c426b 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -108,7 +108,7 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *pHcd, uint8_t uChann if ((endpointType == EP_TYPE_INTR)) { - // Disable the channel interupt and retransfer below + // Disable the channel interrupt and retransfer below pTransferDescriptor->state = USB_TYPE_IDLE ; HAL_HCD_DisableInt(pHcd, uChannel); } @@ -444,7 +444,7 @@ void USBHALHost::UsbIrqhandler() #if ARC_USB_FULL_SIZE // fix from Lix Paulian : https://community.st.com/t5/stm32-mcus-products/stm32f4-stm32f7-usb-host-core-interrupt-flood/td-p/436225/page/4 - // Enable USB_OTG_HCINT_NAK interupts for CTRL and BULK on USB_OTG_GINTSTS_SOF (1ms) + // Enable USB_OTG_HCINT_NAK interrupts for CTRL and BULK on USB_OTG_GINTSTS_SOF (1ms) uint32_t ch_num; HCD_HandleTypeDef* hhcd = (HCD_HandleTypeDef *)usb_hcca; @@ -459,7 +459,7 @@ void USBHALHost::UsbIrqhandler() HAL_HCD_IRQHandler((HCD_HandleTypeDef *)usb_hcca); - // Disable USB_OTG_HCINT_NAK interupts for CTRL and BULK on USB_OTG_GINTSTS_HCINT + // Disable USB_OTG_HCINT_NAK interrupts for CTRL and BULK on USB_OTG_GINTSTS_HCINT if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT) && hhcd->Init.dma_enable == 0) { for (ch_num = 0; ch_num < hhcd->Init.Host_channels; ch_num++) From 88edfeddc6a79d62308df8f1bea4986ae3d58e02 Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sat, 11 Nov 2023 12:20:15 +0000 Subject: [PATCH 04/13] Spelling --- src/targets/TARGET_STM/USBHALHost_STM.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index 97c426b..69b7319 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -123,7 +123,7 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *pHcd, uint8_t uChann pTransferDescriptor->retry = 0xffffffff; // Disable retries else { - // if the retry count is 0 then initialise downward counting retry + // if the retry count is 0 then initialize downward counting retry // otherwise decrement retry count if(pTransferDescriptor->retry == 0) pTransferDescriptor->retry = uRetryCount; @@ -134,7 +134,7 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *pHcd, uint8_t uChann // If our retry count has got down to 0 or we are an Ack then submit request again if((pTransferDescriptor->retry == 0) || (pTransferDescriptor->size==0)) { - // initialise downward counting retry + // initialize downward counting retry pTransferDescriptor->retry = uRetryCount; // resubmit the request. From 864f722b1cc34c1f5ba06e1b3e07786a35ceece7 Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sun, 12 Nov 2023 11:32:02 +0000 Subject: [PATCH 05/13] Parseing midi jacks --- src/USBHost/IUSBEnumerator.h | 1 + src/USBHost/USBHost.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/USBHost/IUSBEnumerator.h b/src/USBHost/IUSBEnumerator.h index 06ea430..d807c4b 100644 --- a/src/USBHost/IUSBEnumerator.h +++ b/src/USBHost/IUSBEnumerator.h @@ -30,6 +30,7 @@ class IUSBEnumerator virtual void setVidPid(uint16_t vid, uint16_t pid) = 0; virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used + virtual void parseConfigEntry(uint8_t type, uint8_t sub_type, uint8_t *data, uint32_t len) {}; }; #endif /*IUSBENUMERATOR_H_*/ diff --git a/src/USBHost/USBHost.cpp b/src/USBHost/USBHost.cpp index c1780f8..b21d9d3 100644 --- a/src/USBHost/USBHost.cpp +++ b/src/USBHost/USBHost.cpp @@ -1066,6 +1066,8 @@ void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uin lenReportDescr = conf_descr[index + 7] | (conf_descr[index + 8] << 8); break; default: + if(parsing_intf) + pEnumerator->parseConfigEntry(id, conf_descr[index+2], &conf_descr[index+3], len_desc-3); break; } index += len_desc; From 1a82f9171012a5802a4f019014187ec3c981f7fb Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sun, 12 Nov 2023 16:10:43 +0000 Subject: [PATCH 06/13] Fix retry issue due to transfer descriptors being reused --- src/targets/TARGET_STM/USBHALHost_STM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index 69b7319..2a1a92f 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -171,7 +171,7 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *pHcd, uint8_t uChann if (pTransferDescriptor->state == USB_TYPE_IDLE) { // Disable retrues - pTransferDescriptor->retry = 0xffffffff; // Disable retries + pTransferDescriptor->retry = 0; // Update transfer descriptor buffer pointer pTransferDescriptor->currBufPtr += HAL_HCD_HC_GetXferCount(pHcd, uChannel); From 7c5d351756ea977fe0367b4bc89c7c01395f8ac2 Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sun, 19 Nov 2023 09:09:11 +0000 Subject: [PATCH 07/13] Fix Channel Halt Interupt spaming --- src/targets/TARGET_STM/USBHALHost_STM.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index 2a1a92f..4aabc40 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -439,12 +439,12 @@ void USBHALHost::_usbisr(void) } } + void USBHALHost::UsbIrqhandler() { #if ARC_USB_FULL_SIZE // fix from Lix Paulian : https://community.st.com/t5/stm32-mcus-products/stm32f4-stm32f7-usb-host-core-interrupt-flood/td-p/436225/page/4 - - // Enable USB_OTG_HCINT_NAK interrupts for CTRL and BULK on USB_OTG_GINTSTS_SOF (1ms) + // Change to also stop flooding of channel halt interrupt uint32_t ch_num; HCD_HandleTypeDef* hhcd = (HCD_HandleTypeDef *)usb_hcca; @@ -454,24 +454,33 @@ void USBHALHost::UsbIrqhandler() { // workaround the interrupts flood issue: re-enable NAK interrupt USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINT_NAK; + + // workaround the interrupts flood issue: re-enable CHH interrupt + USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINT_CHH; } } + HAL_HCD_IRQHandler((HCD_HandleTypeDef *)usb_hcca); - // Disable USB_OTG_HCINT_NAK interrupts for CTRL and BULK on USB_OTG_GINTSTS_HCINT if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT) && hhcd->Init.dma_enable == 0) { for (ch_num = 0; ch_num < hhcd->Init.Host_channels; ch_num++) { - if (USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NAK) + if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) || (hhcd->hc[ch_num].ep_type == EP_TYPE_BULK)) { - if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) || (hhcd->hc[ch_num].ep_type == EP_TYPE_BULK)) + if (USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NAK) { // workaround the interrupts flood issue: disable NAK interrupt USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINT_NAK; } - } + + if (USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_CHH) + { + // workaround the interrupts flood issue: disable CHH interrupt + USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINT_CHH; + } + } } } #else From 55fa2a6bcdd41c4d4d101c03959685b68b6fa72d Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sun, 19 Nov 2023 12:09:49 +0000 Subject: [PATCH 08/13] CHH flood fix only for CONTROL endpoints --- src/targets/TARGET_STM/USBHALHost_STM.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index 4aabc40..fc2edc3 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -456,7 +456,8 @@ void USBHALHost::UsbIrqhandler() USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINT_NAK; // workaround the interrupts flood issue: re-enable CHH interrupt - USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINT_CHH; + if(hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) + USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINT_CHH; } } @@ -467,6 +468,7 @@ void USBHALHost::UsbIrqhandler() { for (ch_num = 0; ch_num < hhcd->Init.Host_channels; ch_num++) { + LogicUint7(USBx_HC(ch_num)->HCINT); if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) || (hhcd->hc[ch_num].ep_type == EP_TYPE_BULK)) { if (USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NAK) @@ -475,7 +477,7 @@ void USBHALHost::UsbIrqhandler() USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINT_NAK; } - if (USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_CHH) + if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_CHH) && (hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL)) { // workaround the interrupts flood issue: disable CHH interrupt USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINT_CHH; From 61ccb56125a395d76fb2830cf79794f4f06d8008 Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Sun, 19 Nov 2023 12:12:35 +0000 Subject: [PATCH 09/13] CHH flood fix only for CONTROL endpoints --- src/targets/TARGET_STM/USBHALHost_STM.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/targets/TARGET_STM/USBHALHost_STM.cpp b/src/targets/TARGET_STM/USBHALHost_STM.cpp index fc2edc3..cdcc7a8 100644 --- a/src/targets/TARGET_STM/USBHALHost_STM.cpp +++ b/src/targets/TARGET_STM/USBHALHost_STM.cpp @@ -468,7 +468,6 @@ void USBHALHost::UsbIrqhandler() { for (ch_num = 0; ch_num < hhcd->Init.Host_channels; ch_num++) { - LogicUint7(USBx_HC(ch_num)->HCINT); if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) || (hhcd->hc[ch_num].ep_type == EP_TYPE_BULK)) { if (USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NAK) From faae263b1adcf5acfb63160bbff0f38a849c8c6c Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Thu, 30 Nov 2023 09:11:55 +0000 Subject: [PATCH 10/13] Enable HS hubs --- src/USBHostHub/USBHostHub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USBHostHub/USBHostHub.cpp b/src/USBHostHub/USBHostHub.cpp index 6854b6f..8b985cc 100644 --- a/src/USBHostHub/USBHostHub.cpp +++ b/src/USBHostHub/USBHostHub.cpp @@ -147,7 +147,7 @@ void USBHostHub::disconnect() if ((hub_intf == -1) && (intf_class == HUB_CLASS) && (intf_subclass == 0) && - (intf_protocol == 0)) { + ((intf_protocol == 0) || (intf_protocol == 1))) { hub_intf = intf_nb; return true; } From afa403e262e398479e6d45b7efb5c340bfba25bb Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Thu, 30 Nov 2023 09:13:42 +0000 Subject: [PATCH 11/13] Add device connected callback to USBHost. Add setEnumeratingDeviceIndex to IUSBEnumerator.h --- src/USBHost/IUSBEnumerator.h | 1 + src/USBHost/USBHost.cpp | 3 +++ src/USBHost/USBHost.h | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/src/USBHost/IUSBEnumerator.h b/src/USBHost/IUSBEnumerator.h index d807c4b..4576d29 100644 --- a/src/USBHost/IUSBEnumerator.h +++ b/src/USBHost/IUSBEnumerator.h @@ -31,6 +31,7 @@ class IUSBEnumerator virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used virtual void parseConfigEntry(uint8_t type, uint8_t sub_type, uint8_t *data, uint32_t len) {}; + virtual void setEnumeratingDeviceIndex(int index) {}; }; #endif /*IUSBENUMERATOR_H_*/ diff --git a/src/USBHost/USBHost.cpp b/src/USBHost/USBHost.cpp index e0670fb..504da31 100644 --- a/src/USBHost/USBHost.cpp +++ b/src/USBHost/USBHost.cpp @@ -225,6 +225,8 @@ void USBHost::usb_process() if ((i < MAX_DEVICE_CONNECTED) && !too_many_hub) { deviceInUse[i] = true; + if(device_connected_callback) + device_connected_callback(i); } } while(0); @@ -960,6 +962,7 @@ USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerato dev->setPid(data[10] | (data[11] << 8)); USB_DBG("CLASS: %02X \t VID: %04X \t PID: %04X", data[4], data[8] | (data[9] << 8), data[10] | (data[11] << 8)); + pEnumerator->setEnumeratingDeviceIndex(index); pEnumerator->setVidPid( data[8] | (data[9] << 8), data[10] | (data[11] << 8) ); res = getConfigurationDescriptor(dev, data, sizeof(data), &total_conf_descr_length); diff --git a/src/USBHost/USBHost.h b/src/USBHost/USBHost.h index 4a156fd..1536782 100644 --- a/src/USBHost/USBHost.h +++ b/src/USBHost/USBHost.h @@ -189,6 +189,15 @@ class USBHost : public USBHALHost { } } + + /** + * Callback for connected device index + */ + void setDeviceConnectedCallback(mbed::Callback callback) + { + device_connected_callback = callback; + } + /** * Instantiate to protect USB thread from accessing shared objects (USBConnectedDevices and Interfaces) */ @@ -287,6 +296,8 @@ class USBHost : public USBHALHost { // buffer for conf descriptor uint8_t data[415]; + mbed::Callback device_connected_callback = nullptr; + /** * Add a transfer on the TD linked list associated to an ED * From d786913f8f3365309e51d9fadeba2c73fcf5ef8c Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Thu, 30 Nov 2023 09:26:24 +0000 Subject: [PATCH 12/13] Enable ARC_USB_FULL_SIZE --- src/USBHost/USBHostConf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/USBHost/USBHostConf.h b/src/USBHost/USBHostConf.h index 7145219..b442a97 100644 --- a/src/USBHost/USBHostConf.h +++ b/src/USBHost/USBHostConf.h @@ -17,6 +17,8 @@ #ifndef USBHOST_CONF_H #define USBHOST_CONF_H +#define ARC_USB_FULL_SIZE=1 + #include "mbed_config.h" #include "Callback.h" #include "Arduino.h" From dba021ead84237d43a38c857b95ed9491c0cf9f8 Mon Sep 17 00:00:00 2001 From: AndrewCapon Date: Thu, 30 Nov 2023 10:35:05 +0000 Subject: [PATCH 13/13] Fix define error! --- src/USBHost/USBHostConf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USBHost/USBHostConf.h b/src/USBHost/USBHostConf.h index b442a97..17c830d 100644 --- a/src/USBHost/USBHostConf.h +++ b/src/USBHost/USBHostConf.h @@ -17,7 +17,7 @@ #ifndef USBHOST_CONF_H #define USBHOST_CONF_H -#define ARC_USB_FULL_SIZE=1 +#define ARC_USB_FULL_SIZE (1) #include "mbed_config.h" #include "Callback.h"