- 积分
- 125
贡献507
飞刀167 FD
注册时间2023-10-17
在线时间52 小时

  
扫一扫,手机访问本帖 
|
参考资料: https://blog.csdn.net/m0_56121792/article/details/135255452 RK3568平台移植EtherCAT Master
前提条件:OK3568J-C开发板;板上系统 linux4.19.232-RT;linux4.19.232-RT 虚拟机并已作过全编译或至少对内核作过编译。
1、下载源码
forlinx@ubuntu:~/3568/EtherCAT_my$ git clone https://gitlab.com/etherlab.org/ethercat.git
新得到的 ethercat 源码文件夹,重命名为 ethercat_gitlab_20250308_ori,作一个备份,命名为 ethercat_gitlab_20250308
2、安装编译igh所需的依赖,实操如下
forlinx@ubuntu:~/3568/EtherCAT_my$ sudo apt-get install autoconf autogen libtool -y
若报有 lock 锁文件,删除后,重新运行指令
3、设置环境
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ export PATH=/home/forlinx/3568/OK3568-linux-sdk232/buildroot/output/rockchip_OK3568-C/host/bin/:$PATH
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ . /home/forlinx/3568/OK3568-linux-sdk232/buildroot/output/rockchip_OK3568-C/host/environment-setup
4、
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ ./bootstrap
5、参考资料中 confiture 指令中加入太多的缺省选项,删之,并且 igb 选项报错,删之,如下
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ ./configure --prefix=/home/forlinx/3568/EtherCAT_my/output_ethercat_gitlab_20250308 --with-linux-dir=/home/forlinx/3568/OK3568-linux-sdk232/kernel-rt --enable-8139too=no --enable-generic=yes --host=aarch64-buildroot-linux-gnu
6、
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ make
7、
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ make install
8、编译模块
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ make modules
注:若以 make ARCH=arm64 CROSS_COMPILE=aarch64-buildroot-linux-gnu- modules 或 make ARCH=arm CROSS_COMPILE=aarch64-buildroot-linux-gnu- modules 指令编译均会报错,原因不明。
9、编译驱动模块
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308$ cd devices
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308/devices$ sudo make install
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308/devices$ cd ../master
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308/master$ sudo make install
10、
forlinx@ubuntu:~/3568/EtherCAT_my/ethercat_gitlab_20250308/master$ cd ../../output_ethercat_gitlab_20250308
forlinx@ubuntu:~/3568/EtherCAT_my/output_ethercat_gitlab_20250308$ mkdir modules
forlinx@ubuntu:~/3568/EtherCAT_my/output_ethercat_gitlab_20250308$ cp /home/forlinx/3568/EtherCAT_my/ethercat_gitlab_20250308/devices/ec_generic.ko /home/forlinx/3568/EtherCAT_my/output_ethercat_gitlab_20250308/modules
forlinx@ubuntu:~/3568/EtherCAT_my/output_ethercat_gitlab_20250308$ cp /home/forlinx/3568/EtherCAT_my/ethercat_gitlab_20250308/master/ec_master.ko /home/forlinx/3568/EtherCAT_my/output_ethercat_gitlab_20250308/modules
11、在虚拟机上编缉配置文件
forlinx@ubuntu:~/3568/EtherCAT_my/output_ethercat_gitlab_20250308$ gedit etc/sysconfig/ethercat
......
MASTER0_DEVICE="6A:7C:E3:E9:CA:9F" ->约33行,MAC值 指向开发板 eth1 网口,用于 EtherCAT
#MASTER1_DEVICE=""
......
DEVICE_MODULES="generic" ->约62行
......
#new add
echo KERNEL==\"EtherCAT[0-9]*\", MODE=\"0664\" > /etc/udev/rules.d/99-EtherCAT.rules
12、生成压缩文件
forlinx@ubuntu:~/3568/EtherCAT_my/output_ethercat_gitlab_20250308$ cd ..
forlinx@ubuntu:~/3568/EtherCAT_my$ tar -cjf output_ethercat_gitlab_20250308.tar.bz2 output_ethercat_gitlab_20250308/
注:其实该操作无用,开发板上会解压失败,原因不明,后面改以 scp 操作实现文件传输
->接下来在开发板上操作
13、按个人实际情况,设定开发板网口IP,需保证桥接网卡两端同区段
root@OK3568-C-buildroot:/# ifconfig eth0 192.168.8.9
root@OK3568-C-buildroot:/# ifconfig eth1 192.168.157.9
注:需测试可以 ping 通,若在win10 下可能需关闭系统防火墙。
14、
root@OK3568-C-buildroot:/home# scp -r forlinx@192.168.8.11:/home/forlinx/3568/EtherCAT_my/output_ethercat_gitlab_20250308 /home
15、将当前版本拷入开发板相应目录
root@OK3568-C-buildroot:/home/output_ethercat_gitlab_20250308# cp etc/init.d/ethercat /etc/init.d
root@OK3568-C-buildroot:/home/output_ethercat_gitlab_20250308# cp etc/ethercat.conf /etc
root@OK3568-C-buildroot:/home/output_ethercat_gitlab_20250308# cp bin/ethercat /usr/bin
root@OK3568-C-buildroot:/home/output_ethercat_gitlab_20250308# cp etc/sysconfig/ethercat /etc/sysconfig
root@OK3568-C-buildroot:/home/output_ethercat_gitlab_20250308# cp modules/ec_* /lib/modules/4.19.232-rt104
root@OK3568-C-buildroot:/home/output_ethercat_gitlab_20250308# cp -d lib/libether* /lib
16、编缉开发板 /lib/modules/4.19.232-rt104/modules.dep 文件,在其内容尾部加入 ec_master.ko ec_generic,ko 两个文件。
17、将手中仅有的伺服驱动器汇川 SV630N in 口与开发板 eth1 以网线连接,驱动器上电,开始测试
root@OK3568-C-buildroot:/home/output_ethercat_gitlab_20250308# cd /usr/bin
root@OK3568-C-buildroot:/usr/bin# modprobe ec_master main_devices=6A:7C:E3:E9:CA:9F
[ 1916.957742] ec_master: loading out-of-tree module taints kernel.
[ 1916.975582] EtherCAT: Master driver 1.6.3 1.6.3-8-g4ce0c74d
[ 1916.976016] EtherCAT: 1 master waiting for devices.
root@OK3568-C-buildroot:/usr/bin#
root@OK3568-C-buildroot:/usr/bin# echo KERNEL==\"EtherCAT[0-9]*\", MODE=\"0664\" > /etc/udev/rules.d/99-EtherCAT.rules
root@OK3568-C-buildroot:/usr/bin# ethercat start
Unknown command start!
帮助类输出信息略去
root@OK3568-C-buildroot:/usr/bin# insmod /lib/modules/4.19.232-rt104/ec_generic.ko
[ 2283.968328] ec_generic: EtherCAT master generic Ethernet device module 1.6.3 1.6.3-8-g4ce0c74d
[ 2283.968414] EtherCAT: Accepting 6A:7C:E3:E9:CA:9F as main device for master 0.
root@OK3568-C-buildroot:/usr/bin# [ 2283.968451] ec_generic: Binding socket to inte**ce 5 (eth1).
[ 2283.973710] EtherCAT 0: Starting EtherCAT-IDLE thread.
[ 2283.974014] EtherCAT 0: Link state of ecm0 changed to UP.
[ 2283.975773] EtherCAT 0: 1 slave(s) responding on main device.
[ 2283.975797] EtherCAT 0: Slave states on main device: INIT.
[ 2283.976442] EtherCAT 0: Scanning bus.
[ 2284.330365] EtherCAT 0: Bus scanning completed in 354 ms.
[ 2284.330406] EtherCAT 0: Using slave 0 as DC reference clock.
[ 2284.330425] EtherCAT 0: Starting EoE thread.
[ 2284.332723] EtherCAT 0: Slave states on main device: PREOP.
root@OK3568-C-buildroot:/usr/bin# ethercat slaves
0 0:0 PREOP + SV630_1Axis_03716
root@OK3568-C-buildroot:/usr/bin#
root@OK3568-C-buildroot:/usr/bin# ethercat cstruct
/* Master 0, Slave 0, "InoSV630N"
* Vendor ID: 0x00100000
* Product code: 0x000c0112
* Revision number: 0x00010000
*/
ec_pdo_entry_info_t slave_0_pdo_entries[] = {
{0x6040, 0x00, 16},
{0x607a, 0x00, 32},
{0x60b8, 0x00, 16},
{0x60fe, 0x01, 32},
{0x603f, 0x00, 16},
{0x6041, 0x00, 16},
{0x6064, 0x00, 32},
{0x6077, 0x00, 16},
{0x60f4, 0x00, 32},
{0x60b9, 0x00, 16},
{0x60ba, 0x00, 32},
{0x60bc, 0x00, 32},
{0x60fd, 0x00, 32},
};
ec_pdo_info_t slave_0_pdos[] = {
{0x1701, 4, slave_0_pdo_entries + 0},
{0x1b01, 9, slave_0_pdo_entries + 4},
};
ec_sync_info_t slave_0_syncs[] = {
{0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
{1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
{2, EC_DIR_OUTPUT, 1, slave_0_pdos + 0, EC_WD_ENABLE},
{3, EC_DIR_INPUT, 1, slave_0_pdos + 1, EC_WD_DISABLE},
{0xff}
};
至此,ethercat_gitlab 1.6.3 已移植成功,只是配置中的实时开关尚未测试,有待后续。
|
|