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
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
By the way, I often have to wait for like 20 seconds before linux let me open the device
Regards
Jeff