嵌入式爱好者

查看: 478|回复: 5

[Linux] 抛砖,记录OKMX6ULL-C开发板移植 IGH EtherCAT 1.6

[复制链接]

4

主题

28

帖子

114

积分

i.MX6UL通行证AM335x通行证

扫一扫,手机访问本帖
发表于 2024-8-12 16:47:57 | 显示全部楼层 |阅读模式
本帖最后由 Vincentwangwt 于 2024-8-12 17:25 编辑

参考资料:
  1、https://blog.csdn.net/yyz_1987/article/details/136760235          EtherCAT 开源主站 IGH 在 linux 开发板的移植和伺服通信测试
  2、https://blog.csdn.net/u014077947/article/details/127402412     EtherCAT IGH 的下载和编译
环境条件:OKMX6ULL-C;VMware Workstation 16 Player,play->release-6ull-u18 虚拟机
操作如下:
1、参照参考资料1,在主机下载 IGH EtherCAT 1.6,传入虚拟机 /home/forlinx/work/EtherCAT_my(路径可自定,这里仅供参考);参考资料虽有实时内核补丁,但本人对此不熟,故未加入;
2、在路径下解压压缩文件,得到文件夹 ethercat-stable-1.6 ,并以命令行进入该文件夹;
3、执行   . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi    布置交叉编译环境;
4、创建 /home/forlinx/work/EtherCAT_my/output 路径;
5、root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6# ./configure --prefix=/home/forlinx/work/EtherCAT_my/output --with-linux-dir=/home/forlinx/work/linux-4.1.15 --enable-8139too=no --enable-generic=yes --host=arm-poky-linux-gnueabi
                --with-linux-dir= 须指向已指向已编译的内核源码;
6、root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6# make
7、root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6# make install
8、root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6# make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- modules
9、root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6# cd devices
root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6/devices# sudo make install

10、root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6/devices# cd ..
root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6# cd master

root@ubuntu:/home/forlinx/work/EtherCAT_my/ethercat-stable-1.6/master# sudo make install

11、root@ubuntu:/home/forlinx/work/EtherCAT_my/output/modules# cp /home/forlinx/work/EtherCAT_my/ethercat-stable-1.6/devices/ec_generic.ko /home/forlinx/work/EtherCAT_my/output/modules

root@ubuntu:/home/forlinx/work/EtherCAT_my/output/modules# cp /home/forlinx/work/EtherCAT_my/ethercat-stable-1.6/master/ec_master.ko /home/forlinx/work/EtherCAT_my/output/modules

12、root@ubuntu:/home/forlinx/work/EtherCAT_my# tar -cjf output.tar.bz2 output/

13、至此,已完成虚拟机交叉编译操作,操作步骤中个别可能需要权限,可以以 sudo su 指令切换至管理员权限;后面将进入开发板操作;
回复

使用道具 举报

4

主题

28

帖子

114

积分

i.MX6UL通行证AM335x通行证

 楼主| 发表于 2024-8-12 17:08:19 | 显示全部楼层
19、进一步测试汇川驱动器SV630NS2R8I与移植安装于开发板的 IGH EtherCAT 1.6.1 主站软件的识别通信,操作及信息如下:

Freescale i.MX Release Distro 4.1.15-2.0.1 fl-imx6ull /dev/ttymxc0

