@@ -136,6 +136,13 @@ static const int syscfg_otg_hs_phy_clk[] = {
136
136
};
137
137
#endif
138
138
139
+ /*
140
+ * Hardcode EP0 max packet size (bMaxPacketSize0) to 64,
141
+ * which is the maximum allowed by the USB Specification
142
+ * and supported by all STM32 USB controllers.
143
+ */
144
+ #define UDC_STM32_EP0_MAX_PACKET_SIZE 64U
145
+
139
146
struct udc_stm32_data {
140
147
PCD_HandleTypeDef pcd ;
141
148
const struct device * dev ;
@@ -152,7 +159,6 @@ struct udc_stm32_config {
152
159
uint32_t num_endpoints ;
153
160
uint32_t pma_offset ;
154
161
uint32_t dram_size ;
155
- uint16_t ep0_mps ;
156
162
uint16_t ep_mps ;
157
163
/* PHY selected for use by instance */
158
164
uint32_t selected_phy ;
@@ -188,19 +194,20 @@ void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
188
194
{
189
195
struct udc_stm32_data * priv = hpcd2data (hpcd );
190
196
const struct device * dev = priv -> dev ;
191
- const struct udc_stm32_config * cfg = dev -> config ;
192
197
struct udc_ep_config * ep ;
193
198
194
199
/* Re-Enable control endpoints */
195
200
ep = udc_get_ep_cfg (dev , USB_CONTROL_EP_OUT );
196
201
if (ep && ep -> stat .enabled ) {
197
- HAL_PCD_EP_Open (& priv -> pcd , USB_CONTROL_EP_OUT , cfg -> ep0_mps ,
202
+ HAL_PCD_EP_Open (& priv -> pcd , USB_CONTROL_EP_OUT ,
203
+ UDC_STM32_EP0_MAX_PACKET_SIZE ,
198
204
EP_TYPE_CTRL );
199
205
}
200
206
201
207
ep = udc_get_ep_cfg (dev , USB_CONTROL_EP_IN );
202
208
if (ep && ep -> stat .enabled ) {
203
- HAL_PCD_EP_Open (& priv -> pcd , USB_CONTROL_EP_IN , cfg -> ep0_mps ,
209
+ HAL_PCD_EP_Open (& priv -> pcd , USB_CONTROL_EP_IN ,
210
+ UDC_STM32_EP0_MAX_PACKET_SIZE ,
204
211
EP_TYPE_CTRL );
205
212
}
206
213
@@ -288,7 +295,6 @@ static int udc_stm32_tx(const struct device *dev, struct udc_ep_config *epcfg,
288
295
struct net_buf * buf )
289
296
{
290
297
struct udc_stm32_data * priv = udc_get_private (dev );
291
- const struct udc_stm32_config * cfg = dev -> config ;
292
298
uint8_t * data ; uint32_t len ;
293
299
HAL_StatusTypeDef status ;
294
300
@@ -302,7 +308,7 @@ static int udc_stm32_tx(const struct device *dev, struct udc_ep_config *epcfg,
302
308
len = buf -> len ;
303
309
304
310
if (epcfg -> addr == USB_CONTROL_EP_IN ) {
305
- len = MIN (cfg -> ep0_mps , buf -> len );
311
+ len = MIN (UDC_STM32_EP0_MAX_PACKET_SIZE , buf -> len );
306
312
}
307
313
308
314
buf -> data += len ;
@@ -444,8 +450,7 @@ static void handle_msg_data_in(struct udc_stm32_data *priv, uint8_t epnum)
444
450
}
445
451
446
452
if (ep == USB_CONTROL_EP_IN && buf -> len ) {
447
- const struct udc_stm32_config * cfg = dev -> config ;
448
- uint32_t len = MIN (cfg -> ep0_mps , buf -> len );
453
+ uint32_t len = MIN (UDC_STM32_EP0_MAX_PACKET_SIZE , buf -> len );
449
454
450
455
HAL_PCD_EP_Transmit (& priv -> pcd , ep , buf -> data , len );
451
456
@@ -643,9 +648,8 @@ static void udc_stm32_mem_init(const struct device *dev)
643
648
644
649
LOG_DBG ("DRAM size: %ub" , cfg -> dram_size );
645
650
646
- if (cfg -> ep_mps % 4 || cfg -> ep0_mps % 4 ) {
647
- LOG_ERR ("Not a 32-bit word multiple: ep0(%u)|ep(%u)" ,
648
- cfg -> ep0_mps , cfg -> ep_mps );
651
+ if (cfg -> ep_mps % 4 ) {
652
+ LOG_ERR ("Not a 32-bit word multiple: ep(%u)" , cfg -> ep_mps );
649
653
return ;
650
654
}
651
655
@@ -657,8 +661,8 @@ static void udc_stm32_mem_init(const struct device *dev)
657
661
priv -> occupied_mem = words * 4 ;
658
662
659
663
/* For EP0 TX, reserve only one MPS */
660
- HAL_PCDEx_SetTxFiFo (& priv -> pcd , 0 , cfg -> ep0_mps / 4 );
661
- priv -> occupied_mem += cfg -> ep0_mps ;
664
+ HAL_PCDEx_SetTxFiFo (& priv -> pcd , 0 , UDC_STM32_EP0_MAX_PACKET_SIZE / 4 );
665
+ priv -> occupied_mem += UDC_STM32_EP0_MAX_PACKET_SIZE ;
662
666
663
667
/* Reset TX allocs */
664
668
for (unsigned int i = 1U ; i < cfg -> num_endpoints ; i ++ ) {
@@ -705,7 +709,6 @@ static int udc_stm32_ep_mem_config(const struct device *dev,
705
709
static int udc_stm32_enable (const struct device * dev )
706
710
{
707
711
struct udc_stm32_data * priv = udc_get_private (dev );
708
- const struct udc_stm32_config * cfg = dev -> config ;
709
712
HAL_StatusTypeDef status ;
710
713
int ret ;
711
714
@@ -720,14 +723,16 @@ static int udc_stm32_enable(const struct device *dev)
720
723
}
721
724
722
725
ret = udc_ep_enable_internal (dev , USB_CONTROL_EP_OUT ,
723
- USB_EP_TYPE_CONTROL , cfg -> ep0_mps , 0 );
726
+ USB_EP_TYPE_CONTROL ,
727
+ UDC_STM32_EP0_MAX_PACKET_SIZE , 0 );
724
728
if (ret ) {
725
729
LOG_ERR ("Failed enabling ep 0x%02x" , USB_CONTROL_EP_OUT );
726
730
return ret ;
727
731
}
728
732
729
733
ret |= udc_ep_enable_internal (dev , USB_CONTROL_EP_IN ,
730
- USB_EP_TYPE_CONTROL , cfg -> ep0_mps , 0 );
734
+ USB_EP_TYPE_CONTROL ,
735
+ UDC_STM32_EP0_MAX_PACKET_SIZE , 0 );
731
736
if (ret ) {
732
737
LOG_ERR ("Failed enabling ep 0x%02x" , USB_CONTROL_EP_IN );
733
738
return ret ;
@@ -1068,12 +1073,10 @@ static const struct udc_api udc_stm32_api = {
1068
1073
#define USB_NUM_BIDIR_ENDPOINTS DT_INST_PROP(0, num_bidir_endpoints)
1069
1074
1070
1075
#if defined(USB ) || defined(USB_DRD_FS )
1071
- #define EP0_MPS 64U
1072
1076
#define EP_MPS 64U
1073
1077
#define USB_BTABLE_SIZE (8 * USB_NUM_BIDIR_ENDPOINTS)
1074
1078
#define USB_RAM_SIZE DT_INST_PROP(0, ram_size)
1075
1079
#else /* USB_OTG_FS */
1076
- #define EP0_MPS USB_OTG_MAX_EP0_SIZE
1077
1080
#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32_otghs )
1078
1081
#define EP_MPS USB_OTG_HS_MAX_PACKET_SIZE
1079
1082
#elif DT_HAS_COMPAT_STATUS_OKAY (st_stm32_otgfs ) || DT_HAS_COMPAT_STATUS_OKAY (st_stm32_usb )
@@ -1094,7 +1097,6 @@ static const struct udc_stm32_config udc0_cfg = {
1094
1097
.num_endpoints = USB_NUM_BIDIR_ENDPOINTS ,
1095
1098
.dram_size = USB_RAM_SIZE ,
1096
1099
.pma_offset = USB_BTABLE_SIZE ,
1097
- .ep0_mps = EP0_MPS ,
1098
1100
.ep_mps = EP_MPS ,
1099
1101
.selected_phy = UDC_STM32_NODE_PHY_ITFACE (DT_DRV_INST (0 )),
1100
1102
.selected_speed = UDC_STM32_NODE_SPEED (DT_DRV_INST (0 )),
@@ -1109,7 +1111,7 @@ static void priv_pcd_prepare(const struct device *dev)
1109
1111
1110
1112
/* Default values */
1111
1113
priv -> pcd .Init .dev_endpoints = cfg -> num_endpoints ;
1112
- priv -> pcd .Init .ep0_mps = cfg -> ep0_mps ;
1114
+ priv -> pcd .Init .ep0_mps = UDC_STM32_EP0_MAX_PACKET_SIZE ;
1113
1115
priv -> pcd .Init .speed = cfg -> selected_speed ;
1114
1116
1115
1117
/* Per controller/Phy values */
@@ -1332,7 +1334,7 @@ static int udc_stm32_driver_init0(const struct device *dev)
1332
1334
ep_cfg_out [i ].caps .out = 1 ;
1333
1335
if (i == 0 ) {
1334
1336
ep_cfg_out [i ].caps .control = 1 ;
1335
- ep_cfg_out [i ].caps .mps = cfg -> ep0_mps ;
1337
+ ep_cfg_out [i ].caps .mps = UDC_STM32_EP0_MAX_PACKET_SIZE ;
1336
1338
} else {
1337
1339
ep_cfg_out [i ].caps .bulk = 1 ;
1338
1340
ep_cfg_out [i ].caps .interrupt = 1 ;
@@ -1352,7 +1354,7 @@ static int udc_stm32_driver_init0(const struct device *dev)
1352
1354
ep_cfg_in [i ].caps .in = 1 ;
1353
1355
if (i == 0 ) {
1354
1356
ep_cfg_in [i ].caps .control = 1 ;
1355
- ep_cfg_in [i ].caps .mps = cfg -> ep0_mps ;
1357
+ ep_cfg_in [i ].caps .mps = UDC_STM32_EP0_MAX_PACKET_SIZE ;
1356
1358
} else {
1357
1359
ep_cfg_in [i ].caps .bulk = 1 ;
1358
1360
ep_cfg_in [i ].caps .interrupt = 1 ;
0 commit comments