IMX6 CAN configuration using canutils and libsocketcan

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

IMX6 CAN configuration using canutils and libsocketcan

6,955 Views
flaviocordova
Contributor I

I have several questions about how handle the CAN, first I find a few documents

winter2012_EcoCariMX53_v1.pdf
https://community.freescale.com/docs/DOC-1437
https://www.kernel.org/doc/Documentation/networking/can.txt
https://gitorious.org/linux-can/can-utils/source/31936b5a173dfe1d0ba0e71859e37cbc42d5bad8:
https://community.freescale.com/servlet/JiveServlet/download/367675-268661/FlexCAN_training_material...

But, dont show how shall be compiled the canutils on the app, for example, if in the app is used the ncurses, I need to add several lines in the makefile to point the locations of the include files and the lib, by the CAN dont say anything

in the https://community.freescale.com/docs/DOC-9619 , page 46 an 47 try to explain how calculate the Bitrate and the escalation, but is not clear enough, also how I can transfer to a code.

The CAN is automatic open when we send the dataframe through "write" function or is necessary open it with other instructions, the documents show the instruction

ifconfig can0 up

When is transmitted through line command.

Could you help me to clarify this points

Regards

0 Kudos
1 Reply

1,738 Views
TomE
Specialist II

> But, dont show how shall be compiled


Can't help with that. It shouldn't need ncurses as it is a simple command-line program.

> page 46 an 47 try to explain how calculate the Bitrate and the escalation, but is not clear enough, also how I can transfer to a code.


You should just be able to specify the "bitrate" and canconfig should do the calculations for you and pick an appropriate set of numbers.

> the documents show the instruction
> ifconfig can0 up

If you type "ifconfig can0" you can see if it is up or down. "ifconfig can0 up" and "ifconfig can0 down" will send it up and down.

SO TOO will "canconfig can0 start" and "canconfig can0 stop", and you can see the results of that with "ifconfig".

So I suggest you do "canconfig can0 stop ; canconfig can0 bitrate nnnn; canconfig can0 start" and then the "ifconfig can0 up" is not necessary.

This is what we have in our custom  /etc/init.d startup script for CAN:

# Configure the first CAN port

/usr/local/sbin/canconfig can1 stop

/usr/local/sbin/canconfig can1 bitrate 1000000

/usr/local/sbin/canconfig can1 restart-ms 1000

/usr/local/sbin/canconfig can1 clockfreq | grep -q 66666666

RC=$?

if [ $RC -eq 0 ]

then

    PARMS="bittiming tq 90 prop-seg 3 phase-seg1 4 phase-seg2 3 sjw 3"

else

    PARMS="bittiming tq 83 prop-seg 4 phase-seg1 4 phase-seg2 3 sjw 3"

fi

/usr/local/sbin/canconfig can1 $PARMS

/usr/local/sbin/canconfig can1 start

# 256-deep CAN transmit queue

/bin/echo 256 > /sys/class/net/can1/tx_queue_len

We're using "mainstream 3.4" linux and not Freescale 2.26, so there'll be differences. Our Linux platform code initially set up the CAN chips with the wrong clock. They supplied 66.66MHz. That can't be divided down to a 1MHz CAN baud rate with a legal tolerance, so we changed it to use the 24MHz clock instead, so the above is written to work on both. We don't rely on the "default" segment programming, but want to select our own.

> The CAN is automatic open when we send the dataframe through "write" function or is necessary open it with other instructions,


You can test CAN with candump (which does what it says) and cansend. You can look at the sources of those to see how they work.


CAN ports are accessed using the same code as NETWORK sockets. The protocol is called "socketcan". Description and sample code showing exactly what to do in the usual place:


http://en.wikipedia.org/wiki/Socketcan

Tom

0 Kudos