diff --git a/Class/AUDIO/Src/usbd_audio.c b/Class/AUDIO/Src/usbd_audio.c index 1dce51a..7b4915b 100644 --- a/Class/AUDIO/Src/usbd_audio.c +++ b/Class/AUDIO/Src/usbd_audio.c @@ -162,8 +162,12 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI 0x02, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ - 0xC0, /* bmAttributes BUS Powred*/ - 0x32, /* bMaxPower = 100 mA*/ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* bMaxPower = 100 mA */ /* 09 byte*/ /* USB Speaker Standard interface descriptor */ @@ -229,7 +233,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI 0x00, /* iTerminal */ /* 09 byte*/ - /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */ + /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwidth */ /* Interface 1, Alternate Setting 0 */ AUDIO_INTERFACE_DESC_SIZE, /* bLength */ USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ @@ -334,7 +338,7 @@ static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) UNUSED(cfgidx); USBD_AUDIO_HandleTypeDef *haudio; - /* Allocate Audio structure */ + /* Allocate Audio structure */ haudio = USBD_malloc(sizeof(USBD_AUDIO_HandleTypeDef)); if (haudio == NULL) @@ -426,95 +430,95 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev, switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS: - switch (req->bRequest) - { - case AUDIO_REQ_GET_CUR: - AUDIO_REQ_GetCurrent(pdev, req); - break; - - case AUDIO_REQ_SET_CUR: - AUDIO_REQ_SetCurrent(pdev, req); - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) + case USB_REQ_TYPE_CLASS: + switch (req->bRequest) { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case AUDIO_REQ_GET_CUR: + AUDIO_REQ_GetCurrent(pdev, req); + break; - case USB_REQ_GET_DESCRIPTOR: - if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE) - { - pbuf = USBD_AUDIO_CfgDesc + 18; - len = MIN(USB_AUDIO_DESC_SIZ, req->wLength); + case AUDIO_REQ_SET_CUR: + AUDIO_REQ_SetCurrent(pdev, req); + break; - (void)USBD_CtlSendData(pdev, pbuf, len); - } - break; - - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&haudio->alt_setting, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES) - { - haudio->alt_setting = (uint8_t)(req->wValue); - } - else - { - /* Call the error management function (command will be nacked */ + default: USBD_CtlError(pdev, req); ret = USBD_FAIL; - } + break; } - else + break; + + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_DESCRIPTOR: + if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE) + { + pbuf = USBD_AUDIO_CfgDesc + 18; + len = MIN(USB_AUDIO_DESC_SIZ, req->wLength); + + (void)USBD_CtlSendData(pdev, pbuf, len); + } + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&haudio->alt_setting, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES) + { + haudio->alt_setting = (uint8_t)(req->wValue); + } + else + { + /* Call the error management function (command will be NAKed */ + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; - - case USB_REQ_CLEAR_FEATURE: - break; - default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; @@ -651,13 +655,13 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset) { if ((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET) { - BufferSize -= 4U; + BufferSize -= 4U; } else { if ((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET)) { - BufferSize += 4U; + BufferSize += 4U; } } } @@ -798,11 +802,11 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef /** -* @brief DeviceQualifierDescriptor -* return Device Qualifier descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_AUDIO_DeviceQualifierDesc); @@ -811,10 +815,10 @@ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length) } /** -* @brief USBD_AUDIO_RegisterInterface -* @param fops: Audio interface callback -* @retval status -*/ + * @brief USBD_AUDIO_RegisterInterface + * @param fops: Audio interface callback + * @retval status + */ uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_AUDIO_ItfTypeDef *fops) { diff --git a/Class/BillBoard/Src/usbd_billboard.c b/Class/BillBoard/Src/usbd_billboard.c index 35b45a1..b14a469 100644 --- a/Class/BillBoard/Src/usbd_billboard.c +++ b/Class/BillBoard/Src/usbd_billboard.c @@ -7,7 +7,7 @@ * - Initialization and Configuration of high and low layer * - Enumeration as BillBoard Device * - Error management - * @verbatim + * @verbatim * * =================================================================== * BillBoard Class Description @@ -150,8 +150,12 @@ __ALIGN_BEGIN static uint8_t USBD_BB_CfgDesc[USB_BB_CONFIG_DESC_SIZ] __ALIGN_EN 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ USBD_IDX_CONFIG_STR, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: bus powered and Support Remote Wake-up */ - 0x00, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /* 09 */ /************** Descriptor of BillBoard interface ****************/ @@ -170,15 +174,19 @@ __ALIGN_BEGIN static uint8_t USBD_BB_CfgDesc[USB_BB_CONFIG_DESC_SIZ] __ALIGN_EN /* USB device Other Speed Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_BB_OtherSpeedCfgDesc[USB_BB_CONFIG_DESC_SIZ] __ALIGN_END = { - 0x09, /* bLength: Configuation Descriptor size */ + 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_BB_CONFIG_DESC_SIZ, 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: */ USBD_IDX_CONFIG_STR, /* iConfiguration: */ - 0xC0, /* bmAttributes: */ - 0x00, /* MaxPower 100 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /************** Descriptor of BillBoard interface ****************/ /* 09 */ @@ -248,50 +256,50 @@ static uint8_t USBD_BB_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS: - break; - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } + case USB_REQ_TYPE_CLASS: break; - - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { - (void)USBD_CtlSendData(pdev, (uint8_t *)&AltSetting, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_SET_INTERFACE: - case USB_REQ_CLEAR_FEATURE: + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&AltSetting, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; diff --git a/Class/CDC/Inc/usbd_cdc.h b/Class/CDC/Inc/usbd_cdc.h index b484218..89e4d05 100644 --- a/Class/CDC/Inc/usbd_cdc.h +++ b/Class/CDC/Inc/usbd_cdc.h @@ -65,6 +65,7 @@ extern "C" { #define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE #define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE +#define CDC_REQ_MAX_DATA_SIZE 0x7U /*---------------------------------------------------------------------*/ /* CDC definitions */ /*---------------------------------------------------------------------*/ diff --git a/Class/CDC/Src/usbd_cdc.c b/Class/CDC/Src/usbd_cdc.c index ae1f9a4..fa5b588 100644 --- a/Class/CDC/Src/usbd_cdc.c +++ b/Class/CDC/Src/usbd_cdc.c @@ -166,15 +166,18 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*---------------------------------------------------------------------------*/ /* Interface Descriptor */ 0x09, /* bLength: Interface Descriptor size */ USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ 0x00, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x01, /* bNumEndpoints: One endpoints used */ @@ -262,8 +265,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*---------------------------------------------------------------------------*/ @@ -348,15 +355,19 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN __ALIGN_BEGIN static uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { - 0x09, /* bLength: Configuation Descriptor size */ + 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_CDC_CONFIG_DESC_SIZ, 0x00, 0x02, /* bNumInterfaces: 2 interfaces */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ - 0xC0, /* bmAttributes: */ - 0x32, /* MaxPower 100 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*Interface Descriptor */ 0x09, /* bLength: Interface Descriptor size */ @@ -576,6 +587,7 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData; + uint16_t len; uint8_t ifalt = 0U; uint16_t status_info = 0U; USBD_StatusTypeDef ret = USBD_OK; @@ -591,7 +603,8 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, (uint8_t *)hcdc->data, req->wLength); - (void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, req->wLength); + len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength); + (void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len); } else { diff --git a/Class/CDC/Src/usbd_cdc_if_template.c b/Class/CDC/Src/usbd_cdc_if_template.c index 60748c3..f863ce1 100644 --- a/Class/CDC/Src/usbd_cdc_if_template.c +++ b/Class/CDC/Src/usbd_cdc_if_template.c @@ -213,7 +213,7 @@ static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len) /** * @brief TEMPLATE_TransmitCplt - * Data transmited callback + * Data transmitted callback * * @note * This function is IN transfer complete callback used to inform user that diff --git a/Class/CDC_ECM/Inc/usbd_cdc_ecm.h b/Class/CDC_ECM/Inc/usbd_cdc_ecm.h index f4bef2c..cdc2d6c 100644 --- a/Class/CDC_ECM/Inc/usbd_cdc_ecm.h +++ b/Class/CDC_ECM/Inc/usbd_cdc_ecm.h @@ -75,6 +75,8 @@ extern "C" { #define CDC_ECM_CONFIG_DESC_SIZ 79U +#define CDC_ECM_DATA_BUFFER_SIZE 2000U + #define CDC_ECM_DATA_HS_IN_PACKET_SIZE CDC_ECM_DATA_HS_MAX_PACKET_SIZE #define CDC_ECM_DATA_HS_OUT_PACKET_SIZE CDC_ECM_DATA_HS_MAX_PACKET_SIZE @@ -173,7 +175,7 @@ typedef struct typedef struct { - uint32_t data[2000 / 4]; /* Force 32bits alignment */ + uint32_t data[CDC_ECM_DATA_BUFFER_SIZE / 4]; /* Force 32bits alignment */ uint8_t CmdOpCode; uint8_t CmdLength; uint8_t Reserved1; /* Reserved Byte to force 4 bytes alignment of following fields */ diff --git a/Class/CDC_ECM/Src/usbd_cdc_ecm.c b/Class/CDC_ECM/Src/usbd_cdc_ecm.c index 731c4a6..a58baa5 100644 --- a/Class/CDC_ECM/Src/usbd_cdc_ecm.c +++ b/Class/CDC_ECM/Src/usbd_cdc_ecm.c @@ -113,7 +113,8 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_ECM_DeviceQualifierDesc[USB_LEN_DEV_QUALIF }; static uint32_t ConnSpeedTab[2] = {CDC_ECM_CONNECT_SPEED_UPSTREAM, - CDC_ECM_CONNECT_SPEED_DOWNSTREAM}; + CDC_ECM_CONNECT_SPEED_DOWNSTREAM + }; /** * @} @@ -157,8 +158,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_ECM_CfgHSDesc[] __ALIGN_END = 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*---------------------------------------------------------------------------*/ @@ -265,8 +270,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_ECM_CfgFSDesc[] __ALIGN_END = 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*---------------------------------------------------------------------------*/ /* IAD descriptor */ @@ -371,8 +380,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_ECM_OtherSpeedCfgDesc[] __ALIGN_END = 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x04, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*--------------------------------------- ------------------------------------*/ /* IAD descriptor */ @@ -602,84 +615,86 @@ static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev, USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *) pdev->pClassData; USBD_CDC_ECM_ItfTypeDef *EcmInterface = (USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData; USBD_StatusTypeDef ret = USBD_OK; - uint8_t ifalt = 0U; + uint16_t len; uint16_t status_info = 0U; + uint8_t ifalt = 0U; switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS : - if (req->wLength != 0U) - { - if ((req->bmRequest & 0x80U) != 0U) + case USB_REQ_TYPE_CLASS : + if (req->wLength != 0U) { - EcmInterface->Control(req->bRequest, - (uint8_t *)hcdc->data, req->wLength); + if ((req->bmRequest & 0x80U) != 0U) + { + EcmInterface->Control(req->bRequest, + (uint8_t *)hcdc->data, req->wLength); - (void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, req->wLength); + len = MIN(CDC_ECM_DATA_BUFFER_SIZE, req->wLength); + (void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len); + } + else + { + hcdc->CmdOpCode = req->bRequest; + hcdc->CmdLength = (uint8_t)req->wLength; + + (void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, req->wLength); + } } else { - hcdc->CmdOpCode = req->bRequest; - hcdc->CmdLength = (uint8_t)req->wLength; - - (void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, req->wLength); - } - } - else - { - EcmInterface->Control(req->bRequest, (uint8_t *)req, 0U); - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; + EcmInterface->Control(req->bRequest, (uint8_t *)req, 0U); } break; - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { - (void)USBD_CtlSendData(pdev, &ifalt, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state != USBD_STATE_CONFIGURED) - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, &ifalt, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_CLEAR_FEATURE: + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state != USBD_STATE_CONFIGURED) + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; @@ -769,7 +784,7 @@ static uint8_t USBD_CDC_ECM_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) if ((CurrPcktLen < hcdc->MaxPcktLen) || (hcdc->RxLength >= CDC_ECM_ETH_MAX_SEGSZE)) { /* USB data will be immediately processed, this allow next USB traffic being - NACKed till the end of the application Xfer */ + NAKed till the end of the application Xfer */ /* Process data by application (ie. copy to app buffer or notify user) hcdc->RxLength must be reset to zero at the end of the call of this function */ @@ -973,7 +988,7 @@ uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev) /* Transmit next packet */ (void)USBD_LL_Transmit(pdev, CDC_ECM_IN_EP, hcdc->TxBuffer, hcdc->TxLength); - ret = USBD_OK; + ret = USBD_OK; } return (uint8_t)ret; @@ -996,7 +1011,7 @@ uint8_t USBD_CDC_ECM_ReceivePacket(USBD_HandleTypeDef *pdev) } /* Prepare Out endpoint to receive next packet */ - (void)USBD_LL_PrepareReceive(pdev, CDC_ECM_OUT_EP,hcdc->RxBuffer, hcdc->MaxPcktLen); + (void)USBD_LL_PrepareReceive(pdev, CDC_ECM_OUT_EP, hcdc->RxBuffer, hcdc->MaxPcktLen); return (uint8_t)USBD_OK; } @@ -1072,7 +1087,7 @@ uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev, /* Transmit notification packet */ if (ReqSize != 0U) { - (void)USBD_LL_Transmit(pdev, CDC_ECM_CMD_EP, (uint8_t *)&(hcdc->Req), ReqSize); + (void)USBD_LL_Transmit(pdev, CDC_ECM_CMD_EP, (uint8_t *) &(hcdc->Req), ReqSize); } return (uint8_t)ret; diff --git a/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c b/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c index 9b96de8..cab0056 100644 --- a/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c +++ b/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c @@ -32,12 +32,12 @@ /* Private variables ---------------------------------------------------------*/ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif __ALIGN_BEGIN static uint8_t UserRxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END; /* Received Data over USB are stored in this buffer */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif __ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END; /* Received Data over CDC_ECM (CDC_ECM interface) are stored in this buffer */ @@ -133,15 +133,15 @@ static int8_t CDC_ECM_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length) /* Add your code here */ break; - case CDC_ECM_SET_ETH_PWRM_PATTERN_FILTER: + case CDC_ECM_SET_ETH_PWRM_PATTERN_FILTER: /* Add your code here */ break; - case CDC_ECM_GET_ETH_PWRM_PATTERN_FILTER: + case CDC_ECM_GET_ETH_PWRM_PATTERN_FILTER: /* Add your code here */ break; - case CDC_ECM_SET_ETH_PACKET_FILTER: + case CDC_ECM_SET_ETH_PACKET_FILTER: /* Check if this is the first time we enter */ if (hcdc_cdc_ecm->LinkStatus == 0U) { @@ -164,7 +164,7 @@ static int8_t CDC_ECM_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length) /* Add your code here */ break; - case CDC_ECM_GET_ETH_STATISTIC: + case CDC_ECM_GET_ETH_STATISTIC: /* Add your code here */ break; @@ -201,7 +201,7 @@ static int8_t CDC_ECM_Itf_Receive(uint8_t *Buf, uint32_t *Len) /** * @brief CDC_ECM_Itf_TransmitCplt - * Data transmited callback + * Data transmitted callback * * @note * This function is IN transfer complete callback used to inform user that diff --git a/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c b/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c index 6109b63..3ce4d77 100644 --- a/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c +++ b/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c @@ -144,10 +144,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_DeviceQualifierDesc[USB_LEN_DEV_QUAL }; static uint8_t MAC_StrDesc[6] = {CDC_RNDIS_MAC_ADDR0, CDC_RNDIS_MAC_ADDR1, CDC_RNDIS_MAC_ADDR2, - CDC_RNDIS_MAC_ADDR3, CDC_RNDIS_MAC_ADDR4, CDC_RNDIS_MAC_ADDR5}; + CDC_RNDIS_MAC_ADDR3, CDC_RNDIS_MAC_ADDR4, CDC_RNDIS_MAC_ADDR5 + }; static uint32_t ConnSpeedTab[2] = {CDC_RNDIS_CONNECT_SPEED_UPSTREAM, - CDC_RNDIS_CONNECT_SPEED_DOWNSTREAM}; + CDC_RNDIS_CONNECT_SPEED_DOWNSTREAM + }; static uint8_t EmptyResponse = 0x00U; @@ -193,8 +195,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_CfgHSDesc[] __ALIGN_END = 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*---------------------------------------------------------------------------*/ /* IAD descriptor */ @@ -298,8 +304,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_CfgFSDesc[] __ALIGN_END = 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*---------------------------------------------------------------------------*/ /* IAD descriptor */ @@ -401,8 +411,12 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_OtherSpeedCfgDesc[] __ALIGN_END = 0x02, /* bNumInterfaces: 2 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x04, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /*---------------------------------------------------------------------------*/ /* IAD descriptor */ @@ -664,114 +678,114 @@ static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev, switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS : - if (req->wLength != 0U) - { - /* Control Request Data from Device to Host, send data prepared by device */ - if ((req->bmRequest & 0x80U) != 0U) + case USB_REQ_TYPE_CLASS : + if (req->wLength != 0U) { - /* Update opcode and length */ - hcdc->CmdOpCode = req->bRequest; - hcdc->CmdLength = (uint8_t)req->wLength; - - if (hcdc->CmdOpCode == CDC_RNDIS_GET_ENCAPSULATED_RESPONSE) + /* Control Request Data from Device to Host, send data prepared by device */ + if ((req->bmRequest & 0x80U) != 0U) { - /* Data of Response Message has already been prepared by USBD_CDC_RNDIS_MsgParsing. - Just check that length is corresponding to right expected value */ - if (req->wLength != Msg->MsgLength) + /* Update opcode and length */ + hcdc->CmdOpCode = req->bRequest; + hcdc->CmdLength = (uint8_t)req->wLength; + + if (hcdc->CmdOpCode == CDC_RNDIS_GET_ENCAPSULATED_RESPONSE) { + /* Data of Response Message has already been prepared by USBD_CDC_RNDIS_MsgParsing. + Just check that length is corresponding to right expected value */ + if (req->wLength != Msg->MsgLength) + { + } + } + + /* Allow application layer to pre-process data or add own processing before sending response */ + ((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, + (uint8_t *)hcdc->data, + req->wLength); + /* Check if Response is ready */ + if (hcdc->ResponseRdy != 0U) + { + /* Clear Response Ready flag */ + hcdc->ResponseRdy = 0U; + + /* Send data on control endpoint */ + (void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, Msg->MsgLength); + } + else + { + /* CDC_RNDIS Specification says: If for some reason the device receives a GET ENCAPSULATED RESPONSE + and is unable to respond with a valid data on the Control endpoint, + then it should return a one-byte packet set to 0x00, rather than + stalling the Control endpoint */ + (void)USBD_CtlSendData(pdev, &EmptyResponse, 1U); } } - - /* Allow application layer to pre-process data or add own processing before sending response */ - ((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, - (uint8_t *)hcdc->data, - req->wLength); - /* Check if Response is ready */ - if (hcdc->ResponseRdy != 0U) - { - /* Clear Response Ready flag */ - hcdc->ResponseRdy = 0U; - - /* Send data on control endpoint */ - (void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, Msg->MsgLength); - } + /* Control Request Data from Host to Device: Prepare reception of control data stage */ else { - /* CDC_RNDIS Specification says: If for some reason the device receives a GET ENCAPSULATED RESPONSE - and is unable to respond with a valid data on the Control endpoint, - then it should return a one-byte packet set to 0x00, rather than - stalling the Control endpoint */ - (void)USBD_CtlSendData(pdev, &EmptyResponse, 1U); + hcdc->CmdOpCode = req->bRequest; + hcdc->CmdLength = (uint8_t)req->wLength; + + (void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, req->wLength); } } - /* Control Request Data from Host to Device: Prepare reception of control data stage */ + /* No Data control request: there is no such request for CDC_RNDIS protocol, + so let application layer manage this case */ else { - hcdc->CmdOpCode = req->bRequest; - hcdc->CmdLength = (uint8_t)req->wLength; - - (void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, req->wLength); - } - } - /* No Data control request: there is no such request for CDC_RNDIS protocol, - so let application layer manage this case */ - else - { - ((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, - (uint8_t *)req, 0U); - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; + ((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, + (uint8_t *)req, 0U); } break; - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { - (void)USBD_CtlSendData(pdev, &ifalt, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state != USBD_STATE_CONFIGURED) - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, &ifalt, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_CLEAR_FEATURE: + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state != USBD_STATE_CONFIGURED) + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; @@ -822,7 +836,7 @@ static uint8_t USBD_CDC_RNDIS_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) if (hcdc->NotificationStatus != 0U) { (void)USBD_CDC_RNDIS_SendNotification(pdev, CONNECTION_SPEED_CHANGE, - 0U, (uint8_t *)ConnSpeedTab); + 0U, (uint8_t *)ConnSpeedTab); hcdc->NotificationStatus = 0U; } @@ -867,7 +881,7 @@ static uint8_t USBD_CDC_RNDIS_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) (hcdc->RxLength >= (CDC_RNDIS_ETH_MAX_SEGSZE + sizeof(USBD_CDC_RNDIS_PacketMsgTypeDef)))) { /* USB data will be immediately processed, this allow next USB traffic being - NACKed till the end of the application Xfer */ + NAKed till the end of the application Xfer */ /* Call data packet message parsing and processing function */ (void)USBD_CDC_RNDIS_ProcessPacketMsg(pdev, (USBD_CDC_RNDIS_PacketMsgTypeDef *)(void *)hcdc->RxBuffer); @@ -1101,7 +1115,7 @@ uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev) /* Transmit next packet */ (void)USBD_LL_Transmit(pdev, CDC_RNDIS_IN_EP, hcdc->TxBuffer, hcdc->TxLength); - ret = USBD_OK; + ret = USBD_OK; } return (uint8_t)ret; @@ -1160,26 +1174,28 @@ uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev, switch (Notif) { - case RESPONSE_AVAILABLE: - (hcdc->Req).wValue = 0U; - (hcdc->Req).wIndex = CDC_RNDIS_CMD_ITF_NBR; - (hcdc->Req).wLength = 0U; - for (Idx = 0U; Idx < 8U; Idx++) - { - (hcdc->Req).data[Idx] = 0U; - } - ReqSize = 8U; - break; + case RESPONSE_AVAILABLE: + (hcdc->Req).wValue = 0U; + (hcdc->Req).wIndex = CDC_RNDIS_CMD_ITF_NBR; + (hcdc->Req).wLength = 0U; - default: - ret = USBD_FAIL; - break; + for (Idx = 0U; Idx < 8U; Idx++) + { + (hcdc->Req).data[Idx] = 0U; + } + + ReqSize = 8U; + break; + + default: + ret = USBD_FAIL; + break; } /* Transmit notification packet */ if (ReqSize != 0U) { - (void)USBD_LL_Transmit(pdev, CDC_RNDIS_CMD_EP, (uint8_t *)&(hcdc->Req), ReqSize); + (void)USBD_LL_Transmit(pdev, CDC_RNDIS_CMD_EP, (uint8_t *) &(hcdc->Req), ReqSize); } return (uint8_t)ret; @@ -1203,39 +1219,39 @@ static uint8_t USBD_CDC_RNDIS_MsgParsing(USBD_HandleTypeDef *pdev, uint8_t *RxBu switch (Msg->MsgType) { /* CDC_RNDIS Initialize message */ - case CDC_RNDIS_INITIALIZE_MSG_ID: - ret = USBD_CDC_RNDIS_ProcessInitMsg(pdev, (USBD_CDC_RNDIS_InitMsgTypeDef *)(void *)Msg); - break; + case CDC_RNDIS_INITIALIZE_MSG_ID: + ret = USBD_CDC_RNDIS_ProcessInitMsg(pdev, (USBD_CDC_RNDIS_InitMsgTypeDef *)(void *)Msg); + break; /* CDC_RNDIS Halt message */ - case CDC_RNDIS_HALT_MSG_ID: - ret = USBD_CDC_RNDIS_ProcessHaltMsg(pdev, (USBD_CDC_RNDIS_HaltMsgTypeDef *)(void *)Msg); - break; + case CDC_RNDIS_HALT_MSG_ID: + ret = USBD_CDC_RNDIS_ProcessHaltMsg(pdev, (USBD_CDC_RNDIS_HaltMsgTypeDef *)(void *)Msg); + break; /* CDC_RNDIS Query message */ - case CDC_RNDIS_QUERY_MSG_ID: - ret = USBD_CDC_RNDIS_ProcessQueryMsg(pdev, (USBD_CDC_RNDIS_QueryMsgTypeDef *)(void *)Msg); - break; + case CDC_RNDIS_QUERY_MSG_ID: + ret = USBD_CDC_RNDIS_ProcessQueryMsg(pdev, (USBD_CDC_RNDIS_QueryMsgTypeDef *)(void *)Msg); + break; /* CDC_RNDIS Set message */ - case CDC_RNDIS_SET_MSG_ID: - ret = USBD_CDC_RNDIS_ProcessSetMsg(pdev, (USBD_CDC_RNDIS_SetMsgTypeDef *)(void *)Msg); - break; + case CDC_RNDIS_SET_MSG_ID: + ret = USBD_CDC_RNDIS_ProcessSetMsg(pdev, (USBD_CDC_RNDIS_SetMsgTypeDef *)(void *)Msg); + break; /* CDC_RNDIS Reset message */ - case CDC_RNDIS_RESET_MSG_ID: - ret = USBD_CDC_RNDIS_ProcessResetMsg(pdev, (USBD_CDC_RNDIS_ResetMsgTypeDef *)(void *)Msg); - break; + case CDC_RNDIS_RESET_MSG_ID: + ret = USBD_CDC_RNDIS_ProcessResetMsg(pdev, (USBD_CDC_RNDIS_ResetMsgTypeDef *)(void *)Msg); + break; /* CDC_RNDIS Keep-Alive message */ - case CDC_RNDIS_KEEPALIVE_MSG_ID: - ret = USBD_CDC_RNDIS_ProcessKeepAliveMsg(pdev, (USBD_CDC_RNDIS_KpAliveMsgTypeDef *)(void *)Msg); - break; + case CDC_RNDIS_KEEPALIVE_MSG_ID: + ret = USBD_CDC_RNDIS_ProcessKeepAliveMsg(pdev, (USBD_CDC_RNDIS_KpAliveMsgTypeDef *)(void *)Msg); + break; /* CDC_RNDIS unsupported message */ - default: - ret = USBD_CDC_RNDIS_ProcessUnsupportedMsg(pdev, (USBD_CDC_RNDIS_CtrlMsgTypeDef *)(void *)Msg); - break; + default: + ret = USBD_CDC_RNDIS_ProcessUnsupportedMsg(pdev, (USBD_CDC_RNDIS_CtrlMsgTypeDef *)(void *)Msg); + break; } return ret; @@ -1318,7 +1334,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessHaltMsg(USBD_HandleTypeDef *pdev, /* Set CDC_RNDIS state to INITIALIZED */ hcdc->State = CDC_RNDIS_STATE_UNINITIALIZED; - /* No response required for this message, so no notification (RESPNSE_AVAILABLE) is sent */ + /* No response required for this message, so no notification (RESPONSE_AVAILABLE) is sent */ UNUSED(Msg); @@ -1393,106 +1409,106 @@ static uint8_t USBD_CDC_RNDIS_ProcessQueryMsg(USBD_HandleTypeDef *pdev, /* Process the OID depending on its code */ switch (Msg->Oid) { - case OID_GEN_SUPPORTED_LIST: - QueryResponse->InfoBufLength = sizeof(CDC_RNDIS_SupportedOIDs); - (void)USBD_memcpy(QueryResponse->InfoBuf, CDC_RNDIS_SupportedOIDs, - sizeof(CDC_RNDIS_SupportedOIDs)); + case OID_GEN_SUPPORTED_LIST: + QueryResponse->InfoBufLength = sizeof(CDC_RNDIS_SupportedOIDs); + (void)USBD_memcpy(QueryResponse->InfoBuf, CDC_RNDIS_SupportedOIDs, + sizeof(CDC_RNDIS_SupportedOIDs)); - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_HARDWARE_STATUS: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = CDC_RNDIS_HW_STS_READY; - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_HARDWARE_STATUS: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = CDC_RNDIS_HW_STS_READY; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_MEDIA_SUPPORTED: - case OID_GEN_MEDIA_IN_USE: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = CDC_RNDIS_MEDIUM_802_3; - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_MEDIA_SUPPORTED: + case OID_GEN_MEDIA_IN_USE: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = CDC_RNDIS_MEDIUM_802_3; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_VENDOR_ID: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = USBD_CDC_RNDIS_VID; - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_VENDOR_ID: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = USBD_CDC_RNDIS_VID; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_MAXIMUM_FRAME_SIZE: - case OID_GEN_TRANSMIT_BLOCK_SIZE: - case OID_GEN_RECEIVE_BLOCK_SIZE: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = CDC_RNDIS_ETH_FRAME_SIZE_MAX; - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_MAXIMUM_FRAME_SIZE: + case OID_GEN_TRANSMIT_BLOCK_SIZE: + case OID_GEN_RECEIVE_BLOCK_SIZE: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = CDC_RNDIS_ETH_FRAME_SIZE_MAX; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_VENDOR_DESCRIPTION: - QueryResponse->InfoBufLength = (strlen(USBD_CDC_RNDIS_VENDOR_DESC) + 1U); - (void)USBD_memcpy(QueryResponse->InfoBuf, USBD_CDC_RNDIS_VENDOR_DESC, - strlen(USBD_CDC_RNDIS_VENDOR_DESC)); + case OID_GEN_VENDOR_DESCRIPTION: + QueryResponse->InfoBufLength = (strlen(USBD_CDC_RNDIS_VENDOR_DESC) + 1U); + (void)USBD_memcpy(QueryResponse->InfoBuf, USBD_CDC_RNDIS_VENDOR_DESC, + strlen(USBD_CDC_RNDIS_VENDOR_DESC)); - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_MEDIA_CONNECT_STATUS: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = CDC_RNDIS_MEDIA_STATE_CONNECTED; - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_MEDIA_CONNECT_STATUS: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = CDC_RNDIS_MEDIA_STATE_CONNECTED; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_MAXIMUM_SEND_PACKETS: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = 1U; - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_MAXIMUM_SEND_PACKETS: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = 1U; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_LINK_SPEED: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = USBD_CDC_RNDIS_LINK_SPEED; - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_LINK_SPEED: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = USBD_CDC_RNDIS_LINK_SPEED; + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_802_3_PERMANENT_ADDRESS: - case OID_802_3_CURRENT_ADDRESS: - QueryResponse->InfoBufLength = 6U; - (void)USBD_memcpy(QueryResponse->InfoBuf, MAC_StrDesc, 6); - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_802_3_PERMANENT_ADDRESS: + case OID_802_3_CURRENT_ADDRESS: + QueryResponse->InfoBufLength = 6U; + (void)USBD_memcpy(QueryResponse->InfoBuf, MAC_StrDesc, 6); + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_802_3_MAXIMUM_LIST_SIZE: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = 1U; /* Only one multicast address supported */ - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_802_3_MAXIMUM_LIST_SIZE: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = 1U; /* Only one multicast address supported */ + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_CURRENT_PACKET_FILTER: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = 0xFFFFFFU; /* USBD_CDC_RNDIS_DEVICE.packetFilter; */ - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_CURRENT_PACKET_FILTER: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = 0xFFFFFFU; /* USBD_CDC_RNDIS_DEVICE.packetFilter; */ + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_802_3_RCV_ERROR_ALIGNMENT: - case OID_802_3_XMIT_ONE_COLLISION: - case OID_802_3_XMIT_MORE_COLLISIONS: - QueryResponse->InfoBufLength = sizeof(uint32_t); - QueryResponse->InfoBuf[0] = 0U; /* Unused OIDs, return zero */ - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_802_3_RCV_ERROR_ALIGNMENT: + case OID_802_3_XMIT_ONE_COLLISION: + case OID_802_3_XMIT_MORE_COLLISIONS: + QueryResponse->InfoBufLength = sizeof(uint32_t); + QueryResponse->InfoBuf[0] = 0U; /* Unused OIDs, return zero */ + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_GEN_MAXIMUM_TOTAL_SIZE: - QueryResponse->InfoBufLength = sizeof(uint32_t); - /* Indicate maximum overall buffer (Ethernet frame and CDC_RNDIS header) the adapter can handle */ - QueryResponse->InfoBuf[0] = (CDC_RNDIS_MESSAGE_BUFFER_SIZE + CDC_RNDIS_ETH_FRAME_SIZE_MAX); - QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_MAXIMUM_TOTAL_SIZE: + QueryResponse->InfoBufLength = sizeof(uint32_t); + /* Indicate maximum overall buffer (Ethernet frame and CDC_RNDIS header) the adapter can handle */ + QueryResponse->InfoBuf[0] = (CDC_RNDIS_MESSAGE_BUFFER_SIZE + CDC_RNDIS_ETH_FRAME_SIZE_MAX); + QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - default: - /* Unknown or unsupported OID */ - QueryResponse->InfoBufLength = 0U; - QueryResponse->Status = CDC_RNDIS_STATUS_FAILURE; - break; + default: + /* Unknown or unsupported OID */ + QueryResponse->InfoBufLength = 0U; + QueryResponse->Status = CDC_RNDIS_STATUS_FAILURE; + break; } /* Setup the response buffer content */ @@ -1507,7 +1523,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessQueryMsg(USBD_HandleTypeDef *pdev, /* Send Notification on Interrupt EP to inform Host that response is ready */ (void)USBD_CDC_RNDIS_SendNotification(pdev, RESPONSE_AVAILABLE, 0U, NULL); - return(uint8_t)USBD_OK; + return (uint8_t)USBD_OK; } @@ -1535,21 +1551,21 @@ static uint8_t USBD_CDC_RNDIS_ProcessSetMsg(USBD_HandleTypeDef *pdev, switch (SetMessage->Oid) { - case OID_GEN_CURRENT_PACKET_FILTER: - /* Setup the packet filter value */ - hcdc->PacketFilter = SetMessage->InfoBuf[0]; - SetResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_GEN_CURRENT_PACKET_FILTER: + /* Setup the packet filter value */ + hcdc->PacketFilter = SetMessage->InfoBuf[0]; + SetResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - case OID_802_3_MULTICAST_LIST: - /* List of multicast addresses on a miniport adapter */ - SetResponse->Status = CDC_RNDIS_STATUS_SUCCESS; - break; + case OID_802_3_MULTICAST_LIST: + /* List of multicast addresses on a miniport adapter */ + SetResponse->Status = CDC_RNDIS_STATUS_SUCCESS; + break; - default: - /* Report an error */ - SetResponse->Status = CDC_RNDIS_STATUS_FAILURE; - break; + default: + /* Report an error */ + SetResponse->Status = CDC_RNDIS_STATUS_FAILURE; + break; } /* Prepare response buffer */ @@ -1637,7 +1653,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessPacketMsg(USBD_HandleTypeDef *pdev, return (uint8_t)USBD_FAIL; } - /* Point to the payload and udpate the message length */ + /* Point to the payload and update the message length */ /* Use temporary storage variables to comply with MISRA-C 2012 rule of (+) operand allowed types */ tmp1 = (uint32_t)PacketMsg; @@ -1653,12 +1669,12 @@ static uint8_t USBD_CDC_RNDIS_ProcessPacketMsg(USBD_HandleTypeDef *pdev, /** -* @brief USBD_CDC_RNDIS_ProcessUnsupportedMsg -* Parse, extract data and check correctness of CDC_RNDIS KeepAlive command. -* @param pdev: USB Device Handle pointer -* @param Msg: Pointer to the message data extracted from SendEncapsulated command -* @retval status -*/ + * @brief USBD_CDC_RNDIS_ProcessUnsupportedMsg + * Parse, extract data and check correctness of CDC_RNDIS KeepAlive command. + * @param pdev: USB Device Handle pointer + * @param Msg: Pointer to the message data extracted from SendEncapsulated command + * @retval status + */ static uint8_t USBD_CDC_RNDIS_ProcessUnsupportedMsg(USBD_HandleTypeDef *pdev, USBD_CDC_RNDIS_CtrlMsgTypeDef *Msg) { diff --git a/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c b/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c index 9408d43..ad88c32 100644 --- a/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c +++ b/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c @@ -38,12 +38,12 @@ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif __ALIGN_BEGIN uint8_t UserRxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END; /* Received Data over USB are stored in this buffer */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif __ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END; /* Received Data over CDC_RNDIS (CDC_RNDIS interface) are stored in this buffer */ @@ -179,14 +179,14 @@ static int8_t CDC_RNDIS_Itf_Receive(uint8_t *Buf, uint32_t *Len) hcdc_cdc_rndis->RxState = 1U; UNUSED(Buf); - UNUSED(Len); + UNUSED(Len); return (0); } /** * @brief CDC_RNDIS_Itf_TransmitCplt - * Data transmited callback + * Data transmitted callback * * @note * This function is IN transfer complete callback used to inform user that diff --git a/Class/CustomHID/Inc/usbd_customhid.h b/Class/CustomHID/Inc/usbd_customhid.h index a1dcd7c..da01685 100644 --- a/Class/CustomHID/Inc/usbd_customhid.h +++ b/Class/CustomHID/Inc/usbd_customhid.h @@ -42,10 +42,16 @@ extern "C" { * @{ */ #define CUSTOM_HID_EPIN_ADDR 0x81U + +#ifndef CUSTOM_HID_EPIN_SIZE #define CUSTOM_HID_EPIN_SIZE 0x02U +#endif #define CUSTOM_HID_EPOUT_ADDR 0x01U + +#ifndef CUSTOM_HID_EPOUT_SIZE #define CUSTOM_HID_EPOUT_SIZE 0x02U +#endif #define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U #define USB_CUSTOM_HID_DESC_SIZ 9U diff --git a/Class/CustomHID/Src/usbd_customhid.c b/Class/CustomHID/Src/usbd_customhid.c index 2680274..bdb25f8 100644 --- a/Class/CustomHID/Src/usbd_customhid.c +++ b/Class/CustomHID/Src/usbd_customhid.c @@ -128,14 +128,17 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DES { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_CUSTOM_HID_CONFIG_DESC_SIZ, - /* wTotalLength: Bytes returned */ + USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: bus powered */ - 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /************** Descriptor of CUSTOM HID interface ****************/ /* 09 */ @@ -186,14 +189,17 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DES { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_CUSTOM_HID_CONFIG_DESC_SIZ, - /* wTotalLength: Bytes returned */ + USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: bus powered */ - 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /************** Descriptor of CUSTOM HID interface ****************/ /* 09 */ @@ -244,14 +250,17 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CO { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_CUSTOM_HID_CONFIG_DESC_SIZ, - /* wTotalLength: Bytes returned */ + USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: bus powered */ - 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /************** Descriptor of CUSTOM HID interface ****************/ /* 09 */ @@ -282,7 +291,7 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CO CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */ 0x03, /* bmAttributes: Interrupt endpoint */ - CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Byte max */ + CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Bytes max */ 0x00, CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ /* 34 */ @@ -412,7 +421,7 @@ static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 0U; pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = 0U; - /* FRee allocated memory */ + /* Free allocated memory */ if (pdev->pClassData != NULL) { ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit(); @@ -441,108 +450,108 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS: - switch (req->bRequest) - { - case CUSTOM_HID_REQ_SET_PROTOCOL: - hhid->Protocol = (uint8_t)(req->wValue); + case USB_REQ_TYPE_CLASS: + switch (req->bRequest) + { + case CUSTOM_HID_REQ_SET_PROTOCOL: + hhid->Protocol = (uint8_t)(req->wValue); + break; + + case CUSTOM_HID_REQ_GET_PROTOCOL: + (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U); + break; + + case CUSTOM_HID_REQ_SET_IDLE: + hhid->IdleState = (uint8_t)(req->wValue >> 8); + break; + + case CUSTOM_HID_REQ_GET_IDLE: + (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U); + break; + + case CUSTOM_HID_REQ_SET_REPORT: + hhid->IsReportAvailable = 1U; + (void)USBD_CtlPrepareRx(pdev, hhid->Report_buf, req->wLength); + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; - case CUSTOM_HID_REQ_GET_PROTOCOL: - (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U); - break; + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) + { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case CUSTOM_HID_REQ_SET_IDLE: - hhid->IdleState = (uint8_t)(req->wValue >> 8); - break; + case USB_REQ_GET_DESCRIPTOR: + if ((req->wValue >> 8) == CUSTOM_HID_REPORT_DESC) + { + len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength); + pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport; + } + else + { + if ((req->wValue >> 8) == CUSTOM_HID_DESCRIPTOR_TYPE) + { + pbuf = USBD_CUSTOM_HID_Desc; + len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength); + } + } - case CUSTOM_HID_REQ_GET_IDLE: - (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U); - break; + (void)USBD_CtlSendData(pdev, pbuf, len); + break; - case CUSTOM_HID_REQ_SET_REPORT: - hhid->IsReportAvailable = 1U; - (void)USBD_CtlPrepareRx(pdev, hhid->Report_buf, req->wLength); + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + hhid->AltSetting = (uint8_t)(req->wValue); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_GET_DESCRIPTOR: - if ((req->wValue >> 8) == CUSTOM_HID_REPORT_DESC) - { - len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength); - pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport; - } - else - { - if ((req->wValue >> 8) == CUSTOM_HID_DESCRIPTOR_TYPE) - { - pbuf = USBD_CUSTOM_HID_Desc; - len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength); - } - } - - (void)USBD_CtlSendData(pdev, pbuf, len); - break; - - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hhid->AltSetting = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_CLEAR_FEATURE: - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; } @@ -564,7 +573,7 @@ uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, return (uint8_t)USBD_FAIL; } - hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; + hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; if (pdev->dev_state == USBD_STATE_CONFIGURED) { @@ -658,7 +667,7 @@ static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) return (uint8_t)USBD_FAIL; } - hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; + hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the application processing */ @@ -684,7 +693,7 @@ uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev) return (uint8_t)USBD_FAIL; } - hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; + hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; /* Resume USB Out process */ (void)USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf, @@ -715,11 +724,11 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev) } /** -* @brief DeviceQualifierDescriptor -* return Device Qualifier descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc); @@ -728,7 +737,7 @@ static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length) } /** -* @brief USBD_CUSTOM_HID_RegisterInterface + * @brief USBD_CUSTOM_HID_RegisterInterface * @param pdev: device instance * @param fops: CUSTOMHID Interface callback * @retval status diff --git a/Class/CustomHID/Src/usbd_customhid_if_template.c b/Class/CustomHID/Src/usbd_customhid_if_template.c index 1fb6edd..97e4337 100644 --- a/Class/CustomHID/Src/usbd_customhid_if_template.c +++ b/Class/CustomHID/Src/usbd_customhid_if_template.c @@ -83,7 +83,7 @@ static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state) UNUSED(event_idx); UNUSED(state); - /* Start next USB packet transfer once data processing is completed */ + /* Start next USB packet transfer once data processing is completed */ USBD_CUSTOM_HID_ReceivePacket(&USBD_Device); return (0); diff --git a/Class/DFU/Inc/usbd_dfu_media_template.h b/Class/DFU/Inc/usbd_dfu_media_template.h index 1ba1422..25efe52 100644 --- a/Class/DFU/Inc/usbd_dfu_media_template.h +++ b/Class/DFU/Inc/usbd_dfu_media_template.h @@ -92,6 +92,6 @@ extern USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops; */ /** -* @} -*/ + * @} + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/DFU/Src/usbd_dfu.c b/Class/DFU/Src/usbd_dfu.c index d179650..db86c05 100644 --- a/Class/DFU/Src/usbd_dfu.c +++ b/Class/DFU/Src/usbd_dfu.c @@ -153,16 +153,19 @@ USBD_ClassTypeDef USBD_DFU = /* USB DFU device Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END = { - 0x09, /* bLength: Configuation Descriptor size */ + 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_DFU_CONFIG_DESC_SIZ, - /* wTotalLength: Bytes returned */ + USB_DFU_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x02, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: bus powered and Supprts Remote Wakeup */ - 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /* 09 */ /********** Descriptor of DFU interface 0 Alternate setting 0 **************/ @@ -339,116 +342,116 @@ static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS: - switch (req->bRequest) - { - case DFU_DNLOAD: - DFU_Download(pdev, req); - break; - - case DFU_UPLOAD: - DFU_Upload(pdev, req); - break; - - case DFU_GETSTATUS: - DFU_GetStatus(pdev); - break; - - case DFU_CLRSTATUS: - DFU_ClearStatus(pdev); - break; - - case DFU_GETSTATE: - DFU_GetState(pdev); - break; - - case DFU_ABORT: - DFU_Abort(pdev); - break; - - case DFU_DETACH: - DFU_Detach(pdev, req); - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) + case USB_REQ_TYPE_CLASS: + switch (req->bRequest) { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case DFU_DNLOAD: + DFU_Download(pdev, req); + break; - case USB_REQ_GET_DESCRIPTOR: - if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE) - { - pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U)); - len = MIN(USB_DFU_DESC_SIZ, req->wLength); - } + case DFU_UPLOAD: + DFU_Upload(pdev, req); + break; - (void)USBD_CtlSendData(pdev, pbuf, len); - break; + case DFU_GETSTATUS: + DFU_GetStatus(pdev); + break; - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)hdfu->alt_setting, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case DFU_CLRSTATUS: + DFU_ClearStatus(pdev); + break; - case USB_REQ_SET_INTERFACE: - if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM) - { - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hdfu->alt_setting = (uint8_t)(req->wValue); - } - else - { + case DFU_GETSTATE: + DFU_GetState(pdev); + break; + + case DFU_ABORT: + DFU_Abort(pdev); + break; + + case DFU_DETACH: + DFU_Detach(pdev, req); + break; + + default: USBD_CtlError(pdev, req); ret = USBD_FAIL; - } - } - else - { - /* Call the error management function (command will be nacked */ - USBD_CtlError(pdev, req); - ret = USBD_FAIL; + break; } break; - case USB_REQ_CLEAR_FEATURE: + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) + { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_DESCRIPTOR: + if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE) + { + pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U)); + len = MIN(USB_DFU_DESC_SIZ, req->wLength); + } + + (void)USBD_CtlSendData(pdev, pbuf, len); + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&hdfu->alt_setting, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM) + { + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + hdfu->alt_setting = (uint8_t)(req->wValue); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + } + else + { + /* Call the error management function (command will be NAKed */ + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; @@ -497,14 +500,14 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev) if (hdfu->dev_state == DFU_STATE_DNLOAD_BUSY) { - /* Decode the Special Command*/ + /* Decode the Special Command */ if (hdfu->wblock_num == 0U) { - if(hdfu->wlength == 1U) + if (hdfu->wlength == 1U) { if (hdfu->buffer.d8[0] == DFU_CMD_GETCOMMANDS) { - /* nothink to do */ + /* Nothing to do */ } } else if (hdfu->wlength == 5U) @@ -530,7 +533,7 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev) } else { - /* .. */ + return (uint8_t)USBD_FAIL; } } else @@ -538,7 +541,7 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev) /* Reset the global length and block number */ hdfu->wlength = 0U; hdfu->wblock_num = 0U; - /* Call the error management function (command will be nacked) */ + /* Call the error management function (command will be NAKed) */ req.bmRequest = 0U; req.wLength = 1U; USBD_CtlError(pdev, &req); @@ -552,7 +555,7 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev) /* Decode the required address */ addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr; - /* Preform the write operation */ + /* Perform the write operation */ if (DfuInterface->Write(hdfu->buffer.d8, (uint8_t *)addr, hdfu->wlength) != USBD_OK) { return (uint8_t)USBD_FAIL; @@ -579,7 +582,7 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev) } else { - /* .. */ + return (uint8_t)USBD_FAIL; } return (uint8_t)USBD_OK; @@ -599,11 +602,11 @@ static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev) /** -* @brief DeviceQualifierDescriptor -* return Device Qualifier descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_DFU_DeviceQualifierDesc); @@ -615,7 +618,7 @@ static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length) * @brief USBD_DFU_GetUsrStringDesc * Manages the transfer of memory interfaces string descriptors. * @param speed : current device speed - * @param index: desciptor index + * @param index: descriptor index * @param length : pointer data length * @retval pointer to the descriptor table or NULL if the descriptor is not supported. */ @@ -640,10 +643,10 @@ static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t inde #endif /** -* @brief USBD_MSC_RegisterStorage -* @param fops: storage callback -* @retval status -*/ + * @brief USBD_MSC_RegisterStorage + * @param fops: storage callback + * @retval status + */ uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev, USBD_DFU_MediaTypeDef *fops) { @@ -659,7 +662,7 @@ uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev, /****************************************************************************** DFU Class requests management -******************************************************************************/ + ******************************************************************************/ /** * @brief DFU_Detach * Handles the DFU DETACH request. @@ -733,7 +736,7 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) /* Unsupported state */ else { - /* Call the error management function (command will be nacked */ + /* Call the error management function (command will be NAKed */ USBD_CtlError(pdev, req); } } @@ -752,7 +755,7 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) } else { - /* Call the error management function (command will be nacked */ + /* Call the error management function (command will be NAKed */ USBD_CtlError(pdev, req); } } @@ -826,7 +829,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) hdfu->dev_status[3] = 0U; hdfu->dev_status[4] = hdfu->dev_state; - /* Call the error management function (command will be nacked */ + /* Call the error management function (command will be NAKed */ USBD_CtlError(pdev, req); } } @@ -836,7 +839,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) hdfu->wlength = 0U; hdfu->wblock_num = 0U; - /* Call the error management function (command will be nacked */ + /* Call the error management function (command will be NAKed */ USBD_CtlError(pdev, req); } } @@ -865,63 +868,63 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev) switch (hdfu->dev_state) { - case DFU_STATE_DNLOAD_SYNC: - if (hdfu->wlength != 0U) - { - hdfu->dev_state = DFU_STATE_DNLOAD_BUSY; - - hdfu->dev_status[1] = 0U; - hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; - hdfu->dev_status[4] = hdfu->dev_state; - - if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE)) + case DFU_STATE_DNLOAD_SYNC: + if (hdfu->wlength != 0U) { - DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_ERASE, hdfu->dev_status); + hdfu->dev_state = DFU_STATE_DNLOAD_BUSY; + + hdfu->dev_status[1] = 0U; + hdfu->dev_status[2] = 0U; + hdfu->dev_status[3] = 0U; + hdfu->dev_status[4] = hdfu->dev_state; + + if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE)) + { + DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_ERASE, hdfu->dev_status); + } + else + { + DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status); + } } - else + else /* (hdfu->wlength==0)*/ { - DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status); - } - } - else /* (hdfu->wlength==0)*/ - { - hdfu->dev_state = DFU_STATE_DNLOAD_IDLE; - - hdfu->dev_status[1] = 0U; - hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; - hdfu->dev_status[4] = hdfu->dev_state; - } - break; - - case DFU_STATE_MANIFEST_SYNC: - if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS) - { - hdfu->dev_state = DFU_STATE_MANIFEST; - - hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/ - hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; - hdfu->dev_status[4] = hdfu->dev_state; - } - else - { - if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) && - (((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U) != 0U)) - { - hdfu->dev_state = DFU_STATE_IDLE; + hdfu->dev_state = DFU_STATE_DNLOAD_IDLE; hdfu->dev_status[1] = 0U; hdfu->dev_status[2] = 0U; hdfu->dev_status[3] = 0U; hdfu->dev_status[4] = hdfu->dev_state; } - } - break; + break; - default: - break; + case DFU_STATE_MANIFEST_SYNC: + if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS) + { + hdfu->dev_state = DFU_STATE_MANIFEST; + + hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/ + hdfu->dev_status[2] = 0U; + hdfu->dev_status[3] = 0U; + hdfu->dev_status[4] = hdfu->dev_state; + } + else + { + if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) && + (((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U) != 0U)) + { + hdfu->dev_state = DFU_STATE_IDLE; + + hdfu->dev_status[1] = 0U; + hdfu->dev_status[2] = 0U; + hdfu->dev_status[3] = 0U; + hdfu->dev_status[4] = hdfu->dev_state; + } + } + break; + + default: + break; } /* Send the status data over EP0 */ @@ -941,23 +944,23 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev) if (hdfu->dev_state == DFU_STATE_ERROR) { hdfu->dev_state = DFU_STATE_IDLE; - hdfu->dev_status[0] = DFU_ERROR_NONE; /*bStatus*/ + hdfu->dev_status[0] = DFU_ERROR_NONE; /* bStatus */ hdfu->dev_status[1] = 0U; hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; /*bwPollTimeout=0ms*/ - hdfu->dev_status[4] = hdfu->dev_state; /*bState*/ - hdfu->dev_status[5] = 0U; /*iString*/ + hdfu->dev_status[3] = 0U; /* bwPollTimeout=0ms */ + hdfu->dev_status[4] = hdfu->dev_state; /* bState */ + hdfu->dev_status[5] = 0U; /* iString */ } else { - /*State Error*/ + /* State Error */ hdfu->dev_state = DFU_STATE_ERROR; - hdfu->dev_status[0] = DFU_ERROR_UNKNOWN; /*bStatus*/ + hdfu->dev_status[0] = DFU_ERROR_UNKNOWN; /* bStatus */ hdfu->dev_status[1] = 0U; hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; /*bwPollTimeout=0ms*/ - hdfu->dev_status[4] = hdfu->dev_state; /*bState*/ - hdfu->dev_status[5] = 0U; /*iString*/ + hdfu->dev_status[3] = 0U; /* bwPollTimeout=0ms */ + hdfu->dev_status[4] = hdfu->dev_state; /* bState */ + hdfu->dev_status[5] = 0U; /* iString */ } } @@ -996,9 +999,9 @@ static void DFU_Abort(USBD_HandleTypeDef *pdev) hdfu->dev_status[0] = DFU_ERROR_NONE; hdfu->dev_status[1] = 0U; hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; /*bwPollTimeout=0ms*/ + hdfu->dev_status[3] = 0U; /* bwPollTimeout=0ms */ hdfu->dev_status[4] = hdfu->dev_state; - hdfu->dev_status[5] = 0U; /*iString*/ + hdfu->dev_status[5] = 0U; /* iString */ hdfu->wblock_num = 0U; hdfu->wlength = 0U; } diff --git a/Class/HID/Inc/usbd_hid.h b/Class/HID/Inc/usbd_hid.h index 40ed729..76fcdc7 100644 --- a/Class/HID/Inc/usbd_hid.h +++ b/Class/HID/Inc/usbd_hid.h @@ -116,7 +116,7 @@ extern USBD_ClassTypeDef USBD_HID; /** @defgroup USB_CORE_Exported_Functions * @{ */ -uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report,uint16_t len); +uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len); uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev); /** diff --git a/Class/HID/Src/usbd_hid.c b/Class/HID/Src/usbd_hid.c index c73dace..da1dd1c 100644 --- a/Class/HID/Src/usbd_hid.c +++ b/Class/HID/Src/usbd_hid.c @@ -105,7 +105,8 @@ static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length); * @{ */ -USBD_ClassTypeDef USBD_HID = { +USBD_ClassTypeDef USBD_HID = +{ USBD_HID_Init, USBD_HID_DeInit, USBD_HID_Setup, @@ -123,17 +124,21 @@ USBD_ClassTypeDef USBD_HID = { }; /* USB HID device FS Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = { +__ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = +{ 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_HID_CONFIG_DESC_SIZ, - /* wTotalLength: Bytes returned */ + USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xE0, /* bmAttributes: bus powered and Support Remote Wake-up */ - 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xE0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0xA0, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /************** Descriptor of Joystick Mouse interface ****************/ /* 09 */ @@ -171,17 +176,21 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN }; /* USB HID device HS Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = { +__ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = +{ 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_HID_CONFIG_DESC_SIZ, - /* wTotalLength: Bytes returned */ + USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xE0, /* bmAttributes: bus powered and Support Remote Wake-up */ - 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xE0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0xA0, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /************** Descriptor of Joystick Mouse interface ****************/ /* 09 */ @@ -219,17 +228,21 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN }; /* USB HID device Other Speed Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = { +__ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = +{ 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_HID_CONFIG_DESC_SIZ, - /* wTotalLength: Bytes returned */ + USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xE0, /* bmAttributes: bus powered and Support Remote Wake-up */ - 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ +#if (USBD_SELF_POWERED == 1U) + 0xE0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0xA0, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */ /************** Descriptor of Joystick Mouse interface ****************/ /* 09 */ @@ -268,7 +281,8 @@ __ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ] /* USB HID device Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END = { +__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END = +{ /* 18 */ 0x09, /* bLength: HID Descriptor size */ HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */ @@ -282,7 +296,8 @@ __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END = { }; /* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { +__ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = +{ USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -295,7 +310,8 @@ __ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_ 0x00, }; -__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END = { +__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END = +{ 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, @@ -384,7 +400,7 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = HID_FS_BINTERVAL; } - /* Open EP IN */ + /* Open EP IN */ (void)USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE); pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 1U; @@ -409,7 +425,7 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U; pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = 0U; - /* FRee allocated memory */ + /* Free allocated memory */ if (pdev->pClassData != NULL) { (void)USBD_free(pdev->pClassData); @@ -436,104 +452,104 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS : - switch (req->bRequest) - { - case HID_REQ_SET_PROTOCOL: - hhid->Protocol = (uint8_t)(req->wValue); - break; + case USB_REQ_TYPE_CLASS : + switch (req->bRequest) + { + case HID_REQ_SET_PROTOCOL: + hhid->Protocol = (uint8_t)(req->wValue); + break; - case HID_REQ_GET_PROTOCOL: - (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U); - break; + case HID_REQ_GET_PROTOCOL: + (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U); + break; - case HID_REQ_SET_IDLE: - hhid->IdleState = (uint8_t)(req->wValue >> 8); - break; + case HID_REQ_SET_IDLE: + hhid->IdleState = (uint8_t)(req->wValue >> 8); + break; - case HID_REQ_GET_IDLE: - (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U); + case HID_REQ_GET_IDLE: + (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U); + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + break; + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) + { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_DESCRIPTOR: + if ((req->wValue >> 8) == HID_REPORT_DESC) + { + len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength); + pbuf = HID_MOUSE_ReportDesc; + } + else if ((req->wValue >> 8) == HID_DESCRIPTOR_TYPE) + { + pbuf = USBD_HID_Desc; + len = MIN(USB_HID_DESC_SIZ, req->wLength); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + (void)USBD_CtlSendData(pdev, pbuf, len); + break; + + case USB_REQ_GET_INTERFACE : + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + hhid->AltSetting = (uint8_t)(req->wValue); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_GET_DESCRIPTOR: - if ((req->wValue >> 8) == HID_REPORT_DESC) - { - len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength); - pbuf = HID_MOUSE_ReportDesc; - } - else if ((req->wValue >> 8) == HID_DESCRIPTOR_TYPE) - { - pbuf = USBD_HID_Desc; - len = MIN(USB_HID_DESC_SIZ, req->wLength); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; - } - (void)USBD_CtlSendData(pdev, pbuf, len); - break; - - case USB_REQ_GET_INTERFACE : - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hhid->AltSetting = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_CLEAR_FEATURE: - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; @@ -651,11 +667,11 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) /** -* @brief DeviceQualifierDescriptor -* return Device Qualifier descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_HID_DeviceQualifierDesc); diff --git a/Class/MSC/Inc/usbd_msc_bot.h b/Class/MSC/Inc/usbd_msc_bot.h index f5b1b6d..fb99095 100644 --- a/Class/MSC/Inc/usbd_msc_bot.h +++ b/Class/MSC/Inc/usbd_msc_bot.h @@ -144,7 +144,7 @@ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, */ /** -* @} -*/ + * @} + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Inc/usbd_msc_data.h b/Class/MSC/Inc/usbd_msc_data.h index 26838de..3aacf04 100644 --- a/Class/MSC/Inc/usbd_msc_data.h +++ b/Class/MSC/Inc/usbd_msc_data.h @@ -99,7 +99,7 @@ extern uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN]; */ /** -* @} -*/ + * @} + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Inc/usbd_msc_scsi.h b/Class/MSC/Inc/usbd_msc_scsi.h index b32ded0..9bf10a9 100644 --- a/Class/MSC/Inc/usbd_msc_scsi.h +++ b/Class/MSC/Inc/usbd_msc_scsi.h @@ -178,8 +178,8 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, */ /** -* @} -*/ + * @} + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Inc/usbd_msc_storage_template.h b/Class/MSC/Inc/usbd_msc_storage_template.h index 0288c30..9591a3b 100644 --- a/Class/MSC/Inc/usbd_msc_storage_template.h +++ b/Class/MSC/Inc/usbd_msc_storage_template.h @@ -92,6 +92,6 @@ extern USBD_StorageTypeDef USBD_MSC_Template_fops; */ /** -* @} -*/ + * @} + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Src/usbd_msc.c b/Class/MSC/Src/usbd_msc.c index fe6e1c6..22b9cb0 100644 --- a/Class/MSC/Src/usbd_msc.c +++ b/Class/MSC/Src/usbd_msc.c @@ -123,7 +123,7 @@ USBD_ClassTypeDef USBD_MSC = /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { - 0x09, /* bLength: Configuation Descriptor size */ + 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_MSC_CONFIG_DESC_SIZ, @@ -131,8 +131,12 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIG 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ - 0xC0, /* bmAttributes: */ - 0x32, /* MaxPower 100 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /******************** Mass Storage interface ********************/ 0x09, /* bLength: Interface Descriptor size */ @@ -166,7 +170,7 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIG /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { - 0x09, /* bLength: Configuation Descriptor size */ + 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_MSC_CONFIG_DESC_SIZ, @@ -174,8 +178,12 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIG 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ - 0xC0, /* bmAttributes: */ - 0x32, /* MaxPower 100 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /******************** Mass Storage interface ********************/ 0x09, /* bLength: Interface Descriptor size */ @@ -207,7 +215,7 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIG __ALIGN_BEGIN static uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { - 0x09, /* bLength: Configuation Descriptor size */ + 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_MSC_CONFIG_DESC_SIZ, @@ -215,8 +223,12 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: */ 0x04, /* iConfiguration: */ - 0xC0, /* bmAttributes: */ - 0x32, /* MaxPower 100 mA */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ /******************** Mass Storage interface ********************/ 0x09, /* bLength: Interface Descriptor size */ @@ -320,7 +332,7 @@ uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) /** * @brief USBD_MSC_DeInit - * DeInitilaize the mass storage configuration + * DeInitialize the mass storage configuration * @param pdev: device instance * @param cfgidx: configuration index * @retval status @@ -350,12 +362,12 @@ uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) return (uint8_t)USBD_OK; } /** -* @brief USBD_MSC_Setup -* Handle the MSC specific requests -* @param pdev: device instance -* @param req: USB request -* @retval status -*/ + * @brief USBD_MSC_Setup + * Handle the MSC specific requests + * @param pdev: device instance + * @param req: USB request + * @retval status + */ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -365,93 +377,100 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* Class request */ - case USB_REQ_TYPE_CLASS: - switch (req->bRequest) - { - case BOT_GET_MAX_LUN: - if ((req->wValue == 0U) && (req->wLength == 1U) && - ((req->bmRequest & 0x80U) == 0x80U)) + case USB_REQ_TYPE_CLASS: + switch (req->bRequest) { - hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun(); - (void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->max_lun, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case BOT_GET_MAX_LUN: + if ((req->wValue == 0U) && (req->wLength == 1U) && + ((req->bmRequest & 0x80U) == 0x80U)) + { + hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun(); + (void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->max_lun, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case BOT_RESET : - if ((req->wValue == 0U) && (req->wLength == 0U) && - ((req->bmRequest & 0x80U) != 0x80U)) - { - MSC_BOT_Reset(pdev); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case BOT_RESET : + if ((req->wValue == 0U) && (req->wLength == 0U) && + ((req->bmRequest & 0x80U) != 0x80U)) + { + MSC_BOT_Reset(pdev); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; - } - break; /* Interface & Endpoint request */ - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->interface, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->interface, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hmsc->interface = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + hmsc->interface = (uint8_t)(req->wValue); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; - case USB_REQ_CLEAR_FEATURE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (req->wValue == USB_FEATURE_EP_HALT) - { - /* Flush the FIFO */ - (void)USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex); + case USB_REQ_CLEAR_FEATURE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + if (req->wValue == USB_FEATURE_EP_HALT) + { + /* Flush the FIFO */ + (void)USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex); - /* Handle BOT error */ - MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex); - } + /* Handle BOT error */ + MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex); + } + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; @@ -459,25 +478,18 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; } /** -* @brief USBD_MSC_DataIn -* handle data IN Stage -* @param pdev: device instance -* @param epnum: endpoint index -* @retval status -*/ + * @brief USBD_MSC_DataIn + * handle data IN Stage + * @param pdev: device instance + * @param epnum: endpoint index + * @retval status + */ uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { MSC_BOT_DataIn(pdev, epnum); @@ -486,12 +498,12 @@ uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) } /** -* @brief USBD_MSC_DataOut -* handle data OUT Stage -* @param pdev: device instance -* @param epnum: endpoint index -* @retval status -*/ + * @brief USBD_MSC_DataOut + * handle data OUT Stage + * @param pdev: device instance + * @param epnum: endpoint index + * @retval status + */ uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) { MSC_BOT_DataOut(pdev, epnum); @@ -500,11 +512,11 @@ uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) } /** -* @brief USBD_MSC_GetHSCfgDesc -* return configuration descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief USBD_MSC_GetHSCfgDesc + * return configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_MSC_CfgHSDesc); @@ -513,11 +525,11 @@ uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length) } /** -* @brief USBD_MSC_GetFSCfgDesc -* return configuration descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief USBD_MSC_GetFSCfgDesc + * return configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_MSC_CfgFSDesc); @@ -526,11 +538,11 @@ uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length) } /** -* @brief USBD_MSC_GetOtherSpeedCfgDesc -* return other speed configuration descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief USBD_MSC_GetOtherSpeedCfgDesc + * return other speed configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_MSC_OtherSpeedCfgDesc); @@ -538,11 +550,11 @@ uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length) return USBD_MSC_OtherSpeedCfgDesc; } /** -* @brief DeviceQualifierDescriptor -* return Device Qualifier descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length) { *length = (uint16_t)sizeof(USBD_MSC_DeviceQualifierDesc); @@ -551,10 +563,10 @@ uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length) } /** -* @brief USBD_MSC_RegisterStorage -* @param fops: storage callback -* @retval status -*/ + * @brief USBD_MSC_RegisterStorage + * @param fops: storage callback + * @retval status + */ uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *fops) { if (fops == NULL) diff --git a/Class/MSC/Src/usbd_msc_bot.c b/Class/MSC/Src/usbd_msc_bot.c index ae68ac0..ab15e54 100644 --- a/Class/MSC/Src/usbd_msc_bot.c +++ b/Class/MSC/Src/usbd_msc_bot.c @@ -90,11 +90,11 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev); /** -* @brief MSC_BOT_Init -* Initialize the BOT Process -* @param pdev: device instance -* @retval None -*/ + * @brief MSC_BOT_Init + * Initialize the BOT Process + * @param pdev: device instance + * @retval None + */ void MSC_BOT_Init(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -111,17 +111,17 @@ void MSC_BOT_Init(USBD_HandleTypeDef *pdev) (void)USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR); (void)USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR); - /* Prapare EP to Receive First BOT Cmd */ + /* Prepare EP to Receive First BOT Cmd */ (void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw, USBD_BOT_CBW_LENGTH); } /** -* @brief MSC_BOT_Reset -* Reset the BOT Machine -* @param pdev: device instance -* @retval None -*/ + * @brief MSC_BOT_Reset + * Reset the BOT Machine + * @param pdev: device instance + * @retval None + */ void MSC_BOT_Reset(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -132,17 +132,17 @@ void MSC_BOT_Reset(USBD_HandleTypeDef *pdev) (void)USBD_LL_ClearStallEP(pdev, MSC_EPIN_ADDR); (void)USBD_LL_ClearStallEP(pdev, MSC_EPOUT_ADDR); - /* Prapare EP to Receive First BOT Cmd */ + /* Prepare EP to Receive First BOT Cmd */ (void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw, USBD_BOT_CBW_LENGTH); } /** -* @brief MSC_BOT_DeInit -* Deinitialize the BOT Machine -* @param pdev: device instance -* @retval None -*/ + * @brief MSC_BOT_DeInit + * DeInitialize the BOT Machine + * @param pdev: device instance + * @retval None + */ void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -150,12 +150,12 @@ void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev) } /** -* @brief MSC_BOT_DataIn -* Handle BOT IN data stage -* @param pdev: device instance -* @param epnum: endpoint index -* @retval None -*/ + * @brief MSC_BOT_DataIn + * Handle BOT IN data stage + * @param pdev: device instance + * @param epnum: endpoint index + * @retval None + */ void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { UNUSED(epnum); @@ -164,29 +164,29 @@ void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) switch (hmsc->bot_state) { - case USBD_BOT_DATA_IN: - if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) - { - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); - } - break; + case USBD_BOT_DATA_IN: + if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) + { + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); + } + break; - case USBD_BOT_SEND_DATA: - case USBD_BOT_LAST_DATA_IN: - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); - break; + case USBD_BOT_SEND_DATA: + case USBD_BOT_LAST_DATA_IN: + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); + break; - default: - break; + default: + break; } } /** -* @brief MSC_BOT_DataOut -* Process MSC OUT data -* @param pdev: device instance -* @param epnum: endpoint index -* @retval None -*/ + * @brief MSC_BOT_DataOut + * Process MSC OUT data + * @param pdev: device instance + * @param epnum: endpoint index + * @retval None + */ void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) { UNUSED(epnum); @@ -212,11 +212,11 @@ void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) } /** -* @brief MSC_BOT_CBW_Decode -* Decode the CBW command and set the BOT state machine accordingly -* @param pdev: device instance -* @retval None -*/ + * @brief MSC_BOT_CBW_Decode + * Decode the CBW command and set the BOT state machine accordingly + * @param pdev: device instance + * @retval None + */ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -273,13 +273,13 @@ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev) } /** -* @brief MSC_BOT_SendData -* Send the requested data -* @param pdev: device instance -* @param buf: pointer to data buffer -* @param len: Data Length -* @retval None -*/ + * @brief MSC_BOT_SendData + * Send the requested data + * @param pdev: device instance + * @param buf: pointer to data buffer + * @param len: Data Length + * @retval None + */ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -294,12 +294,12 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t } /** -* @brief MSC_BOT_SendCSW -* Send the Command Status Wrapper -* @param pdev: device instance -* @param status : CSW status -* @retval None -*/ + * @brief MSC_BOT_SendCSW + * Send the Command Status Wrapper + * @param pdev: device instance + * @param status : CSW status + * @retval None + */ void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -317,11 +317,11 @@ void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status) } /** -* @brief MSC_BOT_Abort -* Abort the current transfer -* @param pdev: device instance -* @retval status -*/ + * @brief MSC_BOT_Abort + * Abort the current transfer + * @param pdev: device instance + * @retval status + */ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev) { @@ -344,12 +344,12 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev) } /** -* @brief MSC_BOT_CplClrFeature -* Complete the clear feature request -* @param pdev: device instance -* @param epnum: endpoint index -* @retval None -*/ + * @brief MSC_BOT_CplClrFeature + * Complete the clear feature request + * @param pdev: device instance + * @param epnum: endpoint index + * @retval None + */ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum) { diff --git a/Class/MSC/Src/usbd_msc_data.c b/Class/MSC/Src/usbd_msc_data.c index d1c3a97..34ef443 100644 --- a/Class/MSC/Src/usbd_msc_data.c +++ b/Class/MSC/Src/usbd_msc_data.c @@ -87,7 +87,7 @@ uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80] = 0x20, 0x20, 0x20 - }; +}; /* USB Mass storage sense 6 Data */ uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN] = diff --git a/Class/MSC/Src/usbd_msc_scsi.c b/Class/MSC/Src/usbd_msc_scsi.c index 5c36a6e..b118933 100644 --- a/Class/MSC/Src/usbd_msc_scsi.c +++ b/Class/MSC/Src/usbd_msc_scsi.c @@ -111,13 +111,13 @@ static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc, /** -* @brief SCSI_ProcessCmd -* Process SCSI commands -* @param pdev: device instance -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_ProcessCmd + * Process SCSI commands + * @param pdev: device instance + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd) { int8_t ret; @@ -125,71 +125,71 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd) switch (cmd[0]) { - case SCSI_TEST_UNIT_READY: - ret = SCSI_TestUnitReady(pdev, lun, cmd); - break; + case SCSI_TEST_UNIT_READY: + ret = SCSI_TestUnitReady(pdev, lun, cmd); + break; - case SCSI_REQUEST_SENSE: - ret = SCSI_RequestSense(pdev, lun, cmd); - break; + case SCSI_REQUEST_SENSE: + ret = SCSI_RequestSense(pdev, lun, cmd); + break; - case SCSI_INQUIRY: - ret = SCSI_Inquiry(pdev, lun, cmd); - break; + case SCSI_INQUIRY: + ret = SCSI_Inquiry(pdev, lun, cmd); + break; - case SCSI_START_STOP_UNIT: - ret = SCSI_StartStopUnit(pdev, lun, cmd); - break; + case SCSI_START_STOP_UNIT: + ret = SCSI_StartStopUnit(pdev, lun, cmd); + break; - case SCSI_ALLOW_MEDIUM_REMOVAL: - ret = SCSI_AllowPreventRemovable(pdev, lun, cmd); - break; + case SCSI_ALLOW_MEDIUM_REMOVAL: + ret = SCSI_AllowPreventRemovable(pdev, lun, cmd); + break; - case SCSI_MODE_SENSE6: - ret = SCSI_ModeSense6(pdev, lun, cmd); - break; + case SCSI_MODE_SENSE6: + ret = SCSI_ModeSense6(pdev, lun, cmd); + break; - case SCSI_MODE_SENSE10: - ret = SCSI_ModeSense10(pdev, lun, cmd); - break; + case SCSI_MODE_SENSE10: + ret = SCSI_ModeSense10(pdev, lun, cmd); + break; - case SCSI_READ_FORMAT_CAPACITIES: - ret = SCSI_ReadFormatCapacity(pdev, lun, cmd); - break; + case SCSI_READ_FORMAT_CAPACITIES: + ret = SCSI_ReadFormatCapacity(pdev, lun, cmd); + break; - case SCSI_READ_CAPACITY10: - ret = SCSI_ReadCapacity10(pdev, lun, cmd); - break; + case SCSI_READ_CAPACITY10: + ret = SCSI_ReadCapacity10(pdev, lun, cmd); + break; - case SCSI_READ_CAPACITY16: - ret = SCSI_ReadCapacity16(pdev, lun, cmd); - break; + case SCSI_READ_CAPACITY16: + ret = SCSI_ReadCapacity16(pdev, lun, cmd); + break; - case SCSI_READ10: - ret = SCSI_Read10(pdev, lun, cmd); - break; + case SCSI_READ10: + ret = SCSI_Read10(pdev, lun, cmd); + break; - case SCSI_READ12: - ret = SCSI_Read12(pdev, lun, cmd); - break; + case SCSI_READ12: + ret = SCSI_Read12(pdev, lun, cmd); + break; - case SCSI_WRITE10: - ret = SCSI_Write10(pdev, lun, cmd); - break; + case SCSI_WRITE10: + ret = SCSI_Write10(pdev, lun, cmd); + break; - case SCSI_WRITE12: - ret = SCSI_Write12(pdev, lun, cmd); - break; + case SCSI_WRITE12: + ret = SCSI_Write12(pdev, lun, cmd); + break; - case SCSI_VERIFY10: - ret = SCSI_Verify10(pdev, lun, cmd); - break; + case SCSI_VERIFY10: + ret = SCSI_Verify10(pdev, lun, cmd); + break; - default: - SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB); - hmsc->bot_status = USBD_BOT_STATUS_ERROR; - ret = -1; - break; + default: + SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB); + hmsc->bot_status = USBD_BOT_STATUS_ERROR; + ret = -1; + break; } return ret; @@ -197,12 +197,12 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd) /** -* @brief SCSI_TestUnitReady -* Process SCSI Test Unit Ready Command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_TestUnitReady + * Process SCSI Test Unit Ready Command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); @@ -237,12 +237,12 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t /** -* @brief SCSI_Inquiry -* Process Inquiry command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_Inquiry + * Process Inquiry command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { uint8_t *pPage; @@ -275,7 +275,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param } else { - pPage = (uint8_t *)&((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; + pPage = (uint8_t *) &((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; len = (uint16_t)pPage[4] + 5U; if (params[4] <= len) @@ -291,12 +291,12 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param /** -* @brief SCSI_ReadCapacity10 -* Process Read Capacity 10 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_ReadCapacity10 + * Process Read Capacity 10 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); @@ -329,12 +329,12 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t /** -* @brief SCSI_ReadCapacity16 -* Process Read Capacity 16 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_ReadCapacity16 + * Process Read Capacity 16 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); @@ -353,7 +353,7 @@ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t hmsc->bot_data_length = ((uint32_t)params[10] << 24) | ((uint32_t)params[11] << 16) | ((uint32_t)params[12] << 8) | - (uint32_t)params[13]; + (uint32_t)params[13]; for (idx = 0U; idx < hmsc->bot_data_length; idx++) { @@ -373,19 +373,19 @@ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t hmsc->bot_data_length = ((uint32_t)params[10] << 24) | ((uint32_t)params[11] << 16) | ((uint32_t)params[12] << 8) | - (uint32_t)params[13]; + (uint32_t)params[13]; return 0; } /** -* @brief SCSI_ReadFormatCapacity -* Process Read Format Capacity command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_ReadFormatCapacity + * Process Read Format Capacity command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); @@ -426,12 +426,12 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uin /** -* @brief SCSI_ModeSense6 -* Process Mode Sense6 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_ModeSense6 + * Process Mode Sense6 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); @@ -450,12 +450,12 @@ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *pa /** -* @brief SCSI_ModeSense10 -* Process Mode Sense10 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_ModeSense10 + * Process Mode Sense10 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); @@ -474,12 +474,12 @@ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *p /** -* @brief SCSI_RequestSense -* Process Request Sense command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_RequestSense + * Process Request Sense command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); @@ -525,14 +525,14 @@ static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t * /** -* @brief SCSI_SenseCode -* Load the last error code in the error list -* @param lun: Logical unit number -* @param sKey: Sense Key -* @param ASC: Additional Sense Code -* @retval none + * @brief SCSI_SenseCode + * Load the last error code in the error list + * @param lun: Logical unit number + * @param sKey: Sense Key + * @param ASC: Additional Sense Code + * @retval none -*/ + */ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC) { UNUSED(lun); @@ -551,12 +551,12 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t /** -* @brief SCSI_StartStopUnit -* Process Start Stop Unit command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_StartStopUnit + * Process Start Stop Unit command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); @@ -592,12 +592,12 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t /** -* @brief SCSI_AllowPreventRemovable -* Process Allow Prevent Removable medium command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_AllowPreventRemovable + * Process Allow Prevent Removable medium command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); @@ -619,12 +619,12 @@ static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, /** -* @brief SCSI_Read10 -* Process Read10 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_Read10 + * Process Read10 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -680,12 +680,12 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params /** -* @brief SCSI_Read12 -* Process Read12 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_Read12 + * Process Read12 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -743,12 +743,12 @@ static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params /** -* @brief SCSI_Write10 -* Process Write10 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_Write10 + * Process Write10 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -823,12 +823,12 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param /** -* @brief SCSI_Write12 -* Process Write12 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_Write12 + * Process Write12 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -907,12 +907,12 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param /** -* @brief SCSI_Verify10 -* Process Verify10 command -* @param lun: Logical unit number -* @param params: Command parameters -* @retval status -*/ + * @brief SCSI_Verify10 + * Process Verify10 command + * @param lun: Logical unit number + * @param params: Command parameters + * @retval status + */ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -934,13 +934,13 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *para } /** -* @brief SCSI_CheckAddressRange -* Check address range -* @param lun: Logical unit number -* @param blk_offset: first block address -* @param blk_nbr: number of block to be processed -* @retval status -*/ + * @brief SCSI_CheckAddressRange + * Check address range + * @param lun: Logical unit number + * @param blk_offset: first block address + * @param blk_nbr: number of block to be processed + * @retval status + */ static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun, uint32_t blk_offset, uint32_t blk_nbr) { @@ -956,11 +956,11 @@ static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun, } /** -* @brief SCSI_ProcessRead -* Handle Read Process -* @param lun: Logical unit number -* @retval status -*/ + * @brief SCSI_ProcessRead + * Handle Read Process + * @param lun: Logical unit number + * @retval status + */ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -993,11 +993,11 @@ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun) } /** -* @brief SCSI_ProcessWrite -* Handle Write Process -* @param lun: Logical unit number -* @retval status -*/ + * @brief SCSI_ProcessWrite + * Handle Write Process + * @param lun: Logical unit number + * @retval status + */ static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; @@ -1036,13 +1036,13 @@ static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun) /** -* @brief SCSI_UpdateBotData -* fill the requested Data to transmit buffer -* @param hmsc handler -* @param params: Data buffer -* @param length: Data length -* @retval status -*/ + * @brief SCSI_UpdateBotData + * fill the requested Data to transmit buffer + * @param hmsc handler + * @param pBuff: Data buffer + * @param length: Data length + * @retval status + */ static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc, uint8_t *pBuff, uint16_t length) { diff --git a/Class/MSC/Src/usbd_msc_storage_template.c b/Class/MSC/Src/usbd_msc_storage_template.c index dc6cc3d..875c1f9 100644 --- a/Class/MSC/Src/usbd_msc_storage_template.c +++ b/Class/MSC/Src/usbd_msc_storage_template.c @@ -88,24 +88,24 @@ USBD_StorageTypeDef USBD_MSC_Template_fops = }; /******************************************************************************* -* Function Name : Read_Memory -* Description : Handle the Read operation from the microSD card. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ + * Function Name : Read_Memory + * Description : Handle the Read operation from the microSD card. + * Input : None. + * Output : None. + * Return : None. + *******************************************************************************/ int8_t STORAGE_Init(uint8_t lun) { return (0); } /******************************************************************************* -* Function Name : Read_Memory -* Description : Handle the Read operation from the STORAGE card. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ + * Function Name : Read_Memory + * Description : Handle the Read operation from the STORAGE card. + * Input : None. + * Output : None. + * Return : None. + *******************************************************************************/ int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) { *block_num = STORAGE_BLK_NBR; @@ -114,60 +114,60 @@ int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_siz } /******************************************************************************* -* Function Name : Read_Memory -* Description : Handle the Read operation from the STORAGE card. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ + * Function Name : Read_Memory + * Description : Handle the Read operation from the STORAGE card. + * Input : None. + * Output : None. + * Return : None. + *******************************************************************************/ int8_t STORAGE_IsReady(uint8_t lun) { return (0); } /******************************************************************************* -* Function Name : Read_Memory -* Description : Handle the Read operation from the STORAGE card. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ + * Function Name : Read_Memory + * Description : Handle the Read operation from the STORAGE card. + * Input : None. + * Output : None. + * Return : None. + *******************************************************************************/ int8_t STORAGE_IsWriteProtected(uint8_t lun) { return 0; } /******************************************************************************* -* Function Name : Read_Memory -* Description : Handle the Read operation from the STORAGE card. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ + * Function Name : Read_Memory + * Description : Handle the Read operation from the STORAGE card. + * Input : None. + * Output : None. + * Return : None. + *******************************************************************************/ int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { return 0; } /******************************************************************************* -* Function Name : Write_Memory -* Description : Handle the Write operation to the STORAGE card. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ + * Function Name : Write_Memory + * Description : Handle the Write operation to the STORAGE card. + * Input : None. + * Output : None. + * Return : None. + *******************************************************************************/ int8_t STORAGE_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { return (0); } /******************************************************************************* -* Function Name : Write_Memory -* Description : Handle the Write operation to the STORAGE card. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ + * Function Name : Write_Memory + * Description : Handle the Write operation to the STORAGE card. + * Input : None. + * Output : None. + * Return : None. + *******************************************************************************/ int8_t STORAGE_GetMaxLun(void) { return (STORAGE_LUN_NBR - 1); diff --git a/Class/Template/Src/usbd_template.c b/Class/Template/Src/usbd_template.c index 1c8ea72..10ced3f 100644 --- a/Class/Template/Src/usbd_template.c +++ b/Class/Template/Src/usbd_template.c @@ -128,7 +128,7 @@ USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver = /* USB TEMPLATE device Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] __ALIGN_END = { - 0x09, /* bLength: Configuation Descriptor size */ + 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */ USB_TEMPLATE_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ @@ -210,36 +210,35 @@ static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev, switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_CLASS : - switch (req->bRequest) - { + case USB_REQ_TYPE_CLASS : + switch (req->bRequest) + { + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + break; + + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) + { + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + break; + default: USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; } return (uint8_t)ret; } - /** * @brief USBD_TEMPLATE_GetCfgDesc * return configuration descriptor @@ -253,18 +252,17 @@ static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length) } /** -* @brief DeviceQualifierDescriptor -* return Device Qualifier descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length) { *length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc); return USBD_TEMPLATE_DeviceQualifierDesc; } - /** * @brief USBD_TEMPLATE_DataIn * handle data IN Stage @@ -289,6 +287,7 @@ static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev) return (uint8_t)USBD_OK; } + /** * @brief USBD_TEMPLATE_EP0_TxReady * handle EP0 TRx Ready event @@ -300,6 +299,7 @@ static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev) return (uint8_t)USBD_OK; } + /** * @brief USBD_TEMPLATE_SOF * handle SOF event @@ -311,6 +311,7 @@ static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev) return (uint8_t)USBD_OK; } + /** * @brief USBD_TEMPLATE_IsoINIncomplete * handle data ISO IN Incomplete event @@ -323,6 +324,7 @@ static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t e return (uint8_t)USBD_OK; } + /** * @brief USBD_TEMPLATE_IsoOutIncomplete * handle data ISO OUT Incomplete event @@ -349,11 +351,11 @@ static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) } /** -* @brief DeviceQualifierDescriptor -* return Device Qualifier descriptor -* @param length : pointer data length -* @retval pointer to descriptor buffer -*/ + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc); diff --git a/Class/VIDEO/Inc/usbd_video.h b/Class/VIDEO/Inc/usbd_video.h new file mode 100644 index 0000000..719f210 --- /dev/null +++ b/Class/VIDEO/Inc/usbd_video.h @@ -0,0 +1,457 @@ +/** + ****************************************************************************** + * @file usbd_video.h + * @author MCD Application Team + * @brief header file for the usbd_video.c file. + ****************************************************************************** + * @attention + * + *