CH438 Linux 驱动详解
一、
CH438是一款常用的USB转串口桥接芯片,广泛应用于嵌入式系统中,本文将详细介绍如何在Linux环境下移植和配置CH438驱动程序,包括硬件电路设计建议、内核配置、应用测试等。
二、硬件电路设计
引脚定义
CS: 片选信号,引脚编号为17。
RD: 读信号,引脚编号为16。
WR: 写信号,引脚编号为15。
E17~E14, E10~E0: 地址线。
E7~E0: 数据线。
GPIO_RANGE: 0x24。
寄存器映射
CH438_CFG0: 配置寄存器0 (0x00)。
CH438_CFG1: 配置寄存器1 (0x04)。
CH438_CFG2: 配置寄存器2 (0x08)。
CH438_CFG3: 配置寄存器3 (0x0C)。
CH438_DAT: 数据寄存器 (0x10)。
CH438_DRV0: 多驱动控制寄存器0 (0x14)。
CH438_DRV1: 多驱动控制寄存器1 (0x18)。
CH438_PULL0: 上拉寄存器0 (0x1C)。
CH438_PULL1: 上拉寄存器1 (0x20)。
CH438_SSR: 状态寄存器 (0x24)。
硬件接口电路图
+---+ +---+ +---+ | | --->| |---> | | | STM32 | | CH438 | PC | | | <---| |<--| | +---+ +---+ +---+
三、驱动移植注意事项
稳定性考虑
CH438驱动程序经过了长期负载运行测试,所有串口在全双工高速率(baudrate115200)下稳定工作。
读写端口速度应宁慢勿快,避免过快的读写操作导致通信失败。
驱动框架选择
该驱动没有使用8250的驱动框架,而是直接通过并口进行操作,确保对CH438的高效控制。
修改8250代码可能导致其他类8250芯片无法正常工作,因此不建议采用这种方式。
四、驱动实现细节
寄存器操作
初始化: 设置合适的读写速度,根据平台速度调整。
数据收发: 通过并口与CH438进行数据传输,使用中断或轮询方式处理数据。
代码示例
#define CH438_BASE (SUNXI_PIO_PBASE + 0x90) #define CH438_MEM_BASE (ioremap(CH438_BASE, ch438_membase)) static struct ch438_pin { int rst, pint; int irqnum; } ch438_pin = {17, 15, 16}; static struct ch438_port { struct uart_port port; char name[16]; unsigned char id; unsigned char acr; unsigned char ier; unsigned char lcr; unsigned char mcr; unsigned char fcr; unsigned char dll; unsigned char dlh; unsigned char msr_saved_flags; int io_num; struct ch438_pin *pin; }; #define CH438_MEM_BASE (SUNXI_GPIOE_BASE) #define RBR_RO 0x00 /* Received Buffer Register */ #define THR_WO 0x00 /* Transmit Holding Register */ #define IER_RO 0x02 /* Interrupt Enable Register */ #define IIR_RO 0x02 /* Interrupt Identification Register */ #define FCR_WO 0x02 /* FIFO Control Register */ #define LCR_RW 0x03 /* Line Control Register */ #define MCR_RW 0x04 /* Modem Control Register */ #define LSR_RO 0x05 /* Line Status Register */ #define MSR_RO 0x06 /* Modem Status Register */ #define SCR_RO 0x07 /* Scratch Register */ #define DLL_RO 0x00 /* Divisor Latch (LSB) */ #define DLH_RO 0x04 /* Divisor Latch (MSB) */ #define SRL_RW 0x0C /* Scratch Register */ #define MSC_RW 0x14 /* Multi-Driving Control Register */
五、问题与解答
1. CH438驱动是否可以替代8250驱动?
不可以,CH438驱动未使用8250驱动框架,直接通过并口操作,确保对CH438的高效控制,修改8250代码可能导致其他类8250芯片无法正常工作。
2. CH438驱动是否支持外部有源晶振?
不支持,建议使用外置有源晶振,内置振荡电路配合无源晶振极不稳定,随时可能停振。
CH438驱动如何获取?
可以邮件联系我司获取CH438 Linux代码。
六、参考资料
[CH438数据手册](http://www.wch.cn/datasheets/ds_CH438Q.pdf)
[CH438 Linux驱动源码](mailto:support@wch.cn)
各位小伙伴们,我刚刚为大家分享了有关“ch438 linux驱动”的知识,希望对你们有所帮助。如果您还有其他相关问题需要解决,欢迎随时提出哦!
文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/42963.html<