How could i use the can1 of iMX6DL Sabreauto

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

How could i use the can1 of iMX6DL Sabreauto

Jump to solution
5,345 Views
Leo_Yang
Contributor II

Hello,everyone: my platform is iMX6DL Sabreauto,and i want to use the CAN to communicate with a USB-CAN adptor .

As you kown,the Ethernet interface and CAN0 using the same io (CAN0_TXD = ENET_MDC),so i want to enable the can1, however , i could't,. 

LTIB : L3.0.35_4.1.0_130816_source i have add the can supports in the configure of LTIB.

(1) At first,the target load image from host via TFTP server.  

MX6DL SABREAUTO U-Boot > tftpboot uImage

FEC: Link is Up 796d

Using FEC0 device TFTP from server 192.168.1.2; our IP address is 192.168.1.3

Filename 'uImage'.

Load address: 0x10800000 Loading: ##.................

done

Bytes transferred = 3866624 (3b0000 hex)

(2) boot ,load rootfs by NFS server

MX6DL SABREAUTO U-Boot > boot .............................

Verifying Checksum ... OK

Loading Kernel Image ... OK

OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.

......................

(3) then,i can see the imx6q-flexcan.1: device had been registered

vcan: Virtual CAN interface driver

CAN device driver interface

flexcan netdevice driver

flexcan imx6q-flexcan.1: device registered (reg_base=ea9a8000, irq=143)

.....................

NET: Registered protocol family 17

can: controller area network core (rev 20090105 abi 8)

NET: Registered protocol family 29

can: raw protocol (rev 20090105)

can: broadcast manager protocol (rev 20090105 t)

(4) Linux boot correctly, when i want to check the can0 and can1 ,i could find the can0 ,not can1

root@freescale ~$ ifconfig -a

can0        Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-0

               NOARP MTU:16 Metric:1

               RX packets:0 errors:0 dropped:0 overruns:0 frame:0

               TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10

               RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

               Interrupt:143

eth0 Link encap:Ethernet ...........

lo Link encap:Local Loopback .................

root@freescale ~$ root@freescale ~$ ip link

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN qlen 10   link/can

3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP q0 link/ether 00:04:9f:20:b4:ca brd ff:ff:ff:ff:ff:ff 

(5) so i try to set up the bitrate of can0, the flexcan.1 was set. I have no ideal how to fix it. Other hand ,linux tell me that it "cannot find device can1"

root@freescale ~$ ip link set can0 up type can bitrate 125000

flexcan imx6q-flexcan.1: writing ctrl=0x0e312005 

root@freescale ~$ ip link set can1 up type can bitrate 125000

Cannot find device "can1"

Did I forgot something ?

Could anyone please guide me.  

Labels (2)
Tags (1)
1 Solution
2,482 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

In another works, althought your command "ip link set can0 up type can bitrate 125000" accessed the "can0" device, the hardware interface CAN1 was used.

View solution in original post

0 Kudos
14 Replies
2,482 Views
nitVi123
Contributor I

Hi Leo Yang \ Babu,


How did you fixed this issue?


I am also facing the same issue.


I tried canutils and libsocketcan as well,but its not working.


I am not able to send or recieve any data using can.


Let me know how you fix it for SabreAuto board.

Nitin

0 Kudos
2,482 Views
Leo_Yang
Contributor II

sorry ,i'm late.

Did you resolve your problem?

(1) make sure the FlexCAN module has registered ,following in boot information :

flexcan imx6q-flexcan.0: device registered

flexcan imx6q-flexcan.1: device registered


(2) Did you have selected the package of NetWorking device in the LTIB?

0 Kudos
2,482 Views
arunswarnam
Contributor II

Hi leo . I face the same issue . I couldnt perform loop back test. According to the last discussion i enabled networking package with can sub system . And when I check only one flex can registered(flexcan0) . How do I register my flexcan1.? Can you also send the uboot parameter that I have to set.?

0 Kudos
2,482 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

To enable the two can, you need add the "can0" in your kernel boot command.


0 Kudos
2,482 Views
Leo_Yang
Contributor II

thank you for your reply .

Actrully, if I added the "can0=1" in bootargs of U-Boot env. I could see the information about the flexcan.0 ,following:

vcan: Virtual CAN interface driver

CAN device driver interface

flexcan netdevice driver

flexcan imx6q-flexcan.0: device registered (reg_base=xxxxxxxxx, irq=xxx)

