Android 串口驱动

Serial Port Driver

Posted by LXG on January 10, 2022

Firefly-RK3288-UART

RK3288

Firefly-RK3288 开发板内置 5 路 UART,分别为 uart0,uart1,uart2,uart3,uart4。

uart0 为 uart_bt,用于蓝牙传输。

uart2 为 uart_dbg,用做调试串口。

uart 1、uart3、uart4 可做外部串口使用,开发板已将其引脚连接至 J10 处,其中 uart4 和 SPI0 引脚复用。

拥有 64 字节的 FIFO 收发缓冲区,支持 5 位、6 位、7 位、8 位数据收发和 DMA 操作。

DTS

调试串口就是将普通串口切换成了console来处理,rockchip调试串口的数据处理代码在arch/arm/mach-rockchip/rk_fiq_debugger.c中,其中dts默认参数如下:

arch/arm/boot/dts/rk3288-firefly.dtsi


	fiq-debugger {
		compatible = "rockchip,fiq-debugger";
		interrupts = <GIC_SPI 155 IRQ_TYPE_LEVEL_HIGH>;
		rockchip,serial-id = <2>;
		rockchip,wake-irq = <0>;
		rockchip,irq-mode-enable = <0>;  /* If enable uart uses irq instead of fiq */
		rockchip,baudrate = <115200>;  /* Only 115200 and 1500000 */
		pinctrl-names = "default";
		pinctrl-0 = <&uart2_xfer>;
	};

关闭调试串口只需要取消CONFIG_FIQ_DEBUGGER宏的配置

/proc/tty/drivers

serial /dev/ttyS 4 64-68 serial


rk3288:/ # cat /proc/tty/drivers
/dev/tty             /dev/tty        5       0 system:/dev/tty
/dev/console         /dev/console    5       1 system:console
/dev/ptmx            /dev/ptmx       5       2 system
rfcomm               /dev/rfcomm   216 0-255 serial
g_serial             /dev/ttyGS    241 0-3 serial
usbserial            /dev/ttyUSB   188 0-511 serial
acm                  /dev/ttyACM   166 0-255 serial
hso                  /dev/ttyHS    243 0-255 serial
serial               /dev/ttyS       4 64-68 serial
pty_slave            /dev/pts      136 0-1048575 pty:slave
pty_master           /dev/ptm      128 0-1048575 pty:master
fiq-debugger         /dev/ttyFIQ   254       0 serial


rk3288:/ # ls -al dev/tty*
crw-rw-rw- 1 root      root           5,   0 2022-01-10 13:47 dev/tty
crw------- 1 root      root         254,   0 2022-01-10 13:47 dev/ttyFIQ0
crw-rw---- 1 bluetooth net_bt_stack   4,  64 2022-01-10 13:47 dev/ttyS0
crwxrwxrwx 1 root      root           4,  65 2022-01-10 13:47 dev/ttyS1
crwxrwxrwx 1 root      root           4,  66 2022-01-10 13:47 dev/ttyS2
crwxrwxrwx 1 root      root           4,  67 2022-01-10 13:47 dev/ttyS3
crwxrwxrwx 1 root      root           4,  68 2022-01-10 13:47 dev/ttyS4
crw-rw---- 1 radio     radio        188,   0 2022-01-10 13:47 dev/ttyUSB0
crw-rw---- 1 radio     radio        188,   1 2022-01-10 14:36 dev/ttyUSB1

串口驱动代码(RK3288)

kernel/drivers/tty/tty_io.c

kernel/drivers/tty/serial/8250/8250_core.c

A33

主控有 5 路 uart 接口,5 路支持 4 线或者 2 线通讯(但十分不建议用 uart0 作为控制台以外的用途),实例中,有些路仅仅写出 2 路的配置形式,但实际使用时只要将其按照 4 路的格式补全,也能支持 4 线通讯

./vendor/softwinner/tools/pack/chips/sun8iw5p1/configs/default/env.cfg


console=ttyS0,115200

./vendor/softwinner/tools/pack/chips/sun8iw5p1/configs/dvk3/sys_config.fex


;----------------------------------------------------------------------------------
;[uart_para] boot debug port configuration
;uart_debug_port = uart port ID for boot debug
;----------------------------------------------------------------------------------
[uart_para]
uart_debug_port = 0
uart_debug_tx   = port:PF02<3><1><default><default>
uart_debug_rx   = port:PF04<3><1><default><default>

;--------------------------------------------------------------------------------
;blue tooth
;bt_used 			---- blue tooth used (0- no used, 1- used)
;bt_uard_id			---- uart index
;--------------------------------------------------------------------------------
[bt_para]
bt_used             = 1
bt_uart_id          = 1

;----------------------------------------------------------------------------------
;uart configuration
;uart_used = uart x enable
;uart_type       = 2:2 wire,4:4 wire,8:8 wire, full function
;----------------------------------------------------------------------------------
[uart0]
uart_used       = 1
uart_port       = 0
uart_type       = 2
uart_tx         = port:PF02<3><1><default><default>
uart_rx         = port:PF04<3><1><default><default>

[uart1]
uart_used       = 1
uart_type       = 4
uart_tx         = port:PG06<2><1><default><default>
uart_rx         = port:PG07<2><1><default><default>
uart_rts        = port:PG08<2><1><default><default>
uart_cts        = port:PG09<2><1><default><default>

[uart2]
uart_used       = 1
uart_type       = 2
uart_tx         = port:PB00<2><1><default><default>
uart_rx         = port:PB01<2><1><default><default>
;uart_rts        = port:PB02<2><1><default><default>
;uart_cts        = port:PB03<2><1><default><default>

[uart3]
uart_used       = 1
uart_type       = 4
uart_tx         = port:PH06<3><1><default><default>
uart_rx         = port:PH07<3><1><default><default>

[uart4]
uart_used       = 1
uart_port       = 4
uart_type       = 2
uart_tx         = port:PA04<2><1><default><default>
uart_rx         = port:PA05<2><1><default><default>
uart_rts        = port:PA06<2><1><default><default>
uart_cts        = port:PA07<2><1><default><default>