fl-imx6ull login: root
Password:
root@fl-imx6ull:~# ifconfig eth0 192.168.8.9
root@fl-imx6ull:~# ifconfig eth1 192.168.157.9
root@fl-imx6ull:~# export PATH=$PATH:/etc/sysconfig
root@fl-imx6ull:~# modprobe ec_master main_devices=62:38:63:34:0f:71
EtherCAT: Master driver 1.6.1 unknown
EtherCAT: 1 master waiting for devices.
root@fl-imx6ull:~# cd /lib/modules/4.1.15-00050-ge85def2
root@fl-imx6ull:/lib/modules/4.1.15-00050-ge85def2# insmod  ec_generic.ko
ec_generic: EtherCAT master generic Ethernet device module 1.6.1 unknown
EtherCAT: Accepting 62:38:63:34:0F:71 as main device for master 0.
ec_generic: Binding socket to inte**ce 5 (eth1).
EtherCAT 0: Starting EtherCAT-IDLE thread.
EtherCAT 0: Link state of ecm0 changed to UP.
root@fl-imx6ull:/lib/modules/4.1.EtherCAT 0: 1 slave(s) responding on main device.
15-00050-ge85def2# EtherCAT 0: Slave states on main device: INIT.
EtherCAT 0: Scanning bus.
EtherCAT 0: Bus scanning completed in 260 ms.
EtherCAT 0: Using slave 0 as DC reference clock.
EtherCAT 0: Starting EoE thread.
EtherCAT 0: Slave states on main device: PREOP.
EtherCAT ERROR 0-0: Timeout after 10000 ms while setting state OP.
EtherCAT 0: Slave states on main device: SAFEOP.
EtherCAT 0: Slave states on main device: SAFEOP + ERROR.

root@fl-imx6ull:/# ethercat master
Master0
  Phase: Idle
  Active: no
  Slaves: 1
  Ethernet devices:
    Main: 62:38:63:34:0f:71 (attached)
      Link: UP
      Tx frames:   199463
      Tx bytes:    12003204
      Rx frames:   199462
      Rx bytes:    12003144
      Tx errors:   0
      Tx frame rate [1/s]:    100    100    639
      Tx rate [KByte/s]:      5.9    5.9   37.6
      Rx frame rate [1/s]:    100    100    639
      Rx rate [KByte/s]:      5.9    5.9   37.6
    Common:
      Tx frames:   199463
      Tx bytes:    12003204
      Rx frames:   199462
      Rx bytes:    12003144
      Lost frames: 0
      Tx frame rate [1/s]:    100    100    639
      Tx rate [KByte/s]:      5.9    5.9   37.6
      Rx frame rate [1/s]:    100    100    639
      Rx rate [KByte/s]:      5.9    5.9   37.6
      Loss rate [1/s]:          0     -0      0
      Frame loss [%]:         0.0   -0.0    0.0
  Distributed clocks:
    Reference clock:   Slave 0
    DC reference time: 0
    Application time:  0
                       2000-01-01 00:00:00.000000000
root@fl-imx6ull:/# ethercat slaves
0  0:0  SAFEOP+ERROR  E  SV630_1Axis_03716
点评回复 支持 1 反对 0

使用道具 举报

4

主题

28

帖子

114

积分

i.MX6UL通行证AM335x通行证

 楼主| 发表于 2024-8-12 17:03:03 | 显示全部楼层
本帖最后由 Vincentwangwt 于 2024-8-12 17:30 编辑

14、root@fl-imx6ull:~/EtherCAT# scp  forlinx@192.168.8.11:/home/forlinx/work/EtherCAT_my/output.tar.bz2 /home/root/EtherCAT
forlinx@192.168.8.11's password:
output.tar.bz2                                100% 1999KB   2.0MB/s   00:01

15、root@fl-imx6ull:~/EtherCAT# tar -jxvf output.tar.bz2

16、个人对软连接型式理解不深,暂弃之,开发板的存贮相对充足,以拷贝代替
root@fl-imx6ull:~/EtherCAT/output# cp etc/init.d/ethercat /etc/init.d           
root@fl-imx6ull:~/EtherCAT/output# cp etc/ethercat.conf /etc                ->参考资料2,新加入
root@fl-imx6ull:~/EtherCAT/output# cp bin/ethercat /usr/bin
root@fl-imx6ull:~/EtherCAT/output# cp etc/sysconfig/ethercat /etc/sysconfig
root@fl-imx6ull:~/EtherCAT/output#

