电子说
Rockchip UART (Universal Asynchronous Receiver/Transmitter) 基于16550A串口标准,完整模块支持以下功能:
用户只需参考 overlay 设置,在overlay属性中添加上UART的overlay文件:
例如:
overlays=rk3588-uart3-m1
overlays=rk3588-uart4-m2
overlays=rk3588-uart7-m1
overlays=rk3588-uart8-m0
Device Drivers() ---> Character devices() ---> Serial drivers
kernel/arch/arm64/boot/dts/rockchip/rk3588s.dtsi
uart2: serial@feb50000 {
compatible = "rockchip,rk3588-uart", "snps,dw-apb-uart";
reg = < 0x0 0xfeb50000 0x0 0x100 >;
interrupts = < GIC_SPI 333 IRQ_TYPE_LEVEL_HIGH >;
clocks = < &cru SCLK_UART2 >, < &cru PCLK_UART2 >;
clock-names = "baudclk", "apb_pclk";
reg-shift = < 2 >;
reg-io-width = < 4 >;
dmas = < &dmac0 10 >, < &dmac0 11 >;
pinctrl-names = "default";
pinctrl-0 = < &uart2m1_xfer >;
status = "disabled";
};
kernel/arch/arm64/boot/dts/rockchip/rk3588-armsom-sige7.dts
UART的板级dts配置只有以下参数允许修改:
dma-names:
pinctrl-0:
status:
&uart2 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = < &uart2m2_xfer >;
}
配置好串口后,硬件接口对应软件上的节点分别为:
UART3: /dev/ttyS3
UART4: /dev/ttyS4
...
串口唤醒系统功能是在系统待机时串口保持打开,并且把串口中断设置为唤醒源。使用时需要在dts中增 加以下参数:
&uart1 { wakeup-source;};
kernel/drivers/soc/rockchip/fiq_debugger/rk_fiq_debugger.c
由于fiq_debugger和普通串口互斥,在使能fiq_debugger节点后必须禁用对应的普通串口uart节点
fiq_debugger: fiq-debugger {
compatible = "rockchip,fiq-debugger";
rockchip,serial-id = < 2 >;
rockchip,wake-irq = < 0 >;
/* If enable uart uses irq instead of fiq */
rockchip,irq-mode-enable = < 1 >;
rockchip,baudrate = < 1500000 >; /* Only 115200 and 1500000 */
interrupts = < GIC_SPI 423 IRQ_TYPE_LEVEL_LOW >;
pinctrl-names = "default";
pinctrl-0 = < &uart2m0_xfer >;
status = "okay";
};
&uart2 {
status = "disabled";
};
以下对几个参数进行说明:
UART调试提供一个官方测试程序:ts_uart.uart(存放在网盘:1. 开发工具->测试工具)、两个测试用文件send_0x55和send_00_ff,该程序可以联系ArmSoM客服获取。 通过adb工具将测试程序放在开发板上一个可执行的路径下,以下放在data路径:
adb rootadb remountadb push ts_uart.uart /dataadb push send_0x55 /dataadb push send_00_ff /data
在开发板上修改测试程序权限:
sudo chmod +x /data/ts_uart.uart
使用以下命令可以获取程序帮助:
console:/ # ./data/ts_uart.uart
Use the following format to run the HS-UART TEST PROGRAM
ts_uart v1.1
For sending data:
./ts_uart < tx_rx(s/r) > < file_name > < flow_control(0/1) > < max_delay(0-
100) > < random_size(0/1) >
tx_rx : send data from file (s) or receive data (r) to put in file
file_name : file name to send data from or place data in
baudrate : baud rate used for TX/RX
flow_control : enables (1) or disables (0) Hardware flow control using RTS/CTS
lines
max_delay : defines delay in seconds between each data burst when sending.
Choose 0 for continuous stream.
random_size : enables (1) or disables (0) random size data bursts when sending.
Choose 0 for max size.
max_delay and random_size are useful for sleep/wakeup over UART testing. ONLY
meaningful when sending data
Examples:
Sending data (no delays)
ts_uart s init.rc 1500000 0 0 0 /dev/ttyS0
loop back mode:
ts_uart m init.rc 1500000 0 0 0 /dev/ttyS0
receive, data must be 0x55
ts_uart r init.rc 1500000 0 0 0 /dev/ttyS0
测试发送的命令如下,send_0x55和send_00_ff为发送的文件:
./data/ts_uart.uart s ./data/send_0x55 1500000 0 0 0 /dev/ttyS3./data/ts_uart.uart s ./data/send_00_ff 1500000 0 0 0 /dev/ttyS3
发送成功可以通过USB转UART小板连接PC端,使用PC端串口调在这里插入代码片
试工具验证。
测试接收的命令如下,receive_0x55为接收的文件:
./data/ts_uart.uart r ./data/receive_0x55 1500000 0 0 0 /dev/ttyS1
可以使用PC端串口调试工具发送数据,测试程序将自动检测,检测到U(0x55)接收正确,检测到其它 字符将打印16进制ASCII码值,可以对照查询接收是否正确。
测试内部自发自收的命令如下:
./data/ts_uart.uart m ./data/send_00_ff 1500000 0 0 0 /dev/ttyS3
按下Ctrl+C停止测试,可以观察到结束log如下。比较发送和接收的数据是否一致:
Sending data from file to port...send:1172, receive:1172 total:1172 # 收发数据一致,测试成功send:3441, receive:3537 total:3441 # 收发数据不一致,测试失败
如果测试失败,说明当前串口存在问题或者有其他程序也在使用同一个串口。可以使用以下命令查看哪 些程序打开了这个串口:
lsof | grep ttyS3
审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !