单片机/MCUwilliam hill官网
直播中

飞洋

6年用户 200经验值
擅长:处理器/DSP
私信 关注
[文章]

瑞米派实时系统与EtherCAT移植-米尔Remi Pi

1.概述
Remi Pi采用瑞萨RZ/G2L作为核心处理器,该处理器搭载双核Cortex-A55@1.2GHz+Cortex-M33@200MHz处理器,其内部集成高性能3D加速引擎Mail-G31 GPU(500MHz)和视频处理单元(支持H.264硬件编解码),16位的DDR4-1600 / DDR3L-1333内存控制器、千兆以太网控制器、USB、CAN、SD卡、MIPI-CSI等外设接口,在工业、医疗、电力等行业都得到广泛的应用。
在开发阶段,建议配合核心板配套的评估套件 MYD-YG2L23-8E1D-120-C-REMI来加速开发。评估套件的详细信息请访问:https://www.myir.cn/shows/23/14.html

2.实时内核设计

  • 实时补丁我们选择RT-Preempt来实现

2.1. 移植补丁
RT补丁可以从RT官网下载5.10.83对应的补丁
https://cdn.kernel.org/pub/linux/kernel/projects/rt/5.10/older/
1.png


  • 把补丁放到自己的工作目录下,然后解压,如图2-1:

  1. hjx@myir-server:~/renesas/04_Sources[        DISCUZ_CODE_858        ]nbsp;tar -xvf patches-5.10.83-rt58.tar.gz
2.png
图2-1. 内核源码


  • 进入到内核源码打补丁,如图2-2:

  1. hjx@myir-server:~/renesas/04_Sources/myir-renesas-linux[        DISCUZ_CODE_859        ]nbsp;for p in `ls -1 ../patches/*.patch`; do patch -p1 < $p; done
3.png
图2-2. 打实时补丁


  • 编译内核源码

  1. hjx@myir-server:~/renesas/04_Sources/myir-renesas-linux[        DISCUZ_CODE_860        ]nbsp;/opt/remi-sdk/environment-setup-aarch64-poky-linux
  2. hjx@myir-server:~/renesas/04_Sources/myir-renesas-linux[        DISCUZ_CODE_860        ]nbsp;make ARCH=arm64 mys_g2lx_defconfig
  3. hjx@myir-server:~/renesas/04_Sources/myir-renesas-linux[        DISCUZ_CODE_860        ]nbsp;make ARCH=arm64 Image dtbs   -j16

更新编译得到的Image即可
2.2. 其他影响性能的配置
禁用CPU Freq自动调频,并设置主频为最高频率:
  1. cd /sys/devices/system/cpu/cpufreq/policy0
  2. echo userspace > scaling_governor
  3. cat scaling_max_freq  > scaling_setspeed

(如不禁用cpufreq调频功能,系统会因动态调频产生极大的偶然延迟)
3.实时性测试

  • 空载测试

  1. cyclictest -p 99 -t 1 -d 100 -i 1000 -D 24h -m -a -n
4.png
图3-1.空载测试


  • CPU&内存满载

  1. cyclictest -p 99 -t 1 -d 100 -i 1000 -D 24h -m -a -n

  • 增加压力

  1. stress-ng --cpu 4 --cpu-method all --io 4 --vm 50 -d 5 --fork 4 --timeout 36000s
5.png
图3-2.满载测试

数据对比:
板卡
MYD-YG2LX-REMI
测试时间
120min
指令
cyclictest &stress-ng
空载
平均 8us
最大 24us
满载
平均 13us
最大 136us
表3-1.数据信息

