2024年1月16日 星期二

STM32MP157f-DK2 add an UART port

Board: STM32MP157f-DK2
OS: buildroot (branch: remotes/origin/st/2022.02)
patch: buildroot-external-st (branch: st/2022.02.7)
add UART7
$ vim output/build/uboot-custom/arch/arm/dts/stm32mp157f-dk2.dts
and
$ vim buildroot-external-st/board/stmicroelectronics/stm32mp1/linux-dts/stm32mp157f-dk2-mx.dts


#include "stm32mp15-pinctrl.dtsi"
...
...
	model = "STMicroelectronics STM32MP157F-DK2 Discovery Board";
	compatible = "st,stm32mp157f-dk2", "st,stm32mp157";

	aliases {
		serial2 = &uart7;
		serial3 = &usart2;
	};

...
...
...
/*for uart7, from stm32mp15-pinctrl.dtsi*/
  &uart7 {
      pinctrl-names = "default", "sleep", "idle";
      pinctrl-0 = <&uart7_pins_c>;
      pinctrl-1 = <&uart7_sleep_pins_c>;
      pinctrl-2 = <&uart7_idle_pins_c>;
      uart-has-rtscts;
      status = "okay";
  };

stm32mp15-pinctrl.dtsi
	uart7_pins_a: uart7-0 {
		pins1 {
			pinmux = <STM32_PINMUX('E', 8, AF7)>; /* UART7_TX */
			bias-disable;
			drive-push-pull;
			slew-rate = <0>;
		};
		pins2 {
			pinmux = <STM32_PINMUX('E', 7, AF7)>, /* UART7_RX */
				 <STM32_PINMUX('E', 10, AF7)>, /* UART7_CTS */
				 <STM32_PINMUX('E', 9, AF7)>; /* UART7_RTS */
			bias-disable;
		};
	};

	uart7_pins_b: uart7-1 {
		pins1 {
			pinmux = <STM32_PINMUX('F', 7, AF7)>; /* UART7_TX */
			bias-disable;
			drive-push-pull;
			slew-rate = <0>;
		};
		pins2 {
			pinmux = <STM32_PINMUX('F', 6, AF7)>; /* UART7_RX */
			bias-disable;
		};
	};

	uart7_pins_c: uart7-2 {
		pins1 {
			pinmux = <STM32_PINMUX('E', 8, AF7)>; /* UART7_TX */
			bias-disable;
			drive-push-pull;
			slew-rate = <0>;
		};
		pins2 {
			pinmux = <STM32_PINMUX('E', 7, AF7)>; /* UART7_RX */
			bias-pull-up;
		};
	};

	uart7_idle_pins_c: uart7-idle-2 {
		pins1 {
			pinmux = <STM32_PINMUX('E', 8, ANALOG)>; /* UART7_TX */
		};
		pins2 {
			pinmux = <STM32_PINMUX('E', 7, AF7)>; /* UART7_RX */
			bias-pull-up;
		};
	};

	uart7_sleep_pins_c: uart7-sleep-2 {
		pins {
			pinmux = <STM32_PINMUX('E', 8, ANALOG)>, /* UART7_TX */
				 <STM32_PINMUX('E', 7, ANALOG)>; /* UART7_RX */
		};
	};

trace dts
$ ag "serial@4000e000"
arch/arm/boot/dts/stm32mp151.dtsi
849:                    usart2: serial@4000e000 {

$ ag "stm32mp151.dtsi"
arch/arm/boot/dts/stm32mp153.dtsi
7:#include "stm32mp151.dtsi"

$ ag "stm32mp153.dtsi"
arch/arm/boot/dts/stm32mp157.dtsi
7:#include "stm32mp153.dtsi"

make
$make linux-rebulid
...
...
install -D /home/ubuntu/STMicroelectronics/buildroot_mp157/output/build/linux-custom/arch/arm/boot/dts/stm32mp157f-dk2-mx.dtb
/home/ubuntu/STMicroelectronics/buildroot_mp157/output/target/boot/stm32mp157f-dk2-mx.dtb
...
...
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------

Comment:
//at buildroot-external-st folder
configs/st_stm32mp157f_dk2_demo_defconfig
77:BR2_TARGET_OPTEE_OS_ADDITIONAL_VARIABLES="CFG_EMBED_DTB_SOURCE_FILE=stm32mp157f-dk2-mx.dts CFG_STM32MP15=y CFG_DRAM_SIZE=0x20000000 CFG_STM32MP1_OPTEE_IN_SYSRAM=y"

//at Makefile
BR2_LINUX_KERNEL_INTREE_DTS_NAME="stm32mp157f-dk2-mx
"BR2_EXTERNAL_ST_PATH="/home/ubuntu/STMicroelectronics/buildroot-external-st"
//修改此dts
BR2_LINUX_KERNEL_CUSTOM_DTS_PATH="$(BR2_EXTERNAL_ST_PATH)/board/stmicroelectronics/stm32mp1/linux-dts/*"

Check dtb
$ cp output/images/stm32mp157f-dk2.dtb ~/temp  & cd ~/temp
$ dtc -I dtb -O dts -o stm32mp157f-dk2.dts stm32mp157f-dk2.dtb
or
//不要編譯這個,編譯時產生的
//arch/arm/boot/dts/stm32mp157f-dk2-mx.dts
$ cp output/target/boot/stm32mp157f-dk2-mx.dtb
$ dtc -I dtb -O dts -o stm32mp157f-dk2-mx.dts stm32mp157f-dk2-mx.dtb


$ vim stm32mp157f-dk2-mx.dts
...
...
Get the address
uart4 = "/soc/serial@40010000
uart7 = "/soc/serial@40018000
...
...
serial@40018000 {
			compatible = "st,stm32h7-uart";
			reg = <0x40018000 0x400>;
			interrupts-extended = <0x18 0x20 0x04>;
			clocks = <0x0c 0x9a>;
			wakeup-source;
			power-domains = <0x19>;
			status = "okay";
			pinctrl-names = "default\0sleep\0idle";
			pinctrl-0 = <0x3c>;
			pinctrl-1 = <0x3d>;
			pinctrl-2 = <0x3e>;
			uart-has-rtscts;
			phandle = <0xb5>;
		};

on EVK board MP157
# cat /proc/device-tree/soc/serial@40010000/status
okay

# cat /proc/device-tree/soc/serial@40018000/status
okay


# cat /proc/tty/driver/stm32-usart
0: uart:stm32-usart mmio:0x40010000 irq:63 tx:5949 rx:256 RTS|CTS|DTR|DSR|CD
2: uart:stm32-usart mmio:0x40018000 irq:64 tx:0 rx:0 CTS|DSR|CD
3: uart:stm32-usart mmio:0x4000E000 irq:62 tx:461 rx:995 RTS|CTS|DTR|DSR|CD

沒有留言:

張貼留言