cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tscott.phoenix
Observer
Observer
7,607 Views
Registered: ‎06-03-2011

Problems with Linux/CAN on Zedboard

Jump to solution

I'm trying to get CAN going under Linux on my Zedboard but things are not working for me.  The kernel appears to see the CAN device is present, but as soon as I try to enable things via “ifconfig can0 up” or “ip link set can0 up”, the CAN driver locks up.

 

I’m following the instructions listed here:

 

http://www.wiki.xilinx.com/Linux+CAN+driver

 

I'm running the kernel found here:

 

https://github.com/Xilinx/linux-xlnx/

 

The specific repo revision I'm using is 6530a9b36265deb4bcf25298ba4e1aba443f6bd4 which is the current tip of the master-next branch.

 

I added the following entry into my zynq-zed.dts file:

 

ps7_can_0: ps7-can@e0008000 {

clock-names = "ref_clk", "aper_clk";

clocks = <&clkc 19>, <&clkc 36>;

compatible = "xlnx,zynq-can-1.0";

interrupt-parent = <&ps7_scugic_0>;

interrupts = <0 28 4>;

reg = <0xe0008000 0x1000>;

} ;

 

I've ensured that the CAN support in the kernel is enabled and built as part of the kernel (ie. it is not a loadable module).  Here is what dmesg is reporting:

 

# dmesg | grep -i can

[    1.077239] vcan: Virtual CAN interface driver

[    1.081615] CAN device driver interface

[    1.089399] XILINX_CAN e0008000.ps7-can: reg_base=0xe086a000 irq=60 clock=7999999, tx fifo depth:64

[    1.418208] can: controller area network core (rev 20120528 abi 9)

[    1.428933] can: raw protocol (rev 20120528)

[    1.433223] can: broadcast manager protocol (rev 20120528 t)

[    1.439054] can: netlink gateway (rev 20130117) max_hops=1

 

I configure the bit timing by doing this: “ip link set can0 type can bitrate 250000".  dmesg reports:

 

[  101.705476] XILINX_CAN e0008000.ps7-can can0: bitrate error 0.0%

[  101.711529] XILINX_CAN e0008000.ps7-can can0: brp=8,prop=1,phase_seg1:1,phase_reg2=1,sjw=1

[  101.719921] XILINX_CAN e0008000.ps7-can can0: Setting BTR0=0x07 BTR1=0x01

[  101.726970] XILINX_CAN e0008000.ps7-can can0: BRPR=0x00000007, BTR=0x00000001

 

"ip link" shows:

 

# ip link

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default

    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 mode DEFAULT group default qlen 10

    link/can

3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000

    link/ether 00:0a:35:00:01:22 brd ff:ff:ff:ff:ff:ff

 

“ifconfig –a” shows:

 

# ifconfig -a

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

          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:60 Memory:e0008000-e0008fff

 

eth0      Link encap:Ethernet  HWaddr 00:0A:35:00:01:22

          inet addr:204.54.81.137  Bcast:204.54.81.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

          TX packets:1618 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:3880919 (3.7 MiB)  TX bytes:257849 (251.8 KiB)

          Interrupt:54 Base address:0xb000

 

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

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

          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:948 (948.0 B)  TX bytes:948 (948.0 B)

 

When I issue “ifconfig can0 up” things hang.  After a bit of debugging, I discovered that hang is occurring in xilinx_can.c in the xcan_start() method, where it while-loops endlessly waiting for the NORMAL bit in XCAN_SR_OFFSET to get set.

 

One oddity that I’ve noticed is that I cannot even use U-Boot to query CAN controller registers.  If I interrupt the boot process and enter “md.l 0xe0008018 1” to read the CAN SR, U-Boot just hangs.  Other CAN registers fail similarly.  I see this behavior with both CAN0 and CAN1.

 

Any thoughts?

 

Thanks,

--tim

0 Kudos
1 Solution

Accepted Solutions
tscott.phoenix
Observer
Observer
10,502 Views
Registered: ‎06-03-2011

After manually configuring those pins, I was able to get the CAN driver to correctly initialize:

 

"devmem 0xf8000728 32 0x1221"

"devmem 0xf800072c 32 0x1220"

"ip link set can0 up" --> This now works!

 

--tim

 

View solution in original post

0 Kudos
10 Replies
tscott.phoenix
Observer
Observer
7,591 Views
Registered: ‎06-03-2011

Here's some more debugging info.  I can run "devmem 0xe0008000" when the kernel is booted up and it appears to be correctly reading from the CAN controller.  To try and make sure that I was actually reading / writing to the CAN registers I did the following experiment:

 

# ip link set can0 type can bitrate 250000
# devmem 0xe0008008
0x00000007
# devmem 0xe000800c
0x00000001
# devmem 0xe0008000 32 1
# devmem 0xe0008008
0x00000000
# devmem 0xe000800c
0x00000000

 

I set the bitrate, verified that the BRPR and BTR registers were set as expected, commanded a reset of CAN, and then finally verified that the BRPR and BTR registers were back to their reset values.  That all worked.

 

--tim

 

 

 

0 Kudos
tscott.phoenix
Observer
Observer
7,590 Views
Registered: ‎06-03-2011

