Skip to content

Commit 6c349f0

Browse files
drivers: usb: udc: stm32: clean up handling of USB buffer table
The ST USB controller (compatible 'st,stm32-usb') is fitted with private SRAM called the Private Memory Area or PMA. This is primarily used to hold data transfered over USB, but it also contains the so-called 'buffer table' (a.k.a. BTABLE) which holds the base address and size of buffers in the PMA allocated to each endpoint. The BTABLE is placed by the driver at the start of the PMA and occupies a fixed size ('USB_BTABLE_SIZE'), which was stored in the driver configuration field 'pma_offset'. This mechanism is unused on non-ST USB controllers from STM32 microcontrollers, but USB_BTABLE_SIZE is still defined (to a dummy value) and stored in the 'pma_offset' field which becomes unused. Remove the 'USB_BTABLE_SIZE' definition and the 'pma_offset' field from the driver configuration, and update the ST USB controller-specific verison of 'udc_stm32_mem_init' to derive the BTABLE size from the number of endpoints that the controller has instead. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent d3adb48 commit 6c349f0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/usb/udc/udc_stm32.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ struct udc_stm32_data {
157157

158158
struct udc_stm32_config {
159159
uint32_t num_endpoints;
160-
uint32_t pma_offset;
161160
uint32_t dram_size;
162161
uint16_t ep_mps;
163162
/* PHY selected for use by instance */
@@ -608,7 +607,12 @@ static inline void udc_stm32_mem_init(const struct device *dev)
608607
struct udc_stm32_data *priv = udc_get_private(dev);
609608
const struct udc_stm32_config *cfg = dev->config;
610609

611-
priv->occupied_mem = cfg->pma_offset;
610+
/**
611+
* Endpoint configuration table is placed at the
612+
* beginning of Private Memory Area and consumes
613+
* 8 bytes for each endpoint.
614+
*/
615+
priv->occupied_mem = (8 * cfg->num_endpoints);
612616
}
613617

614618
static int udc_stm32_ep_mem_config(const struct device *dev,
@@ -1074,7 +1078,6 @@ static const struct udc_api udc_stm32_api = {
10741078

10751079
#if defined(USB) || defined(USB_DRD_FS)
10761080
#define EP_MPS 64U
1077-
#define USB_BTABLE_SIZE (8 * USB_NUM_BIDIR_ENDPOINTS)
10781081
#define USB_RAM_SIZE DT_INST_PROP(0, ram_size)
10791082
#else /* USB_OTG_FS */
10801083
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
@@ -1083,7 +1086,6 @@ static const struct udc_api udc_stm32_api = {
10831086
#define EP_MPS USB_OTG_FS_MAX_PACKET_SIZE
10841087
#endif
10851088
#define USB_RAM_SIZE DT_INST_PROP(0, ram_size)
1086-
#define USB_BTABLE_SIZE 0
10871089
#endif /* USB */
10881090

10891091
static struct udc_stm32_data udc0_priv;
@@ -1096,7 +1098,6 @@ static struct udc_data udc0_data = {
10961098
static const struct udc_stm32_config udc0_cfg = {
10971099
.num_endpoints = USB_NUM_BIDIR_ENDPOINTS,
10981100
.dram_size = USB_RAM_SIZE,
1099-
.pma_offset = USB_BTABLE_SIZE,
11001101
.ep_mps = EP_MPS,
11011102
.selected_phy = UDC_STM32_NODE_PHY_ITFACE(DT_DRV_INST(0)),
11021103
.selected_speed = UDC_STM32_NODE_SPEED(DT_DRV_INST(0)),

0 commit comments

Comments
 (0)