usb: device_next: Fix Mass Storage on STM32

Mass Storage enumeration failed because udc_stm32_ep_mem_config() was only
increasing priv->occupied_mem on endpoint enable, and not decreasing it on
endpoint disable. Fix the issue by decreasing priv->occupied_mem
on endpoint disable.

Signed-off-by: Arne Bohnsack <arne.bohnsack@draeger.com>
This commit is contained in:
Arne Bohnsack 2024-04-19 14:02:37 +02:00 committed by Fabio Baltieri
commit 38edec68d4

View file

@ -465,14 +465,17 @@ static int udc_stm32_ep_mem_config(const struct device *dev,
return 0;
}
words = MIN(ep->mps, cfg->ep_mps) / 4;
words = (words <= 64) ? words * 2 : words;
if (!enable) {
if (priv->occupied_mem >= (words * 4)) {
priv->occupied_mem -= (words * 4);
}
HAL_PCDEx_SetTxFiFo(&priv->pcd, USB_EP_GET_IDX(ep->addr), 0);
return 0;
}
words = MIN(ep->mps, cfg->ep_mps) / 4;
words = (words <= 64) ? words * 2 : words;
if (cfg->dram_size - priv->occupied_mem < words * 4) {
LOG_ERR("Unable to allocate FIFO for 0x%02x", ep->addr);
return -ENOMEM;