Skip to content

Commit 7095e16

Browse files
authored
Merge pull request #2660 from fpistm/stm32_mw_usb
chore(usb): update to latest USB device and host mw
2 parents a192198 + f817247 commit 7095e16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4396
-4265
lines changed

libraries/USBDevice/inc/usbd_conf.h

+10
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ extern "C" {
115115
#define USBD_DEBUG_LEVEL 0U
116116
#endif /* USBD_DEBUG_LEVEL */
117117

118+
#ifndef USBD_USER_REGISTER_CALLBACK
119+
#define USBD_USER_REGISTER_CALLBACK 0U
120+
#endif /* USBD_USER_REGISTER_CALLBACK */
121+
118122
/* ECM, RNDIS, DFU Class Config */
119123
#ifndef USBD_SUPPORT_USER_STRING_DESC
120124
#define USBD_SUPPORT_USER_STRING_DESC 0U
@@ -144,6 +148,12 @@ extern "C" {
144148
#endif /* USBD_CDC_INTERVAL */
145149

146150
/* DFU Class Config */
151+
#ifndef USBD_DFU_VENDOR_CMD_ENABLED
152+
#define USBD_DFU_VENDOR_CMD_ENABLED 0U
153+
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
154+
#ifndef USBD_DFU_VENDOR_EXIT_ENABLED
155+
#define USBD_DFU_VENDOR_EXIT_ENABLED 1U
156+
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
147157
#ifndef USBD_DFU_MAX_ITF_NUM
148158
#define USBD_DFU_MAX_ITF_NUM 1U
149159
#endif /* USBD_DFU_MAX_ITF_NUM */

system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,19 @@ static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnu
742742
*/
743743
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
744744
{
745-
UNUSED(pdev);
746-
UNUSED(epnum);
745+
USBD_AUDIO_HandleTypeDef *haudio;
746+
747+
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
748+
{
749+
return (uint8_t)USBD_FAIL;
750+
}
751+
752+
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
753+
754+
/* Prepare Out endpoint to receive next audio packet */
755+
(void)USBD_LL_PrepareReceive(pdev, epnum,
756+
&haudio->buffer[haudio->wr_ptr],
757+
AUDIO_OUT_PACKET);
747758

748759
return (uint8_t)USBD_OK;
749760
}

system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c

+12-126
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ EndBSPDependencies */
4545
/* Includes ------------------------------------------------------------------*/
4646
#include "usbd_customhid.h"
4747
#include "usbd_ctlreq.h"
48-
#include "usbd_def.h"
4948

5049

5150
/** @addtogroup STM32_USB_DEVICE_LIBRARY
@@ -168,7 +167,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_
168167
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
169168
0x01,
170169
0x00, /* bCountryCode: Hardware target country */
171-
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
170+
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors
171+
to follow */
172172
0x22, /* bDescriptorType */
173173
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
174174
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
@@ -193,128 +193,6 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_
193193
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
194194
/* 41 */
195195
};
196-
197-
/* USB CUSTOM_HID device HS Configuration Descriptor */
198-
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
199-
{
200-
0x09, /* bLength: Configuration Descriptor size */
201-
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
202-
LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
203-
HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
204-
0x01, /* bNumInterfaces: 1 interface */
205-
0x01, /* bConfigurationValue: Configuration value */
206-
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
207-
#if (USBD_SELF_POWERED == 1U)
208-
0xC0, /* bmAttributes: Bus Powered according to user configuration */
209-
#else
210-
0x80, /* bmAttributes: Bus Powered according to user configuration */
211-
#endif
212-
USBD_MAX_POWER, /* MaxPower (mA) */
213-
214-
/************** Descriptor of CUSTOM HID interface ****************/
215-
/* 09 */
216-
0x09, /* bLength: Interface Descriptor size */
217-
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
218-
0x00, /* bInterfaceNumber: Number of Interface */
219-
0x00, /* bAlternateSetting: Alternate setting */
220-
0x02, /* bNumEndpoints */
221-
0x03, /* bInterfaceClass: CUSTOM_HID */
222-
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
223-
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
224-
0, /* iInterface: Index of string descriptor */
225-
/******************** Descriptor of CUSTOM_HID *************************/
226-
/* 18 */
227-
0x09, /* bLength: CUSTOM_HID Descriptor size */
228-
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
229-
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
230-
0x01,
231-
0x00, /* bCountryCode: Hardware target country */
232-
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
233-
0x22, /* bDescriptorType */
234-
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
235-
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
236-
/******************** Descriptor of Custom HID endpoints ********************/
237-
/* 27 */
238-
0x07, /* bLength: Endpoint Descriptor size */
239-
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType */
240-
241-
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
242-
0x03, /* bmAttributes: Interrupt endpoint */
243-
LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */
244-
HIBYTE(CUSTOM_HID_EPIN_SIZE),
245-
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
246-
/* 34 */
247-
248-
0x07, /* bLength: Endpoint Descriptor size */
249-
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
250-
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
251-
0x03, /* bmAttributes: Interrupt endpoint */
252-
LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */
253-
HIBYTE(CUSTOM_HID_EPOUT_SIZE),
254-
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
255-
/* 41 */
256-
};
257-
258-
/* USB CUSTOM_HID device Other Speed Configuration Descriptor */
259-
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
260-
{
261-
0x09, /* bLength: Configuration Descriptor size */
262-
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
263-
LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
264-
HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
265-
0x01, /* bNumInterfaces: 1 interface */
266-
0x01, /* bConfigurationValue: Configuration value */
267-
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
268-
#if (USBD_SELF_POWERED == 1U)
269-
0xC0, /* bmAttributes: Bus Powered according to user configuration */
270-
#else
271-
0x80, /* bmAttributes: Bus Powered according to user configuration */
272-
#endif
273-
USBD_MAX_POWER, /* MaxPower (mA) */
274-
275-
/************** Descriptor of CUSTOM HID interface ****************/
276-
/* 09 */
277-
0x09, /* bLength: Interface Descriptor size */
278-
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
279-
0x00, /* bInterfaceNumber: Number of Interface */
280-
0x00, /* bAlternateSetting: Alternate setting */
281-
0x02, /* bNumEndpoints */
282-
0x03, /* bInterfaceClass: CUSTOM_HID */
283-
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
284-
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
285-
0, /* iInterface: Index of string descriptor */
286-
/******************** Descriptor of CUSTOM_HID *************************/
287-
/* 18 */
288-
0x09, /* bLength: CUSTOM_HID Descriptor size */
289-
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
290-
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
291-
0x01,
292-
0x00, /* bCountryCode: Hardware target country */
293-
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
294-
0x22, /* bDescriptorType */
295-
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
296-
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
297-
/******************** Descriptor of Custom HID endpoints ********************/
298-
/* 27 */
299-
0x07, /* bLength: Endpoint Descriptor size */
300-
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
301-
302-
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
303-
0x03, /* bmAttributes: Interrupt endpoint */
304-
LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */
305-
HIBYTE(CUSTOM_HID_EPIN_SIZE),
306-
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
307-
/* 34 */
308-
309-
0x07, /* bLength: Endpoint Descriptor size */
310-
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
311-
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
312-
0x03, /* bmAttributes: Interrupt endpoint */
313-
LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */
314-
HIBYTE(CUSTOM_HID_EPOUT_SIZE),
315-
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
316-
/* 41 */
317-
};
318196
#endif /* USE_USBD_COMPOSITE */
319197

320198
/* USB CUSTOM_HID device Configuration Descriptor */
@@ -329,7 +207,7 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALI
329207
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors
330208
to follow */
331209
0x22, /* bDescriptorType */
332-
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
210+
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
333211
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
334212
};
335213

