# STM32 VCP - Receive data from PC

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?

• Full receive buffer somewhere perhaps, hardware or software handshaking kicking in? – KalleMP May 12 '15 at 8:52
• I posted the answer, there must have been a handshaking issue in the software. – Milan Tenk May 12 '15 at 13:11
• – user101731 Feb 27 '16 at 6:48

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.