From a2f0488a9e616592b076c1ad16589e20828a0e96 Mon Sep 17 00:00:00 2001 From: ThomasKuehne <2562574+ThomasKuehne@users.noreply.github.com> Date: Sun, 19 May 2024 09:06:13 +0000 Subject: [PATCH] chore(radio): stm32_mw_usb_device v2.11.2 catchup (#4757) --- .../common/arm/stm32/usbd_hid_joystick.c | 16 +-- .../Inc/usbd_composite_builder.h | 18 ++-- .../Src/usbd_composite_builder.c | 39 +++---- .../Class/CustomHID/Inc/usbd_customhid.h | 13 ++- .../Class/CustomHID/Src/usbd_customhid.c | 100 ++++++++++++++---- .../Src/usbd_customhid_if_template.c | 61 +++++++++++ .../Class/HID/Inc/usbd_hid.h | 24 +++-- .../Class/HID/Src/usbd_hid.c | 30 ++++-- .../Class/MSC/Inc/usbd_msc_data.h | 4 +- .../Class/MSC/Inc/usbd_msc_scsi.h | 2 +- .../Class/MSC/Src/usbd_msc.c | 12 +-- .../Class/MSC/Src/usbd_msc_bot.c | 28 ++--- .../Class/MSC/Src/usbd_msc_data.c | 72 ++++--------- .../Class/MSC/Src/usbd_msc_scsi.c | 31 ++++-- .../Core/Inc/usbd_core.h | 5 +- .../Core/Inc/usbd_def.h | 11 +- .../Core/Src/usbd_core.c | 58 +++++----- .../Core/Src/usbd_ctlreq.c | 19 ++-- 18 files changed, 341 insertions(+), 202 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index 64300d157..c7c77b5a6 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -312,7 +312,7 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) (void)USBD_LL_OpenEP(pdev, HIDInEpAdd, USBD_EP_TYPE_INTR, hid_in_pkt_size); pdev->ep_in[HIDInEpAdd & 0xFU].is_used = 1U; - hhid->state = HID_IDLE; + hhid->state = USBD_HID_IDLE; return (uint8_t)USBD_OK; } @@ -373,19 +373,19 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re case USB_REQ_TYPE_CLASS : switch (req->bRequest) { - case HID_REQ_SET_PROTOCOL: + case USBD_HID_REQ_SET_PROTOCOL: hhid->Protocol = (uint8_t)(req->wValue); break; - case HID_REQ_GET_PROTOCOL: + case USBD_HID_REQ_GET_PROTOCOL: (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U); break; - case HID_REQ_SET_IDLE: + case USBD_HID_REQ_SET_IDLE: hhid->IdleState = (uint8_t)(req->wValue >> 8); break; - case HID_REQ_GET_IDLE: + case USBD_HID_REQ_GET_IDLE: (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U); break; @@ -507,9 +507,9 @@ uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t if (pdev->dev_state == USBD_STATE_CONFIGURED) { - if (hhid->state == HID_IDLE) + if (hhid->state == USBD_HID_IDLE) { - hhid->state = HID_BUSY; + hhid->state = USBD_HID_BUSY; (void)USBD_LL_Transmit(pdev, HIDInEpAdd, report, len); } else { return (uint8_t)USBD_BUSY; @@ -625,7 +625,7 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) UNUSED(epnum); /* Ensure that the FIFO is empty before a new transfer, this condition could be caused by a new transfer before the end of the previous transfer */ - ((USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = HID_IDLE; + ((USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = USBD_HID_IDLE; return (uint8_t)USBD_OK; } diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Inc/usbd_composite_builder.h b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Inc/usbd_composite_builder.h index 6d6175571..3a8aac3f9 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Inc/usbd_composite_builder.h +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Inc/usbd_composite_builder.h @@ -172,10 +172,10 @@ typedef struct #if (USBD_CMPSIT_ACTIVATE_CDC == 1) || (USBD_CMPSIT_ACTIVATE_RNDIS == 1) || (USBD_CMPSIT_ACTIVATE_CDC_ECM == 1) typedef struct { -/* - * CDC Class specification revision 1.2 - * Table 15: Class-Specific Descriptor Header Format - */ + /* + * CDC Class specification revision 1.2 + * Table 15: Class-Specific Descriptor Header Format + */ /* Header Functional Descriptor */ uint8_t bLength; uint8_t bDescriptorType; @@ -204,10 +204,10 @@ typedef struct typedef struct { -/* - * CDC Class specification revision 1.2 - * Table 16: Union Interface Functional Descriptor - */ + /* + * CDC Class specification revision 1.2 + * Table 16: Union Interface Functional Descriptor + */ /* Union Functional Descriptor */ uint8_t bLength; uint8_t bDescriptorType; @@ -249,7 +249,7 @@ uint8_t USBD_CMPST_ClearConfDesc(USBD_HandleTypeDef *pdev); pEpDesc->bDescriptorType = USB_DESC_TYPE_ENDPOINT; \ pEpDesc->bEndpointAddress = (epadd); \ pEpDesc->bmAttributes = (eptype); \ - pEpDesc->wMaxPacketSize = (epsize); \ + pEpDesc->wMaxPacketSize = (uint16_t)(epsize); \ if(speed == (uint8_t)USBD_SPEED_HIGH) \ { \ pEpDesc->bInterval = HSinterval; \ diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Src/usbd_composite_builder.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Src/usbd_composite_builder.c index 76ce567fd..e14c5cd81 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Src/usbd_composite_builder.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CompositeBuilder/Src/usbd_composite_builder.c @@ -844,7 +844,7 @@ static void USBD_CMPSIT_HIDMouseDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 1U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_HID == 1 */ @@ -881,7 +881,7 @@ static void USBD_CMPSIT_MSCDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __IO /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 1U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_MSC == 1 */ @@ -979,7 +979,7 @@ static void USBD_CMPSIT_CDCDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __IO /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 2U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_CDC == 1 */ @@ -1018,7 +1018,7 @@ static void USBD_CMPSIT_DFUDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __IO /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 1U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); UNUSED(idx); } @@ -1113,7 +1113,7 @@ static void USBD_CMPSIT_CDC_ECMDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, _ /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 2U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_CDC_ECM */ @@ -1249,7 +1249,7 @@ static void USBD_CMPSIT_AUDIODesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __I pSpEpDesc->bDescriptorType = USB_DESC_TYPE_ENDPOINT; pSpEpDesc->bEndpointAddress = pdev->tclasslist[pdev->classId].Eps[0].add; pSpEpDesc->bmAttributes = USBD_EP_TYPE_ISOC; - pSpEpDesc->wMaxPacketSize = USBD_AUDIO_GetEpPcktSze(pdev, 0U, 0U); + pSpEpDesc->wMaxPacketSize = (uint16_t)USBD_AUDIO_GetEpPcktSze(pdev, 0U, 0U); pSpEpDesc->bInterval = 0x01U; pSpEpDesc->bRefresh = 0x00U; pSpEpDesc->bSynchAddress = 0x00U; @@ -1267,7 +1267,7 @@ static void USBD_CMPSIT_AUDIODesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __I /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 2U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_AUDIO */ @@ -1363,7 +1363,7 @@ static void USBD_CMPSIT_RNDISDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __I /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 2U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_RNDIS == 1 */ @@ -1407,7 +1407,7 @@ static void USBD_CMPSIT_CUSTOMHIDDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 1U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_CUSTOMHID == 1U */ @@ -1585,8 +1585,7 @@ static void USBD_CMPSIT_VIDEODesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __I /* USB Standard VS Interface Descriptor - data transfer mode */ /* Interface 1, Alternate Setting 1*/ - __USBD_CMPSIT_SET_IF(1U, 1U, 1U, UVC_CC_VIDEO, \ - SC_VIDEOSTREAMING, PC_PROTOCOL_UNDEFINED, 0U); + __USBD_CMPSIT_SET_IF(1U, 1U, 1U, UVC_CC_VIDEO, SC_VIDEOSTREAMING, PC_PROTOCOL_UNDEFINED, 0U); /* Standard VS (Video Streaming) data Endpoint */ pSVCDEP = ((USBD_StandardVCDataEPDescTypeDef *)(pConf + *Sze)); @@ -1609,7 +1608,7 @@ static void USBD_CMPSIT_VIDEODesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __I /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 2U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_VIDEO == 1 */ @@ -1645,7 +1644,7 @@ static void USBD_CMPSIT_PRNTDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __IO /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 1U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_PRINTER == 1 */ @@ -1715,7 +1714,7 @@ static void USBD_CMPSIT_CCIDDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __IO /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 1U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_CCID == 1 */ @@ -1735,8 +1734,8 @@ static void USBD_CMPSIT_MTPDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __IO /* Append MTP Interface descriptor */ __USBD_CMPSIT_SET_IF((pdev->tclasslist[pdev->classId].Ifs[0]), (0U), \ - (uint8_t)(pdev->tclasslist[pdev->classId].NumEps), USB_MTP_INTRERFACE_CLASS, USB_MTP_INTRERFACE_SUB_CLASS, - USB_MTP_INTRERFACE_PROTOCOL, (0U)); + (uint8_t)(pdev->tclasslist[pdev->classId].NumEps), USB_MTP_INTRERFACE_CLASS, \ + USB_MTP_INTRERFACE_SUB_CLASS, USB_MTP_INTRERFACE_PROTOCOL, (0U)); if (speed == (uint8_t)USBD_SPEED_HIGH) { @@ -1757,7 +1756,7 @@ static void USBD_CMPSIT_MTPDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, __IO /* Update Config Descriptor and IAD descriptor */ ((USBD_ConfigDescTypeDef *)pConf)->bNumInterfaces += 1U; - ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = *Sze; + ((USBD_ConfigDescTypeDef *)pConf)->wTotalLength = (uint16_t)(*Sze); } #endif /* USBD_CMPSIT_ACTIVATE_MTP == 1 */ @@ -1778,7 +1777,8 @@ uint32_t USBD_CMPSIT_SetClassID(USBD_HandleTypeDef *pdev, USBD_CompositeClassTy for (idx = 0U; idx < pdev->NumClasses; idx++) { /* Check if the class correspond to the requested type and if it is active */ - if (((USBD_CompositeClassTypeDef)(pdev->tclasslist[idx].ClassType) == Class) && ((pdev->tclasslist[idx].Active) == 1U)) + if (((USBD_CompositeClassTypeDef)(pdev->tclasslist[idx].ClassType) == Class) && + ((pdev->tclasslist[idx].Active) == 1U)) { if (inst == Instance) { @@ -1817,7 +1817,8 @@ uint32_t USBD_CMPSIT_GetClassID(USBD_HandleTypeDef *pdev, USBD_CompositeClassTy for (idx = 0U; idx < pdev->NumClasses; idx++) { /* Check if the class correspond to the requested type and if it is active */ - if (((USBD_CompositeClassTypeDef)(pdev->tclasslist[idx].ClassType) == Class) && ((pdev->tclasslist[idx].Active) == 1U)) + if (((USBD_CompositeClassTypeDef)(pdev->tclasslist[idx].ClassType) == Class) && + ((pdev->tclasslist[idx].Active) == 1U)) { if (inst == Instance) { diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h index d5e599ead..2f4c6344f 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h @@ -106,7 +106,12 @@ typedef struct _USBD_CUSTOM_HID_Itf int8_t (* Init)(void); int8_t (* DeInit)(void); int8_t (* OutEvent)(uint8_t event_idx, uint8_t state); - +#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED + int8_t (* CtrlReqComplete)(uint8_t request, uint16_t wLength); +#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ +#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED + uint8_t *(* GetReport)(uint16_t *ReportLength); +#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ } USBD_CUSTOM_HID_ItfTypeDef; typedef struct @@ -162,9 +167,13 @@ extern USBD_ClassTypeDef USBD_CUSTOM_HID; /** @defgroup USB_CORE_Exported_Functions * @{ */ +#ifdef USE_USBD_COMPOSITE +uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, + uint8_t *report, uint16_t len, uint8_t ClassId); +#else uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len); - +#endif /* USE_USBD_COMPOSITE */ uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev); uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev, diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c index b6cdc3727..8207618a1 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c @@ -136,8 +136,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_ { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ - 0x00, + LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */ + HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor @@ -170,8 +170,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_ 0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */ 0x22, /* bDescriptorType */ - USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */ - 0x00, + LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */ + HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /******************** Descriptor of Custom HID endpoints ********************/ /* 27 */ 0x07, /* bLength: Endpoint Descriptor size */ @@ -179,8 +179,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_ CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */ 0x03, /* bmAttributes: Interrupt endpoint */ - CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Bytes max */ - 0x00, + LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */ + HIBYTE(CUSTOM_HID_EPIN_SIZE), CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ /* 34 */ @@ -188,8 +188,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_ USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */ 0x03, /* bmAttributes: Interrupt endpoint */ - CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ - 0x00, + LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */ + HIBYTE(CUSTOM_HID_EPOUT_SIZE), CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ /* 41 */ }; @@ -207,8 +207,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALI 0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */ 0x22, /* bDescriptorType */ - USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */ - 0x00, + LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */ + HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), }; #ifndef USE_USBD_COMPOSITE @@ -263,8 +263,8 @@ static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR); - CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR); + CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId); + CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (pdev->dev_speed == USBD_SPEED_HIGH) @@ -294,9 +294,11 @@ static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init(); +#ifndef USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED /* Prepare Out endpoint to receive 1st packet */ (void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); +#endif /* USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED */ return (uint8_t)USBD_OK; } @@ -314,8 +316,8 @@ static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR); - CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR); + CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId); + CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ /* Close CUSTOM_HID EP IN */ @@ -352,6 +354,9 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, { USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint16_t len = 0U; +#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED + uint16_t ReportLength = 0U; +#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ uint8_t *pbuf = NULL; uint16_t status_info = 0U; USBD_StatusTypeDef ret = USBD_OK; @@ -383,10 +388,59 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, break; case CUSTOM_HID_REQ_SET_REPORT: +#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED + if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL) + { + /* Let the application decide when to enable EP0 to receive the next report */ + ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest, + req->wLength); + } +#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ +#ifndef USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED hhid->IsReportAvailable = 1U; (void)USBD_CtlPrepareRx(pdev, hhid->Report_buf, MIN(req->wLength, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE)); +#endif /* USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED */ break; +#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED + case CUSTOM_HID_REQ_GET_REPORT: + if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport != NULL) + { + ReportLength = req->wLength; + + /* Get report data buffer */ + pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport(&ReportLength); + } + + if ((pbuf != NULL) && (ReportLength != 0U)) + { + len = MIN(ReportLength, req->wLength); + + /* Send the report data over EP0 */ + (void)USBD_CtlSendData(pdev, pbuf, len); + } + else + { +#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED + if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL) + { + /* Let the application decide what to do, keep EP0 data phase in NAK state and + use USBD_CtlSendData() when data become available or stall the EP0 data phase */ + ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest, + req->wLength); + } + else + { + /* Stall EP0 if no data available */ + USBD_CtlError(pdev, req); + } +#else + /* Stall EP0 if no data available */ + USBD_CtlError(pdev, req); +#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ + } + break; +#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ default: USBD_CtlError(pdev, req); @@ -475,25 +529,31 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, * Send CUSTOM_HID Report * @param pdev: device instance * @param buff: pointer to report + * @param ClassId: The Class ID * @retval status */ +#ifdef USE_USBD_COMPOSITE +uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, + uint8_t *report, uint16_t len, uint8_t ClassId) +{ + USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[ClassId]; +#else uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len) { - USBD_CUSTOM_HID_HandleTypeDef *hhid; + USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; +#endif /* USE_USBD_COMPOSITE */ - if (pdev->pClassDataCmsit[pdev->classId] == NULL) + if (hhid == NULL) { return (uint8_t)USBD_FAIL; } #ifdef USE_USBD_COMPOSITE /* Get Endpoint IN address allocated for this class instance */ - CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR); + CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, ClassId); #endif /* USE_USBD_COMPOSITE */ - hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - if (pdev->dev_state == USBD_STATE_CONFIGURED) { if (hhid->state == CUSTOM_HID_IDLE) @@ -657,7 +717,7 @@ uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev) #ifdef USE_USBD_COMPOSITE /* Get OUT Endpoint address allocated for this class instance */ - CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR); + CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c index 1f4d15b98..85881bdc5 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c @@ -33,6 +33,14 @@ EndBSPDependencies */ static int8_t TEMPLATE_CUSTOM_HID_Init(void); static int8_t TEMPLATE_CUSTOM_HID_DeInit(void); static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state); + +#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED +static int8_t TEMPLATE_CUSTOM_HID_CtrlReqComplete(uint8_t request, uint16_t wLength); +#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ + +#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED +static uint8_t *TEMPLATE_CUSTOM_HID_GetReport(uint16_t *ReportLength); +#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ /* Private variables ---------------------------------------------------------*/ extern USBD_HandleTypeDef USBD_Device; @@ -44,6 +52,12 @@ USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops = TEMPLATE_CUSTOM_HID_Init, TEMPLATE_CUSTOM_HID_DeInit, TEMPLATE_CUSTOM_HID_OutEvent, +#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED + TEMPLATE_CUSTOM_HID_CtrlReqComplete, +#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ +#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED + TEMPLATE_CUSTOM_HID_GetReport, +#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ }; /* Private functions ---------------------------------------------------------*/ @@ -95,3 +109,50 @@ static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state) return (0); } +#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED +/** + * @brief TEMPLATE_CUSTOM_HID_CtrlReqComplete + * Manage the CUSTOM HID control request complete + * @param request: control request + * @param wLength: request wLength + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t TEMPLATE_CUSTOM_HID_CtrlReqComplete(uint8_t request, uint16_t wLength) +{ + UNUSED(wLength); + + switch (request) + { + case CUSTOM_HID_REQ_SET_REPORT: + + break; + + case CUSTOM_HID_REQ_GET_REPORT: + + break; + + default: + break; + } + + return (0); +} +#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ + + +#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED +/** + * @brief TEMPLATE_CUSTOM_HID_GetReport + * Manage the CUSTOM HID control Get Report request + * @param event_idx: event index + * @param state: event state + * @retval return pointer to HID report + */ +static uint8_t *TEMPLATE_CUSTOM_HID_GetReport(uint16_t *ReportLength) +{ + UNUSED(ReportLength); + uint8_t *pbuff; + + return (pbuff); +} +#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h b/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h index ed0c9bb7d..8b22a8df9 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h @@ -60,14 +60,14 @@ extern "C" { #define HID_FS_BINTERVAL 0x0AU #endif /* HID_FS_BINTERVAL */ -#define HID_REQ_SET_PROTOCOL 0x0BU -#define HID_REQ_GET_PROTOCOL 0x03U +#define USBD_HID_REQ_SET_PROTOCOL 0x0BU +#define USBD_HID_REQ_GET_PROTOCOL 0x03U -#define HID_REQ_SET_IDLE 0x0AU -#define HID_REQ_GET_IDLE 0x02U +#define USBD_HID_REQ_SET_IDLE 0x0AU +#define USBD_HID_REQ_GET_IDLE 0x02U -#define HID_REQ_SET_REPORT 0x09U -#define HID_REQ_GET_REPORT 0x01U +#define USBD_HID_REQ_SET_REPORT 0x09U +#define USBD_HID_REQ_GET_REPORT 0x01U /** * @} */ @@ -78,9 +78,9 @@ extern "C" { */ typedef enum { - HID_IDLE = 0, - HID_BUSY, -} HID_StateTypeDef; + USBD_HID_IDLE = 0, + USBD_HID_BUSY, +} USBD_HID_StateTypeDef; typedef struct @@ -88,7 +88,7 @@ typedef struct uint32_t Protocol; uint32_t IdleState; uint32_t AltSetting; - HID_StateTypeDef state; + USBD_HID_StateTypeDef state; } USBD_HID_HandleTypeDef; /* @@ -134,7 +134,11 @@ extern USBD_ClassTypeDef USBD_HID; /** @defgroup USB_CORE_Exported_Functions * @{ */ +#ifdef USE_USBD_COMPOSITE +uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len, uint8_t ClassId); +#else uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len); +#endif /* USE_USBD_COMPOSITE */ uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev); /** diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c index 075a660da..fdf757810 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c @@ -295,7 +295,7 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR); + HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (pdev->dev_speed == USBD_SPEED_HIGH) @@ -311,7 +311,7 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) (void)USBD_LL_OpenEP(pdev, HIDInEpAdd, USBD_EP_TYPE_INTR, HID_EPIN_SIZE); pdev->ep_in[HIDInEpAdd & 0xFU].is_used = 1U; - hhid->state = HID_IDLE; + hhid->state = USBD_HID_IDLE; return (uint8_t)USBD_OK; } @@ -329,7 +329,7 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR); + HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ /* Close HID EPs */ @@ -372,19 +372,19 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re case USB_REQ_TYPE_CLASS : switch (req->bRequest) { - case HID_REQ_SET_PROTOCOL: + case USBD_HID_REQ_SET_PROTOCOL: hhid->Protocol = (uint8_t)(req->wValue); break; - case HID_REQ_GET_PROTOCOL: + case USBD_HID_REQ_GET_PROTOCOL: (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U); break; - case HID_REQ_SET_IDLE: + case USBD_HID_REQ_SET_IDLE: hhid->IdleState = (uint8_t)(req->wValue >> 8); break; - case HID_REQ_GET_IDLE: + case USBD_HID_REQ_GET_IDLE: (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U); break; @@ -472,16 +472,24 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re return (uint8_t)ret; } + /** * @brief USBD_HID_SendReport * Send HID Report * @param pdev: device instance * @param buff: pointer to report + * @param ClassId: The Class ID * @retval status */ +#ifdef USE_USBD_COMPOSITE +uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len, uint8_t ClassId) +{ + USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[ClassId]; +#else uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len) { USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; +#endif /* USE_USBD_COMPOSITE */ if (hhid == NULL) { @@ -490,14 +498,14 @@ uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR); + HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, ClassId); #endif /* USE_USBD_COMPOSITE */ if (pdev->dev_state == USBD_STATE_CONFIGURED) { - if (hhid->state == HID_IDLE) + if (hhid->state == USBD_HID_IDLE) { - hhid->state = HID_BUSY; + hhid->state = USBD_HID_BUSY; (void)USBD_LL_Transmit(pdev, HIDInEpAdd, report, len); } } @@ -607,7 +615,7 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) UNUSED(epnum); /* Ensure that the FIFO is empty before a new transfer, this condition could be caused by a new transfer before the end of the previous transfer */ - ((USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = HID_IDLE; + ((USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = USBD_HID_IDLE; return (uint8_t)USBD_OK; } diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h index f946b957a..c96d2b84e 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h @@ -39,8 +39,8 @@ extern "C" { /** @defgroup USB_INFO_Exported_Defines * @{ */ -#define MODE_SENSE6_LEN 0x17U -#define MODE_SENSE10_LEN 0x1BU +#define MODE_SENSE6_LEN 0x04U +#define MODE_SENSE10_LEN 0x08U #define LENGTH_INQUIRY_PAGE00 0x06U #define LENGTH_INQUIRY_PAGE80 0x08U #define LENGTH_FORMAT_CAPACITIES 0x14U diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h index 0d0bbc5b2..477affbb4 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h @@ -82,7 +82,7 @@ extern "C" { #define UNIT_ATTENTION 6U #define DATA_PROTECT 7U #define BLANK_CHECK 8U -#define VENDOR_SPECIFIC 9U +#define MSC_VENDOR_SPECIFIC 9U #define COPY_ABORTED 10U #define ABORTED_COMMAND 11U #define VOLUME_OVERFLOW 13U diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c index ad5daebd6..7f2152f38 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c @@ -229,8 +229,8 @@ uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (pdev->dev_speed == USBD_SPEED_HIGH) @@ -273,8 +273,8 @@ uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ /* Close MSC EPs */ @@ -313,8 +313,8 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c index 0816de93e..c51b01361 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c @@ -101,8 +101,8 @@ void MSC_BOT_Init(USBD_HandleTypeDef *pdev) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) @@ -139,8 +139,8 @@ void MSC_BOT_Reset(USBD_HandleTypeDef *pdev) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) @@ -259,8 +259,8 @@ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) @@ -335,8 +335,8 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) @@ -366,8 +366,8 @@ void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) @@ -400,8 +400,8 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) @@ -439,8 +439,8 @@ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c index fabd835c2..1641c20fe 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c @@ -91,62 +91,32 @@ uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80] = /* USB Mass storage sense 6 Data */ uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN] = { - 0x22, - 0x00, - 0x00, - 0x00, - 0x08, - 0x12, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 + 0x03, /* MODE DATA LENGTH. The number of bytes that follow. */ + 0x00, /* MEDIUM TYPE. 00h for SBC devices. */ + 0x00, /* DEVICE-SPECIFIC PARAMETER. For SBC devices: + * bit 7: WP. Set to 1 if the media is write-protected. + * bits 6..5: reserved + * bit 4: DPOFUA. Set to 1 if the device supports the DPO and FUA bits + * bits 3..0: reserved */ + 0x00 /* BLOCK DESCRIPTOR LENGTH */ }; -/* USB Mass storage sense 10 Data */ +/* USB Mass storage sense 10 Data */ uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] = { - 0x00, - 0x26, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x08, - 0x12, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 + 0x00, /* MODE DATA LENGTH MSB. */ + 0x06, /* MODE DATA LENGTH LSB. The number of bytes that follow. */ + 0x00, /* MEDIUM TYPE. 00h for SBC devices. */ + 0x00, /* DEVICE-SPECIFIC PARAMETER. For SBC devices: + * bit 7: WP. Set to 1 if the media is write-protected. + * bits 6..5: reserved + * bit 4: DPOFUA. Set to 1 if the device supports the DPO and FUA bits + * bits 3..0: reserved */ + 0x00, /* LONGLBA Set to zero */ + 0x00, /* Reserved */ + 0x00, /* BLOCK DESCRIPTOR LENGTH MSB. */ + 0x00 /* BLOCK DESCRIPTOR LENGTH LSB. */ }; /** * @} diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c index af7a0d5a2..3c0fe2f48 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c @@ -291,7 +291,8 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param else { - pPage = (uint8_t *) & ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; + pPage = (uint8_t *) & ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId]) \ + ->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; len = (uint16_t)pPage[4] + 5U; if (params[4] <= len) @@ -324,7 +325,8 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t return -1; } - ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size); + ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, + &hmsc->scsi_blk_size); if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { @@ -359,7 +361,7 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); - uint8_t idx; + uint32_t idx; int8_t ret; USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; @@ -368,7 +370,8 @@ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t return -1; } - ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size); + ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, + &hmsc->scsi_blk_size); if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { @@ -474,6 +477,12 @@ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *pa return -1; } + /* Check If media is write-protected */ + if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) + { + MSC_Mode_Sense6_data[2] |= 0x80U; + } + if (params[4] <= len) { len = params[4]; @@ -503,6 +512,12 @@ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *p return -1; } + /* Check If media is write-protected */ + if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) + { + MSC_Mode_Sense10_data[3] |= 0x80U; + } + if (params[8] <= len) { len = params[8]; @@ -832,7 +847,7 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ @@ -921,7 +936,7 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param } #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ @@ -1075,7 +1090,7 @@ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); + MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ len = MIN(len, MSC_MEDIA_PACKET); @@ -1124,7 +1139,7 @@ static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun) #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); + MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); #endif /* USE_USBD_COMPOSITE */ len = MIN(len, MSC_MEDIA_PACKET); diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_core.h b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_core.h index 7b7dff540..4672921be 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_core.h +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_core.h @@ -86,13 +86,16 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); +#if (USBD_USER_REGISTER_CALLBACK == 1U) +USBD_StatusTypeDef USBD_RegisterDevStateCallback(USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback); +#endif /* USBD_USER_REGISTER_CALLBACK */ #ifdef USE_USBD_COMPOSITE USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass, USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr); USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev); -uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type); +uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type, uint8_t ClassId); #endif /* USE_USBD_COMPOSITE */ uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index); diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_def.h b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_def.h index 3c1902fd9..2a295d78b 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_def.h +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Inc/usbd_def.h @@ -390,8 +390,15 @@ typedef struct _USBD_HandleTypeDef #ifdef USE_USBD_COMPOSITE USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS]; #endif /* USE_USBD_COMPOSITE */ +#if (USBD_USER_REGISTER_CALLBACK == 1U) + void (* DevStateCallback)(uint8_t dev_state, uint8_t cfgidx); /*!< User Notification callback */ +#endif /* USBD_USER_REGISTER_CALLBACK */ } USBD_HandleTypeDef; +#if (USBD_USER_REGISTER_CALLBACK == 1U) +typedef void (*USBD_DevStateCallbackTypeDef)(uint8_t dev_state, uint8_t cfgidx); /*!< pointer to User callback function */ +#endif /* USBD_USER_REGISTER_CALLBACK */ + /* USB Device endpoint direction */ typedef enum { @@ -416,7 +423,9 @@ typedef enum */ __STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr) { - uint16_t _SwapVal, _Byte1, _Byte2; + uint16_t _SwapVal; + uint16_t _Byte1; + uint16_t _Byte2; uint8_t *_pbuff = addr; _Byte1 = *(uint8_t *)_pbuff; diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_core.c b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_core.c index 544c2a923..186a309cc 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_core.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_core.c @@ -358,10 +358,22 @@ USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev) return ret; } - - #endif /* USE_USBD_COMPOSITE */ +#if (USBD_USER_REGISTER_CALLBACK == 1U) +/** + * @brief USBD_RegisterDevStateCallback + * @param pdev : Device Handle + * @param pUserCallback: User Callback + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_RegisterDevStateCallback(USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback) +{ + pdev->DevStateCallback = pUserCallback; + + return USBD_OK; +} +#endif /* USBD_USER_REGISTER_CALLBACK */ /** * @brief USBD_Start * Start the USB Device Core. @@ -629,19 +641,6 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, (void)USBD_CtlSendStatus(pdev); } } - else - { -#if 0 - if (pdev->ep0_state == USBD_EP0_STATUS_OUT) - { - /* - * STATUS PHASE completed, update ep0_state to idle - */ - pdev->ep0_state = USBD_EP0_IDLE; - (void)USBD_LL_StallEP(pdev, 0U); - } -#endif - } } else { @@ -726,16 +725,6 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, } } } - else - { -#if 0 - if ((pdev->ep0_state == USBD_EP0_STATUS_IN) || - (pdev->ep0_state == USBD_EP0_IDLE)) - { - (void)USBD_LL_StallEP(pdev, 0x80U); - } -#endif - } if (pdev->dev_test_mode != 0U) { @@ -862,7 +851,11 @@ USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev) { - pdev->dev_old_state = pdev->dev_state; + if (pdev->dev_state != USBD_STATE_SUSPENDED) + { + pdev->dev_old_state = pdev->dev_state; + } + pdev->dev_state = USBD_STATE_SUSPENDED; return USBD_OK; @@ -1123,20 +1116,21 @@ uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index) * @param pdev: device instance * @param ep_dir: USBD_EP_IN or USBD_EP_OUT * @param ep_type: USBD_EP_TYPE_CTRL, USBD_EP_TYPE_ISOC, USBD_EP_TYPE_BULK or USBD_EP_TYPE_INTR + * @param ClassId: The Class ID * @retval Address of the selected endpoint or 0xFFU if no endpoint found. */ -uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type) +uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type, uint8_t ClassId) { uint8_t idx; /* Find the EP address in the selected class table */ - for (idx = 0; idx < pdev->tclasslist[pdev->classId].NumEps; idx++) + for (idx = 0; idx < pdev->tclasslist[ClassId].NumEps; idx++) { - if (((pdev->tclasslist[pdev->classId].Eps[idx].add & USBD_EP_IN) == ep_dir) && \ - (pdev->tclasslist[pdev->classId].Eps[idx].type == ep_type) && \ - (pdev->tclasslist[pdev->classId].Eps[idx].is_used != 0U)) + if (((pdev->tclasslist[ClassId].Eps[idx].add & USBD_EP_IN) == ep_dir) && \ + (pdev->tclasslist[ClassId].Eps[idx].type == ep_type) && \ + (pdev->tclasslist[ClassId].Eps[idx].is_used != 0U)) { - return (pdev->tclasslist[pdev->classId].Eps[idx].add); + return (pdev->tclasslist[ClassId].Eps[idx].add); } } diff --git a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c index c7336476d..af9a0154c 100644 --- a/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c +++ b/radio/src/thirdparty/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c @@ -454,7 +454,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r #ifdef USE_USBD_COMPOSITE if ((uint8_t)(pdev->NumClasses) > 0U) { - pbuf = (uint8_t *)USBD_CMPSIT.GetHSConfigDescriptor(&len); + pbuf = (uint8_t *)USBD_CMPSIT.GetHSConfigDescriptor(&len); } else #endif /* USE_USBD_COMPOSITE */ @@ -468,12 +468,12 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r #ifdef USE_USBD_COMPOSITE if ((uint8_t)(pdev->NumClasses) > 0U) { - pbuf = (uint8_t *)USBD_CMPSIT.GetFSConfigDescriptor(&len); + pbuf = (uint8_t *)USBD_CMPSIT.GetFSConfigDescriptor(&len); } else #endif /* USE_USBD_COMPOSITE */ { - pbuf = (uint8_t *)pdev->pClass[0]->GetFSConfigDescriptor(&len); + pbuf = (uint8_t *)pdev->pClass[0]->GetFSConfigDescriptor(&len); } pbuf[1] = USB_DESC_TYPE_CONFIGURATION; } @@ -558,7 +558,6 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r #if (USBD_SUPPORT_USER_STRING_DESC == 1U) pbuf = NULL; - for (uint32_t idx = 0U; (idx < pdev->NumClasses); idx++) { if (pdev->pClass[idx]->GetUsrStrDescriptor != NULL) @@ -576,13 +575,12 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r } } } - #endif /* USBD_SUPPORT_USER_STRING_DESC */ #if (USBD_CLASS_USER_STRING_DESC == 1U) if (pdev->pDesc->GetUserStrDescriptor != NULL) { - pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, (req->wValue), &len); + pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, LOBYTE(req->wValue), &len); } else { @@ -751,6 +749,13 @@ static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReq { (void)USBD_CtlSendStatus(pdev); pdev->dev_state = USBD_STATE_CONFIGURED; + +#if (USBD_USER_REGISTER_CALLBACK == 1U) + if (pdev->DevStateCallback != NULL) + { + pdev->DevStateCallback(USBD_STATE_CONFIGURED, cfgidx); + } +#endif /* USBD_USER_REGISTER_CALLBACK */ } } else @@ -895,7 +900,7 @@ static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) } else if (req->wValue == USB_FEATURE_TEST_MODE) { - pdev->dev_test_mode = req->wIndex >> 8; + pdev->dev_test_mode = (uint8_t)(req->wIndex >> 8); (void)USBD_CtlSendStatus(pdev); } else