Skip to content

Commit

Permalink
usb: stm32: fix calculation of TX FIFO sizes
Browse files Browse the repository at this point in the history
The RX FIFO size is in words, so needs to be subtracted from the total
memory size *after* it's divided by 4.

Fixes #70789.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
  • Loading branch information
arbrauns authored and jhedberg committed Apr 8, 2024
1 parent 4399750 commit c481525
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/usb/device/usb_dc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ static const struct gpio_dt_spec ulpi_reset =
#define TX_FIFO_NUM USB_NUM_BIDIR_ENDPOINTS

/* We need a minimum size for RX FIFO */
#define USB_FIFO_RX_MIN 160
#define RX_FIFO_EP_WORDS 160

/* 4-byte words TX FIFO */
#define TX_FIFO_WORDS ((USB_RAM_SIZE - USB_FIFO_RX_MIN - 64) / 4)
#define TX_FIFO_WORDS ((USB_RAM_SIZE - 64) / 4 - RX_FIFO_EP_WORDS)

/* Allocate FIFO memory evenly between the TX FIFOs */
/* except the first TX endpoint need only 64 bytes */
Expand Down Expand Up @@ -446,7 +446,7 @@ static int usb_dc_stm32_init(void)
#else /* USB_OTG_FS */

/* TODO: make this dynamic (depending usage) */
HAL_PCDEx_SetRxFiFo(&usb_dc_stm32_state.pcd, USB_FIFO_RX_MIN);
HAL_PCDEx_SetRxFiFo(&usb_dc_stm32_state.pcd, RX_FIFO_EP_WORDS);
for (i = 0U; i < USB_NUM_BIDIR_ENDPOINTS; i++) {
if (i == 0) {
/* first endpoint need only 64 byte for EP_TYPE_CTRL */
Expand Down

0 comments on commit c481525

Please sign in to comment.