@@ -148,6 +148,37 @@ int stm32_dt_pinctrl_configure(const struct soc_gpio_pinctrl *pinctrl,
148148}
149149
150150#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32f1_pinctrl )
151+ /* Z_AFIO_REMAP is keeping the value of AFIO_MAPR_SWJ_CFG_x */
152+ #if defined(CONFIG_GPIO_STM32_SWJ_ENABLE )
153+ /* reset state */
154+ #define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_RESET
155+ #elif defined(CONFIG_GPIO_STM32_SWJ_NONJTRST )
156+ /* released PB4 */
157+ #define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_NOJNTRST
158+ #elif defined(CONFIG_GPIO_STM32_SWJ_NOJTAG )
159+ /* released PB4 PB3 PA15 */
160+ #define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_JTAGDISABLE
161+ #elif defined(CONFIG_GPIO_STM32_SWJ_DISABLE )
162+ /* released PB4 PB3 PA13 PA14 PA15 */
163+ #define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_DISABLE
164+ #endif
165+
166+ /* enable remap : modify MAPR and keep the AFIO_MAPR_SWJ_CFG_x */
167+ #define enable_remap (REMAP_PIN ) MODIFY_REG(AFIO->MAPR,\
168+ (REMAP_PIN | AFIO_MAPR_SWJ_CFG), \
169+ (REMAP_PIN | Z_AFIO_REMAP))
170+
171+ /* enable partial remap : modify MAPR and keep the AFIO_MAPR_SWJ_CFG_x */
172+ #define enable_partial_remap (REMAP_PIN , PARTIAL_REMAP ) \
173+ MODIFY_REG(AFIO->MAPR, \
174+ (REMAP_PIN | AFIO_MAPR_SWJ_CFG), \
175+ (PARTIAL_REMAP | Z_AFIO_REMAP))
176+
177+ /* disable remap : modify MAPR and keep the AFIO_MAPR_SWJ_CFG_x */
178+ #define disable_remap (REMAP_PIN ) MODIFY_REG(AFIO->MAPR,\
179+ (REMAP_PIN | AFIO_MAPR_SWJ_CFG), \
180+ Z_AFIO_REMAP)
181+
151182/**
152183 * @brief Helper function to check and apply provided pinctrl remap
153184 * configuration
@@ -182,78 +213,91 @@ int stm32_dt_pinctrl_remap(const struct soc_gpio_pinctrl *pinctrl,
182213#if DT_NODE_HAS_STATUS (DT_NODELABEL (can1 ), okay )
183214 case DT_REG_ADDR (DT_NODELABEL (can1 )):
184215 if (remap == REMAP_1 ) {
185- /* PB8/PB9 */
186- LL_GPIO_AF_RemapPartial2_CAN1 ();
216+ /* PB8/PB9 (CAN_REMAP = 0b10) */
217+ enable_partial_remap (AFIO_MAPR_CAN_REMAP ,
218+ AFIO_MAPR_CAN_REMAP_REMAP2 );
187219 } else if (remap == REMAP_2 ) {
188- /* PD0/PD1 */
189- LL_GPIO_AF_RemapPartial3_CAN1 ();
220+ /* PD0/PD1 (CAN_REMAP = 0b11) */
221+ enable_partial_remap (AFIO_MAPR_CAN_REMAP ,
222+ AFIO_MAPR_CAN_REMAP_REMAP3 );
190223 } else {
191- /* NO_REMAP: PA11/PA12 */
192- LL_GPIO_AF_RemapPartial1_CAN1 ();
224+ /* NO_REMAP: PA11/PA12 (CAN_REMAP = 0b00) */
225+ enable_partial_remap (AFIO_MAPR_CAN_REMAP ,
226+ AFIO_MAPR_CAN_REMAP_REMAP1 );
193227 }
194228 break ;
195229#endif
196230#if DT_NODE_HAS_STATUS (DT_NODELABEL (can2 ), okay )
197231 case DT_REG_ADDR (DT_NODELABEL (can2 )):
198232 if (remap == REMAP_1 ) {
199233 /* PB5/PB6 */
200- LL_GPIO_AF_EnableRemap_CAN2 ( );
234+ enable_remap ( AFIO_MAPR_CAN2_REMAP );
201235 } else {
202236 /* PB12/PB13 */
203- LL_GPIO_AF_DisableRemap_CAN2 ( );
237+ disable_remap ( AFIO_MAPR_CAN2_REMAP );
204238 }
205239 break ;
206240#endif
207241#if DT_NODE_HAS_STATUS (DT_NODELABEL (i2c1 ), okay )
208242 case DT_REG_ADDR (DT_NODELABEL (i2c1 )):
209243 if (remap == REMAP_1 ) {
210- LL_GPIO_AF_EnableRemap_I2C1 ( );
244+ enable_remap ( AFIO_MAPR_I2C1_REMAP );
211245 } else {
212- LL_GPIO_AF_DisableRemap_I2C1 ( );
246+ disable_remap ( AFIO_MAPR_I2C1_REMAP );
213247 }
214248 break ;
215249#endif
216250#if DT_NODE_HAS_STATUS (DT_NODELABEL (timers1 ), okay )
217251 case DT_REG_ADDR (DT_NODELABEL (timers1 )):
218252 if (remap == REMAP_1 ) {
219- LL_GPIO_AF_RemapPartial_TIM1 ();
253+ enable_partial_remap (AFIO_MAPR_TIM1_REMAP ,
254+ AFIO_MAPR_TIM1_REMAP_PARTIALREMAP );
220255 } else if (remap == REMAP_2 ) {
221- LL_GPIO_AF_EnableRemap_TIM1 ();
256+ enable_partial_remap (AFIO_MAPR_TIM1_REMAP ,
257+ AFIO_MAPR_TIM1_REMAP_FULLREMAP );
222258 } else {
223- LL_GPIO_AF_DisableRemap_TIM1 ();
259+ enable_partial_remap (AFIO_MAPR_TIM1_REMAP ,
260+ AFIO_MAPR_TIM1_REMAP_NOREMAP );
224261 }
225262 break ;
226263#endif
227264#if DT_NODE_HAS_STATUS (DT_NODELABEL (timers2 ), okay )
228265 case DT_REG_ADDR (DT_NODELABEL (timers2 )):
229266 if (remap == REMAP_1 ) {
230- LL_GPIO_AF_RemapPartial1_TIM2 ();
267+ enable_partial_remap (AFIO_MAPR_TIM2_REMAP ,
268+ AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1 );
231269 } else if (remap == REMAP_2 ) {
232- LL_GPIO_AF_RemapPartial2_TIM2 ();
270+ enable_partial_remap (AFIO_MAPR_TIM2_REMAP ,
271+ AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2 );
233272 } else if (remap == REMAP_FULL ) {
234- LL_GPIO_AF_EnableRemap_TIM2 ();
273+ enable_partial_remap (AFIO_MAPR_TIM2_REMAP ,
274+ AFIO_MAPR_TIM2_REMAP_FULLREMAP );
235275 } else {
236- LL_GPIO_AF_DisableRemap_TIM2 ();
276+ enable_partial_remap (AFIO_MAPR_TIM2_REMAP ,
277+ AFIO_MAPR_TIM2_REMAP_NOREMAP );
237278 }
238279 break ;
239280#endif
240281#if DT_NODE_HAS_STATUS (DT_NODELABEL (timers3 ), okay )
241282 case DT_REG_ADDR (DT_NODELABEL (timers3 )):
242283 if (remap == REMAP_1 ) {
243- LL_GPIO_AF_RemapPartial_TIM3 ();
284+ enable_partial_remap (AFIO_MAPR_TIM3_REMAP ,
285+ AFIO_MAPR_TIM3_REMAP_PARTIALREMAP );
244286 } else if (remap == REMAP_2 ) {
245- LL_GPIO_AF_EnableRemap_TIM3 ();
287+ enable_partial_remap (AFIO_MAPR_TIM3_REMAP ,
288+ AFIO_MAPR_TIM3_REMAP_FULLREMAP );
246289 } else {
247- LL_GPIO_AF_DisableRemap_TIM3 ();
290+ enable_partial_remap (AFIO_MAPR_TIM3_REMAP ,
291+ AFIO_MAPR_TIM3_REMAP_NOREMAP );
248292 }
249293 break ;
250294#endif
251295#if DT_NODE_HAS_STATUS (DT_NODELABEL (timers4 ), okay )
252296 case DT_REG_ADDR (DT_NODELABEL (timers4 )):
253297 if (remap == REMAP_1 ) {
254- LL_GPIO_AF_EnableRemap_TIM4 ( );
298+ enable_remap ( AFIO_MAPR_TIM4_REMAP );
255299 } else {
256- LL_GPIO_AF_DisableRemap_TIM4 ( );
300+ disable_remap ( AFIO_MAPR_TIM4_REMAP );
257301 }
258302 break ;
259303#endif
@@ -341,38 +385,41 @@ int stm32_dt_pinctrl_remap(const struct soc_gpio_pinctrl *pinctrl,
341385#if DT_NODE_HAS_STATUS (DT_NODELABEL (usart1 ), okay )
342386 case DT_REG_ADDR (DT_NODELABEL (usart1 )):
343387 if (remap == REMAP_1 ) {
344- LL_GPIO_AF_EnableRemap_USART1 ( );
388+ enable_remap ( AFIO_MAPR_USART1_REMAP );
345389 } else {
346- LL_GPIO_AF_DisableRemap_USART1 ( );
390+ disable_remap ( AFIO_MAPR_USART1_REMAP );
347391 }
348392 break ;
349393#endif
350394#if DT_NODE_HAS_STATUS (DT_NODELABEL (usart2 ), okay )
351395 case DT_REG_ADDR (DT_NODELABEL (usart2 )):
352396 if (remap == REMAP_1 ) {
353- LL_GPIO_AF_EnableRemap_USART2 ( );
397+ enable_remap ( AFIO_MAPR_USART2_REMAP );
354398 } else {
355- LL_GPIO_AF_DisableRemap_USART2 ( );
399+ disable_remap ( AFIO_MAPR_USART2_REMAP );
356400 }
357401 break ;
358402#endif
359403#if DT_NODE_HAS_STATUS (DT_NODELABEL (usart3 ), okay )
360404 case DT_REG_ADDR (DT_NODELABEL (usart3 )):
361405 if (remap == REMAP_2 ) {
362- LL_GPIO_AF_EnableRemap_USART3 ();
406+ enable_partial_remap (AFIO_MAPR_USART3_REMAP ,
407+ AFIO_MAPR_USART3_REMAP_FULLREMAP );
363408 } else if (remap == REMAP_1 ) {
364- LL_GPIO_AF_RemapPartial_USART3 ();
409+ enable_partial_remap (AFIO_MAPR_USART3_REMAP ,
410+ AFIO_MAPR_USART3_REMAP_PARTIALREMAP );
365411 } else {
366- LL_GPIO_AF_DisableRemap_USART3 ();
412+ enable_partial_remap (AFIO_MAPR_USART3_REMAP ,
413+ AFIO_MAPR_USART3_REMAP_NOREMAP );
367414 }
368415 break ;
369416#endif
370417#if DT_NODE_HAS_STATUS (DT_NODELABEL (spi1 ), okay )
371418 case DT_REG_ADDR (DT_NODELABEL (spi1 )):
372419 if (remap == REMAP_1 ) {
373- LL_GPIO_AF_EnableRemap_SPI1 ( );
420+ enable_remap ( AFIO_MAPR_SPI1_REMAP );
374421 } else {
375- LL_GPIO_AF_DisableRemap_SPI1 ( );
422+ disable_remap ( AFIO_MAPR_SPI1_REMAP );
376423 }
377424 break ;
378425#endif
0 commit comments