飞凌嵌入式
直播中

华仔stm32

3年用户 2984经验值
擅长:嵌入式技术
私信 关注
[技术]

【飞凌RK3568开发板试用体验】测试CAN

1、安装python-can模块

root@ok3568:~# pip3 install python-can
Collecting python-can
  Downloading python_can-4.1.0-py3-none-any.whl (241 kB)
     |████████████████████████████████| 241 kB 75 kB/s 
Collecting msgpack~=1.0.0; platform_system != "Windows"
  Downloading msgpack-1.0.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (313 kB)
     |████████████████████████████████| 313 kB 35 kB/s 
Collecting wrapt~=1.10
  Downloading wrapt-1.14.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (81 kB)
     |████████████████████████████████| 81 kB 28 kB/s 
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from python-can) (45.2.0)
Collecting typing-extensions>=3.10.0.0
  Downloading typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Collecting packaging
  Downloading packaging-21.3-py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 27 kB/s 
Collecting pyparsing!=3.0.5,>=2.0.2
  Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
     |████████████████████████████████| 98 kB 28 kB/s 
Installing collected packages: msgpack, wrapt, typing-extensions, pyparsing, packaging, python-can
Successfully installed msgpack-1.0.4 packaging-21.3 pyparsing-3.0.9 python-can-4.1.0 typing-extensions-4.4.0 wrapt-1.14.1

2、在ubuntu下面测试can0是否可以正常工作:

forlinx@ok3568:~$ ifconfig -a
can0: flags=128<NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 67

can1: flags=128<NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 68

这里看到了有can0、can1。
3、配置can0的波特率为500K:
forlinx@ok3568:~$ sudo ip link set can0 type can bitrate 500000
4、打开can0:

forlinx@ok3568:~$ sudo ip link set can0 up
pTNETLINK answers[ :1 7I6n6v.a1l6i6d8 1a1r]g urmoecnkcthi
 _canfd fe570000.can can0: incorrect/missing data bit-timing

这里出错了,然后各种找资料,终于在一篇帖子上找到了出现同一问题:
image.png

5、准备修改设备树,找到rk3568.dts文件在:/OK3568-linux-source/kernel/arch/arm64/boot/dts/rockchip/rk3568.dtsi
的2763行:

compatible = "rockchip-scr";
		reg = <0x0 0xfe560000 0x0 0x10000>;
		interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&scr_pins>;
		clocks = <&cru PCLK_SCR>;
		clock-names = "g_pclk_sim_card";
		status = "disabled";
	};

	can0: can@fe570000 {
		compatible = "rockchip,canfd-1.0";
		reg = <0x0 0xfe570000 0x0 0x1000>;
		interrupts = <GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>;
		clocks = <&cru CLK_CAN0>, <&cru PCLK_CAN0>;
		clock-names = "baudclk", "apb_pclk";
		resets = <&cru SRST_CAN0>, <&cru SRST_P_CAN0>;
		reset-names = "can", "can-apb";
		tx-fifo-depth = <1>;
		rx-fifo-depth = <6>;
		status = "disabled";
	};

	can1: can@fe580000 {
		compatible = "rockchip,canfd-1.0";
		reg = <0x0 0xfe580000 0x0 0x1000>;
		interrupts = <GIC_SPI 2 IRQ_TYPE_LEVEL_HIGH>;
		clocks = <&cru CLK_CAN1>, <&cru PCLK_CAN1>;
		clock-names = "baudclk", "apb_pclk";
		resets = <&cru SRST_CAN1>, <&cru SRST_P_CAN1>;
		reset-names = "can", "can-apb";
		tx-fifo-depth = <1>;
		rx-fifo-depth = <6>;
		status = "disabled";
	};

	can2: can@fe590000 {
		compatible = "rockchip,canfd-1.0";
		reg = <0x0 0xfe590000 0x0 0x1000>;
		interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
		clocks = <&cru CLK_CAN2>, <&cru PCLK_CAN2>;
		clock-names = "baudclk", "apb_pclk";
		resets = <&cru SRST_CAN2>, <&cru SRST_P_CAN2>;
		reset-names = "can", "can-apb";
		tx-fifo-depth = <1>;
		rx-fifo-depth = <6>;
		status = "disabled";
	};

果然配置成了canfd-1.0,这里修改为can-1.0

编译后,我把boot.img误烧到了Boot_linux下面,结果

f49641200687264e63b47f5ab6b0eed.png
image.png

按住recovery 键不要松开,然后按一下 reset 键系统复位。也没有检测到设备,只能试着用SD来启动了。
image.png
制作SD成功后,把SD卡插入开发板,启动
image.png
是可以启动,但是不是烧写进硬盘。重来:
image.png
终于成功了:
image.png

再次测试can启用:

[root@ok3568:/]# ip link set can0 type can bitrate 500000
[root@ok3568:/]# ip link set can0 up
[  153.712359] IPv6: ADDRCONF(NETDEV_UP): can0: link is not ready
[  153.7[root@ok3568:/]# 12459] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready```

发送数据:

[root@ok3568:/]# cansend can0 111#12345678
[root@ok3568:/]#
[root@ok3568:/]# cansend can0 111#0102030405060708
[root@ok3568:/]#

image.png
接收数据:

[root@ok3568:/]# candump can0
  can0  121   [2]  01 01
  can0  121   [2]  01 01
  can0  121   [2]  01 01
  can0  121   [2]  01 01
  can0  121   [8]  01 02 03 04 05 06 07 08
  can0  121   [8]  01 02 03 04 05 06 07 08
  can0  121   [8]  01 02 03 04 05 06 07 09

image.png

到此CAN的基本调试可以了,就是可惜烧录不是很会。走了很多弯弯路呀。还好手头上的配件多。
做评测,就是折腾。

更多回帖

发帖
×
20
完善资料,
赚取积分