flexcan imx6q-flexcan.1: device registered (reg_base=ea9a8000, irq=143)


But,beacuse  I wanna use the TFTP and NFS, so I can NOT use the FlexCAN0. My point is I wanna FlexCAN1 and what should  I do .


root@freescale ~$ ip link set can0 up type can bitrate 125000

flexcan imx6q-flexcan.1: writing ctrl=0x0e312005

root@freescale ~$ ip link set can1 up type can bitrate 125000

Cannot find device "can1"


thank you again.


0 Kudos
2,482 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

Hi Leo, the boot parameter is just "can0", not "can0=1".

0 Kudos
2,482 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

By the way, in my side both "can0" and "can0=1" work.

And the two commands also work well.

ip link set can0 up type can bitrate 125000

ip link set can1 up type can bitrate 125000

0 Kudos
2,482 Views
Leo_Yang
Contributor II

Mr.Li,

     I'm so sorry about my mistake, I'm really really crazy right now.

Actully ,I do not want use the CAN0, I need CAN1, but the Linux always tell me "Cannot find device "can1",


     root@freescale ~$ ip link set can0 up type can bitrate 125000

     flexcan imx6q-flexcan.1: writing ctrl=0x0e312005

     root@freescale ~$ ip link set can1 up type can bitrate 125000

     Cannot find device "can1"


     Could you show me your response of cmd ( ip link set can1 up type can bitrate 125000 )?

     Maybe the can0 is flexCAN1 and can1 is flexCAN0 ?


     thank you for your patient !

0 Kudos
2,483 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

In another works, althought your command "ip link set can0 up type can bitrate 125000" accessed the "can0" device, the hardware interface CAN1 was used.

0 Kudos
2,482 Views
Leo_Yang
Contributor II

Thanks a lot. The  CAN is working well , I'm able to test CAN successfully.

Thanks a lot for your timely reply.

0 Kudos
2,482 Views
Babu
Contributor I

Hi Leo Yang,

I am trying to setup can0 on  IMX6Q sabreauto board. I am having similar kind of issue.. My CAN driver is up, but not able to send data out.

Can you post your flexcan driver and kernel configuration for can0( Which is Hardware can1).

Thank you

0 Kudos
2,481 Views
Leo_Yang
Contributor II

Hi,

      First of all , did you have read this tips ,All Boards FlexCAN [https://community.freescale.com/docs/DOC-1437] ,do NOT forget the following spec files Can_specs.tar.gz ( attached below ).

      Then , I had tested to open the device in Qt by following code:

#include <QCoreApplication>

#include <QTextStream>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <sys/stat.h>

#include <sys/fcntl.h>

#include <termios.h>

#include <errno.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>

#define PF_CAN (29)

int main(int argc, char *argv[])

{

    QCoreApplication a(argc, argv);

    int nbytes;

    struct sockaddr_can addr;

    struct can_frame frame;

    struct ifreq ifr;

    char *ifname = "can0";

    int s         = 0 ;

    int i         = 0 ;

    int isCanOpen = 0 ;

    if((s = socket( PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {

        perror("Error while opening socket");

        return -1;

    }else{

        printf("Creat socket complete \n");

        strcpy(ifr.ifr_name, ifname);

        ioctl(s, SIOCGIFINDEX, &ifr);

        addr.can_family  = PF_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;

        }else{

            printf("Bind socket complete \n");

            isCanOpen = 1 ;

        }

    }

    frame.can_id  = 10 ;

    frame.can_dlc = 8 ;

    for (i = 0; i < frame.can_dlc; ++i){

        frame.data[i]=i;

    }

    nbytes = write(s, &frame,sizeof(struct can_frame));

    return(0);

}

0 Kudos
2,482 Views
Babu
Contributor I

Thanks a lot.. it worked for me....

Babu A

0 Kudos
2,482 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

In your kernel, you only enabled one hardware CAN device successfully. It is hardware interface CAN1, since there is only one CAN device, the hardware CAN1 will be registered as linux device "can0".

I think you had modified some kernel code, which caused hardware CAN0 driver can't be loaded successfully.

In Freescale default BSP, with boot parameter "can0", the kernel will register two CAN devices, hardware device CAN0 was registered first, it will be linux device "can0"; hardware device CAN1 was registered second, then it will be linux device "can1".

Without the boot parameter "can0", the hardware CAN0 will not be registered, so only hardware device CAN1 was registered, it will be linux device "can0".