STM32L4xx HAL Library USB bug. Function USB_WritePMA does not work properly when compiled with "-O3" option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-06-18 11:42 PM
I used latest CubeMX version and found another one bug in stm32l4xx_ll_usb.c generated by it. If you will compile code using "-O3" optimization level, function USB_WritePMA will not work properly.
/**
* @brief Copy a buffer from user memory area to packet memory area (PMA)
* @param USBx USB peripheral instance register address.
* @param pbUsrBuf pointer to user memory area.
* @param wPMABufAddr address into PMA.
* @param wNBytes: no. of bytes to be copied.
* @retval None
*/
void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
{
uint32_t n = ((uint32_t)wNBytes + 1U) >> 1;
uint32_t BaseAddr = (uint32_t)USBx;
uint32_t i, temp1, temp2;
uint16_t *pdwVal;
uint8_t *pBuf = pbUsrBuf;
pdwVal = (uint16_t *)(BaseAddr + 0x400U + ((uint32_t)wPMABufAddr * PMA_ACCESS));
for (i = n; i != 0U; i--)
{
temp1 = (uint16_t) * pBuf;
pBuf++;
temp2 = temp1 | ((uint16_t)((uint16_t) * pBuf << 8));
*pdwVal = (uint16_t)temp2;
pdwVal++;
#if PMA_ACCESS > 1U
pdwVal++;
#endif
pBuf++;
}
}
To fix it, please replace line:
uint16_t *pdwVal;
to
volatile uint16_t *pdwVal;
Solved! Go to Solution.
- Labels:
-
STM32Cube MCU Packages
-
STM32L4 Series
-
USB
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-06-19 2:48 AM
Hello @Evgeny Sobolev​ ,
We are aware about this issue and it will be fixed in the coming release of STM32CubeL4 firmware package.
Thanks for your contribution and sorry for the inconvenience this has caused.
Best Regards,
Imen
Thanks
Imen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-06-19 2:48 AM
Hello @Evgeny Sobolev​ ,
We are aware about this issue and it will be fixed in the coming release of STM32CubeL4 firmware package.
Thanks for your contribution and sorry for the inconvenience this has caused.
Best Regards,
Imen
Thanks
Imen
