4
\$\begingroup\$

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?

\$\endgroup\$
9
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks for guiding me to the answer. For me, the key to this was adding a call to 'USBD_CDC_ReceivePacket(&USBD_Device);' within the receive callback... 'static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len)' It looks to be needed to tell the host PC driver that we have received the packet OK. \$\endgroup\$ – sergeantKK Sep 22 '16 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.