按照学习的资料,我首先修改了以下地方,在dts里使能UART
sun8i-v3s.dtsi:
uart0_pins_a: uart0@0 { pins = "PB8", "PB9";function = "uart0";bias-pull-up; };
uart1_pins_a: uart1@0 { pins = "PE21", "PE22";function = "uart1";bias-pull-up; };
uart2_pins_a: uart2@0 { pins = "PB0", "PB1";function = "uart2";bias-pull-up; };
sun8i-v3s-licheepi-zero.dts:
&uart0 { pinctrl-0 = <&uart0_pins_a>;pinctrl-names = "default";status = "okay"; };
&uart1 { pinctrl-0 = <&uart1_pins_a>;pinctrl-names = "default";status = "okay"; };
&uart2 { pinctrl-0 = <&uart2_pins_a>;pinctrl-names = "default";status = "okay"; };
最后在licheepi zero的dev文件夹下确实发现了有ttyS0、ttyS1、ttyS2等文件,但是按照例子打开ttyS1,还是提示打开失败
fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK);
搞不懂了,另外,sun8i-v3s.dtsi和sun8i-v3s-licheepi-zero.dts这俩文件我改的是linux内核里的,不是u-boot里的,难道u-boot里的这俩文件也要改?
离线
我看了一下,与串口有关的log就这点:
[ 0.067694] io scheduler noop registered
[ 0.067701] io scheduler deadline registered
[ 0.067930] io scheduler cfq registered (default)
[ 0.072067] sun8i-v3s-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver
[ 0.141961] Serial: 8250/16550 driver, 8 ports, IRQ sharing disabled
[ 0.145388] console [ttyS0] disabled
[ 0.165615] 1c28000.serial: ttyS0 at MMIO 0x1c28000 (irq = 34, base_baud = 1500000) is a U6_16550A
[ 0.765465] console [ttyS0] enabled
[ 0.790420] 1c28400.serial: ttyS1 at MMIO 0x1c28400 (irq = 35, base_baud = 1500000) is a U6_16550A
这是不对?而且我ttyS1和ttyS2都试过,都打不开。
我这是LicheePi Zero,带底板的那种,修改了linux/arch/arm/boot/dts下边的文件,加上了串口1和串口2的内容
我的设备树是用的sun8i-v3s-licheepi-zero-dock.dtb
根文件系统用的是资料上推荐的rootfs_brmin,
在开发板上的dev/下有如下文件:
而且我在编译内核的时候,发现有这么几条提醒,似乎有问题:
DTC arch/arm/dts/sun8i-v3s-licheepi-zero.dtb
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (unit_address_vs_reg): Node /soc/pinctrl@01c20800/uart0@0 has a unit name, but no reg property
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (unit_address_vs_reg): Node /soc/pinctrl@01c20800/mmc0@0 has a unit name, but no reg property
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (unit_address_vs_reg): Node /soc/pinctrl@01c20800/ahci_pwr_pin@0 has a unit name, but no reg property
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (unit_address_vs_reg): Node /soc/pinctrl@01c20800/usb0_vbus_pin@0 has a unit name, but no reg property
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (unit_address_vs_reg): Node /soc/pinctrl@01c20800/usb1_vbus_pin@0 has a unit name, but no reg property
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (unit_address_vs_reg): Node /soc/pinctrl@01c20800/usb2_vbus_pin@0 has a unit name, but no reg property
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/mmc@01c0f000 simple-bus unit address format error, expected "1c0f000"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/mmc@01c10000 simple-bus unit address format error, expected "1c10000"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/mmc@01c11000 simple-bus unit address format error, expected "1c11000"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/usb@01c19000 simple-bus unit address format error, expected "1c19000"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/phy@01c19400 simple-bus unit address format error, expected "1c19400"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/clock@01c20000 simple-bus unit address format error, expected "1c20000"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/rtc@01c20400 simple-bus unit address format error, expected "1c20400"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/pinctrl@01c20800 simple-bus unit address format error, expected "1c20800"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/timer@01c20c00 simple-bus unit address format error, expected "1c20c00"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/watchdog@01c20ca0 simple-bus unit address format error, expected "1c20ca0"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/serial@01c28000 simple-bus unit address format error, expected "1c28000"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/serial@01c28400 simple-bus unit address format error, expected "1c28400"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/serial@01c28800 simple-bus unit address format error, expected "1c28800"
arch/arm/dts/sun8i-v3s-licheepi-zero.dtb: Warning (simple_bus_reg): Node /soc/interrupt-controller@01c81000 simple-bus unit address format error, expected "1c81000"
SHIPPED dts/dt.dtb
1. 不需要改 u-boot 里面的设备树配置和驱动
2. 你看下 kernel 的 log, 有没有提示这三个 串口都启动成功了,有可能别的复用,导致 IO 冲突,有些ttyS没有成功。
最近编辑记录 gunge204 (2019-08-27 21:30:54)
离线
分别试了,结果是这个:
#
# echo "test" > /dev/ttyS1
#
# echo "test" > /dev/ttyS2
-sh: write error: Input/output error
#
#
好像是1还行,2不行?
echo "test" > /dev/ttyS1
试一试这个命令
最近编辑记录 gunge204 (2019-08-27 21:36:32)
离线
对,ttyS2根本没在log里出现,除了修改那两个文件之外,设备树还要配置哪里?
还是那俩文件我改的地方不对?一楼的那几句话分别应该放在文件的什么地方?
另外,我的代码其实很简单,贴出来看看(以ttyS2为例,ttyS1是一样的):
#include <termios.h> //linux下的串口驱动头文件
#include <stdio.h>
//#include <sys/stat.h>
#include <unistd.h>
//#include <sys/signal.h>
//#include <signal.h>
#include <sys/types.h>
#include <fcntl.h> //define O_WRONLY and O_RDONLY
#include <string.h>
#include <stdlib.h>
int main()
{
int fd, i;
struct termios ttyCfg;
char buf[1024];
char strBuf[] = "Hello! This message from Licheepi ttyS2\n";
//尝试打开tty1
fd = open("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd = -1)
{
printf("Err INfo: open ttyS2 error!\n");
return EXIT_FAILURE;
}
//初始化串口--------------------------
tcgetattr(fd, &ttyCfg); //获取终端的新参数,获得串口指向termios结构的指针
ttyCfg.c_cflag |= (CLOCAL | CREAD); //忽略调制解调器,使用接收器
cfsetispeed(&ttyCfg, B115200); //设置输入波特率
cfsetospeed(&ttyCfg, B115200); //设置输出波特率
ttyCfg.c_cflag &= ~CSIZE; //屏蔽其他标志位
ttyCfg.c_cflag |= CS8; //8位数据位
ttyCfg.c_cflag &= ~CSTOPB; //1位停止位
ttyCfg.c_cflag &= ~PARENB; //无校验
ttyCfg.c_cflag &= ~CRTSCTS; //不使用流控
ttyCfg.c_cc[VTIME] = 0; //非规范模式读取时的超时时间
ttyCfg.c_cc[VMIN] = 0; //非规范模式读取时的最小字符数
tcflush(fd, TCIFLUSH); //清空串口数据和请求
tcsetattr(fd, TCSANOW, &ttyCfg); //参数保存到tty1串口,TCSANOW:不等数据传输完毕就立即改变属性。
while (1)
{
//发送点数据测试--------------------
printf("Licheepi send somthing use ttyS2\n");
write(fd, strBuf, strlen(strBuf));
usleep(2000000); //us
//接收到的数据打印出来--------------
i = read(fd, buf, 1000);
if (i > 0)
{
printf("Licheepi ttyS2 receive from PC,len=%d, message:%s\n", i, buf);
}
}
close(fd);
return (0);
}
ttyS2 在 log 没有出现吧, 说明设备树配置有问题.
ttyS1 可以, 说明前面你的代码有问题.
最近编辑记录 gunge204 (2019-08-27 22:19:43)
离线
结贴:
1、设备树确实有问题,因为我用的linux是4.10.y分支,改用4.13.y分之后,重新编译,设备树正常
2、ttyS1文件打不开的原因,不是因为真的打不开,而是一句低级错误的代码造成的(哈哈哈):
fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd = -1)
{
printf("Err INfo: open ttyS1 error!\n");
return EXIT_FAILURE;
}
最后,感谢晕哥,你的判断完全正确!
离线