4.EtherCAT IGH移植
4.1. 下载EtherCAT IGH源码
到官网下载1.5版本的EtherCAT源码,如图4-1:
https://gitlab.com/etherlab.org/ethercat/-/tree/stable-1.5?ref_type=heads
6.png
图4-1. 下载源码


  • 解压EtherCAT源码

  1. hjx@myir-server:~/renesas/04_Sources[        DISCUZ_CODE_865        ]nbsp;tar -xvf ethercat-stable-1.5.tar.bz2
  2. hjx@myir-server:~/renesas/04_Sources[        DISCUZ_CODE_865        ]nbsp;cd ethercat-stable-1.5


  • 加载sdk环境变量

  1. hjx@myir-server:~/renesas/04_Sources/myir-renesas-linux[        DISCUZ_CODE_866        ]nbsp;source /opt/remi-sdk/environment-setup-aarch64-poky-linux

4.2. 编译EtherCAT源码

  • 生成configure文件

  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_867        ]nbsp;./bootstrap
  2. + touch ChangeLog
  3. + mkdir -p m4
  4. + autoreconf -i
  5. libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'autoconf'.
  6. libtoolize: copying file 'autoconf/ltmain.sh'
  7. libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
  8. libtoolize: copying file 'm4/libtool.m4'
  9. libtoolize: copying file 'm4/ltoptions.m4'
  10. libtoolize: copying file 'm4/ltsugar.m4'
  11. libtoolize: copying file 'm4/ltversion.m4'
  12. libtoolize: copying file 'm4/lt~obsolete.m4'
  13. configure.ac:56: installing 'autoconf/ar-lib'
  14. configure.ac:55: installing 'autoconf/compile'
  15. configure.ac:58: installing 'autoconf/config.guess'
  16. configure.ac:58: installing 'autoconf/config.sub'
  17. configure.ac:42: installing 'autoconf/install-sh'
  18. configure.ac:42: installing 'autoconf/missing'
  19. examples/dc_user/Makefile.am: installing 'autoconf/depcomp'


  • configure设置

  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_868        ]nbsp;mkdir  output
  2. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_868        ]nbsp;./configure --prefix=/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output --with-linux-dir=/home/hjx/renesas/04_Sources/myir-renesas-linux  --enable-8139too=no  --enable-generic=yes   --host=aarch64-poky-linux
(--prefix=/home/hjx/renesas/04_Sources/output 指定输出目录、--with-linux-dir=/home/hjx/renesas/04_Sources/myir-renesas-linux指定内核源码目录)
  1. configure: loading site script /opt/remi-sdk/site-config-aarch64-poky-linux
  2. checking for a BSD-compatible install... /usr/bin/install -c
  3. checking whether build environment is sane... yes
  4. checking for aarch64-poky-linux-strip... aarch64-poky-linux-strip
  5. checking for a thread-safe mkdir -p... /bin/mkdir -p
  6. checking for gawk... gawk
  7. checking whether make sets $(MAKE)... yes
  8. checking whether make supports nested variables... yes
  9. checking whether make supports nested variables... (cached) yes
  10. checking for a sed that does not truncate output... (cached) sed
  11. checking for aarch64-poky-linux-pkg-config... no
  12. checking for pkg-config... /opt/remi-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/pkg-config
  13. checking pkg-config is at least version 0.9.0... yes
  14. checking whether make supports the include directive... yes (GNU style)
  15. ..........
  16. ...............
  17. config.status: creating examples/xenomai/Makefile
  18. config.status: creating examples/xenomai_posix/Makefile
  19. config.status: creating include/Makefile
  20. config.status: creating lib/Makefile
  21. config.status: creating lib/libethercat.pcconfig.status: creating master/Kbuild
  22. config.status: creating master/Makefileconfig.status: creating script/Makefile
  23. config.status: creating script/init.d/Makefile
  24. config.status: creating script/init.d/ethercat
  25. config.status: creating script/sysconfig/Makefile
  26. config.status: creating tool/Makefile
  27. config.status: creating tty/Kbuild
  28. config.status: creating tty/Makefile
  29. config.status: creating config.h
  30. config.status: executing depfiles commands
  31. config.status: executing libtool commands


  • 编译源码

  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_870        ]nbsp;  make
  2. make all-recursive
  3. make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
  4. Making all in include
  5. make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
  6. make[2]: Nothing to be done for 'all'.
  7. make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
  8. Making all in script
  9. make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script'
  10. Making all in init.d
  11. make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
  12. make[3]: Nothing to be done for 'all'.
  13. make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
  14. Making all in sysconfig
  15. make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/sysconfig'
  16. make[3]: Nothing to be done for 'all'.
  17. make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/sysconfig'
  18. ......
  19. ......
  20. make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples/user'
  21. make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
  22. make[3]: Nothing to be done for 'all-am'.
  23. make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
  24. make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
  25. make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
  26. make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
  27. make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'


  • 编译modules

  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_871        ]nbsp; make  modules
  2. make[1]: Entering directory '/home/hjx/renesas/04_Sources/myir-renesas-linux'
  3. CC [M]  /home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples/mini/mini.o
  4. LD [M]  /home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples/mini/ec_mini.o
  5. CC [M]  /home/hjx/renesas/04_Sources/ethercat-stable-1.5/master/cdev.o
  6. CC [M]  /home/hjx/renesas/04_Sources/ethercat-stable-1.5/master/coe_emerg_ring.o
  7. CC [M]  /home/hjx/renesas/04_Sources/ethercat-stable-1.5/master/datagram.o
  8. ...........
  9. ............
  10. make[1]: Leaving directory '/home/hjx/renesas/04_Sources/myir-renesas-linux'

