Access CAN-FD on S32V234

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Access CAN-FD on S32V234

2,462 Views
xuewong
Contributor I

Hello,

I am planing to use the CAN-FD on the S32V234 for sending out can message. Is there any example on how to do this on the linux enviornment?

Thank you

0 Kudos
Reply
2 Replies

1,737 Views
KushalShahNXP
NXP Employee
NXP Employee

Hi Xue,

S32V234 devices supports CAN-FD. So it may be some BSP settings that needs to be done. You can download Yocto distribution and modify BSP according to your need. Please visit www.nxp.com/s32v >> SOFTWARE & TOOLS to download Linux BSP and its user manual. Linux BSP User Manual has information to download Yocto.

For physical connections please make sure right port and pins are connected to probe/other device. You do simple test by connection can0 and can1 of the same device.

Regards,

Kushal

0 Kudos
Reply

1,737 Views
xuewong
Contributor I

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() ?

0 Kudos
Reply