STMicroelectronics / stm32u5-classic-coremw-apps

Provide a set of applications for STM32U5xx series based on the STM32 Classic Core Middleware libraries.
Other
16 stars 6 forks source link

CDC App stalls on second character in from USB side #3

Open sdzienge opened 6 months ago

sdzienge commented 6 months ago

When typing 1 character at a time I see that the first character is successfully transmitted, but the second never completes. Second character is received, and a successful start of the DMA transmission is indicated, but no events fire (half, complete, or error). This locks up the receive side of the USB as USB_CDC_ReceivePacket is never called. Communication in the other direction continues to work fine. Characters received by the uart (STLink VCP) always results in characters being transmitted on out the USB CDC side.

sdzienge commented 6 months ago

Problem seems to be with using HAL_UART_Transmit_DMA for transfers of len = 1. I made the change below and the stalls went away. I could have used HAL_UART_Transmit_IT and used the uart ISR to call HAL_UART_TxCpltCallback to make it more symmetrical with the DMA path, but that seemed unnecessary.

static int8_t CDC_Itf_Receive(uint8_t Buf, uint32_t Len) { if (Len == 1) { HAL_UART_Transmit(&UartHandle, Buf, Len, 0); USBD_CDC_ReceivePacket(&hUsbDeviceFS); } else { HAL_UART_Transmit_DMA(&UartHandle, Buf, Len); } return (USBD_OK); }