Skip to content

Commit ab86531

Browse files
committed
fix to max usb transfer sizes for CDC ACM drivers with variable backing buffer size
1 parent f8bee0a commit ab86531

File tree

2 files changed

+16
-9
lines changed
  • demos
    • ARMCM4-STM32F407-WAVESHARE-OPEN-407I-C-USB_HS_ULPI
    • ARMCM4-STM32F407-WAVESHARE-OPEN-407I-C-USB_HS_ULPI-USB-MASS-STORAGE-VCOM

2 files changed

+16
-9
lines changed

demos/ARMCM4-STM32F407-WAVESHARE-OPEN-407I-C-USB_HS_ULPI-USB-MASS-STORAGE-VCOM/usb_msd_cfg.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424
#include "usb_msd.h"
2525

2626

27+
#ifndef MIN
28+
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
29+
#endif
2730

2831
#if STM32_USB_USE_OTG2 && STM32_USE_USB_OTG2_HS
2932
#define USB_MAX_PACKET_SIZE 512
33+
#define USB_CDC_DESCRIPTOR_MAX_PACKET_SIZE MIN(512, SERIAL_USB_BUFFERS_SIZE)
3034
#define USB_CDC_INTERUPT_INTERVAL 0x10
3135
#else
3236
#define USB_MAX_PACKET_SIZE 64
@@ -161,12 +165,12 @@ static const uint8_t msd_configuration_descriptor_data[] = {
161165
/* Endpoint 3 Descriptor. */
162166
USB_DESC_ENDPOINT (USB_CDC_DATA_AVAILABLE_EP, /* bEndpointAddress.*/
163167
0x02, /* bmAttributes (Bulk). */
164-
USB_MAX_PACKET_SIZE, /* wMaxPacketSize. */
168+
USB_CDC_DESCRIPTOR_MAX_PACKET_SIZE, /* wMaxPacketSize. */
165169
0x00), /* bInterval. */
166170
/* Endpoint 1 Descriptor. */
167171
USB_DESC_ENDPOINT (USB_CDC_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/
168172
0x02, /* bmAttributes (Bulk). */
169-
USB_MAX_PACKET_SIZE, /* wMaxPacketSize. */
173+
USB_CDC_DESCRIPTOR_MAX_PACKET_SIZE, /* wMaxPacketSize. */
170174
0x00), /* bInterval. */
171175

172176

@@ -324,8 +328,8 @@ static const USBEndpointConfig epCDC1config = {
324328
NULL,
325329
sduDataTransmitted,
326330
sduDataReceived,
327-
0x0040,
328-
0x0040,
331+
USB_CDC_DESCRIPTOR_MAX_PACKET_SIZE,
332+
USB_CDC_DESCRIPTOR_MAX_PACKET_SIZE,
329333
&epCDC1instate,
330334
&epCDC1outstate,
331335
2,
@@ -369,7 +373,7 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
369373
case USB_EVENT_ADDRESS:
370374
return;
371375
case USB_EVENT_CONFIGURED:
372-
chSysLockFromIsr()
376+
chSysLockFromIsr();
373377
msdp->reconfigured_or_reset_event = TRUE;
374378
usbInitEndpointI(usbp, msdp->ms_ep_number, &epDataConfig);
375379

@@ -386,7 +390,7 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
386390

387391
/* signal that the device is connected */
388392
chEvtBroadcastI(&msdp->evt_connected);
389-
chSysUnlockFromIsr()
393+
chSysUnlockFromIsr();
390394
return;
391395
case USB_EVENT_SUSPEND:
392396
return;

demos/ARMCM4-STM32F407-WAVESHARE-OPEN-407I-C-USB_HS_ULPI/usbcfg.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
#include "ch.h"
2222
#include "hal.h"
2323

24+
#ifndef MIN
25+
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
26+
#endif
2427

2528
#if STM32_USB_USE_OTG2 && STM32_USE_USB_OTG2_HS
26-
#define MAX_USB_PACKET_SIZE 512
29+
#define MAX_USB_PACKET_SIZE MIN(512, SERIAL_USB_BUFFERS_SIZE)
2730
#else
2831
#define MAX_USB_PACKET_SIZE 64
2932
#endif
@@ -238,8 +241,8 @@ static const USBEndpointConfig ep1config = {
238241
NULL,
239242
sduDataTransmitted,
240243
sduDataReceived,
241-
0x0040,
242-
0x0040,
244+
MAX_USB_PACKET_SIZE,
245+
MAX_USB_PACKET_SIZE,
243246
&ep1instate,
244247
&ep1outstate,
245248
2,

0 commit comments

Comments
 (0)