这里写目录标题
1、安装编译igh所需的依赖
编译平台:Ubuntu
,因此输入如下命令安装依赖包。
apt-get install autoconf autogen libtool -y
2、方法一
1、下载EtherCAT Master 源码
git clone https://gitlab.com/etherlab.org/ethercat.git
2、编译EtherCAT Master和安装
cd ethercat
./bootstrap
sudo ./bootstrap
#配置包括 指定安装目录、指定 linux 内核目录、指定模块目录、指定需要编译的驱动 、
指定 xenomai 目录、编译链等
sudo ./configure --enable-8139too=no
//sudo ./configure --with-module-dir=/lib/modules/4.19.196-xenomai-3.1 --enable-generic --enable-8139too=no --enable-cycles --enable-hrtimer --with-xenomai-dir=/usr/xenomai --prefix=/opt/etherlab
//./configure --prefix=/home/lorentz/ethercat/build-xenomai --with-linux-dir=../rk3568/rk-linux5.10/kernel --enable-8139too=no --enable-e100=no --enable-e1000=no --enable-e1000e=no --enable-r8169=no --enable-generic=yes --enable-ccat=no --enable-igb=yes --enable-igc=no CC=/home/lorentz/rk3568/rk-linux5.10/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc --host=aarch64-none-linux-gnu
//./configure --prefix=/home/wh/arm_rtlinux/IgH_ECAT --with-linux-dir=dir=/home/wh/arm_bbb-debian-3.8.13-lcd/kernel --with-module-dir=dir=../lib/modules/3.8.13-xenomai-2.6.3 --enable-generic-enable-rtdm =yes --enable-8139too=no --with-8139too-kernel=3.8 --with-xenomai-dir=/usr/xenomai CC=arm-linux gnueabihf-gcc host=arm-linux-gnueabihf
sudo make -j4 #编译
sudo make modules #编译模块
sudo make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- modules #编译模块 ARM
sudo make install #安装
sudo make modules_install #安装模块
错误
sudo apt-get install pkg-config
3、方法二
签名问题
$ sudo apt install curl
$ export KEYRING=/usr/share/keyrings/etherlab.gpg
$ curl -fsSL https://download.opensuse.org/repositories/science:/EtherLab/Debian_12/Release.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
//$curl -fsSL https://download.opensuse.org/repositories/science:/EtherLab/xUbuntu_20.04/Release.key | gpg --dearmor | tee "$KEYRING" >/dev/null
$ cd /etc/apt/sources.list.d
$ ls
$ cat science_EtherLab.list
$ sudo rm -f science_EtherLab.list
$ echo "deb [signed-by=$KEYRING] https://download.opensuse.org/repositories/science:/EtherLab/Debian_12/ ./" | sudo tee /etc/apt/sources.list.d/etherlab.list > /dev/null
$ cat etherLab.list
$ sudo apt update
4、ethercat主站配置
#获取到网卡的mac地址
ifconfig
gedit etc/sysconfig/ethercat
将下面两行按照文件的位置填进去
MASTER0_DEVICE="54:48:10:d4:2b:c3"
DEVICE_MODULES="generic"
#你需要在上面2个文件中的MASTER0_DEVICE=后添加你的网卡的mac地址形如MASTER0_DEVICE="b8:ae:ed:7e:6e:66", 然后把DEVICE_MODULES=添加"generic"或r8169形如DEVICE_MODULES="generic"然后执行sudo depmod命令
#lspci | grep -i ethernet 查看自己网卡型号
sudo depmod
cd /opt/etherlab
sudo mkdir /etc/sysconfig #创建文件夹
sudo cp etc/sysconfig/ethercat /etc/sysconfig/ #复制配置文件
sudo cp /opt/etherlab/etc/init.d/ethercat /etc/init.d/ #复制启动脚本
sudo chmod a+x /etc/init.d/ethercat
sudo update-rc.d ethercat defaults
//sudo ln -s /opt/etherlab/bin/ethercat /usr/local/bin/ethercat
5、测试
开启主站
sudo /etc/init.d/ethercat start
主站详细信息
sudo ethercat master
从站详细信息
sudo ethercat cstruct
6、安装linuxcnc-ethercat
git clone https://github.com/sittner/linuxcnc-ethercat
cd linuxcnc-ethercat
make configure
make
sudo make install
错误1
$ halrun
halcmd: loadrt lcec
Note: Using POSIX realtime
lcec: dlopen: /usr/lib/linuxcnc/modules/lcec.so: undefined symbol: ecrt_slave_config_sdo
<stdin>:3: waitpid failed /usr/bin/rtapi_app lcec
<stdin>:3: /usr/bin/rtapi_app exited without becoming ready
<stdin>:3: insmod for lcec failed, returned -1
halcmd: Note: Using POSIX realtime
$ ldd -r /usr/lib/linuxcnc/modules/lcec.so
linux-vdso.so.1 (0x00007ffc6a1fc000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb029394000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb0291b3000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb0294b6000)
undefined symbol: hal_exit (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_sdo (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_domain_process (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: hal_param_new (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_sync_slave_clocks (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_release_master (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_slave_config (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_sdo16 (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: hal_malloc (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_state (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_pdos (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_vsnprintf (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_receive (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_sdo_upload (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_sync_reference_clock (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_watchdog (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_shmem_delete (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_activate (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_domain_reg_pdo_entry_list (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_state (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: hal_init (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_dc (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_idn (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_deactivate (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_task_pll_set_correction (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_send (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_shmem_new (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_request_master (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_complete_sdo (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_snprintf (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: hal_export_funct (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: hal_ready (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_shmem_getptr (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_print_msg (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: hal_pin_new (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_domain_size (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_task_pll_get_reference (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_read_real (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_read_idn (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_sdo32 (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_create_domain (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: rtapi_get_time (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_slave_config_sdo8 (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_domain_queue (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_domain_data (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_application_time (/usr/lib/linuxcnc/modules/lcec.so)
undefined symbol: ecrt_master_reference_clock_time (/usr/lib/linuxcnc/modules/lcec.so)
解决方法
覆写 ~/linuxcnc-ethercat/src/realtime.mk 文件,如下
include ../config.mk
include Kbuild
cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
.PHONY: all clean install
ifeq ($(BUILDSYS),kbuild)
module = $(patsubst %.o,%.ko,$(obj-m))
ifeq (,$(findstring -Wframe-larger-than=,$(EXTRA_CFLAGS)))
EXTRA_CFLAGS += $(call cc-option,-Wframe-larger-than=2560)
endif
重新编译
cd ~/linuxcnc-ethercat
make clean
make
sudo make install
错误2
Failed to open /dev/EtherCAT0: Permission denied
LCEC: requesting master 0 (index 0) failed
lcec: rtapi_app_main: Invalid argument (-22)
./test.hal:5: waitpid failed /usr/bin/rtapi_app lcec
./test.hal:5: /usr/bin/rtapi_app exited without becoming ready
./test.hal:5: insmod for lcec failed, returned -1
解决方法
sudo chown your_username /dev/EtherCAT0
将 your_username 替换为实际的用户名。
参考
https://blog.csdn.net/sf9090/article/details/125965172
https://blog.csdn.net/weixin_40185941/article/details/135538499
https://blog.csdn.net/weixin_42599219/article/details/127218091
https://blog.csdn.net/weixin_42599219/article/details/126154182
https://tencentcloud.csdn.net/65b378f92c13685765deee85.html
https://blog.csdn.net/m0_56121792/article/details/135255452
https://blog.csdn.net/qq_22654551/article/details/143085077
https://blog.csdn.net/qq_69923281/article/details/144132319?