背景
硬件小白画了块D1s板子, 调试串口的接线是:
针脚 |
功能复用 |
丝印 |
PE08 |
UART3_TX |
TX |
PE09 |
UART3_RX |
RX |
调通调试串口=硬件Hello world
Melis玩法
首先修改了projects/d1s-nezha/configs/sys_config_nor.fex
@@ -79,9 +79,9 @@ twi_scl = port:PH14<2><default><default><default>
twi_sda = port:PH15<2><default><default><default>
[uart_para]
-uart_debug_port = 0
-uart_debug_tx = port:PE02<6><1><default><default>
-uart_debug_rx = port:PE03<6><1><default><default>
+uart_debug_port = 3
+uart_debug_tx = port:PE08<5><1><default><default>
+uart_debug_rx = port:PE09<5><1><default><default>
[jtag_para]
jtag_enable = 1
@@ -210,9 +210,13 @@ twi3_sda = port:PE07<4><1><default><default>
;uart configuration
;uart_type --- 2 (2 wire), 4 (4 wire), 8 (8 wire, full function)
;----------------------------------------------------------------------------------
-[uart0]
-uart_tx = port:PB08<6><1><default><default>
-uart_rx = port:PB09<6><1><default><default>
+;[uart0]
+;uart_tx = port:PB08<6><1><default><default>
+;uart_rx = port:PB09<6><1><default><default>
+
+[uart3]
+uart_tx = port:PE08<5><1><default><default>
+uart_rx = port:PE09<5><1><default><default>
;----------------------------------------------------------------------------------
;SPI controller configuration
@@ -743,7 +747,7 @@ vo_vs = port:PD21<7><0><default><default>
;----------------------------------------------------------------------------------
[tv0]
-used = 1
+used = 0
dac_src0 = 0
dac_type0 = 0
@@ -760,8 +764,8 @@ pwm_pin = port:PD16<5><default><default><default>
[pwm1]
pwm_positive = port:PD02<3><default><default><default>
-[pwm2]
-pwm_pin = port:PE08<4><default><default><default>
+;[pwm2]
+;pwm_pin = port:PE08<4><default><default><default>
[pwm3]
pwm_positive = port:PD04<3><default><default><default>
@@ -837,12 +841,12 @@ pwm_positive = port:PL10<7><0><default><default>
;vinc(x)_sensor_list: use sensor list
;--------------------------------------------------------------------------------
[vind0]
-vind0_used = 1
+vind0_used = 0
vind0_clk = 432000000
vind0_isp = 322000000
[vind0/csi0]
-csi0_used = 1
+csi0_used = 0
csi0_pck = port:PE02<2><default><default><default>
csi0_hsync = port:PE00<2><default><default><default>
csi0_vsync = port:PE01<2><default><default><default>
@@ -850,8 +854,8 @@ csi0_d0 = port:PE04<2><default><default><default>
csi0_d1 = port:PE05<2><default><default><default>
csi0_d2 = port:PE06<2><default><default><default>
csi0_d3 = port:PE07<2><default><default><default>
-csi0_d4 = port:PE08<2><default><default><default>
-csi0_d5 = port:PE09<2><default><default><default>
+;csi0_d4 = port:PE08<2><default><default><default>
+;csi0_d5 = port:PE09<2><default><default><default>
csi0_d6 = port:PE10<2><default><default><default>
csi0_d7 = port:PE11<2><default><default><default>
@@ -872,7 +876,7 @@ actuator0_afvdd = "afvcc-csi"
actuator0_afvdd_vol = 2800000
[vind0/sensor0]
-sensor0_used = 1
+sensor0_used = 0
然后发现编译,打包, 启动发现: PE08有输出了, 但是PE09无法输入Console; 遂探寻探寻UART驱动:
找一下包含uart关键字的文件, 大致推断其驱动源码(有生成.o的大概率就是有效的源码):
find . -name "*uart*.c"
./ekernel/arch/riscv/csp/csp_uart.c
./ekernel/drivers/hal/source/uart/hal_uart.c
./ekernel/drivers/hal/test/uart/test_uart.c
./ekernel/drivers/hal/test/lpuart/test_lpuart.c
./ekernel/drivers/test/test_uart.c
./ekernel/drivers/drv/source/serial/uart_drv_dms.c
./ekernel/drivers/drv/source/serial/uart_drv.c
./ekernel/components/aw/multi_console/uart_console.c
追踪UART针脚功能复用的实现, 并反推高层调用链路:
ekernel/drivers/hal/source/uart/hal_uart.c: uart_pinctrl_init()
{
实现了UART针脚的功能复用
}
ekernel/drivers/hal/source/uart/hal_uart.c: hal_uart_init(){
uart_pinctrl_init(..);
}
看看谁调hal_uart_init():
./ekernel/drivers/drv/source/serial/uart_drv.c: .initialize=hal_uart_init
根据D1s的BSP层番号:sun20iw1可知:
./ekernel/arch/riscv/sunxi/sun20iw1/init.c: sunxi_driver_uart_init(...)
{
123 #ifdef CONFIG_DRIVER_SERIAL
124 char uartname[6];
125 void sunxi_driver_uart_init(void);
126 sunxi_driver_uart_init();
127 sprintf(uartname, "uart%d", CONFIG_CLI_UART_PORT);
128 rt_console_set_device(uartname);
129 #endif
}
原来还有一个CONFIG_CLI_UART_PORT值给到软件层面的console进行交互!
再搜CONFIG_CLI_UART_PORT发现: grep -irn "CONFIG_CLI_UART_PORT" .
.config就有具体的值.
于是: make menuconfig, 按'/'搜CONFIG_CLI_UART_PORT, 就可以合规的修改串口:
重新编译, 打包, 烧录, 调试串口一切正常.
Tina LInux玩法
修改device/config/chips/d1s/configs/nezha/sys_config.fex:
[uart_para]
uart_debug_port = 3
uart_debug_tx = port:PE08<5><1><default><default>
uart_debug_rx = port:PE09<5><1><default><default>
PS: 了解到sys_config.fex会经过转化成二进制文件, 在设备启动时会加载到boot0, 作为参数列表.
配置linux下的设备树的: device/config/chips/d1s/configs/nezha/board.dts
/* 修改 */
uart3_pins_a: uart3_pins@0 { /* For EVB1 board */
pins = "PE8", "PE9";
function = "uart3";
/* muxsel = <5>; */
drive-strength = <10>;
bias-pull-up;
};
uart3_pins_b: uart3_pins@1 { /* For EVB1 board */
pins = "PE8", "PE9";
function = "gpio_in";
};
...
&uart3 {
pinctrl-names = "default", "sleep";
pinctrl-0 = <&uart3_pins_a>;
pinctrl-1 = <&uart3_pins_b>;
status = "okay";
};
编译, 烧录, 启动发现: 串口没输出; 通过adb确认系统启动成功且PE8, PE9针脚功能配置正确(通过查看寄存器)
遂思考u-boot的bootargs是否没有配置正确, 发现./lichee/linux-5.4/arch/riscv/boot/dts/sunxi/sun20iw1p1.dtsi里有bootargs踪迹, 遂修改:
编译, 烧录, 启动发现: 只有boot0程序(./lichee/brandy-2.0/spl/nboot/main/boot0_main.c)有输出, 且支持输入验证, 但kernel仍旧没有内容输出.
思考: 除了"uart"关键字还有"ttyS"关键字也指代串口, 所以在常用的配置目录下搜了一下
grep -rn "ttyS" ./device/config/chips/d1s
./device/config/chips/d1s/configs/default/env_burn.cfg:5:console=ttyS0,115200
./device/config/chips/d1s/configs/default/env.cfg:5:console=ttyS0,115200
./device/config/chips/d1s/configs/nezha/env.cfg:5:console=ttyS0,115200
Binary file ./device/config/chips/d1s/bin/u-boot-sun20iw1p1.bin matches
遂修改: ./device/config/chips/d1s/configs/nezha/env.cfg;
启动系统是有输出!!!完毕撒花: