Darius B

STM32L4 USB double buffer HAL bug2

Discussion created by Darius B on Mar 2, 2018

Project was generated with CubeX v4.24, STM32L4 package version 1.11.0

 

At file   stm32l4xx_ll_usb.c  need exchange 2 lines.

Bug:  Software use same buffer, which used  USB hardware peripheral.

USB hardware peripheral  used DATA1 buffer, so need fill DATA0 buffer.

 

HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx , USB_EPTypeDef *ep, uint8_t dma)

{

.............

.............

 

#if 1//Ok
        /* Write the data to the USB endpoint */
        if (PCD_GET_ENDPOINT(USBx, ep->num)& USB_EP_DTOG_TX)
        {
          /* Set the Double buffer counter for pmabuffer0 */
          PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
          pmabuffer = ep->pmaaddr0;
        }
        else
        {
            /* Set the Double buffer counter for pmabuffer1 */
            PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
            pmabuffer = ep->pmaaddr1;
        }
        USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, len);
        PCD_FreeUserBuffer(USBx, ep->num, ep->is_in);

 

#else//STM HAL error

 

      /* Write the data to the USB endpoint */
      if (PCD_GET_ENDPOINT(USBx, ep->num)& USB_EP_DTOG_TX)
      {
        /* Set the Double buffer counter for pmabuffer1 */
        PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
        pmabuffer = ep->pmaaddr1;
      }
      else
      {
        /* Set the Double buffer counter for pmabuffer0 */
        PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
        pmabuffer = ep->pmaaddr0;
      }
      USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, len);
      PCD_FreeUserBuffer(USBx, ep->num, ep->is_in);
#endif

 

BR

Darius Babrauskas

Outcomes