Hello,
I have an application where I use this wonderful library to be able to use a PEAK USB CAN adapter on my Mac. An embedded device is connected to the PEAK adapter. The application on the embedded device and the application on the Mac side worked flawlessly for some years now. Recently, I had to upgrade the PCBUSB-Library to version 0.12 (before that, I've used version 0.9), because the newer version of the Apples C++ compiler was requiring a native ARM library.
The application is a bootloader and installing a new firmware takes ~ 1 minute when using 1MBit CAN bus speed. Once in a while (1 out of 5-10), the protocol between Mac and embedded device is violated. The protocol stack then starts to report the reception of messages that were already received some time before.
To make sure, that the problem is not within the implementation of the bootloader protocol, I've attached a logic analyzer and indeed I was not able to confirm the double received messages.
When I see that problem, there are always multiple messages that where twice and they are then received in the same order as they where original received. Here is an example of a message type that is reported to be received by the Mac application:
...
CTL: 401: 06 00 47 10 00 00 01 00 8
CTL: 401: 06 00 48 10 00 00 01 00 8
CTL: 401: 06 00 49 10 00 00 01 00 8
CTL: 401: 06 00 4a 10 00 00 01 00 8
CTL: 401: 06 00 4b 10 00 00 01 00 8 <-- first time
CTL: 401: 06 00 4c 10 00 00 01 00 8
CTL: 401: 06 00 4d 10 00 00 01 00 8
CTL: 401: 06 00 4e 10 00 00 01 00 8
CTL: 401: 06 00 4f 10 00 00 01 00 8
CTL: 401: 06 00 50 10 00 00 01 00 8
CTL: 401: 06 00 51 10 00 00 01 00 8
CTL: 401: 06 00 52 10 00 7e 00 00 8
CTL: 401: 06 00 54 10 00 00 01 00 8
CTL: 401: 06 00 55 10 00 00 01 00 8
CTL: 401: 06 00 56 10 00 00 01 00 8
CTL: 401: 06 00 57 10 00 00 01 00 8
CTL: 401: 06 00 58 10 00 00 01 00 8
CTL: 401: 06 00 59 10 00 00 01 00 8
CTL: 401: 06 00 5a 10 00 00 01 00 8
CTL: 401: 06 00 5b 10 00 00 01 00 8
CTL: 401: 06 00 5c 10 00 00 01 00 8
CTL: 401: 06 00 5d 10 00 00 01 00 8
CTL: 401: 06 00 5e 10 00 00 01 00 8
CTL: 401: 06 00 5f 10 00 00 01 00 8
CTL: 401: 06 00 60 10 00 00 01 00 8
CTL: 401: 06 00 61 10 00 00 01 00 8
CTL: 401: 06 00 62 10 00 00 01 00 8
CTL: 401: 06 00 63 10 00 00 01 00 8
CTL: 401: 06 00 64 10 00 00 01 00 8
CTL: 401: 06 00 65 10 00 00 01 00 8
CTL: 401: 06 00 66 10 00 00 01 00 8
CTL: 401: 06 00 67 10 00 00 01 00 8
CTL: 401: 06 00 4b 10 00 00 01 00 8 <-- second time
CTL: 401: 06 00 4c 10 00 00 01 00 8
CTL: 401: 06 00 4d 10 00 00 01 00 8
CTL: 401: 06 00 4e 10 00 00 01 00 8
....
The message acknowledges the reception of a certain bit of data. The first byte (the 06) is an opcode, the next 4 bytes are an address, followed by a 16 byte length information. After the reception of the memory for the address 0x00016700, the received block is acknowledged and then, out of a sudden, the reception of the block at 0x00014b00 is received again.
I've traced such an error situation with a logic analyzer and can see, that the double messages are not send over the CAN bus. Beside the messages above, I suspect that there are the same amount of messages received twice. But as they contain only an opcode, I can not distinguish them from the ones that are expected at that moment.
To me, this looks like there is a reception ring buffer, what when either overflows or wraps is not empty anymore, but full and thus the application will receive the data twice.