Skip to content

Commit 6717196

Browse files
author
Rudi Horn
committed
fixed bug in descriptor, small changes to USB class
1 parent a144bca commit 6717196

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

cores/arduino/USB.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ void USB::begin() {
3131
if (!initialized) initialize();
3232
}
3333

34+
void USB::register_msc(USBD_StorageTypeDef* fops) {
35+
USBD_MSC_RegisterStorage(&hUSBD_Device, fops);
36+
}
37+
3438
void USB::initialize() {
3539
hUSBD_Device_CDC = &hUSBD_Device;
3640

3741
/* Init Device Library */
3842
if (USBD_Init(&hUSBD_Device, &USBD_Desc, 0) == USBD_OK) {
3943
#ifdef USBD_USE_CDC
4044
/* Add Supported Class */
41-
if (USBD_RegisterClass(&hUSBD_Device_CDC, &USBD_CDC) == USBD_OK) {
45+
if (USBD_RegisterClass(&hUSBD_Device, &USBD_CDC) == USBD_OK) {
4246
/* Add CDC Interface Class */
43-
if (USBD_CDC_RegisterInterface(&hUSBD_Device_CDC, &USBD_CDC_fops) == USBD_OK) {
47+
if (USBD_CDC_RegisterInterface(&hUSBD_Device, &USBD_CDC_fops) == USBD_OK) {
4448
/* Start Device Process */
4549
USBD_Start(&hUSBD_Device_CDC);
4650
initialized = true;
@@ -51,12 +55,9 @@ void USB::initialize() {
5155
if (USBD_RegisterClass(&hUSBD_Device, &USBD_CDC_MSC) == USBD_OK) {
5256
/* Add CDC Interface Class */
5357
if (USBD_CDC_RegisterInterface(&hUSBD_Device, &USBD_CDC_fops) == USBD_OK) {
54-
/* Add MSC Interface Class */
55-
if (USBD_MSC_RegisterStorage(&hUSBD_Device, &USBD_MSC_fops) == USBD_OK) {
56-
/* Start Device Process */
57-
USBD_Start(&hUSBD_Device);
58-
initialized = true;
59-
}
58+
/* Start Device Process */
59+
USBD_Start(&hUSBD_Device);
60+
initialized = true;
6061
}
6162
}
6263
#endif

cores/arduino/USB.h

+3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
#if defined (USBCON)
2323
#include "Stream.h"
2424
#include "usbd_core.h"
25+
#include "usbd_msc.h"
2526

2627
class USB {
2728
public:
29+
void register_msc(USBD_StorageTypeDef* fops);
30+
2831
void begin(void);
2932

3033
void end(void);

cores/arduino/stm32/usb/cdc_msc/usbd_cdc_msc.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ USBD_ClassTypeDef USBD_CDC_MSC =
8787
#pragma data_alignment=4
8888
#endif
8989
/* USB COMPOSITE device Configuration Descriptor */
90-
static uint8_t USBD_COMPOSITE_CfgDesc[USB_CDC_MSC_CONFIG_DESC_SIZ] =
90+
static uint8_t USBD_COMPOSITE_CfgFSDesc[USB_CDC_MSC_CONFIG_DESC_SIZ] =
9191
{
9292
0x09, /* bLength: Configuation Descriptor size */
93-
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */
93+
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
9494
USB_CDC_MSC_CONFIG_DESC_SIZ,
9595
/* wTotalLength: Bytes returned */
9696
0x00,
@@ -198,16 +198,16 @@ static uint8_t USBD_COMPOSITE_CfgDesc[USB_CDC_MSC_CONFIG_DESC_SIZ] =
198198
0x05, /* Endpoint descriptor type */
199199
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */
200200
0x02, /* Bulk endpoint type */
201-
LOBYTE(MSC_MAX_HS_PACKET),
202-
HIBYTE(MSC_MAX_HS_PACKET),
201+
LOBYTE(MSC_MAX_FS_PACKET),
202+
HIBYTE(MSC_MAX_FS_PACKET),
203203
0x00, /* Polling interval in milliseconds */
204204

205205
0x07, /* Endpoint descriptor length = 7 */
206206
0x05, /* Endpoint descriptor type */
207207
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */
208208
0x02, /* Bulk endpoint type */
209-
LOBYTE(MSC_MAX_HS_PACKET),
210-
HIBYTE(MSC_MAX_HS_PACKET),
209+
LOBYTE(MSC_MAX_FS_PACKET),
210+
HIBYTE(MSC_MAX_FS_PACKET),
211211
0x00 /* Polling interval in milliseconds */
212212
};
213213

@@ -325,8 +325,8 @@ static uint8_t USBD_COMPOSITE_Setup(USBD_HandleTypeDef *pdev,
325325
*/
326326
static uint8_t *USBD_COMPOSITE_GetCfgDesc(uint16_t *length)
327327
{
328-
*length = sizeof(USBD_COMPOSITE_CfgDesc);
329-
return USBD_COMPOSITE_CfgDesc;
328+
*length = sizeof(USBD_COMPOSITE_CfgFSDesc);
329+
return USBD_COMPOSITE_CfgFSDesc;
330330
}
331331

332332
/**

cores/arduino/stm32/usb/msc/usbd_msc_storage_if.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ int8_t STORAGE_GetMaxLun(void);
5454
/* USB Mass storage Standard Inquiry Data */
5555
int8_t STORAGE_Inquirydata[] = /* 36 */
5656
{
57-
5857
/* LUN 0 */
5958
0x00,
6059
0x80,
@@ -82,6 +81,7 @@ USBD_StorageTypeDef USBD_MSC_fops =
8281
STORAGE_Inquirydata,
8382

8483
};
84+
8585
/*******************************************************************************
8686
* Function Name : Read_Memory
8787
* Description : Handle the Read operation from the microSD card.
@@ -144,6 +144,7 @@ int8_t STORAGE_Read(uint8_t lun, uint8_t *buf,
144144
{
145145
return 0;
146146
}
147+
147148
/*******************************************************************************
148149
* Function Name : Write_Memory
149150
* Description : Handle the Write operation to the STORAGE card.
@@ -156,6 +157,7 @@ int8_t STORAGE_Write(uint8_t lun, uint8_t *buf,
156157
{
157158
return (0);
158159
}
160+
159161
/*******************************************************************************
160162
* Function Name : Write_Memory
161163
* Description : Handle the Write operation to the STORAGE card.

0 commit comments

Comments
 (0)