CAN driver implementation and testing

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

CAN driver implementation and testing

6,712 Views
ramanjineyuluth
Contributor II

Hi,
I am new to CAN driver implementation in Linux. The CAN driver already is there in Linux "drivers/net/can/Flexcan.c". When I compiled kernel source it generates the Flexcan.o file but in the below link inserting all CAN related modules. To test CAN these all modules we have to include or not? Please see the link: http://www.armadeus.com/wiki/index.php?title=CAN_bus_Linux_driver
I am having two i.mx6q sabrelite boards how to communicate these two boards using CAN protocol. To communicate Flexcan.c driver file we have to implement application program or not? If you have any CAN application program Please share us, it is very useful to understand and communicate with CAN driver. If application program is not there please give me good suggestion how application is communicate with the driver code. Please help me how to test CAN between two embedded Linux boards.

Thanks & Regards,
Ram.

Labels (1)
7 Replies

3,379 Views
ramanjineyuluth
Contributor II

Hi Gary,

Thanks for your reply.

I will test CAN driver with existing kernel code. In this kernel source code the CAN modules are compiled as built in kernel, so there is no chance to insert modules manually because it is selected as [*] - built in kernel. When we poweron the board those modules are automatically inserted.

May I know why these may modules are inserting to test CAN. In manual there is only FlexCAN, Only Flexcan module is not  enough to test the CAN. May I know why dependents modules are required?

Can you please send any document how two I.MX6Q sabrelite boards are communicating with CAN.

The Flexcan driver understanding is difficult to me, Just I have to know Flexcan Initialization and how to send and receive CAN message. In Flexcan driver "flexcan_start_xmit" function is used to transfer CAN message, may I right?

Can you please explain this start_xmit function and receive CAN message functions.

Thanks,

Ramanjineyulu.

0 Kudos

3,379 Views
gary_bisson
Senior Contributor III

Hi Ramanjineyulu,

I do not understand your question about module/built-in. We chose built-in for convenience, you can switch to module if you'd like but that makes absolutely no difference.

What dependencies are you talking about?

As for documentation, I do not understand either. This is standard CAN protocol, if you want to read about it, please read the standard:

ISO 11898-1:2015 - Road vehicles -- Controller area network (CAN) -- Part 1: Data link layer and phy...

I'm also not sure to understand why you want to go so deep in the driver functions (flexcan_start_xmit), you shouldn't have to modify those and should only use user-space program to send/receive frames like the can-utils. Especially since this driver relies on the net interface, it cannot be explained in a few lines of a blog post. But definitely you shouldn't have to worry about it and just use can-utils as you base to create your app that leverages CAN.

Regards,

Gary

0 Kudos

3,379 Views
ramanjineyuluth
Contributor II

Hi,

Thanks for your reply.

I am using Ubuntu OS and Linux kernel version is 3.10.17.

In this kernel I have configured

Networking support  --->

    <M>   CAN bus subsystem support --->

        --- CAN bus subsystem support

        <M>   Raw CAN Protocol (raw access with CAN-ID filtering)

        <M>   Broadcast Manager CAN Protocol (with content filtering)

              CAN Device Drivers  --->

                 <M> Platform CAN drivers with Netlink support

                  [*]   CAN bit-timing calculation  

and saved the configuration.

I gave make command Eg: make all

It generates the zImage in arch/arm/boot/zImage but it won't generate uImage.

After that I have given "make uImage LOADADDR=0x10008000" it generates the uImage.

I have copied this uImage into the SDCARD first partition it boot's the kernel but unable to get the root filesystem.

In console it shows the "Waiting for root device /dev/mmcblk3p2"

Do you know how to generate uImage for I.MX6Q sabrelite board. Once this issue is solved then I have to insert the CAN modules into the target board.

Thanks,

Ram.

0 Kudos

3,379 Views
gary_bisson
Senior Contributor III

Hi Ram,

1) CAN driver is already enabled in our builds, you don't have to re-build the kernel on your own, it just works.

2) I suggest you grab our latest Ubuntu Trusty image since yours is using an outdated kernel:

https://www.boundarydevices.com/eula?file=20160330-nitrogen-3.14.52_1.1.0_ga-trusty-en_US-lxde_armhf...

3) In case you still want to create your own kernel for another reason, please read the following article:

https://boundarydevices.com/ubuntunizing-i-mx6-kernels/

Regards,

Gary

0 Kudos

3,379 Views
manish_kumar02
Contributor I

Hi Gary,

i am facing the issue in getting CAN0 in /sys/class/net

In this kernel I have configured

Networking support  --->

    <M>   CAN bus subsystem support --->

        --- CAN bus subsystem support

        <M>   Raw CAN Protocol (raw access with CAN-ID filtering)

        <M>   Broadcast Manager CAN Protocol (with content filtering)

              CAN Device Drivers  --->

                 <M> Platform CAN drivers with Netlink support

                  [*]   CAN bit-timing calculation  

apart from that i have followed the chapter Chapter 39 FlexCAN Driver i have done all the configuration right and followed this document too 

How to Configure and Use CAN Bus | RidgeRun Developer 

can you please let us know i am not getting can0 in my  /sys/class/net list ..

regards Manish

0 Kudos

3,379 Views
igorpadykov
NXP Employee
NXP Employee

also very simple flexcan test can be found in unit tests(imx-test package)

folder imx-test-5.4/test/can

www.nxp.com/lgfiles/NMG/MAD/YOCTO/imx-test-5.4.tar.gz

Best regards

igor

0 Kudos

3,379 Views
gary_bisson
Senior Contributor III

Hi Ram,

The link you provided is actually very nice and explains how to communicate using CAN. You need to have the user-space CAN utils tools:

https://github.com/linux-can/can-utils

Please specify which OS image you are using currently. If it is Ubuntu/Debian you should be able to download the tools with:

$ sudo apt-get install can-utils

If you are using Yocto, you need to add the "can-utils" package to your local.conf.

Then you'll be able to use cansend/candump to send/receive frames at a specific baudrate.

Regards,

Gary