I have a Ubuntu Linux (x64) kernel 5.4.0-66-generic with a PCAN-USB FD attached and configured it for CAN FD as follows:
Code: Select all
ip link set can0 up type can bitrate 500000 sample-point 0.750 dbitrate 2000000 dsample-point 0.800 fd on
Code: Select all
/* set socket options */
{
int value;
value = 0;
// disable loopback
setsockopt(mCANhandle[CAN_PORT_INDEX], SOL_CAN_RAW, CAN_RAW_LOOPBACK,
&value, sizeof(value));
// enable error filter, note that actual error frame support depends on kernel driver
value = CAN_ERR_MASK;
setsockopt(mCANhandle[CAN_PORT_INDEX], SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
&value, sizeof(value));
// enable can fd
value = 1;
setsockopt(mCANhandle[CAN_PORT_INDEX], SOL_CAN_RAW, CAN_RAW_FD_FRAMES,
&value, sizeof(value));
}
Error (16 bytes, ID, data0-4): 0x00000004 0x00 0x04 0x00 0x00 0x00
Error (16 bytes, ID, data0-4): 0x00000004 0x00 0x10 0x00 0x00 0x00
Error (16 bytes, ID, data0-4): 0x00000004 0x00 0x01 0x00 0x00 0x00
Error (16 bytes, ID, data0-4): 0x00000004 0x00 0x04 0x00 0x00 0x00
According to linux/can/error.h, ID=0x4 means "controller problems", ok. The important information is in data byte 1:
Code: Select all
/* error status of CAN-controller / data[1] */
#define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */
#define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */
#define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */
#define CAN_ERR_CRTL_RX_WARNING 0x04 /* reached warning level for RX errors */
#define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */
#define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */
#define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */
/* (at least one error counter exceeds */
/* the protocol-defined level of 127) */
#define CAN_ERR_CRTL_ACTIVE 0x40 /* recovered to error active state */
Code: Select all
$ ip -details -statistics link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 minmtu 0 maxmtu 0
can <FD> state ERROR-PASSIVE (berr-counter tx 0 rx 135) restart-ms 0
bitrate 500000 sample-point 0.750
tq 12 prop-seg 59 phase-seg1 60 phase-seg2 40 sjw 1
pcan_usb_fd: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp-inc 1
dbitrate 2000000 dsample-point 0.800
dtq 12 dprop-seg 15 dphase-seg1 16 dphase-seg2 8 dsjw 1
pcan_usb_fd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp-inc 1
clock 80000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 2 2 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
RX: bytes packets errors dropped overrun mcast
13300 1939 2 0 2 0
TX: bytes packets errors dropped carrier collsns
150003 102478 0 0 0 0
Code: Select all
$ ip -details -statistics link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 minmtu 0 maxmtu 0
can <FD> state ERROR-ACTIVE (berr-counter tx 0 rx 83) restart-ms 0
bitrate 500000 sample-point 0.750
tq 12 prop-seg 59 phase-seg1 60 phase-seg2 40 sjw 1
pcan_usb_fd: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024 brp-inc 1
dbitrate 2000000 dsample-point 0.800
dtq 12 dprop-seg 15 dphase-seg1 16 dphase-seg2 8 dsjw 1
pcan_usb_fd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024 dbrp-inc 1
clock 80000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 2 2 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
RX: bytes packets errors dropped overrun mcast
13578 1985 2 0 2 0
TX: bytes packets errors dropped carrier collsns
151749 102847 0 0 0 0
- Why are the error frames and device status showing receive errors even though my application only transmits?
- Why after recovery to error active is no error frame with status CAN_ERR_CRTL_ACTIVE generated?
Cheers,
Chris