USB CDC Serial Freezing on large frames

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
Tazzi
Posts: 20
Joined: Wed Jan 08, 2020 12:45 am

USB CDC Serial Freezing on large frames

Post by Tazzi »

I am using the native USB lines from a STM32F303RE on a Nucleo F303RE board, with the 1.5Kohm pullup resistor so my computer happily detects the device and assigns a virtual serial port. I have set the arduino options to use the native USB CDC serial , using the default usb speed and default optimisation.

The issue I am facing is if I send a large buffer from the PC through serial to the board, it freezes/hangs up.
I can send 64bytes in one hit all day long, but as soon as I send say, 4000bytes, as soon as my PC software code does a Serial.write(Buffer,0,buffer.length), it will then come up saying "serial device not functioning" or something along the lines since part way through the transfer the STM freezes.
After that, I cannot send a single byte to the STM device until rebooting the board.

From what I understand with USB, is all data packets (For low speed) are 64bytes long. If a buffer to send is larger then 64bytes, then it is split up and sent in 64byte packets. The USB library then saves the received data into a buffer which is what the main sketch reads from.
I originally figured it might be the RX buffer assigned is filling up and it then basically freaks out when out of space, but I have tried increase the buffer from the default to 4096+ bytes, and the problem persists. I believe I could send about 103bytes, anything more resulted in the serial device not functioning error.

It seemed very weird to be able to send 103bytes. Even if the STM was slow in processing the bytes.. it should be able to still do it slowly at least but it just hard faults an becomes completely unresponsive

I can attach a sketch and program to simulate the issue. Just not sure if this is a STM32F3 specific issue, or affects other devices too?

Has anyone tried sending large serial frames through the native USB serial port?
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: USB CDC Serial Freezing on large frames

Post by fpiSTM »

Right, you should post your sketch.
Then I will try.
Tazzi
Posts: 20
Joined: Wed Jan 08, 2020 12:45 am

Re: USB CDC Serial Freezing on large frames

Post by Tazzi »

fpiSTM wrote: Thu Jan 09, 2020 3:07 pm Right, you should post your sketch.
Then I will try.
No problem,
Attached is the windows program, all it does is connect to the desired comport and then send a buffer of requested size, then will read back the bytes and verify they match.

Here is the sketch code:

Code: Select all

void setup() {
  delay(100);
  SerialUSB.begin();
  while(!SerialUSB){};
}

void loop() {
 if(SerialUSB.available() > 0)
 {
    uint8_t val = SerialUSB.read();
    SerialUSB.write(val);
    SerialUSB.flush();
 }
}
Post Reply

Return to “General discussion”