编译通过会对应生成ethercat-stable-1.5/devices/ec_generic.ko和ethercat-stable-1.5/master/ec_master.ko
4.3. 安装EtherCAT
安装成功后前面指定/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output目录下有编译生成的各种用户空间的文件。
  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_872        ]nbsp;make install
  2. Making install in include
  3. make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
  4. make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
  5. make[2]: Nothing to be done for 'install-exec-am'.
  6. /bin/mkdir -p '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output/include'/
  7. usr/bin/install -c -m 644 ecrt.h ectty.h '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output/include'
  8. make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
  9. make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
  10. Making install in script
  11. make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script'
  12. Making install in init.d
  13. make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
  14. make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
  15. make[3]: Nothing to be done for 'install-exec-am'
  16. ............
  17. ..........
  18. make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
  19. make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
  20. make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
  21. make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
  22. make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
  23. make[2]: Nothing to be done for 'install-exec-am'.
  24. make[2]: Nothing to be done for 'install-data-am'.
  25. make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
  26. make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'

4.4. 将EtharCAT相关文件打包
在/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output目录下创建modules文件夹,并复制ec_generic.ko和ec_master.ko到modules下
  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_873        ]nbsp; mkdir -p output/modules
  2. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_873        ]nbsp; cp devices/ec_generic.ko  output/modules/
  3. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_873        ]nbsp; cp master/ec_master.ko   output/modules/
  4. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_873        ]nbsp;ls output
  5. bin etc  include  lib  modules  sbin share


  • 压缩output输出文件

  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_874        ]nbsp;tar -jcvf output.tar.bz2
  2. output/  
  3. output/etc/
  4. output/etc/ethercat.conf
  5. output/etc/init.d/
  6. output/etc/init.d/ethercat
  7. output/etc/sysconfig/
  8. output/etc/sysconfig/ethercat
  9. output/sbin/
  10. output/sbin/ethercatctl
  11. output/include/
  12. output/include/ectty.h
  13. output/include/ecrt.h
  14. output/modules/
  15. output/modules/ec_master.ko
  16. output/modules/ec_generic.ko
  17. output/share/
  18. output/share/bash-completion/
  19. output/share/bash-completion/completions/
  20. output/share/bash-completion/completions/ethercat
  21. output/bin/
  22. output/bin/ethercat
  23. output/lib/
  24. output/lib/libethercat.so
  25. output/lib/pkgconfig/
  26. output/lib/pkgconfig/libethercat.pc
  27. output/lib/libethercat.so.1.2.0
  28. output/lib/cmake/
  29. output/lib/cmake/ethercat/
  30. output/lib/cmake/ethercat/ethercat-config.cmake
  31. output/lib/libethercat.a
  32. output/lib/libethercat.la
  33. output/lib/libethercat.so.1
  34. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5[        DISCUZ_CODE_874        ]nbsp;ls output.tar.bz2
  35. output.tar.bz2

