关于imx6ul mcp2515 driver

cancel
Showing results for 
Search instead for 
Did you mean: 

关于imx6ul mcp2515 driver

2,487 Views
embed
Contributor I

问题:

使用imx6ul的,添加1路spi can总线芯片mcp2515,内核版本linux-3.14.52. 使用cansend/candump工具测试没有数据收发,以下是我们的电路和配置及log信息,请问有人碰到此类问题吗,能帮忙看一下吗?

1、电路

155105_155105.png2016-07-03 21_40_51屏幕截图.png

2、管脚

      CS1-->GPIO4_IO28

      INT1-->GPIO5_IO02

      其他使用ECSPI2管脚

3、DTS配置

/{

...

        clocks {

                mcp251x_clock: mcp251x_clock {

                        compatible = "fixed-clock";

                        #clock-cells = <0>;

                        clock-frequency  = <8000000>;

                };

        };

...

};

&ecspi2 {

        compatible = "fsl,imx51-ecspi";

        fsl,spi-num-chipselects = <1>;

        cs-gpios = <0>;

        pinctrl-names = "default";

        pinctrl-0 = <&pinctrl_ecspi2>,<&pinctrl_ecspi2_cs>;

        status = "okay";

        can0: mcp2515@0 {

                compatible = "microchip,mcp2515";

                cs-gpios = <&gpio4 28 0>;

                reg = <0>;

                spi-max-frequency = <1000000>;

                clocks = <&mcp251x_clock>;

                interrupt-parent = <&gpio5>;

                interrupts = <2 0x2>;

                vdd-supply = <&reg_can_3v3>;

                xceiver-supply = <&reg_can_3v3>;

        };

};

&iomuxc{

                pinctrl_ecspi2: ecspi2grp{

                        fsl,pins = <

                                MX6UL_PAD_CSI_DATA00__ECSPI2_SCLK       0x100b1

                                MX6UL_PAD_CSI_DATA02__ECSPI2_MOSI       0x100b1

                                MX6UL_PAD_CSI_DATA03__ECSPI2_MISO       0x100b1

                        >;

                };

                pinctrl_ecspi2_cs: ecspi2csgrp {

                        fsl,pins = <

                                MX6UL_PAD_CSI_DATA07__GPIO4_IO28        0x80000000

                        >;

                };

};

4、Linux版本与配置

    linux-3.14.52

CONFIG_CAN=y

CONFIG_CAN_RAW=y

CONFIG_CAN_BCM=y

CONFIG_CAN_GW=y

#

# CAN Device Drivers

#

CONFIG_CAN_VCAN=y

# CONFIG_CAN_SLCAN is not set

CONFIG_CAN_DEV=y

CONFIG_CAN_CALC_BITTIMING=y

# CONFIG_CAN_LEDS is not set

# CONFIG_CAN_AT91 is not set

# CONFIG_CAN_TI_HECC is not set

CONFIG_CAN_MCP251X=y

CONFIG_CAN_FLEXCAN=y

# CONFIG_CAN_GRCAN is not set

# CONFIG_CAN_M_CAN is not set

# CONFIG_CAN_SJA1000 is not set

# CONFIG_CAN_C_CAN is not set

# CONFIG_CAN_CC770 is not set

5、启动log

启动脚本

/sbin/ifconfig can0 down

/sbin/ifconfig can1 down

/sbin/ifconfig can2 down

/sbin/ifconfig can0 txqueuelen 100

/sbin/ifconfig can1 txqueuelen 100

/sbin/ifconfig can2 txqueuelen 100

/sbin/ip link set can0 up type can bitrate 250000 restart-ms 10

/sbin/ip link set can1 up type can bitrate 250000 restart-ms 10

/sbin/ip link set can2 up type can bitrate 250000 restart-ms 10

log:

...

[    1.308895] spi_imx 200c000.ecspi: registered master spi1

[    1.309943] spi spi1.0: spi_imx_setup: mode 0, 8 bpw, 1000000 hz

[    1.309985] spi spi1.0: setup mode 0, 8 bits/w, 1000000 Hz max --> 0

[    1.310343] spi_imx 200c000.ecspi: registered child spi1.0

[    1.310376] spi_imx 200c000.ecspi: probed

[    1.317230] vcan: Virtual CAN interface driver

[    1.321717] CAN device driver interface

[    1.326035] mcp251x spi1.0: spi_imx_setup: mode 0, 8 bpw, 1000000 hz

[    1.326072] mcp251x spi1.0: setup mode 0, 8 bits/w, 1000000 Hz max --> 0

[    1.326498] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[    1.336678] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[    1.336855] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[    1.336983] mcp251x spi1.0: CANCTRL 0xe3

[    1.338271] mcp251x spi1.0: probed

[    1.344136] flexcan 2090000.can: gpr /soc/aips-bus@02000000/iomuxc-gpr@020e4000 req_gpr 0x10 req_bit 1 ack_gpr 0x10 ack_bit 17

[    1.344306] flexcan 2090000.can: device registered (reg_base=a0998000, irq=142)

[    1.353676] flexcan 2094000.can: gpr /soc/aips-bus@02000000/iomuxc-gpr@020e4000 req_gpr 0x10 req_bit 2 ack_gpr 0x10 ack_bit 18