I just read this in the TMR:

 

After the CEN bit is set to 1 the CAN controller waits for a sequence of 11 recessive bits before exiting configuration mode.

 

I don't have any of the MIO pins configured properly nor do I have my PHY connected to the Zedboard.  This may be this issue.

0 Kudos
tscott.phoenix
Observer
Observer
10,503 Views
Registered: ‎06-03-2011

After manually configuring those pins, I was able to get the CAN driver to correctly initialize:

 

"devmem 0xf8000728 32 0x1221"

"devmem 0xf800072c 32 0x1220"

"ip link set can0 up" --> This now works!

 

--tim

 

View solution in original post

0 Kudos
ethanlu2
Visitor
Visitor
6,479 Views
Registered: ‎01-24-2015
Linaro ubuntu linux can't find command devmem??
Do i need to install specific software for devman command?
0 Kudos
tscott.phoenix
Observer
Observer
6,465 Views
Registered: ‎06-03-2011

I've never used Linaro so I'm afraid I'm not going to be much help there.

 

FWIW, I believe I was using buildroot to generate the filesystem and related tools.  The kernel I used is mentioned in my initial post.

0 Kudos
oabril
Visitor
Visitor
4,948 Views
Registered: ‎07-17-2015

Hi,

 

I think a have the same problems: 

 

This is my config:

 

in pcw.dtsi:

 

&can0 {
status = "okay";
};

 

in zynq-7000.dtsi

 

can0: can@e0008000 {
compatible = "xlnx,zynq-can-1.0";
status = "disabled";
clocks = <&clkc 19>, <&clkc 36>;
clock-names = "can_clk", "pclk";
reg = <0xe0008000 0x1000>;
interrupts = <0 28 4>;
interrupt-parent = <&intc>;
tx-fifo-depth = <0x40>;
rx-fifo-depth = <0x40>;
};

 

dmesg | grep -i can

 

[ 1.887537] CAN device driver interface
[ 2.217030] can: controller area network core (rev 20120528 abi 9)
[ 2.228078] can: raw protocol (rev 20120528)
[ 2.232397] can: broadcast manager protocol (rev 20120528 t)
[ 2.238055] can: netlink gateway (rev 20130117) max_hops=1

 

ip link set can0 type can bitrate 125000
[ 35.393130] xilinx_can e0008000.can can0: bitrate error 0.0%

 

ifconfig can0 up
[ 41.929562] xilinx_can e0008000.can can0: timed out for correct mode
[ 41.935841] xilinx_can e0008000.can can0: xcan_chip_start failed!
ifconfig: SIOCSIFFLAGS: Connection timed out

 

Would you please explain me what do you mean write 0x1221 and 0x1220 to the devmem ???

 

"devmem 0xf8000728 32 0x1221"
"devmem 0xf800072c 32 0x1220"

 

If I do that ifconfig can0 up works, but if a send data with cansend nothing happens.

 

Do you have an idea that could be happening?

 

Thanks, 

 

 

 

 

tscott.phoenix
Observer
Observer
4,944 Views
Registered: ‎06-03-2011

It's been quite a while since I worked on this, but I believe the devmem operations were simply to configure the MIO pins for CAN operation.

 

Here are the last notes I took about this.  Hope it helps:

 

  • To get this going requires two updates:
    • DTS

                ps7_can_0: ps7-can@e0008000 {

                        clock-names = "ref_clk", "aper_clk";

                        clocks = <&clkc 19>, <&clkc 36>;

                        compatible = "xlnx,zynq-can-1.0";

                        interrupt-parent = <&ps7_scugic_0>;

                        interrupts = <0 28 4>;

                        reg = <0xe0008000 0x1000>;

                } ;

  • /etc/network/interfaces

auto can0

iface can0 inet manual

        pre-up ip link set $IFACE type can bitrate 250000

        pre-up /sbin/devmem 0xf8000728 32 0x1621

        pre-up /sbin/devmem 0xf800072c 32 0x1620

        up /sbin/ifconfig $IFACE up

        down /sbin/ifconfig $IFACE down

 

--> This configures the MIO pins on the board's JE header for 3.3v / CAN operation and initializes the CAN interface

 

--tim

 

0 Kudos
oabril
Visitor
Visitor
4,940 Views
Registered: ‎07-17-2015

From your message: "configure the MIO pins for CAN operation."

That's something I dont understand, the way I configure the Pin-out is by Vivado (in block design), adding a CAN0 in the pins 10 and 11 in the MIO. Then after exporting my design I have everything working in my linux.

Would you explain me a little more about this values and where can I found info about that??

 

Thanks, 

0 Kudos
tscott.phoenix
Observer
Observer
4,937 Views
Registered: ‎06-03-2011

You still have to configure the operation of those pins.

 

Look for this file: ug585-Zynq-7000-TRM.pdf and search for the address 0xF8000728 for further information about the pin configuration.

 

--tim

 

0 Kudos
htkim40
Newbie
Newbie
2,142 Views
Registered: ‎07-19-2017

Hi, 

 

I guess I am running into the exact same problem as you with the exact same error. Did you ever find a solution to your issue? 

 

THanks, 

 

Jason

0 Kudos