XuSenfeng

个人站

复读了,更新随缘,有的文件不全或者图片缺失具体看我的笔记库(https://github.com/XuSenfeng/note)


串口

目录

串口

我们要做的就是在文件中修改设备树, 在启动的时候uboot设置为使用串口ttymxc0, 就是6ull串口一, 我们真正要做的就是在设备树中添加所要使用的串口节点信息。当系统启动以后串口驱动和设备匹配成功,相应的串口就会被驱动起来,生成/dev/ttymxcX(X=0….n)文件

在编写的时候主要实现的是uart_driver结构体

struct uart_driver {
	struct module		*owner;
	const char		*driver_name;
	const char		*dev_name;
	int			 major;
	int			 minor;
	int			 nr;
	struct console		*cons;

	/*
	 * these are private; the low level driver should not
	 * touch these; they should be initialised to NULL
	 */
	struct uart_state	*state;
	struct tty_driver	*tty_driver;
};

需要驱动编写人员实现注册

另一个就是uart_port表示一个具体的port,uart_port定义在include/linux/serial_core.h文件, 用于描述一个具体的串口端口

每个具体的UART都有一个uart_port, 使用函数uart_add_one_port向函数添加一个端口, uart_remove_one_port卸载端口, 这个里面有一个uart_ops包含所有的操作函数, 这个结构体办函了针对结构体所有的操作

驱动文件在driver/tty/serial/imx.c文件中

通过usrt_driver的dev_name决定挂载设备的名字, major设置主设备号207, 还有串口个数等的处理

之后就是uart_port处理, 是用自己定义的结构体imx_port, 里面包含了uart_port

串口处理函数imx_rxint中断处理函数接收到数据以后使用函数tty_insert_flip_char把它放到tty里面

实际使用

主要就是修改设备树, 使能对应的串口

默认情况下使能了两个串口, 使能的是uart1和2, 实际上使用的1连接电脑

&uart3 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_uart3>;
	status = "okay";
};

测试–移植minicom

要进行库的移植

linux下的软件移植基本就是自己编译源码, 首先进行配置, 然后编译

  1. 执行文件.configure
jiao@jiao-virtual-machine:~/linux/tool/ncurses-6.0$ ./configure --prefix=/home/jiao/linux/tool/ncurses --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --with-shared --without-profile --disable-stripping --without-progs --with-manpages --without-tests

第一个参数设置输出的文件, 不设置的话就是默认安装位置, 会替代ubuntu的文件

  1. make
  2. make install
  3. 把得到的文件放到/usr下的对应的文件夹除了bin
  4. 同样的方法编译minicom
jiao@jiao-virtual-machine:~/linux/tool/minicom-2.7.1$ ./configure CC=arm-linux-gnueabihf-gcc --prefix=/home/jiao/linux/tool/minicom --host=arm-linux-gnueabihf CPPFLAGS=-I/home/jiao/linux/tool/ncurses/include LDFLAGS=-L/home/jiao/linux/tool/ncurses/lib -enable-cfg-dir=/etc/minicon
  1. make
  2. make install
  3. bin文件复制到/usr/bin
  4. 设置文件/etc/passwd加入root:x:0:0:root:/root:/bin/sh
  5. 在文件/etc/profile加入
#!/bin/bash
LD_LIBRARY_PATH=/lib:/usr/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

export TERM=vt100
export TERMINFO=/usr/share/terminfo
  1. minicom -s 启动