Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
stm32-pinctrl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Linaro Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_STM32_PINCTRL_H_
8#define ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_STM32_PINCTRL_H_
9
11
12/* Adapted from Linux: include/dt-bindings/pinctrl/stm32-pinfunc.h */
13
18#define STM32_AF0 0x0
19#define STM32_AF1 0x1
20#define STM32_AF2 0x2
21#define STM32_AF3 0x3
22#define STM32_AF4 0x4
23#define STM32_AF5 0x5
24#define STM32_AF6 0x6
25#define STM32_AF7 0x7
26#define STM32_AF8 0x8
27#define STM32_AF9 0x9
28#define STM32_AF10 0xa
29#define STM32_AF11 0xb
30#define STM32_AF12 0xc
31#define STM32_AF13 0xd
32#define STM32_AF14 0xe
33#define STM32_AF15 0xf
34#define STM32_ANALOG 0x10
35
41#define PIN_NO(port, line) (((port) - 'A') * 0x10 + (line))
42#define STM32_PINMUX(port, line, mode) (((PIN_NO(port, line)) << 8) | (STM32_ ## mode))
43
58/* Alternate functions */
59#define STM32_FUNC_ALT_0 0
60#define STM32_FUNC_ALT_1 1
61#define STM32_FUNC_ALT_2 2
62#define STM32_FUNC_ALT_3 3
63#define STM32_FUNC_ALT_4 4
64#define STM32_FUNC_ALT_5 5
65#define STM32_FUNC_ALT_6 6
66#define STM32_FUNC_ALT_7 7
67#define STM32_FUNC_ALT_8 8
68#define STM32_FUNC_ALT_9 9
69#define STM32_FUNC_ALT_10 10
70#define STM32_FUNC_ALT_11 11
71#define STM32_FUNC_ALT_12 12
72#define STM32_FUNC_ALT_13 13
73#define STM32_FUNC_ALT_14 14
74#define STM32_FUNC_ALT_15 15
75#define STM32_AFR_MASK 0xF
76#define STM32_AFR_SHIFT 0
77
78/* GPIO Mode */
79#define STM32_MODER_INPUT_MODE (0x0<<STM32_MODER_SHIFT)
80#define STM32_MODER_OUTPUT_MODE (0x1<<STM32_MODER_SHIFT)
81#define STM32_MODER_ALT_MODE (0x2<<STM32_MODER_SHIFT)
82#define STM32_MODER_ANALOG_MODE (0x3<<STM32_MODER_SHIFT)
83#define STM32_MODER_MASK 0x3
84#define STM32_MODER_SHIFT 4
85
86/* GPIO Output type */
87#define STM32_OTYPER_PUSH_PULL (0x0<<STM32_OTYPER_SHIFT)
88#define STM32_OTYPER_OPEN_DRAIN (0x1<<STM32_OTYPER_SHIFT)
89#define STM32_OTYPER_MASK 0x1
90#define STM32_OTYPER_SHIFT 6
91
92/* GPIO speed */
93#define STM32_OSPEEDR_LOW_SPEED (0x0<<STM32_OSPEEDR_SHIFT)
94#define STM32_OSPEEDR_MEDIUM_SPEED (0x1<<STM32_OSPEEDR_SHIFT)
95#define STM32_OSPEEDR_HIGH_SPEED (0x2<<STM32_OSPEEDR_SHIFT)
96#define STM32_OSPEEDR_VERY_HIGH_SPEED (0x3<<STM32_OSPEEDR_SHIFT)
97#define STM32_OSPEEDR_MASK 0x3
98#define STM32_OSPEEDR_SHIFT 7
99
100/* GPIO High impedance/Pull-up/pull-down */
101#define STM32_PUPDR_NO_PULL (0x0<<STM32_PUPDR_SHIFT)
102#define STM32_PUPDR_PULL_UP (0x1<<STM32_PUPDR_SHIFT)
103#define STM32_PUPDR_PULL_DOWN (0x2<<STM32_PUPDR_SHIFT)
104#define STM32_PUPDR_MASK 0x3
105#define STM32_PUPDR_SHIFT 9
106
107/* Alternate functions definitions */
108#define STM32_PINMUX_ALT_FUNC_0 (STM32_FUNC_ALT_0 | STM32_MODER_ALT_MODE)
109#define STM32_PINMUX_ALT_FUNC_1 (STM32_FUNC_ALT_1 | STM32_MODER_ALT_MODE)
110#define STM32_PINMUX_ALT_FUNC_2 (STM32_FUNC_ALT_2 | STM32_MODER_ALT_MODE)
111#define STM32_PINMUX_ALT_FUNC_3 (STM32_FUNC_ALT_3 | STM32_MODER_ALT_MODE)
112#define STM32_PINMUX_ALT_FUNC_4 (STM32_FUNC_ALT_4 | STM32_MODER_ALT_MODE)
113#define STM32_PINMUX_ALT_FUNC_5 (STM32_FUNC_ALT_5 | STM32_MODER_ALT_MODE)
114#define STM32_PINMUX_ALT_FUNC_6 (STM32_FUNC_ALT_6 | STM32_MODER_ALT_MODE)
115#define STM32_PINMUX_ALT_FUNC_7 (STM32_FUNC_ALT_7 | STM32_MODER_ALT_MODE)
116#define STM32_PINMUX_ALT_FUNC_8 (STM32_FUNC_ALT_8 | STM32_MODER_ALT_MODE)
117#define STM32_PINMUX_ALT_FUNC_9 (STM32_FUNC_ALT_9 | STM32_MODER_ALT_MODE)
118#define STM32_PINMUX_ALT_FUNC_10 (STM32_FUNC_ALT_10 | STM32_MODER_ALT_MODE)
119#define STM32_PINMUX_ALT_FUNC_11 (STM32_FUNC_ALT_11 | STM32_MODER_ALT_MODE)
120#define STM32_PINMUX_ALT_FUNC_12 (STM32_FUNC_ALT_12 | STM32_MODER_ALT_MODE)
121#define STM32_PINMUX_ALT_FUNC_13 (STM32_FUNC_ALT_13 | STM32_MODER_ALT_MODE)
122#define STM32_PINMUX_ALT_FUNC_14 (STM32_FUNC_ALT_14 | STM32_MODER_ALT_MODE)
123#define STM32_PINMUX_ALT_FUNC_15 (STM32_FUNC_ALT_15 | STM32_MODER_ALT_MODE)
124
125/* Useful definitions */
126#define STM32_PUSHPULL_NOPULL (STM32_OTYPER_PUSH_PULL | STM32_PUPDR_NO_PULL)
127#define STM32_OPENDRAIN_PULLUP (STM32_OTYPER_OPEN_DRAIN | STM32_PUPDR_PULL_UP)
128#define STM32_PUSHPULL_PULLUP (STM32_OTYPER_PUSH_PULL | STM32_PUPDR_PULL_UP)
129
130#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_STM32_PINCTRL_H_ */