I am using STM32 HAL VCP firmware generated by CubeMX on STM32F4 discovery board. The Virtual COM Port works, I can transmit from the microcontroller to the PC as many messages I want. But in the other direction, from PC to microcontroller I can send only one message. If I try to send a second one, the static int8_t CDC_Receive_FS (char* Buf, uint32_t *Len)
callback won't be called, and on the PC RealTerm hangs. My client program hangs too, when it tries to write in the COM port second time.
On microntroller side I removed all of my code in CDC_Receive_FS()
, it returns currently only USBD_OK
. In the main function there is only a HAL_Delay()
periodically called, I tried to remove this too, but it had no effect.
Any ideas, what could be the problem?
Best Answer
I found the answer for my own question. There is a well documentated example on the following webpage: http://visualgdb.com/tutorials/arm/stm32/usb/
First of all, I had to complete the generated code in
static int8_t CDC_Receive_FS (char* Buf, uint32_t *Len)
as it is written in the source above.After that I had to create and implement the
int VCP_read(void *pBuffer, int size)
function, as it is written in the above mentioned source.The key point was, that I had to call periodically the
int VCP_read(void *pBuffer, int size)
function, to read out from the buffer the received data. If I don't call this function, the PC can't write next time the COM port.