16.1root@fl-imx6ull:~/EtherCAT/output# vi etc/sysconfig/ethercat

......
#MASTER0_DEVICE=""
#modify up line
MASTER0_DEVICE="62:38:63:34:0f:71"                   ->MAC值 指向开发板 eth1 网口

#MASTER1_DEVICE=""

......

#DEVICE_MODULES=""
#modify up line
DEVICE_MODULES="generic"

......

#new add
echo KERNEL==\"EtherCAT[0-9]*\", MODE=\"0664\" > /etc/udev/rules.d/99-EtherCAT.rules

        注:该编缉操作亦可在虚拟机上完成;

16.2、root@fl-imx6ull:/# export PATH=$PATH:/etc/sysconfig        ->追加路径,但实际测试似不是非常必要
root@fl-imx6ull:/# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/etc/sysconfig

17、root@fl-imx6ull:/# modprobe ec_master main_devices=62:38:63:34:0f:71
EtherCAT: Master driver 1.6.1 unknown
EtherCAT: 1 master waiting for devices.

root@fl-imx6ull:/lib/modules/4.1.15-00050-ge85def2# insmod  ec_generic.ko       ec_generic: EtherCAT master generic Ethernet device module 1.6.1 unknown
EtherCAT: Accepting 62:38:63:34:0F:71 as main device for master 0.
ec_generic: Binding socket to inte**ce 5 (eth1).
EtherCAT 0: Starting EtherCAT-IDLE thread.

root@fl-imx6ull:/lib/modules/4.1.15-00050-ge85def2# cd /etc/init.d

root@fl-imx6ull:/# ethercat master                        
Master0
  Phase: Idle
  Active: no
  Slaves: 0
  Ethernet devices:
    Main: 62:38:63:34:0f:71 (attached)
      Link: DOWN
      Tx frames:   0
      Tx bytes:    0
      Rx frames:   0
      Rx bytes:    0
      Tx errors:   0
      Tx frame rate [1/s]:      0      0      0
      Tx rate [KByte/s]:      0.0    0.0    0.0
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
    Common:
      Tx frames:   0
      Tx bytes:    0
      Rx frames:   0
      Rx bytes:    0
      Lost frames: 0
      Tx frame rate [1/s]:      0      0      0
      Tx rate [KByte/s]:      0.0    0.0    0.0
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
      Loss rate [1/s]:          0      0      0
      Frame loss [%]:         0.0    0.0    0.0
  Distributed clocks:
    Reference clock:   None
    DC reference time: 0
    Application time:  0
                       2000-01-01 00:00:00.000000000

root@fl-imx6ull:/etc/init.d# ./ethercat stop
Shutting down EtherCAT master 1.6.1 EtherCAT 0: Master thread exited.
EtherCAT 0: Releasing main device 62:38:63:34:0F:71.
ec_generic: Unloading.
EtherCAT: Master module cleaned up.
done
root@fl-imx6ull:/etc/init.d# ./ethercat start
Starting EtherCAT master 1.6.1 EtherCAT: Master driver 1.6.1 unknown
EtherCAT: 1 master waiting for devices.
ec_generic: EtherCAT master generic Ethernet device module 1.6.1 unknown
EtherCAT: Accepting 62:38:63:34:0F:71 as main device for master 0.
ec_generic: Binding socket to inte**ce 5 (eth1).
EtherCAT 0: Starting EtherCAT-IDLE thread.
done
root@fl-imx6ull:/etc/init.d#

18、至此,个人认为 IGH EtherCAT 主站已被移植至开发板,但是否合用,尚有待进一步测试;
点评回复 支持 反对

使用道具 举报

4

主题

28

帖子

114

积分

i.MX6UL通行证AM335x通行证

 楼主| 发表于 2024-8-12 17:13:00 | 显示全部楼层
以上,为个人测试移植安装 IGH EtherCAT 1.6 至 OKMX6ULL-C 开发板的测试操作记录,难免有疪漏,请原谅;也请对此先达高手不吝置喙。
点评回复 支持 反对

