STM32L433 USB transmit & received at the same time HAL lib bug.
There bug in STM HAL Lib generated by cube mx.
Problem:
I am using usb communication on STM32L433. I have high speed traffic both direction on the same endpoint. USB is stopped in one of the direction, and doesn't transmit/receive data any more.
Why:
Interrupt flag of another interrupt cleared when read->modify->write process.
For examle. We had out endpoint interrupt and call macros PCD_CLEAR_RX_EP_CTR. But after status value is read, register was modifyed by hardware (another interrupt flag was set). When software will write new value it will clear this flag and it handler will be not called.
Solution:
stm32l4xx_hal_pcd.h, replace macros to:
#define PCD_CLEAR_RX_EP_CTR(USBx, bEpNum) do { \
register uint16_t _wRegVal; \
\
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (0x7FFFU & USB_EPREG_MASK); \
_wRegVal |= USB_EP_CTR_TX; \
\
PCD_SET_ENDPOINT((USBx), (bEpNum), _wRegVal); \
} while(0) /* PCD_CLEAR_RX_EP_CTR */
#define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) do { \
register uint16_t _wRegVal; \
\
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (0xFF7FU & USB_EPREG_MASK); \
_wRegVal |= USB_EP_CTR_RX; \
\
PCD_SET_ENDPOINT((USBx), (bEpNum), _wRegVal); \
} while(0) /* PCD_CLEAR_TX_EP_CTR */