22
22
#include <zephyr/dt-bindings/pinctrl/stm32-pinctrl.h>
23
23
#endif
24
24
25
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_pinctrl )
26
+ /* Required for GPIO LL definitions we use */
27
+ #include <stm32_ll_gpio.h>
28
+ #endif
29
+
25
30
#ifdef __cplusplus
26
31
extern "C" {
27
32
#endif
@@ -32,7 +37,7 @@ extern "C" {
32
37
typedef struct pinctrl_soc_pin {
33
38
/** Pinmux settings (port, pin and function). */
34
39
uint32_t pinmux ;
35
- /** Pin configuration (bias, drive and slew rate). */
40
+ /** Pin configuration (bias, drive, slew rate, I/O retime) */
36
41
uint32_t pincfg ;
37
42
} pinctrl_soc_pin_t ;
38
43
@@ -55,6 +60,23 @@ typedef struct pinctrl_soc_pin {
55
60
#define STM32_OUTPUT_HIGH 0x1
56
61
#define STM32_GPIO_OUTPUT 0x1
57
62
63
+ /**
64
+ * @brief Definitions for the various fields related to I/O synchronization
65
+ *
66
+ * NOTES:
67
+ * (1) Series-specific CMSIS and GPIO LL definitions are used here.
68
+ * This is OK as long as the macros are never used on series where
69
+ * the underlying definitions do not exist.
70
+ * (2) I/O delay values definitions from GPIO LL definitions are used
71
+ * directly to ensure greater portability to other platforms.
72
+ */
73
+ #define STM32_IOSYNC_DELAY_DIRECTION_OUTPUT 0x0
74
+ #define STM32_IOSYNC_DELAY_DIRECTION_INPUT GPIO_ADVCFGRL_DLYPATH0
75
+ #define STM32_IOSYNC_RETIME_EDGE_RISING 0x0
76
+ #define STM32_IOSYNC_RETIME_EDGE_FALLING GPIO_ADVCFGRL_INVCLK0
77
+ #define STM32_IOSYNC_RETIME_EDGE_BOTH GPIO_ADVCFGRL_DE0
78
+ #define STM32_IOSYNC_RETIME_ENABLE GPIO_ADVCFGRL_RET0
79
+
58
80
#ifdef CONFIG_SOC_SERIES_STM32F1X
59
81
/**
60
82
* @brief Utility macro to initialize pincfg field in #pinctrl_pin_t (F1).
@@ -71,6 +93,36 @@ typedef struct pinctrl_soc_pin {
71
93
((STM32_OUTPUT_HIGH * DT_PROP(node_id, output_high)) << STM32_ODR_SHIFT) | \
72
94
(DT_ENUM_IDX(node_id, slew_rate) << STM32_MODE_OSPEED_SHIFT))
73
95
#else
96
+
97
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_pinctrl )
98
+ /* Inner helper macro for Z_PINCTRL_STM32_IOSYNC_INIT */
99
+ #define Z_PINCTRL_STM32_IOSYNC_INIT_INNER (delay_path , retime_edge , retime_enable , delay_ps ) \
100
+ ((CONCAT(STM32_IOSYNC_DELAY_DIRECTION_, delay_path) << STM32_IODELAY_DIRECTION_SHIFT) | \
101
+ ((retime_enable) << STM32_IORETIME_ENABLE_SHIFT) | \
102
+ (CONCAT(STM32_IOSYNC_RETIME_EDGE_, retime_edge) << STM32_IORETIME_EDGE_SHIFT) | \
103
+ (CONCAT(LL_GPIO_DELAY_, delay_ps) << STM32_IODELAY_LENGTH_SHIFT))
104
+
105
+ /**
106
+ * @brief Utility macro to initialize fields of @ref{pinctrl_pin_t}.pincfg
107
+ * related to the I/O synchronization feature
108
+ *
109
+ * @param node_id Pinctrl node identifier
110
+ *
111
+ * NOTE: a default value for st,retime-edge is specified to ensure the macro expands properly.
112
+ * However, this default value is never used, as I/O retiming is not enabled unless the property
113
+ * was explicitly specified in Device Tree.
114
+ */
115
+ #define Z_PINCTRL_STM32_IOSYNC_INIT (node_id ) \
116
+ Z_PINCTRL_STM32_IOSYNC_INIT_INNER( \
117
+ DT_STRING_UPPER_TOKEN(node_id, st_io_delay_path), \
118
+ DT_STRING_UPPER_TOKEN_OR(node_id, st_retime_edge, RISING), \
119
+ STM32_IOSYNC_RETIME_ENABLE * DT_NODE_HAS_PROP(node_id, st_retime_edge), \
120
+ DT_PROP(node_id, st_io_delay_ps))
121
+ #else /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_pinctrl) */
122
+ /** Dummy value for series without I/O synchronization feature */
123
+ #define Z_PINCTRL_STM32_IOSYNC_INIT (node_id ) 0
124
+ #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_pinctrl) */
125
+
74
126
/**
75
127
* @brief Utility macro to initialize pincfg field in #pinctrl_pin_t (non-F1).
76
128
*
@@ -86,7 +138,8 @@ typedef struct pinctrl_soc_pin {
86
138
((STM32_OUTPUT_HIGH * DT_PROP(node_id, output_high)) << STM32_ODR_SHIFT) | \
87
139
((STM32_GPIO_OUTPUT * DT_PROP(node_id, output_low)) << STM32_MODER_SHIFT) | \
88
140
((STM32_GPIO_OUTPUT * DT_PROP(node_id, output_high)) << STM32_MODER_SHIFT) | \
89
- (DT_ENUM_IDX(node_id, slew_rate) << STM32_OSPEEDR_SHIFT))
141
+ (DT_ENUM_IDX(node_id, slew_rate) << STM32_OSPEEDR_SHIFT) | \
142
+ (Z_PINCTRL_STM32_IOSYNC_INIT(node_id)))
90
143
#endif /* CONFIG_SOC_SERIES_STM32F1X */
91
144
92
145
/**
0 commit comments