使用道具 举报

4

主题

28

帖子

114

积分

i.MX6UL通行证AM335x通行证

 楼主| 发表于 2024-8-16 10:20:39 | 显示全部楼层
附上一个最简单的关于 IGH Ethercat 的Qt 工程 Ecat_Test_II,仅为测试前面所建立环境对 Qt 是否适用,过程记录如下:

编缉工程文件
QT       += core gui

INCLUDEPATH += /home/forlinx/work/EtherCAT_my/output/include                  #新加入
LIBS += -L/home/forlinx/work/EtherCAT_my/output/lib -lethercat                       #新加入

编缉头文件
private:
    Ui::MainWindow *ui;

    ec_master_t *master     =   NULL;                  //新加入

编缉 Forms 文件,加入按钮 pushButton_ec_master_init、pushButton_ec_master_clear,并 go slot...,建立槽函数

编缉源文件,仅对槽函数加入操作
void MainWindow::on_pushButton_ec_master_init_clicked()
{
    master = ecrt_request_master(0);
    if (!master)
    {
        if( DEBUG_INFO_MAIN_MainWindow)
            qDebug()    <<  "IGH EtherCAT master request failed! ";

        return;
    }
    else
    {
        if( DEBUG_INFO_SUB_MainWindow)
            qDebug()    <<  "IGH EtherCAT master request success! ";
    }
}

void MainWindow::on_pushButton_ec_master_clear_clicked()
{
    // 清理EtherCAT资源
    ecrt_release_master(master);
}

编译之,可以通过。

将编译生成的可运行文件 Ecat_Test_II,传至开发板上,给予权限,运行;
root@fl-imx6ull:~/qt_my/Ecat_Test_II# ./Ecat_Test_II
./Ecat_Test_II: error while loading shared libraries: libethercat.so.1: cannot open shared object file: No such file or directory

运行报错,尝试将前面编译生成的库文件,加入开发板 lib 文件夹;
root@fl-imx6ull:/lib# cp /home/root/EtherCAT/output/lib/libether* /lib

再次运行 Qt 程序
root@fl-imx6ull:/lib# cd /home/root/qt_my/Ecat_Test_II
root@fl-imx6ull:~/qt_my/Ecat_Test_II# ./Ecat_Test_II
libEGL warning: DRI2: failed to authenticate
这次程序可以正常启动,尝试点击按钮 “pushButton_ec_master_init”,调试端口输出信息如下
EtherCAT: Requesting master 0...
EtherCAT: Successfully requested master 0.
IGH EtherCAT master request success!
EtherCAT 0: Releasing master...
EtherCAT 0: Released.
root@fl-imx6ull:~/qt_my/Ecat_Test_II# ethercat master
Master0
  Phase: Idle
  Active: no
  Slaves: 0
  Ethernet devices:
    Main: 62:38:63:34:0f:71 (attached)
      Link: DOWN
      Tx frames:   0
      Tx bytes:    0
      Rx frames:   0
      Rx bytes:    0
      Tx errors:   0
      Tx frame rate [1/s]:      0      0      0
      Tx rate [KByte/s]:      0.0    0.0    0.0
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
    Common:
      Tx frames:   0
      Tx bytes:    0
      Rx frames:   0
      Rx bytes:    0
      Lost frames: 0
      Tx frame rate [1/s]:      0      0      0
      Tx rate [KByte/s]:      0.0    0.0    0.0
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
      Loss rate [1/s]:          0      0      0
      Frame loss [%]:         0.0    0.0    0.0
  Distributed clocks:
    Reference clock:   None
    DC reference time: 0
    Application time:  0
                       2000-01-01 00:00:00.000000000

从以上测试结果可以看出,前面搭建的 IGH EtherCAT 1.6 环境,可以正常编译运行关于 EtherCAT 的 Qt 程序。

点评回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-21 11:14

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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