corrupted CAN frames

CAN-Interface for PCI Express Mini
Post Reply
bryancole
Posts: 11
Joined: Thu 29. Nov 2018, 16:32

corrupted CAN frames

Post by bryancole » Mon 13. Dec 2021, 10:52

I have an application using both buses on a PCAN-miniPCIe device. The host OS is linux kernel-4.18.10 and I'm using the socketcan drivers built in to the kernel.
Both interfaces are active on this device and the host is receiving maybe a few hundred messages per second at 1MB baud rate (i.e. not a particularly high message rate).
The application code is running one socket for each interface and each socket is handling received messages in a separate thread. The COB-IDs in use on the two interfaces are distinct.
Over a 12 hour period or so, I see about 5 to 10 corrupted can frames. Note, the are no errors reported by the interface. I simply see CAN frames with COB-IDs expected socket A appearing on socket B and vice versa. I think the data bytes associated
with these COB IDs is not consistent so it is not just a matter of the frames being delivered to the wrong socket; their data is also mixed up. I don't believe there is any shared state between the two sockets
on the user-space side of the application.

Has anyone heard of any problem matching this description? I've not idea if this is a hardware, driver or socketcan stack bug. Obviously, it might be something in my user-space code but I can't figure out what. The sockets
are operating independently and don't share any state. My applications runs fine for hours (ignoring most of these corrupted CAN frames) but occasionally one arrives that causes a fatal error. :( I'm at a loss.

Any ideas welcome.
Thanks,
BC

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: corrupted CAN frames

Post by M.Heidemann » Mon 13. Dec 2021, 11:18

Hello,

Have you checked for error frames yet?

for example using:

Code: Select all

candump can0 -e
?

Are there any error frames logged?

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

bryancole
Posts: 11
Joined: Thu 29. Nov 2018, 16:32

Re: corrupted CAN frames

Post by bryancole » Mon 13. Dec 2021, 18:33

Hmm... seem like socketcan doesn't report err-frames by default. That's something I'll need to look into. I think the error rate is fairly low as since I've never seen an error-count more than zero when I look at the
output of "ip -details link show can0" etc.
I'm looking for error frames using this command-line:
candump any,0~0,#FFFFFFFF -e -x -ta
I've seen a few "lost arbitration" errors (as you would expect), but nothing that corresponds to a corrupted CAN frame. I've observed one corruption over the last hour but there were no other error-frames at the same or similar time.

bryancole
Posts: 11
Joined: Thu 29. Nov 2018, 16:32

Re: corrupted CAN frames

Post by bryancole » Mon 13. Dec 2021, 19:03

OK. Think I found the problem. Silly me. Turns out there was an accidentally shared buffer that both threads were using to receive CAN frames. Sorry for the line-noise... I'll just go and eat worms now.

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: corrupted CAN frames

Post by M.Heidemann » Tue 14. Dec 2021, 08:35

Hello,

Don't be so hard on yourself, stuff like this can happen to anyone.

Thank you for the feedback!

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply