Pages: 1 2 [3]   Go Down
Author Topic: Data loss when sending to native USB port (SerialUSB)  (Read 8501 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not yet, I'll wait until the patch is reliable before making a pull request. At the moment it's still losing data somewhere.

It can't be directly related to the issue you linked to (because UHD_ functions are for USB host, but here we are using UDD_ functions for USB device mode). However I am convinced that the bug is in libsam rather than SerialUSB.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

were you able to test it with my code?
Logged

Canada
Offline Offline
Sr. Member
****
Karma: 13
Posts: 424
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I do seem to be getting occasional errors but only about once every several gigabytes, which makes it hard to debug as I don't know if it's a problem with the code or the cable or with the way I am testing it. Testing so far indicates it is a problem with transmission (SerialUSB.write())

I think there's a problem in the ring buffer, where OVERFLOW of variable "i" (which is an unsigned 32 bit integer) is not dealt with. In the ring buffer code below, where i = (i + 1) % CDC_SERIAL_BUFFER_SIZE;, the value of "i" will keep counting up by one for each iteration (until it overflows), but the value of the statement will count from 0-511 then recycle (for CDC_SERIAL_BUFFER_SIZE = 512).

Ring buffer code in CDC.cpp:
Code:
ring_buffer *buffer = &cdc_rx_buffer;
uint32_t i = (uint32_t)(buffer->head+1) % CDC_SERIAL_BUFFER_SIZE;

// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
while (i != buffer->tail) {
uint32_t c;
if (!USBD_Available(CDC_RX)) {
udd_ack_fifocon(CDC_RX);
break;
}
c = USBD_Recv(CDC_RX);
// c = UDD_Recv8(CDC_RX & 0xF);
buffer->buffer[buffer->head] = c;
buffer->head = i;

i = (i + 1) % CDC_SERIAL_BUFFER_SIZE;
}
   
« Last Edit: October 25, 2013, 08:19:44 am by dlloyd » Logged

Electricity is really just organized lightning - George Carlin

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think there's a problem in the ring buffer

The ring buffer no longer exists in the code being discussed (see stimmers attached files and the thread).

I'm having a lot of problems running Paul Stoffregen's multi-byte benchmark on a fairly new Macbook pro, which is strange as he managed to get reportable results on a Macbook pro.

stimmers test scripts all work perfectly however smiley-confuse.

The host hangs before the end of the test. Resetting the due causes the host to signal an error (number of bytes delivered) and it aborts. The due however is happily waiting in a 'nothing to receive' loop.

I'm now sending sequenced data and stuff appears to be going missing. I really want to use this so I'll be resuming  in the morning!
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is an updated version of the alternative USB serial code. This fixes one of the problems I was having with the receive_test benchmark and fixes a memory corruption bug.

* CDC.cpp (7.84 KB - downloaded 39 times.)
* USBAPI.h (7.07 KB - downloaded 38 times.)
* USBCore.cpp (22.66 KB - downloaded 53 times.)
Logged


Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi stimmer!

I'd like to follow this one, but its not very handy to manually copy the files and figure out what changed from the last time, it will be much more practical if you start a branch on github. I understand that the patch may be not complete, but I'd really appreciate if you can do that :-)

Logged

C.

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd already made a branch, I just forgot to say smiley It's here:

https://github.com/stimmer/Arduino/tree/ide-1.5.x-usb-fast
Logged


Pages: 1 2 [3]   Go Up
Jump to: