serial over usb issue

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
jeff
Posts: 2
Joined: Thu May 23, 2019 2:32 pm

serial over usb issue

Post by jeff »

Hello.

I'm experiencing some problem with the serial over USB driver.
As everyone, I use usbcfg.c & usbcfg.h files, but i'm not using the SerialUSBDriver as an BaseSequentialStream because the write method is obqWriteTimeout (hal_buffers.c:721) and this function use critical zone during the duration of the copy.

I'm sending a determined amount of data from a control loop that run at 10khz. So I wanted to get rid of this critical zone and copy.
To do so, I get an empty buffer with :

Code: Select all

obqGetEmptyBufferTimeout(&SDU1.obqueue, TIME_IMMEDIATE);

and check that there's enough space in the buffer to store my data:

Code: Select all

available_size = ((uint32_t)SDU1.obqueue.top - (uint32_t)SDU1.obqueue.ptr);
chDbgAssert(available_size >= (required_size+4), "Not enough space in the free buffer.");


Then I fill the buffer in my control loop, and at the end of the loop, I push the full buffer:

Code: Select all

obqPostFullBuffer(&SDU1.obqueue, pushed_size);



In halconf.h, I set SERIAL_USB_BUFFERS_SIZE to 128, which is the USB data endpoint maximum packet size and is enough to store the data of a loop but not two. I tested this code on two board, one custom with an STM32F7 ( I cleaned the data cache on this platform before sending full buffer with SCB_CleanDCache_by_Addr ) and a nucleo-f446re.

On both this target, I have got the same behaviour .... it works :D !!.... most of the time :|
What I send is a structure that begin with a sync word, and x values.

- Sometime, a struct amongst the others are dropped by my state machine on my computed ( the sync word isn't found, so I seems that data were corrupted ! ). But when it works, there's absolutely no corruption for minutes...

- Sometime, almost every struct is corrupted and I noticed that when I initialise only a little part of the sent struct, things seems to get worse... In this case, doing :

Code: Select all

std::memset(SDU1.ob, 0xFF,sizeof(SDU1.ob));

before sduStart seems to help.

- sometime I can't read any more data in the device on my computer ( my software isn't crashed :lol: ). I unplugged then plugged the USB cable, and I can read data again. It seems that the linux usb driver isn't really stable ?
By the way, I often have to wait for like 20 seconds before linux let me open the device :roll:

Regards
Jeff
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: serial over usb issue

Post by Giovanni »

Hi,

Have you considered not using buffering but the USB API directly? there is an example under /testhal/STM32/STM32F7xx/USB_RAW

About the problem, somebody reported that the Linux and Windows CDC hosts do not send zero size packets to terminate transactions as required by the specification. You may try to workaround this by doing reads operations of packet size maximum.

Giovanni
jeff
Posts: 2
Joined: Thu May 23, 2019 2:32 pm

Re: serial over usb issue

Post by jeff »

You're right, I could use the USB API directly, but I don't think that will change anything ?
I will try your workaround :)
Post Reply