至此IGH交叉编译完成,下面是在对应arm目标板上的操作。
4.5. 移植EtherCAT相关库到开发板
将上面制作好的output.tar.bz2传到开发板上,然后解压出来。
  1. root@myir-remi-1g:~# tar -xvf output.tar.bz2output/
  2. output/
  3. etc/output/
  4. etc/ethercat.conf
  5. output/etc/init.d/
  6. output/etc/init.d/ethercat
  7. output/etc/sysconfig/
  8. output/etc/sysconfig/ethercat
  9. output/sbin/
  10. output/sbin/ethercatctl
  11. output/include/
  12. output/include/ectty.h
  13. output/include/ecrt.h
  14. output/modules/
  15. output/modules/ec_master.ko
  16. output/modules/ec_generic.ko
  17. output/share/
  18. output/share/bash-completion/
  19. output/share/bash-completion/completions/
  20. output/share/bash-completion/completions/ethercat
  21. output/bin/
  22. output/bin/ethercat
  23. output/lib/
  24. output/lib/libethercat.so
  25. output/lib/pkgconfig/
  26. output/lib/pkgconfig/libethercat.pc
  27. output/lib/libethercat.so.1.2.0
  28. output/lib/cmake/
  29. output/lib/cmake/ethercat/
  30. output/lib/cmake/ethercat/ethercat-config.cmake
  31. output/lib/libethercat.a
  32. output/lib/libethercat.la
  33. output/lib/libethercat.so.1

将output目录下各文件目录的内容复制到板子根文件系统根目录下相应目录下,例如:cp bin/ethercat /bin/(include目录不用复制)
  1. root@myir-remi-1g:~/output# ls
  2. bin etc  include  lib  modules  sbin  share
  3. root@myir-remi-1g:~/output# cp bin/ethercat /bin/
  4. root@myir-remi-1g:~/output# cp etc/ethercat.conf /etc/
  5. root@myir-remi-1g:~/output# cp etc/init.d/*  /etc/init.d
  6. root@myir-remi-1g:~/output# cp -r etc/sysconfig/ /etc/
  7. root@myir-remi-1g:~/output# cp  lib/libethercat.* /lib64/
  8. root@myir-remi-1g:~/output# cp -r lib/pkgconfig /lib64/
  9. root@myir-remi-1g:~/output# cp modules/ec_master.ko /lib/modules/5.10.83-cip1-yocto-standard/
  10. root@myir-remi-1g:~/output# cp sbin/ethercatctl  /sbin/
4.6. 启动EtherCAT
4.6.1. 配置主站的MAC地址
  1. root@myir-remi-1g:~# depmod
  2. root@myir-remi-1g:~# modprobe ec_master main_devices=1E:ED:19:27:1A:B3
4.6.2. 启动EtherCAT
  1. root@myir-remi-1g:~# /etc/init.d/ethercat start
  2. Starting EtherCAT master 1.5.2 done
至此所有步骤完成。


米尔瑞米派 Remi Pi
瑞萨第一款MPU生态板卡,兼容树莓派扩展模块
采用瑞萨RZ/G2L工业级处理器,便于企业客户产品开发;
Remi Pi兼容树莓派所有配件,方便产品原型搭建和创新应用;
更多的工业接口,兼顾开发、学习和实际应用;
软件系统丰富,支持Debian/Ubuntu/Linux等。
5.webp.jpg

更多回帖

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