工控网首页
>

应用设计

>

ARM嵌入式系统串口扩展

ARM嵌入式系统串口扩展

ARM嵌入式系统常常会遇到多串口应用需求,而ARM芯片系统原生的UART数目有限,因此就需要通过其他高速总线来扩展更多的接口。本文就以Toradex 基于NXPi.MX6D/6Q处理器的Apalis i.MX6D/Q ARM计算机模块,在Linux系统下通过EXAR方案扩展8路串口。

Apalis i.MX6D/Q模块自身最多可以支持 5 UART 串口输出。兼容高速TIA/EIA-232F(最高 5Mbit/s)。支持78 或者 9(用于RS485)位数据,1或者2位停止位。其中 UART1 为全功能串口,其余部分串口也可支持 RTSCTS 信号。

Linux 系统中一般会保留一个串口用于应用调试开发以及系统升级。虽然 SSH 等功能也可以用于远程网络访问以及系统调试,但是对于嵌入式产品,系统启动时,特别是 Uboot 启动的信息,可以有助于功能调试以及问题定位。而这部分信息只能从串口输出。Toradex 模块在更新Linux BSP 的时候也同样需要在 Uboot 进行。

Apalis i.MX6Q/D 模块剩余的4个串口,除了可以使用TTL 电平直接控制相应的外设,也可以扩展为 RS232/RS485/RS422 常用的工业控制端口。对于更多串口的需求,目前有多种方案实现串口扩展,例如通过 USBSPIMemory BusI2C以及 PCIe 等总线。 Memory Bus PCIe 相对于其他总线具有更高的实时性,在同一个接口上也能够扩展出更多的串口。对于串口数量以及数据实时性较高的应用可以优先选择这两种扩展方案。与此同时, Memory Bus PCIe 属于高速信号总线,在 PCB 布线方面需要一些特殊考虑。Toradex 为此也提供了免费的 PCB 设计指导。下面我们就将介绍如何使用 EXAR 基于 PCIe 总线的XR17V358方案,扩展 8 路串口。

1). XR17V358方案简介及驱动下载

XR17V358 扩展的 8 个串口均支持RTS/CTS 或者 DTR/DSR 流控功能,每个串口带有 256 字节的 FIFO,独立时钟输出,支持半双工 RS485,最高传输速度为 25 Mbps XR17V358 使用 PCIe 2.0 Gen 1 Apalis i.MX6Q/D 相连接,保证高速实时地数据传输。EXAR 目前为 XR17V358 提供了 Windows Linux 驱动。这里我们采用其最新的 Linux 驱动,并移植到 Apalis i.MX6 平台上。驱动源码下载地址http://www.exar.com/common/content/document.ashx?id=20121

2). 配置编译环境

在编译之前,还需要下载  Apalis i.MX6 Linux 内核以及交叉编译工具。

a). Apalis i.MX6 Linux 内核下载

$ git clone -b toradex_imx_3.14.28_1.0.0_ga-nextgit://git.toradex.com/linux-toradex.git

b). 交叉编译工具下载

$ wgethttp://releases.linaro.org/14.11/components/toolchain/binaries/arm-linux-gnueabihf/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz

$ tar xvfgcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz

$ ln -sgcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf gcc-linaro

$ export ARCH=arm

$ export PATH=~/gcc-linaro/bin/:$PATH

$ export CROSS_COMPILE=arm-linux-gnueabihf-

注意:上面的路径需要对应交叉编译工具实际解压的目录。

c). 编译 Linux 内核,为XR17V358  提供必要的配置文件。

$ make apalis_imx6_defconfig

$ make -j4 uImage LOADADDR=10008000

d). 编译  XR17V358 驱动

// 编辑 Makefile 文件,将KERNEL_SRC  指向 Linux 内核所在目录

KERNEL_SRC =/home/ban/Toradex/oe-core-tegra/LinuxKernel/v2.5/mx6/toradex_imx_3.14.28_1.0.0_ga-next/linux-toradex

// 保持后运行 make 命令进行编译,确保上面提到的 ARCHPATH CROSS_COMPILE 参数仍然有效。

$ make

// 编译成功后会生成针对 ARM 处理器的内核模块文件  xr17v35x.ko

$ file xr17v35x.ko

xr17v35x.ko: ELF 32-bit LSB  relocatable, ARM, EABI5 version 1 (SYSV),BuildID[sha1]=399121b7862105b185e24b45ba3522f14158295e, not stripped

e). 安装驱动

xr17v35x.ko 复制到 Apalis i.MX6 模块上,并安装

root@apalis-imx6:~# insmod xr17v35x.ko

[ 151.156648] Exar PCIe (XR17V35x) serial driver Revision: 2.0

root@apalis-imx6:~# lspci

00:00.0 PCI bridge: Device 16c3:abcd (rev01)

01:00.0 PCI bridge: PLX Technology, Inc.PEX 8605 PCI Express 4-port Gen2 Switch (rev aa)

02:01.0 PCI bridge: PLX Technology, Inc.PEX 8605 PCI Express 4-port Gen2 Switch (rev aa)

02:02.0 PCI bridge: PLX Technology, Inc.PEX 8605 PCI Express 4-port Gen2 Switch (rev aa)

02:03.0 PCI bridge: PLX Technology, Inc.PEX 8605 PCI Express 4-port Gen2 Switch (rev aa)

03:00.0 Serial controller: Exar Corp.Device 0358 (rev 03)

/dev 目录下出现对应的串口设备文件 ttyXR0 ttyXR7

root@apalis-imx6:/dev# ls

autofs              network_latency     tty18               tty60

block               network_throughput  tty19               tty61

bus                 null                tty2                tty62

char                port                tty20               tty63

console             ppp                 tty21               tty7

cpu_dma_latency     ptmx                tty22               tty8

cuse                ptp0                tty23               tty9

disk                pts                 tty24               ttyXR0

dri                 ram0                tty25               ttyXR1

fb                  ram1                tty26               ttyXR2

fb0                 ram10               tty27               ttyXR3

fb1                 ram11               tty28               ttyXR4

fb2                 ram12               tty29               ttyXR5

fb3                 ram13               tty3                ttyXR6

fd                  ram14               tty30               ttyXR7

f). 设置波特率

root@apalis-imx6:~# stty -F /dev/ttyXR0115200

驱动加载完毕后,在 Linux 中可以和其他串口一样正常使用。

投诉建议

提交

查看更多评论
其他资讯

查看更多

在 Linux 系统上 Docker 容器的性能影响

上游优先 - Toradex 采用主线内核支持

NXP iMX8M Plus M7核心FreeRTOS开发

嵌入式Linux上使用Ramoops

使用容器编译Yocto镜像