Some update. i was able to bring up the can0 and can1 with the linux SocketCAN command:
>>ip link set can0 type can bitrate 500000
>>ip link set can0 up
However, when i try to enable can fd with
>>ip link set can0 type can bitrate 500000 dbitrate dbitrate 4000000 fd on
I got the error message:
RTNETLINK answers: Operation not supported
It seems like CAN-FD is not supported, although the documentation of the S32V234 board specified that the CAN port is a CAN-FD port. It this has something to do with the linux bsp setting? I am using the bsp come with S32DS for vision.
Since i was able to bring up the raw can, i did some test with some simple SocketCAN example:
TO write:
int
main(int argc, char** argv)
{
int s;
int nbytes;
struct sockaddr_can addr;
struct can_frame frame;
struct ifreq ifr;
const char *ifname = argv[1];
if((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
perror("Error while opening socket");
return -1;
}
strcpy(ifr.ifr_name, ifname);
ioctl(s, SIOCGIFINDEX, &ifr);
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
printf("%s at index %d\n", ifname, ifr.ifr_ifindex);
if(bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Error in socket bind");
return -2;
}
frame.can_id = 0x123;
frame.can_dlc = 2;
frame.data[0] = 0x11;
frame.data[1] = 0x22;
nbytes = write(s, &frame, sizeof(frame));
printf("Wrote %d bytes\n", nbytes);
perror("write");
return 0;
}
To Read:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/raw.h>
int
main(int argc, char** argv)
{
int s;
int nbytes;
struct sockaddr_can addr;
struct can_frame frame;
struct ifreq ifr;
const char *ifname = argv[1];
if((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
perror("Error while opening socket");
return -1;
}
strcpy(ifr.ifr_name, ifname);
ioctl(s, SIOCGIFINDEX, &ifr);
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
printf("%s at index %d\n", ifname, ifr.ifr_ifindex);
if(bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Error in socket bind");
return -2;
}
while(true){
nbytes = read(s, &frame, sizeof(frame));
if(nbytes > 0){
printf("%d\n",frame.can_id);
}
else
{
usleep(1e6);
}
}
return 0;
}
This code is working fine when i test it with a virtual can setup in the S32V234 board. However, i cannot read any thing when run on can0 or can1. Is this mean the physical can bus has to connect to another physical can bus for read() / write() ?