cancel
Showing results for 
Search instead for 
Did you mean: 

usb hangs: stm32f4

mark2399
Associate II
Posted on January 31, 2014 at 17:31

Hi,

I am implementing a CDC USB device using the STM32f4 and STM USB libraries.

What I am finding is that after sending a number of multi-byte packets from the PC > STM32 the OUT pipe effectively hangs and I receive no further data from the PC. I can see the packet sent to the device (software packet sniffer) but I receive no interrupt on the STM32 to indicate that an OUT packet has been received.

BTW I'm not sending huge buffers of data, I can make it go wrong by sending 4 byte sequences in real term. After a random number of goes it no longer receives packets. If I send single byte packets it just won't go wrong using real term.

I have tested that I can continually send IN packets to the PC even when the OUT pipe has hung. It's almost as though an interrupt flag hasn't been cleared or something.

Has anyone else experienced this? Seems like a strange timing issue to me.

I'll continue to delve...
3 REPLIES 3
chen
Associate II
Posted on January 31, 2014 at 18:06

Hi

Silly question : Are you emptying the USB data buffer in the STM32?

What happens in the USB CDC driver when the buffer APP_Rx_Buffer[]

fills?

mark2399
Associate II
Posted on February 03, 2014 at 10:35

Hi Chen_Chung,

That is a good question. I will double check this area of the code. As no-one else seems to have had this problem is seems most likely that I have introduced a subtle bug.

regards,

Mark

work
Associate II
Posted on February 12, 2016 at 16:20

Hi,

I know this is an old thread, but I'm experiencing a similar problem at the moment using the USB CDC class driver v2.4.1. My software sends data chunks (11 bytes each) from the STM32 to the PC at a frequency of 250 Hz, while the PC sends data packets (9 bytes) at a frequency of e.g. 100 Hz. This works well for some seconds, but then CDC_Receive_FS doesn't get called anymore. However, data is still sent from STM32 to the PC.

This is how my receive function and the required variables look like:

#define APP_RX_DATA_SIZE  CDC_DATA_FS_MAX_PACKET_SIZE

uint8_t USB_RX_BUFFER[3 * APP_RX_DATA_SIZE];

uint_fast16_t USB_RX_BUFFER_PRODUCER_POS = 0;

uint_fast16_t USB_RX_BUFFER_CONSUMER_POS = 0;

uint_fast16_t USB_RX_BUFFER_WRAPAROUND_POS = 0;

static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)

{

    USB_RX_BUFFER_PRODUCER_POS += *Len;

    if (USB_RX_BUFFER_PRODUCER_POS >= 2*APP_RX_DATA_SIZE)

    {

        USB_RX_BUFFER_WRAPAROUND_POS = USB_RX_BUFFER_PRODUCER_POS;

        USB_RX_BUFFER_PRODUCER_POS = 0;

    }

    USBD_CDC_SetRxBuffer(hUsbDevice_0, USB_RX_BUFFER + USB_RX_BUFFER_PRODUCER_POS);

    USBD_CDC_ReceivePacket(hUsbDevice_0);

    return (USBD_OK);

}