@@ -601,7 +479,15 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
601479
}
602480
}
603481

604-
(void)USBD_CtlSendData(pdev, pbuf, len);
482+
if (pbuf != NULL)
483+
{
484+
(void)USBD_CtlSendData(pdev, pbuf, len);
485+
}
486+
else
487+
{
488+
USBD_CtlError(pdev, req);
489+
ret = USBD_FAIL;
490+
}
605491
break;
606492

607493
case USB_REQ_GET_INTERFACE:

system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu.h

+19
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ extern "C" {
6565

6666
#define DFU_DESCRIPTOR_TYPE 0x21U
6767

68+
#define DFU_VENDOR_CMD_MAX 32U
69+
6870

6971
/**************************************************/
7072
/* DFU Requests DFU states */
@@ -126,6 +128,11 @@ extern "C" {
126128
#define DFU_MANIFEST_MASK (1U << 2)
127129
#define DFU_STATUS_DEPTH 6U
128130

131+
#define IS_DFU_DOWNLOAD 0x0DFDFU
132+
#define IS_DFU_UPLOAD 0x1DFDFU
133+
#define IS_DFU_SETADDRESSPOINTER 0x2DFDFU
134+
#define IS_DFU_PHY_ADDRESS 0x3DFDFU
135+
129136
typedef enum
130137
{
131138
DFU_DETACH = 0U,
@@ -176,6 +183,7 @@ typedef struct
176183
uint32_t wblock_num;
177184
uint32_t wlength;
178185
uint32_t data_ptr;
186+
uint32_t app_addr_ptr;
179187
uint32_t alt_setting;
180188

181189
uint8_t dev_status[DFU_STATUS_DEPTH];
@@ -193,6 +201,17 @@ typedef struct
193201
uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len);
194202
uint8_t *(* Read)(uint8_t *src, uint8_t *dest, uint32_t Len);
195203
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
204+
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
205+
uint16_t (* GetVendorCMD)(uint8_t *cmd, uint8_t *cmdlength);
206+
uint16_t (* VendorDownloadCMD)(uint8_t *pbuf, uint32_t BlockNumber, uint32_t wlength, uint32_t *status);
207+
uint16_t (* VendorUploadCMD)(uint32_t Add, uint32_t BlockNumber, uint32_t *status);
208+
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
209+
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
210+
uint16_t (* VendorCheck)(uint8_t *pbuf, uint32_t ReqType, uint32_t *status);
211+
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
212+
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
213+
uint16_t (* LeaveDFU)(uint32_t Add);
214+
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
196215
} USBD_DFU_MediaTypeDef;
197216

198217
typedef struct

0 commit comments

Comments
 (0)