AnsweredAssumed Answered

STM32 USB HAL TxFIFO Error

Question asked by Merle Skelton on Feb 23, 2018
Latest reply on May 5, 2018 by Alex Beck

This is a reposting of STM32F7 HAL LL Driver Bug with a more descriptive name.

I am using the USB FS device with the CDC class. I used STM32CubeMX V4.23.0 with the STM32CubeF7 V1.8.0 add-on. The max packet size is set to 64 bytes and the EP TX FIFO buffer for the EP is set to 64 bytes in USBD_LL_Init(). I was sending various sized messages over the IN pipe. When I tried to send a 64-byte message, it failed...no transmit complete callback. Stepping through stm32f7xx_hal_pcd.c, I discovered in PCD_WriteEmptyTxFifo() #1287 (see code below) the packet was not being written to the Tx FIFO for transmission. Here is the code in question:

while ( (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b && // Fixed when changed > to >=

            ep->xfer_count < ep->xfer_len &&

            ep->xfer_len != 0)

What is happening is that when a packet is rounded to long words and 'len32b'  equals the Tx FIFO buffer size, the first condition of the above while() fails and the packet is not written to the FIFO. A re-enumeration is required to restore the EP to working.

When the '>' is changed to '>=', it works. I suspect that because packet sizes 61-64 bytes will round to 16 long words, all packets of these sizes will also fail. I verified that 63 byte packet fail. Probably increasing the Tx FIFO size to 128 bytes would also solve the issue, but I am using almost all of the EPs and I have run out of Tx FIFO buffer total size (1280 bytes).

Please correct this error and check for other boundary conditions in the next HAL release.

 

I also see the problem with the STM32H7 driver. I am using STM32CubeMX V4.24.0 and STM32H7xx V1.1.0. The line of code is here:

stm32f7xx_hal_pcd.c, PCD_WriteEmptyTxFifo(), #1310.

Outcomes