deleted>Frq08988 mNo edit summary |
Registered User mNo edit summary |
||
(16 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude> | <noinclude>{{ApplicableFor | ||
{{ | |MPUs list=STM32MP13x, STM32MP15x | ||
|MPUs checklist=STM32MP13x,STM32MP15x | |||
}}</noinclude> | |||
</noinclude> | |||
== Purpose == | == Purpose == | ||
The purpose of this article is to explain how to configure the [[GPIO internal peripheral]] through '''the pin controller (pinctrl) framework''', '''when this peripheral is assigned to Linux<sup>®</sup> OS (Cortex-A)'''. The configuration is performed using the [[Device tree]]. | The purpose of this article is to explain how to configure the [[GPIO internal peripheral]] through '''the pin controller (pinctrl) framework''', '''when this peripheral is assigned to Linux<sup>®</sup> OS (Cortex-A)'''. The configuration is performed using the [[Device tree]]. | ||
Line 14: | Line 9: | ||
This article also provides an example explaining how to add a new pin in the device tree. | This article also provides an example explaining how to add a new pin in the device tree. | ||
If the peripheral is assigned to another execution context, refer to [[How to assign an internal peripheral to a runtime context]] article for guidelines on peripheral assignment and configuration. | |||
== DT bindings documentation == | == DT bindings documentation == | ||
Line 21: | Line 18: | ||
*generic DT bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt | Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt}}, Generic pinctrl device tree bindings</ref> used by the pinctrl framework. | *generic DT bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt | Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt}}, Generic pinctrl device tree bindings</ref> used by the pinctrl framework. | ||
*vendor pinctrl DT bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl. | *vendor pinctrl DT bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml | Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml}}, STM32 pinctrl device tree bindings</ref> used by the stm32-pinctrl driver: this binding document explains how to write device tree files for pinctrl. | ||
== DT configuration == | == DT configuration == | ||
=== DT configuration (STM32 level) === | === DT configuration (STM32 level) === | ||
The pin controller node is composed of several parts: | |||
The pin controller node is composed of | |||
==== STM32 pin controller information ==== | ==== STM32 pin controller information ==== | ||
pinctrl: | The pin controller node is located in the SOC dtsi file | ||
* for {{MicroprocessorDevice | device=13}} ''stm32mp131.dtsi''<ref name="stm32mp131_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp131.dtsi | stm32mp131.dtsi}} STM32MP13 SOC device tree file</ref> | |||
* for {{MicroprocessorDevice | device=15}} ''stm32mp151.dtsi''<ref name="stm32mp151_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi | stm32mp151.dtsi}} STM32MP15 SOC device tree file</ref> | |||
For example: | |||
pinctrl: pinctrl@50002000 { {{Highlight|Comments}} | |||
#address-cells = <1>; | #address-cells = <1>; | ||
#size-cells = <1>; | #size-cells = <1>; | ||
Line 45: | Line 44: | ||
==== GPIO bank information ==== | ==== GPIO bank information ==== | ||
The GPIO bank information nodes are located in the SOC dtsi file | |||
pinctrl: | * for {{MicroprocessorDevice | device=13}} ''stm32mp131.dtsi''<ref name="stm32mp131_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp131.dtsi | stm32mp131.dtsi}} STM32MP13 SOC device tree file</ref> | ||
* for {{MicroprocessorDevice | device=15}} ''stm32mp151.dtsi''<ref name="stm32mp151_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi | stm32mp151.dtsi}} STM32MP15 SOC device tree file</ref> | |||
For example: | |||
pinctrl: pinctrl@50002000 { {{Highlight|Comments}} | |||
... | ... | ||
Line 74: | Line 76: | ||
}; | }; | ||
The GPIO bank definition may be completed by the pinctrl package dtsi files, as, for example for {{MicroprocessorDevice | device=15}} ''stm32mp15xxaa-pinctrl.dtsi''<ref name="stm32mp15_pin_package_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp15xxaa-pinctrl.dtsi | stm32mp15xxaa-pinctrl.dtsi}} STM32MP15 Pinctrl device tree file</ref>. | |||
&pinctrl { | |||
st,package = <STM32MP_PKG_AA>; | |||
gpioa: gpio@50002000 { | |||
status = "okay"; | |||
ngpios = <16>; | |||
gpio-ranges = <&pinctrl 0 0 16>; | |||
}; | |||
gpiob: gpio@50003000 { | |||
status = "okay"; | |||
ngpios = <16>; | |||
gpio-ranges = <&pinctrl 0 16 16>; | |||
}; | |||
{{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}} | {{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}} | ||
==== Pin state definition ==== | ==== Pin state definition ==== | ||
The pin states are defined in the pinctrl dtsi file | |||
* for {{MicroprocessorDevice | device=13}} ''stm32mp13-pinctrl.dtsi'' <ref name="stm32mp13_pin_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp13-pinctrl.dtsi | stm32mp13-pinctrl.dtsi}} STM32MP13 pinctrl device tree file</ref> | |||
pinctrl | * for {{MicroprocessorDevice | device=15}} ''stm32mp15-pinctrl.dtsi'' <ref name="stm32mp15_pin_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp15-pinctrl.dtsi | stm32mp15-pinctrl.dtsi}} STM32MP15 pinctrl device tree file</ref> | ||
For example: | |||
&pinctrl { | |||
... | ... | ||
usart3_pins_a: usart3@0 { {{Highlight|Comments}} | usart3_pins_a: usart3@0 { {{Highlight|Comments}} | ||
Line 101: | Line 121: | ||
=== DT configuration (board level) === | === DT configuration (board level) === | ||
==== Pin state selection ==== | |||
As seen in [[Pinctrl_device_tree_configuration#Pin state definition|Pin controller configuration]] (pin state definition part), all pin states are defined inside the pin controller node. | As seen in [[Pinctrl_device_tree_configuration#Pin state definition|Pin controller configuration]] (pin state definition part), all pin states are defined inside the pin controller node. | ||
Line 119: | Line 139: | ||
}; | }; | ||
</pre> | </pre> | ||
==== GPIO bank secure information (OP-TEE device tree) ==== | |||
The secure aware GPIO banks (see [[GPIO internal peripheral#Security_support|Security support]]) may contain some specific secure settings. A peripheral set as secure '''MUST''' use secure GPIOs. | |||
The specific '''st,protreg''' binding defined in the [[OP-TEE_overview|OP-TEE]] device tree sets the security at boot time and prevents non secure peripherals from using pins. | |||
For example: | |||
&gpiob { | |||
st,protreg = <(TZPROT(1)|TZPROT(6))>; {{Highlight|--> pins 1 and 6 are configured as secure}} | |||
}; | |||
{{Warning|If this property is not defined, all the GPIOs of the bank are set as non secure, so not compatible with a secure peripheral}} | |||
=== DT configuration examples === | === DT configuration examples === | ||
Line 130: | Line 162: | ||
::Each pin requires an internal pull-up. | ::Each pin requires an internal pull-up. | ||
:2. Write your pin state phandle in '' | :2. Write your pin state phandle in ''stm32mp15-pinctrl.dtsi''. | ||
<pre> | <pre> | ||
pinctrl | &pinctrl { | ||
... | ... | ||
foo_pins_a: foo@0 { | foo_pins_a: foo@0 { | ||
Line 159: | Line 191: | ||
==How to configure GPIOs using STM32CubeMX== | ==How to configure GPIOs using STM32CubeMX== | ||
The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree# | The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree#STM32_MPU|platform configuration device tree]] files.<br /> | ||
The STM32CubeMX may not support all the properties described in the above [[#DT bindings documentation|DT bindings documentation]] paragraph. If so, the tool inserts '''user sections''' in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to [[STM32CubeMX]] user manual for further information. | The STM32CubeMX may not support all the properties described in the above [[#DT bindings documentation|DT bindings documentation]] paragraph. If so, the tool inserts '''user sections''' in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to [[STM32CubeMX]] user manual for further information. | ||
==References== | ==References== | ||
Please refer to the following links for additional information: | Please refer to the following links for additional information: | ||
<references /> | |||
< | <noinclude> | ||
[[Category:Device tree configuration]] | |||
[[Category:IOs pin management|2]] | |||
{{PublicationRequestId | 8781 | 2018-09-20 | AnneJ}} | |||
{{ArticleBasedOnModel|Peripheral or framework device tree configuration model}} | |||
</noinclude> |
Latest revision as of 17:14, 26 October 2022
1. Purpose[edit source]
The purpose of this article is to explain how to configure the GPIO internal peripheral through the pin controller (pinctrl) framework, when this peripheral is assigned to Linux® OS (Cortex-A). The configuration is performed using the Device tree.
To better understand I/O management, it is recommended to read the Overview of GPIO pins article.
This article also provides an example explaining how to add a new pin in the device tree.
If the peripheral is assigned to another execution context, refer to How to assign an internal peripheral to a runtime context article for guidelines on peripheral assignment and configuration.
2. DT bindings documentation[edit source]
The Pinctrl device tree bindings are composed of:
- generic DT bindings[1] used by the pinctrl framework.
- vendor pinctrl DT bindings[2] used by the stm32-pinctrl driver: this binding document explains how to write device tree files for pinctrl.
3. DT configuration[edit source]
3.1. DT configuration (STM32 level)[edit source]
The pin controller node is composed of several parts:
3.1.1. STM32 pin controller information[edit source]
The pin controller node is located in the SOC dtsi file
For example:
Template:Highlight #address-cells = <1>; #size-cells = <1>; ranges = <0 0x50002000 0xa400>; Template:Highlight interrupt-parent = <&exti>; Template:Highlight st,syscfg = <&exti 0x60 0xff>; Template:Highlight pins-are-numbered; ... };pinctrl: pinctrl@50002000 {
3.1.2. GPIO bank information[edit source]
The GPIO bank information nodes are located in the SOC dtsi file
For example:
Template:Highlight ... gpioa: gpio@50002000 { gpio-controller; #gpio-cells = <2>; interrupt-controller; Template:Highlight #interrupt-cells = <2>; reg = <0x0 0x400>; Template:Highlight clocks = <&rcc GPIOA>; Template:Highlight st,bank-name = "GPIOA"; status = "disabled"; }; gpiob: gpio@50003000 { gpio-controller; #gpio-cells = <2>; interrupt-controller; #interrupt-cells = <2>; reg = <0x1000 0x400>; clocks = <&rcc GPIOB>; st,bank-name = "GPIOB"; status = "disabled"; }; ... };pinctrl: pinctrl@50002000 {
The GPIO bank definition may be completed by the pinctrl package dtsi files, as, for example for STM32MP15x lines stm32mp15xxaa-pinctrl.dtsi[5].
&pinctrl {
st,package = <STM32MP_PKG_AA>;
gpioa: gpio@50002000 {
status = "okay";
ngpios = <16>;
gpio-ranges = <&pinctrl 0 0 16>;
};
gpiob: gpio@50003000 {
status = "okay";
ngpios = <16>;
gpio-ranges = <&pinctrl 0 16 16>;
};
3.1.3. Pin state definition[edit source]
The pin states are defined in the pinctrl dtsi file
For example:
Template:Highlight pins1 { pinmux = <STM32_PINMUX('B', 10, AF7)>, /* USART3_TX */ Template:Highlight <STM32_PINMUX('G', 8, AF8)>; /* USART3_RTS */ Template:Highlight bias-disable; Template:Highlight drive-push-pull; Template:Highlight slew-rate = <0>; Template:Highlight }; pins2 { pinmux = <STM32_PINMUX('B', 12, AF8)>, /* USART3_RX */ <STM32_PINMUX('I', 10, AF8)>; /* USART3_CTS_NSS */ bias-disable; }; }; ... };&pinctrl { ... usart3_pins_a: usart3@0 {
- - Refer to GPIO internal peripheral for more details on hardware pin configuration.
3.2. DT configuration (board level)[edit source]
3.2.1. Pin state selection[edit source]
As seen in Pin controller configuration (pin state definition part), all pin states are defined inside the pin controller node.
Each device that requires pins has to select the desired pin state phandle inside the board device tree file (see Device tree for more explanations about device tree file split).
The STM32MP1 devices feature a lot of possible pin combinations for a given internal peripheral. From one board to another, different sets of pins can consequently be used for an internal peripheral. Note that "_a", "_b" suffixes are used to identify pin muxing combinations in the device tree pinctrl file. The right suffixed combination must then be used in the device tree board file.
- Example:
&usart3 {
...
pinctrl-names = "default","sleep";
pinctrl-0 = <&usart3_pins_a>;
pinctrl-1 = <&usart3_sleep_pins_a>;
...
};
3.2.2. GPIO bank secure information (OP-TEE device tree)[edit source]
The secure aware GPIO banks (see Security support) may contain some specific secure settings. A peripheral set as secure MUST use secure GPIOs.
The specific st,protreg binding defined in the OP-TEE device tree sets the security at boot time and prevents non secure peripherals from using pins.
For example:
Template:Highlight };&gpiob { st,protreg = <(TZPROT(1)|TZPROT(6))>;
3.3. DT configuration examples[edit source]
3.3.1. How to add new pin states[edit source]
To add new pin states and affect them to a foo_device, proceed as follows:
- 1. Find the pins you need:
- In the example below, the foo_device needs to configure PC13, PG8 and PI2.
- AF2 is selected as alternate function on PC13, and AF5 on PG8 and PI2.
- Each pin requires an internal pull-up.
- 2. Write your pin state phandle in stm32mp15-pinctrl.dtsi.
&pinctrl {
...
foo_pins_a: foo@0 {
pins {
pinmux = <STM32_PINMUX('C', 13, AF2)>,
<STM32_PINMUX('G', 8, AF5)>,
<STM32_PINMUX('I', 2, AF5)>;
bias-pull-up;
};
};
...
};
- All the possible settings are described in GPIO internal peripheral.
- 3. Select the pin state phandle required for your device in the board file.
&foo {
...
pinctrl-names = "default";
pinctrl-0 = <&foo_pins_a>;
...
};
4. How to configure GPIOs using STM32CubeMX[edit source]
The STM32CubeMX tool can be used to configure the STM32MPU device and get the corresponding platform configuration device tree files.
The STM32CubeMX may not support all the properties described in the above DT bindings documentation paragraph. If so, the tool inserts user sections in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to STM32CubeMX user manual for further information.
5. References[edit source]
Please refer to the following links for additional information:
- ↑ Template:CodeSource, Generic pinctrl device tree bindings
- ↑ Template:CodeSource, STM32 pinctrl device tree bindings
- ↑ Jump up to: 3.0 3.1 Template:CodeSource STM32MP13 SOC device tree file
- ↑ Jump up to: 4.0 4.1 Template:CodeSource STM32MP15 SOC device tree file
- ↑ Template:CodeSource STM32MP15 Pinctrl device tree file
- ↑ Template:CodeSource STM32MP13 pinctrl device tree file
- ↑ Template:CodeSource STM32MP15 pinctrl device tree file