Skip to content

Commit 8940344

Browse files
drivers: usb: udc: stm32: allow EP max packet size up to HW capabilities
The maximal packet size (for non-control endpoints) was obtained by the driver from HAL definitions which appear to not properly reflect hardware capabilities. Update driver to allow endpoints with wMaxPacketSize up to the maximal value allowed by the USB Specification depending on operation mode, since all STM32 USB controllers always support these values. Also move the EP max packet size field in the 'struct udc_stm32_config' to avoid implicit padding and add a documentation comment. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent 88aab2b commit 8940344

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

drivers/usb/udc/udc_stm32.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
121121
(PCD_SPEED_HIGH_IN_FULL), \
122122
(PCD_SPEED_HIGH))))
123123

124+
/*
125+
* Returns max packet size allowed for endpoints of 'usb_node'
126+
*
127+
* Hardware always supports the maximal value allowed
128+
* by the USB Specification at a given operating speed:
129+
* 1024 bytes in High-Speed, 1023 bytes in Full-Speed
130+
*/
131+
#define UDC_STM32_NODE_EP_MPS(node_id) \
132+
((UDC_STM32_NODE_SPEED(node_id) == PCD_SPEED_HIGH) ? 1024U : 1023U)
133+
134+
124135
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
125136
#define USB_USBPHYC_CR_FSEL_24MHZ USB_USBPHYC_CR_FSEL_1
126137
#endif
@@ -158,11 +169,12 @@ struct udc_stm32_data {
158169
struct udc_stm32_config {
159170
uint32_t num_endpoints;
160171
uint32_t dram_size;
161-
uint16_t ep_mps;
162172
/* PHY selected for use by instance */
163173
uint32_t selected_phy;
164174
/* Speed selected for use by instance */
165175
uint32_t selected_speed;
176+
/* Maximal packet size allowed for endpoints */
177+
uint16_t ep_mps;
166178
};
167179

168180
enum udc_stm32_msg_type {
@@ -1070,18 +1082,7 @@ static const struct udc_api udc_stm32_api = {
10701082
* Kconfig system.
10711083
*/
10721084
#define USB_NUM_BIDIR_ENDPOINTS DT_INST_PROP(0, num_bidir_endpoints)
1073-
1074-
#if defined(USB) || defined(USB_DRD_FS)
1075-
#define EP_MPS 64U
1076-
#define USB_RAM_SIZE DT_INST_PROP(0, ram_size)
1077-
#else /* USB_OTG_FS */
1078-
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
1079-
#define EP_MPS USB_OTG_HS_MAX_PACKET_SIZE
1080-
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otgfs) || DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usb)
1081-
#define EP_MPS USB_OTG_FS_MAX_PACKET_SIZE
1082-
#endif
1083-
#define USB_RAM_SIZE DT_INST_PROP(0, ram_size)
1084-
#endif /* USB */
1085+
#define USB_RAM_SIZE DT_INST_PROP(0, ram_size)
10851086

10861087
static struct udc_stm32_data udc0_priv;
10871088

@@ -1093,7 +1094,7 @@ static struct udc_data udc0_data = {
10931094
static const struct udc_stm32_config udc0_cfg = {
10941095
.num_endpoints = USB_NUM_BIDIR_ENDPOINTS,
10951096
.dram_size = USB_RAM_SIZE,
1096-
.ep_mps = EP_MPS,
1097+
.ep_mps = UDC_STM32_NODE_EP_MPS(DT_DRV_INST(0)),
10971098
.selected_phy = UDC_STM32_NODE_PHY_ITFACE(DT_DRV_INST(0)),
10981099
.selected_speed = UDC_STM32_NODE_SPEED(DT_DRV_INST(0)),
10991100
};

0 commit comments

Comments
 (0)