5

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?

Milan Tenk
  • 465
  • 2
  • 8
  • 20
  • 1
    Full receive buffer somewhere perhaps, hardware or software handshaking kicking in? – KalleMP May 12 '15 at 08:52
  • I posted the answer, there must have been a handshaking issue in the software. – Milan Tenk May 12 '15 at 13:11
  • check this link: [https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Read data from PC to STM32 via USB CDC&currentviews=40](https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Read%20data%20from%20PC%20to%20STM32%20via%20USB%20CDC&currentviews=40) –  Feb 27 '16 at 06:48

1 Answers1

9

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.

Milan Tenk
  • 465
  • 2
  • 8
  • 20
  • 2
    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. – sergeantKK Sep 22 '16 at 16:35