[    1.353844] flexcan 2094000.can: device registered (reg_base=a09a0000, irq=143)

...

[   15.479788] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.489946] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490078] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490235] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490364] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490501] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490627] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490756] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.490869] mcp251x spi1.0: CNF: 0x00 0x00 0x00

[   15.495556] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.495692] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.495824] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.495950] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496076] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496205] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496332] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.496460] mx51_ecspi_clkdiv: fin: 60000000, fspi: 1000000, post: 2, pre: 14

[   15.509531] flexcan 2090000.can can1: writing ctrl=0x07292005

[   15.515520] flexcan 2090000.can can1: flexcan_set_bittiming: mcr=0x5980000f ctrl=0x07292005

[   15.515543] flexcan 2090000.can can1: flexcan_chip_start: writing mcr=0x7de2020d

[   15.515565] flexcan 2090000.can can1: flexcan_chip_start: writing ctrl=0x0729ac55

[   15.515602] flexcan 2090000.can can1: flexcan_chip_start: reading mcr=0x64e2020d ctrl=0x0729ac55

[   15.528534] flexcan 2094000.can can2: writing ctrl=0x07292005

[   15.534736] flexcan 2094000.can can2: flexcan_set_bittiming: mcr=0x5980000f ctrl=0x07292005

[   15.534765] flexcan 2094000.can can2: flexcan_chip_start: writing mcr=0x7de2020d

[   15.534786] flexcan 2094000.can can2: flexcan_chip_start: writing ctrl=0x0729ac55

[   15.534825] flexcan 2094000.can can2: flexcan_chip_start: reading mcr=0x64e2020d ctrl=0x0729ac55

6、当前问题

查看/sys/class/spi_master/已经注册成功。

使用cansend发送数据失败,接收数据失败。

将DTS配置成

&ecspi2 {

        compatible = "fsl,imx51-ecspi";

        fsl,spi-num-chipselects = <1>;

        cs-gpios = <0>;

        pinctrl-names = "default";

        pinctrl-0 = <&pinctrl_ecspi2>,<&pinctrl_ecspi2_cs>;

        status = "okay";

        spidev@0 {

                compatible = "spidev";

                spi-max-frequency = <10000000>;

                reg = <0>;

        };

};

使用spi_test测试,SPI输出脚有波形。

CAN总线总是不成功,收发都有问题。

是否有人碰到过类似的问题。帮忙解答一下。

Labels (1)
0 Kudos
10 Replies

798 Views
xswyzao
Contributor II

我们也用imx6接的mcp2515,直接用的是4.1.15内核,是可以正常收发的。

0 Kudos

798 Views
lphwork
Contributor I

请问你的dts是怎么配置的,我这边是spi4改出来的,但是spi的clk没有波形呢,请指导一下我吧,谢谢你了!lphwork@aliyun.com我的邮箱,或者给我你的联系方式也可以。

0 Kudos

798 Views
zhangxinxing
Contributor I

你好,请教一下。我现在按照这个楼主这个做法做了,能在/sys/class/spi_master看到新增了一个SPI设备,但在/sys/class/net下面还是只有can0和can1(看不到预想的can2设备)。请问下可能是什么问题?另外上面的硬件接法中,INT引脚必须要接上吗?不接有啥影响?

0 Kudos

798 Views
embed
Contributor I

canutils工具已经移植过去,确实没有数据收发,使用周立功CAN卡,CANTest显示发送失败,板子这端发送也是不成功。

0 Kudos

798 Views
embed
Contributor I

还是驱动程序的问题,目前已经解决。驱动程序可以使用https://github.com/msperl/mcp2515/blob/master/mcp2515.c

0 Kudos

316 Views
FGBLH
Contributor I

调试成功的设备树能发出来看看吗?1130349616@qq.com

0 Kudos

798 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hi,

    从log上看,mcp2515已经注册成功了:spi1.0位置上。那么你可以先这样看看:

(1)用netcfg命令,看看can device是否存在。

(2)CPU SPI发数据时,MCP2515的CS脚有没有被拉低。

伟东

0 Kudos

798 Views
embed
Contributor I

(1)我没有使用netcfg查看,直接查看了/sys/class/spi_master/spi1/spi1.0/,使用ifconfig 也可以看到已经添加了can的设备,并且使用ip link set can0 up type can bitrate 25000可以配置成功,

(2)发送数据时,片选确定是拉低的,但是spi的mosi没有波形。用can总线收发工具也没有数据

0 Kudos

798 Views
zhangxinxing
Contributor I

你好,请教一下。我现在按照这个楼主这个做法做了,能在/sys/class/spi_master看到新增了一个SPI设备,但在/sys/class/net下面还是只有can0和can1(看不到预想的can2设备)。请问下可能是什么问题?另外上面的硬件接法中,INT引脚必须要接上吗?不接有啥影响?

0 Kudos

798 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hi,

    你的系统中,SPI to CAN bus经过驱动之后,已经是CAN设备,所以你不能用SPI test去测试它,而是要使用linux提供CAN总线测试命令,可以参考这个链接:

https://community.nxp.com/docs/DOC-1437

如果这个不够详细,你可以在我们论坛上搜索一下其他的帖子。

伟东

0 Kudos