2222#include <zephyr/dt-bindings/pinctrl/stm32-pinctrl.h>
2323#endif
2424
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+
2530#ifdef __cplusplus
2631extern "C" {
2732#endif
@@ -32,7 +37,7 @@ extern "C" {
3237typedef struct pinctrl_soc_pin {
3338 /** Pinmux settings (port, pin and function). */
3439 uint32_t pinmux ;
35- /** Pin configuration (bias, drive and slew rate). */
40+ /** Pin configuration (bias, drive, slew rate, I/O retime) */
3641 uint32_t pincfg ;
3742} pinctrl_soc_pin_t ;
3843
@@ -55,6 +60,23 @@ typedef struct pinctrl_soc_pin {
5560#define STM32_OUTPUT_HIGH 0x1
5661#define STM32_GPIO_OUTPUT 0x1
5762
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+
5880#ifdef CONFIG_SOC_SERIES_STM32F1X
5981/**
6082 * @brief Utility macro to initialize pincfg field in #pinctrl_pin_t (F1).
@@ -71,6 +93,36 @@ typedef struct pinctrl_soc_pin {
7193 ((STM32_OUTPUT_HIGH * DT_PROP(node_id, output_high)) << STM32_ODR_SHIFT) | \
7294 (DT_ENUM_IDX(node_id, slew_rate) << STM32_MODE_OSPEED_SHIFT))
7395#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+
74126/**
75127 * @brief Utility macro to initialize pincfg field in #pinctrl_pin_t (non-F1).
76128 *
@@ -86,7 +138,8 @@ typedef struct pinctrl_soc_pin {
86138 ((STM32_OUTPUT_HIGH * DT_PROP(node_id, output_high)) << STM32_ODR_SHIFT) | \
87139 ((STM32_GPIO_OUTPUT * DT_PROP(node_id, output_low)) << STM32_MODER_SHIFT) | \
88140 ((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)))
90143#endif /* CONFIG_SOC_SERIES_STM32F1X */
91144
92145/**
0 commit comments