cancel
Showing results for 
Search instead for 
Did you mean: 

Still about USB Virtual Com Port (SOLVED)

Zanon.Luciano
Senior

Hi, I'm trying to transfer a text file via USB cable from the PC to my development board (stm3210-c), I generated the project with CubeMx, my board is configured as a device and I loaded the virtual com port as a Class for FS IP.

Now when I try to transfer a text file from the PC to my device card it happens that the data arrive too fast and I can't process it, so the reception routine CDC_Receive_FS (called the ISR) must be able to manage the flow of incoming data.

As described in UM1734 (USB data transfer flow) The PCD layer provides all the APIs required to start and control a transfer flow.

HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)

HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)

HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)

HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)

HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)

Is there anyone who has experience using the HAL_PCD_EP_SetStall and HAL_PCD_EP_ClrStall APIs in order to control the incoming flux data?

Can help me with any suggestions?

Or is there a reference project for these APIs?

Thanks in advance.

3 REPLIES 3
Pavel A.
Evangelist III

IMHO you don't need to use stall.

Instead, look how to use hardware flow control (RTS/CTS) and send CTS status to host. Or, use ctrl/S ctrl/Q flow control.

The host app should support this.

-- pa

Hi

Data from Host is blocked until you call USBD_CDC_ReceivePacket(..) inside CDC_Receive_FS callback.

So, process first your already received data an after this call USBD_CDC_ReceivePacket(..)

Hello, thank you for your helpful reply.

I have tested your suggestion and seems to work well.

From the CDC_Receive_FS callback routine (which is executed as ISR) I load a circular buffer and only when this is full I return to main program without executing the USBD_CDC_ReceivePacket (..).

In the main program I execute the data processing and empty the circular buffer, when it is empty I call the USBD_CDC_ReceivePacket(..) execution which reactivates the data shipment from the host. :smiling_face_with_smiling_eyes: