我有 MaaxBoard-Avnet 和 Mcp2515。我正在尝试使用 MaaxBoard 运行 mcp2515,以便 spi 到 CAN。
Mcp2515 在内核 4.14 上与 MaaxBoard 一起使用,但是当我为内核 5.4 尝试相同的配置时。mcp2515 无法工作。我试图在下面解释我的研究和结果。
我使用https://github.com/Avnet/meta-maaxboard/tree/zeus上的步骤编译了一个图像。我IMAGE_INSTALL_append = " can-utils"
在 yocto local.conf文件中添加了 can 命令。
内核配置:
Networking support --->
<*> CAN bus subsystem support --->
--- CAN bus subsystem support
<*> Raw CAN Protocol (raw access with CAN-ID filtering)
<*> Broadcast Manager CAN Protocol (with content filtering)
CAN Device Drivers --->
<*> Virtual Local CAN Interface (vcan)
<*> Platform CAN drivers with Netlink support
[*] CAN bit-timing calculation
CAN SPI interfaces --->
<*> Microchip 251x series SPI CAN Controller
.dts 配置:
/*
* Copyright 2019 EMBEST
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* 40-pin extended GPIO, expanded into SPI, I2C, PWM and other interfaces */
&iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
imx8mq-evk {
pinctrl_hog: hoggrp {
fsl,pins = <
/*Default GPIOs*/
MX8MQ_IOMUXC_NAND_READY_B_GPIO3_IO16 0x19 /* PIN 7, GPIO 4 */
MX8MQ_IOMUXC_NAND_WE_B_GPIO3_IO17 0x19 /* PIN 11, GPIO 17 */
// MX8MQ_IOMUXC_NAND_DATA02_GPIO3_IO8 0x19 /* PIN 13, MCP2515 INT_1 */
// MX8MQ_IOMUXC_NAND_DATA03_GPIO3_IO9 0x19 /* PIN 15, MCP2515 INT_2 */
MX8MQ_IOMUXC_NAND_RE_B_GPIO3_IO15 0x19 /* PIN 22, GPIO 25 */
MX8MQ_IOMUXC_GPIO1_IO03_GPIO1_IO3 0x19 /* PIN 36, GPIO 16 CAN_STB_Maax_Out */
// MX8MQ_IOMUXC_NAND_DATA05_GPIO3_IO11 0x19 /* PIN 37, TRIG_SN65DS183_EN */
//MX8MQ_IOMUXC_NAND_CE1_B_GPIO3_IO2 0x19 /* PIN 26, MCP2515 CS_2 */
MX8MQ_IOMUXC_NAND_CLE_GPIO3_IO5 0x19 /* PIN 29, GPIO 5 */
MX8MQ_IOMUXC_NAND_DATA04_GPIO3_IO10 0x19 /* PIN 31, GPIO 6 */
MX8MQ_IOMUXC_SAI2_TXC_GPIO4_IO25 0x19 /* PIN 12, GPIO 18 */
// MX8MQ_IOMUXC_GPIO1_IO15_GPIO1_IO15 0x19 /* PIN 32 WTD_INTERLOCK_Maax */
MX8MQ_IOMUXC_SAI2_RXFS_GPIO4_IO21 0x19 /* PIN 35, GPIO 19 */
MX8MQ_IOMUXC_SAI2_RXD0_GPIO4_IO23 0x19 /* PIN 38, GPIO 20 */
MX8MQ_IOMUXC_SAI2_TXD0_GPIO4_IO26 0x19 /* PIN 40, GPIO 21 */
>;
};
pinctrl_ecspi1: ecspi1grp {
fsl,pins = <
MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9 0x16 // CAN 0 CS
MX8MQ_IOMUXC_NAND_CE1_B_GPIO3_IO2 0x16 // CAN 1 CS GPIO3_IO02
MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI 0x16
MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO 0x16
MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK 0x1816
MX8MQ_IOMUXC_NAND_DATA02_GPIO3_IO8 0x146 // LVTTL Enabled, Pull-up Enabled, Slew Rate Field :Slow Interrupt pin CAN0
MX8MQ_IOMUXC_NAND_DATA03_GPIO3_IO9 0x146 // LVTTL Enabled, Pull-up Enabled, Slew Rate Field :Slow Interrupt pin CAN1
>;
};
pinctrl_i2c2: i2c2grp {
fsl,pins = <
MX8MQ_IOMUXC_I2C2_SCL_I2C2_SCL 0x4000007f
MX8MQ_IOMUXC_I2C2_SDA_I2C2_SDA 0x4000007f
>;
};
pinctrl_i2c3: i2c3grp {
fsl,pins = <
MX8MQ_IOMUXC_I2C3_SCL_I2C3_SCL 0x4000007f
MX8MQ_IOMUXC_I2C3_SDA_I2C3_SDA 0x4000007f
>;
};
pinctrl_i2c4: i2c4grp {
fsl,pins = <
MX8MQ_IOMUXC_I2C4_SCL_I2C4_SCL 0x4000007f
MX8MQ_IOMUXC_I2C4_SDA_I2C4_SDA 0x4000007f
>;
};
pinctrl_uart2: uart2grp {
fsl,pins = <
MX8MQ_IOMUXC_UART2_RXD_UART2_DCE_RX 0x49
MX8MQ_IOMUXC_UART2_TXD_UART2_DCE_TX 0x49
>;
};
};
};
&ecspi1{
fsl,spi-num-chipselects = < 2 >;
cs-gpios = <&gpio5 9 0 >,<&gpio3 2 0 > ;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_ecspi1 >;
status = "okay";
#address-cells=<1>;
#size-cells=<1>;
can0: spidev@0x00{
compatible = "microchip,mcp2515";
clocks = <&osc_8m>;
interrupt-parent =<&gpio3>; // GPIO3_IO08
interrupts = <8 IRQ_TYPE_EDGE_FALLING>;
spi-max-frequency = <8000000>;
reg = <0>;
};
can1: spidev@0x01{
compatible = "microchip,mcp2515";
clocks = <&osc_8m>;
interrupt-parent =<&gpio3>; // GPIO3_IO09
interrupts = <9 IRQ_TYPE_EDGE_FALLING>;
spi-max-frequency = <8000000>;
reg = <1>;
};
};
&i2c2 {
clock-frequency = <100000>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c2>;
status = "okay";
};
&i2c3 {
clock-frequency = <100000>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c3>;
status = "okay";
};
&i2c4 {
clock-frequency = <100000>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c4>;
status = "okay";
};
&uart2 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart2>;
assigned-clocks = <&clk IMX8MQ_CLK_UART2>;
assigned-clock-parents = <&clk IMX8MQ_CLK_25M>;
status = "okay";
};
我还在imx8mq.dtsi文件上创建了新的时钟节点。部分时钟节点:
osc_8m: clock-osc-8m {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency= <8000000>;
clock-output-names = "osc_8m";
};
Dmesg 输出:
dmesg | grep can
输出:
[ 1.347960] imx-dcss 32e00000.display-controller: ctxld: can't get irq number
[ 2.005331] caam-snvs 30370000.caam-snvs: can't get snvs clock
[ 2.106505] can: controller area network core (rev 20170425 abi 9)
[ 2.117207] can: raw protocol (rev 20170425)
[ 2.121489] can: broadcast manager protocol (rev 20170425 t)
[ 2.127166] can: netlink gateway (rev 20190810) max_hops=1
dmesg | grep mcp
输出:
[ 2.380741] mcp251x spi0.0: CANCTRL 0x0a
[ 2.380748] mcp251x spi0.0: Cannot initialize MCP2515. Wrong wiring?
[ 2.387132] mcp251x spi0.0: Probe failed, err=19
[ 2.402094] mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?
[ 2.408470] mcp251x spi0.1: Probe failed, err=19
dmesg | grep spi
输出:
[ 1.393667] spi_imx 30820000.spi: dma setup error -19, use pio
[ 1.400139] spi_imx 30820000.spi: probed
[ 2.380741] mcp251x spi0.0: CANCTRL 0x0a
[ 2.380748] mcp251x spi0.0: Cannot initialize MCP2515. Wrong wiring?
[ 2.387132] mcp251x spi0.0: Probe failed, err=19
[ 2.402094] mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?
[ 2.408470] mcp251x spi0.1: Probe failed, err=19
Mcp2515 连接到 MaaxBoard:
Mcp2515 Output MaaxBoard Pin Number
INT -------------> 13
SCK(SCLK) -------------> 23
SI(MOSI) -------------> 19
SO(MISO) -------------> 21
CS(CE0) -------------> 24
GND -------------> 6
Vcc(3.3V) --------------> 1
ip link set can0 up type can bitrate 125000
命令输出为:Cannot find device "can0"
如果你能帮我弄清楚在哪里看,那就太好了。
谢谢。