嵌入式爱好者

查看: 61|回复: 3

[Linux] 抛砖,记录OK3568J-C开发板linux4.19.232-RT移植 IGH EtherCAT 1.6.3

[复制链接]

5

主题

34

帖子

125

积分

i.MX6UL通行证RK3568通行证AM335x通行证

扫一扫,手机访问本帖
发表于 3 天前 | 显示全部楼层 |阅读模式
参考资料:        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 已移植成功,只是配置中的实时开关尚未测试,有待后续。


回复

使用道具 举报

5

主题

34

帖子

125

积分

i.MX6UL通行证RK3568通行证AM335x通行证

 楼主| 发表于 3 天前 | 显示全部楼层
此次移植及程序测试,尚有诸多不足,本人对系统的实时特性并不精通,最小同步周期只能稳定达到5ms,有待后续改进,也请高手不吝置喙。
点评回复 支持 1 反对 0

使用道具 举报

5

主题

34

帖子

125

积分

i.MX6UL通行证RK3568通行证AM335x通行证

 楼主| 发表于 3 天前 | 显示全部楼层
在新环境下重构在 OKMX6ULL-C开发板测试可以运行的程序
修改其工程文件,加入
...
INCLUDEPATH += /home/forlinx/3568/EtherCAT_my/output_ethercat_gitlab_20250308/include
LIBS += -L/home/forlinx/3568/EtherCAT_my/output_ethercat_gitlab_20250308/lib -lethercat
...

源文件内容不作修改。

root@OK3568-C-buildroot:/usr/bin# cd /home/qt_my
root@OK3568-C-buildroot:/home/qt_my# scp forlinx@192.168.8.11:/home/forlinx/3568/work_my/qt_my/Ecat_Test_console_05_II/Ecat_Test_console_05_II /home/qt_my


root@OK3568-C-buildroot:/home/qt_my# ./Ecat_Test_console_05_II
Using priority 99.
[ 3265.363125] EtherCAT: Requesting master 0...
[ 3265.363163] EtherCAT: Successfully requested master 0.
Configuring PDOs...
*Success to configuring slave PDOs*
Activating master...
[ 3266.363593] EtherCAT 0: Domain0: Logical address 0x00000000, 40 byte, expected working counter 3.
Starting cyclic function.
[ 3266.363617] EtherCAT 0:   Datagram domain0-0-main: Logical offset 0x00000000,  40 byte, type LRW.
1 slave(s).
[ 3266.363673] EtherCAT 0: Master thread exited.
AL states: 0x02.
[ 3266.363695] EtherCAT 0: Stopping EoE thread.
Link is up.
[ 3266.363732] EtherCAT 0: EoE thread exited.
slave: State 0x02.
[ 3266.363755] EtherCAT 0: Starting EoE thread.
slave: online.
[ 3266.363970] EtherCAT 0: Starting EtherCAT-OP thread.
slave: status_check 0x0000    0x0000.
sync_ref_counter 0.
slave: status_check 0x0000    0x0000.
sync_ref_counter 1.
slave: status_check 0x0000    0x0000.
sync_ref_counter 0.
slave: status_check 0x0000    0x0000.
sync_ref_counter 1.

...
slave: status_check 0x000C    0x122C.
sync_ref_counter 1.
slave: status_check 0x000C    0x122C.
sync_ref_counter 0.
slave: status_check 0x0040    0x1650.
sync_ref_counter 1.
slave: status_check 0x0040    0x1650.
sync_ref_counter 0.
slave: status_check 0x0040    0x1650.
sync_ref_counter 1.

...        ...
slave: status_check 0x0040    0x1650.
sync_ref_counter 0.
slave: status_check 0x0021    0x1631.
sync_ref_counter 1.
[ 3277.935693] EtherCAT 0: Slave states on main device: OP.
slave: status_check 0x0021    0x1631.
sync_ref_counter 0.
slave: status_check 0x0023    0x1633.
sync_ref_counter 1.

...        ...
slave: status_check 0x0023    0x1633.
sync_ref_counter 0.
slave: status_check 0x0027    0x1637.
sync_ref_counter 1.
slave: status_check 0x0027    0x1637.
sync_ref_counter 0.
slave: position 0x34CE2.
slave: status_check 0x0027    0x1637.
sync_ref_counter 1.
...        ...
中间约略去4032行类似信息
...        ...
slave: status_check 0x0027    0x1637.
sync_ref_counter 0.
slave: position 0x642A.
slave: status_check 0x0027    0x1637.
sync_ref_counter 1.
slave: status_check 0x0027    0x1637.
sync_ref_counter 0.
slave: position 0x6842.
^C                ->强制退出程序
[ 3294.174917] EtherCAT 0: Releasing master...
[ 3294.174989] EtherCAT 0: Master thread exited.

[ 3294.175014] EtherCAT 0: Stopping EoE thread.
root@OK3568-C-buildroot:/home/qt_my# [ 3294.175053] EtherCAT 0: EoE thread exited.
[ 3294.175082] EtherCAT 0: Starting EoE thread.
[ 3294.175344] EtherCAT 0: Starting EtherCAT-IDLE thread.
[ 3294.175457] EtherCAT 0: Released.
[ 3294.181714] EtherCAT 0: Slave states on main device: PREOP.


->该程序再连续执行数次,皆成功驱使电机正常运转;该程序在OKMX6ULL-C 上有程序运行初期同步成功率比较差的问题,在当前条件下得到改善。
->说明,该 ethercat v1.6.3 比之前的版本强,开发板 linux 4.19.232-rt 亦不可或缺。


点评回复 支持 反对

使用道具 举报

5

主题

34

帖子

125

积分

i.MX6UL通行证RK3568通行证AM335x通行证

 楼主| 发表于 3 天前 | 显示全部楼层
附上测试源代码。


Ecat_Test_console_05_II.zip

5.92 KB, 下载次数: 1, 下载积分: 贡献 1

点评回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2025-3-26 01:18

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表