1. Activation of a USART or UART instance[edit source]
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 USART3_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 USART3_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, USART3_RTS, and USART3_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, USART3_RTS, USART3_CTS_NSS, USART3_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 = ðernet0;
};
- 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.
- ↑ arch/arm/boot/dts/stm32mp157-pinctrl.dtsi , STM32MP157 pinctrl device tree file
- ↑ 2.0 2.1 arch/arm/boot/dts/stm32mp157c-ev1.dts , STM32MP157c ev1 board device tree file