Serial TTY device tree configuration

Revision as of 16:25, 19 February 2019 by Registered User

1. Activation of a USART or UART instance[edit source]

Info white.png Information
Some UART pins are available on GPIO expansion and Arduino connectors (depending on the connectors available on the board).

To communicate with a UART instance, an RS232 card must be plugged on the UART pins.

The example below shows how to configure and enable a UART instance at board level, based on STM32MP157C-EV1 board USART3 example.
Note: For STM32 boards, the configuration is already defined in the device tree. Only the device activation is needed.

To activate a UART instance, please follow steps below:

  • Define the instance pin configuration (ex: stm32mp157-pinctrl.dtsi [1]).
usart3_pins_a: usart3-0 {
	pins1 {
		/* USART3 TX and RTS pins activation for default mode */
		pinmux = <STM32_PINMUX('B', 10, AF7)>, /* USART3_TX */
			 <STM32_PINMUX('G', 8, AF8)>; /* USART3_RTS */
		bias-disable;
		drive-push-pull;
		slew-rate = <0>;
	};
	pins2 {
		/* USART3 RX and CTS_NSS pins activation for default mode */
		pinmux = <STM32_PINMUX('B', 12, AF8)>, /* USART3_RX */
			 <STM32_PINMUX('I', 10, AF8)>; /* USART3_CTS_NSS */
		bias-disable;
	};
};

usart3_idle_pins_a: usart3-idle-0 {
	pins1 {
		/* USART3 TX, RTS, and CTS_NSS pins deactivation for sleep mode */
		pinmux = <STM32_PINMUX('B', 10, ANALOG)>, /* USART3_TX */
			 <STM32_PINMUX('G', 8, ANALOG)>, /* USART3_RTS */
			 <STM32_PINMUX('I', 10, ANALOG)>; /* USART3_CTS_NSS */      
	};
	pins2 {
		/* USART3_RX pin still active for wake up */
		pinmux = <STM32_PINMUX('B', 12, AF8)>; /* USART3_RX */
		bias-disable;
	};
};

usart3_sleep_pins_a: usart3-sleep-0 {
	pins {
		/* USART3_TX, RTS, CTS_NSS, and RX pins deactivation for sleep mode */
		pinmux = <STM32_PINMUX('B', 10, ANALOG)>, /* USART3_TX */
			 <STM32_PINMUX('G', 8, ANALOG)>, /* USART3_RTS */
			 <STM32_PINMUX('I', 10, ANALOG)>, /* USART3_CTS_NSS */
			 <STM32_PINMUX('B', 12, ANALOG)>; /* USART3_RX */
	};
};
  • Define the serial alias for this instance at board level (ex: stm32mp157c-ev1.dts [2]).
aliases {
	/* Serial1 alias (ie ttySTM1) assigned to usart3 */
	serial1 = &usart3;
	ethernet0 = &ethernet0;
};
  • Configure and activate the instance at board level (ex: stm32mp157c-ev1.dts [2]).
&usart3 {
	pinctrl-names = "default", "sleep", "idle";	/* pin configurations definition */
	pinctrl-0 = <&usart3_pins_a>;			/* default pin configuration selection */
	pinctrl-1 = <&usart3_sleep_pins_a>;		/* sleep pin configuration selection */
	pinctrl-2 = <&usart3_idle_pins_a>;		/* idle pin configuration selection */
	status = "okay";				/* device activation */
};

Note: The pin configuration selected has to be aligned with the pin configuration described in the board datasheet.

  1. arch/arm/boot/dts/stm32mp157-pinctrl.dtsi , STM32MP157 pinctrl device tree file
  2. 2.0 2.1 arch/arm/boot/dts/stm32mp157c-ev1.dts , STM32MP157c ev1 board device tree file
No categories assignedEdit