sama5d3x 启用UART设备

购买的开发板未使用UART,只能自己硬着头皮添加。但AT91的linux也是过于庞大,所以开始寻找切入点

首先看这篇文章:http://blog.csdn.net/21cnbao/article/details/8457546

有了这个设备树,问题就简化了,所以在/linux-at91/arch/arm/boot/dts/中看到有:


先看sama5d3.dtsi,如usart0:

/ {
	model = "Atmel SAMA5D3 family SoC";
	compatible = "atmel,sama5d3";
	interrupt-parent = <&aic>;

	aliases {
		serial0 = &dbgu;
		serial1 = &usart0;
		serial2 = &usart1;
		serial3 = &usart2;
		serial4 = &usart3;
		gpio0 = &pioA;
		gpio1 = &pioB;
		gpio2 = &pioC;
		gpio3 = &pioD;
		gpio4 = &pioE;
		tcb0 = &tcb0;
		tcb1 = &tcb1;
		i2c0 = &i2c0;
		i2c1 = &i2c1;
		i2c2 = &i2c2;
		ssc0 = &ssc0;
		ssc1 = &ssc1;
	};
......

usart0: serial@f001c000 {
				compatible = "atmel,at91sam9x5-usart";
				reg = <0xf001c000 0x100>;
				interrupts = <12 4 5>;
				atmel,use-dma-rx;
				dma-rx = <&dma0 0x20000204>;
				atmel,use-dma-tx;
				dma-tx = <&dma0 0x10002030>;
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_usart0>;
				status = "disabled";
			};

......
pinctrl@fffff200 {
......
usart0 {
			pinctrl_usart0: usart0-0 {
					atmel,pins =
							<3 17 0x1 0x0	/* PD17 periph A */
							 3 18 0x1 0x1>;	/* PD18 periph A with pullup */
					};

					pinctrl_usart0_rts_cts: usart0_rts_cts-0 {
						atmel,pins =
							<3 15 0x1 0x0	/* PD15 periph A, conflicts with SPI0_NPCS2, CANTX0 */
							 3 16 0x1 0x0>;	/* PD16 periph A, conflicts with SPI0_NPCS3, PWMFI3 */
					};
			};

可见需要启用uart,也只需要在该3处加入UART的配置即可

serial4 = &usart3;
+serial5 = &uart0;
+serial6 = &uart1;
gpio0 = &pioA;

+uart0: serial@f0024000 {
+                               compatible = "atmel,at91sam9260-usart";
+                               reg = <0xf0024000 0x100>;
+                               interrupts = <16 4 5>;
+                               pinctrl-names = "default";
+                               pinctrl-0 = <&pinctrl_uart0>;
+                               status = "disabled";
+                       };

+uart1: serial@f8028000 {
+                               compatible = "atmel,at91sam9260-usart";
+                               reg = <0xf8028000 0x100>;
+                               interrupts = <17 4 5>;
+                               pinctrl-names = "default";
+                               pinctrl-0 = <&pinctrl_uart1>;
+                               status = "disabled";
+                       };

//......

//uart0的引脚配置,原文件中已经存在

这样,sama5d3.dtsi 就配置好了,但是可以看到,所有设备的status都是disabled。所以还需要找到启用这些设备的文件

经参考和查看,这个文件就是sama5d3mb.dtsi,于是我在usart2的配置后面加入了:

usart2:.....

+uart0: serial@f0024000 {
+                               pinctrl-names = "default";
+                               pinctrl-0 = <&pinctrl_uart0>;
+                               status = "okay";
+                       };

+uart1: serial@f8028000 {
+                               pinctrl-names = "default";
+                               pinctrl-0 = <&pinctrl_uart1>;
+                               status = "okay";
+                       };


这样,设备树应该就已经配置好了,那么我们试一下吧,make dtbs 通过,将设备文件写入,重启系统。 执行 ls /dev/ttyS*  : 还是没有出现ttyS5 和ttyS6。看来我还漏了什么东西。设备树应该是配置好了,只能在内核中找答案。最后把目标定格在了/linux-at91/arch/arm/mach-at91/ 中的sama5d3.c这个文件中,在这个文件中需要初始化设备,顾我们可以加入以下代码:


在 static struct clk *periph_clocks[] __initdata ={ 中加入

+&uart0_clk,
+&uart1_clk,

static struct clk_lookup periph_clocks_lookups[] = { 中加入

+ CLKDEV_CON_DEV_ID("usart", "f0024000.serial", &uart0_clk),
+ CLKDEV_CON_DEV_ID("usart", "f8028000.serial", &uart1_clk),


另外请自行在sama5d3.h中做相应的修改,

OK,大工告成,make uImage, 将新生成的uImage写入开发板




没有更多推荐了,返回首页