Skip to content

Commit ac1a56e

Browse files
committed
drivers: pinmux stm32F1 remap IP without changing the SWJ_CFG
Change the REMAP bits of the AFIO_MAPR of the stm32F1x soc with local MACRO without changing the SWJ_CFG (write-only bits). The serial wire JTAG configuration is taken from the Z_AFIO_REMAP (value of the CONFIG_GPIO_STM32_SWJ_xxx)) and not read from the MAPR register. It accesses to the MAPR register directly instead of LL functions. Note that Remapping on the MAPR2 is not to change. Signed-off-by: Francois Ramu <[email protected]>
1 parent 9e2b9c7 commit ac1a56e

File tree

1 file changed

+78
-31
lines changed

1 file changed

+78
-31
lines changed

drivers/pinmux/pinmux_stm32.c

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,37 @@ int stm32_dt_pinctrl_configure(const struct soc_gpio_pinctrl *pinctrl,
153153
}
154154

155155
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
156+
/* Z_AFIO_REMAP is keeping the value of AFIO_MAPR_SWJ_CFG_x */
157+
#if defined(CONFIG_GPIO_STM32_SWJ_ENABLE)
158+
/* reset state */
159+
#define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_RESET
160+
#elif defined(CONFIG_GPIO_STM32_SWJ_NONJTRST)
161+
/* released PB4 */
162+
#define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_NOJNTRST
163+
#elif defined(CONFIG_GPIO_STM32_SWJ_NOJTAG)
164+
/* released PB4 PB3 PA15 */
165+
#define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_JTAGDISABLE
166+
#elif defined(CONFIG_GPIO_STM32_SWJ_DISABLE)
167+
/* released PB4 PB3 PA13 PA14 PA15 */
168+
#define Z_AFIO_REMAP AFIO_MAPR_SWJ_CFG_DISABLE
169+
#endif
170+
171+
/* enable remap : modify MAPR and keep the AFIO_MAPR_SWJ_CFG_x */
172+
#define enable_remap(REMAP_PIN) MODIFY_REG(AFIO->MAPR,\
173+
(REMAP_PIN | AFIO_MAPR_SWJ_CFG), \
174+
(REMAP_PIN | Z_AFIO_REMAP))
175+
176+
/* enable partial remap : modify MAPR and keep the AFIO_MAPR_SWJ_CFG_x */
177+
#define enable_partial_remap(REMAP_PIN, PARTIAL_REMAP) \
178+
MODIFY_REG(AFIO->MAPR, \
179+
(REMAP_PIN | AFIO_MAPR_SWJ_CFG), \
180+
(PARTIAL_REMAP | Z_AFIO_REMAP))
181+
182+
/* disable remap : modify MAPR and keep the AFIO_MAPR_SWJ_CFG_x */
183+
#define disable_remap(REMAP_PIN) MODIFY_REG(AFIO->MAPR,\
184+
(REMAP_PIN | AFIO_MAPR_SWJ_CFG), \
185+
Z_AFIO_REMAP)
186+
156187
/**
157188
* @brief Helper function to check and apply provided pinctrl remap
158189
* configuration
@@ -187,78 +218,91 @@ int stm32_dt_pinctrl_remap(const struct soc_gpio_pinctrl *pinctrl,
187218
#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay)
188219
case DT_REG_ADDR(DT_NODELABEL(can1)):
189220
if (remap == REMAP_1) {
190-
/* PB8/PB9 */
191-
LL_GPIO_AF_RemapPartial2_CAN1();
221+
/* PB8/PB9 (CAN_REMAP = 0b10) */
222+
enable_partial_remap(AFIO_MAPR_CAN_REMAP,
223+
AFIO_MAPR_CAN_REMAP_REMAP2);
192224
} else if (remap == REMAP_2) {
193-
/* PD0/PD1 */
194-
LL_GPIO_AF_RemapPartial3_CAN1();
225+
/* PD0/PD1 (CAN_REMAP = 0b11) */
226+
enable_partial_remap(AFIO_MAPR_CAN_REMAP,
227+
AFIO_MAPR_CAN_REMAP_REMAP3);
195228
} else {
196-
/* NO_REMAP: PA11/PA12 */
197-
LL_GPIO_AF_RemapPartial1_CAN1();
229+
/* NO_REMAP: PA11/PA12 (CAN_REMAP = 0b00) */
230+
enable_partial_remap(AFIO_MAPR_CAN_REMAP,
231+
AFIO_MAPR_CAN_REMAP_REMAP1);
198232
}
199233
break;
200234
#endif
201235
#if DT_NODE_HAS_STATUS(DT_NODELABEL(can2), okay)
202236
case DT_REG_ADDR(DT_NODELABEL(can2)):
203237
if (remap == REMAP_1) {
204238
/* PB5/PB6 */
205-
LL_GPIO_AF_EnableRemap_CAN2();
239+
enable_remap(AFIO_MAPR_CAN2_REMAP);
206240
} else {
207241
/* PB12/PB13 */
208-
LL_GPIO_AF_DisableRemap_CAN2();
242+
disable_remap(AFIO_MAPR_CAN2_REMAP);
209243
}
210244
break;
211245
#endif
212246
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay)
213247
case DT_REG_ADDR(DT_NODELABEL(i2c1)):
214248
if (remap == REMAP_1) {
215-
LL_GPIO_AF_EnableRemap_I2C1();
249+
enable_remap(AFIO_MAPR_I2C1_REMAP);
216250
} else {
217-
LL_GPIO_AF_DisableRemap_I2C1();
251+
disable_remap(AFIO_MAPR_I2C1_REMAP);
218252
}
219253
break;
220254
#endif
221255
#if DT_NODE_HAS_STATUS(DT_NODELABEL(timers1), okay)
222256
case DT_REG_ADDR(DT_NODELABEL(timers1)):
223257
if (remap == REMAP_1) {
224-
LL_GPIO_AF_RemapPartial_TIM1();
258+
enable_partial_remap(AFIO_MAPR_TIM1_REMAP,
259+
AFIO_MAPR_TIM1_REMAP_PARTIALREMAP);
225260
} else if (remap == REMAP_2) {
226-
LL_GPIO_AF_EnableRemap_TIM1();
261+
enable_partial_remap(AFIO_MAPR_TIM1_REMAP,
262+
AFIO_MAPR_TIM1_REMAP_FULLREMAP);
227263
} else {
228-
LL_GPIO_AF_DisableRemap_TIM1();
264+
enable_partial_remap(AFIO_MAPR_TIM1_REMAP,
265+
AFIO_MAPR_TIM1_REMAP_NOREMAP);
229266
}
230267
break;
231268
#endif
232269
#if DT_NODE_HAS_STATUS(DT_NODELABEL(timers2), okay)
233270
case DT_REG_ADDR(DT_NODELABEL(timers2)):
234271
if (remap == REMAP_1) {
235-
LL_GPIO_AF_RemapPartial1_TIM2();
272+
enable_partial_remap(AFIO_MAPR_TIM2_REMAP,
273+
AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1);
236274
} else if (remap == REMAP_2) {
237-
LL_GPIO_AF_RemapPartial2_TIM2();
275+
enable_partial_remap(AFIO_MAPR_TIM2_REMAP,
276+
AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2);
238277
} else if (remap == REMAP_FULL) {
239-
LL_GPIO_AF_EnableRemap_TIM2();
278+
enable_partial_remap(AFIO_MAPR_TIM2_REMAP,
279+
AFIO_MAPR_TIM2_REMAP_FULLREMAP);
240280
} else {
241-
LL_GPIO_AF_DisableRemap_TIM2();
281+
enable_partial_remap(AFIO_MAPR_TIM2_REMAP,
282+
AFIO_MAPR_TIM2_REMAP_NOREMAP);
242283
}
243284
break;
244285
#endif
245286
#if DT_NODE_HAS_STATUS(DT_NODELABEL(timers3), okay)
246287
case DT_REG_ADDR(DT_NODELABEL(timers3)):
247288
if (remap == REMAP_1) {
248-
LL_GPIO_AF_RemapPartial_TIM3();
289+
enable_partial_remap(AFIO_MAPR_TIM3_REMAP,
290+
AFIO_MAPR_TIM3_REMAP_PARTIALREMAP);
249291
} else if (remap == REMAP_2) {
250-
LL_GPIO_AF_EnableRemap_TIM3();
292+
enable_partial_remap(AFIO_MAPR_TIM3_REMAP,
293+
AFIO_MAPR_TIM3_REMAP_FULLREMAP);
251294
} else {
252-
LL_GPIO_AF_DisableRemap_TIM3();
295+
enable_partial_remap(AFIO_MAPR_TIM3_REMAP,
296+
AFIO_MAPR_TIM3_REMAP_NOREMAP);
253297
}
254298
break;
255299
#endif
256300
#if DT_NODE_HAS_STATUS(DT_NODELABEL(timers4), okay)
257301
case DT_REG_ADDR(DT_NODELABEL(timers4)):
258302
if (remap == REMAP_1) {
259-
LL_GPIO_AF_EnableRemap_TIM4();
303+
enable_remap(AFIO_MAPR_TIM4_REMAP);
260304
} else {
261-
LL_GPIO_AF_DisableRemap_TIM4();
305+
disable_remap(AFIO_MAPR_TIM4_REMAP);
262306
}
263307
break;
264308
#endif
@@ -346,38 +390,41 @@ int stm32_dt_pinctrl_remap(const struct soc_gpio_pinctrl *pinctrl,
346390
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay)
347391
case DT_REG_ADDR(DT_NODELABEL(usart1)):
348392
if (remap == REMAP_1) {
349-
LL_GPIO_AF_EnableRemap_USART1();
393+
enable_remap(AFIO_MAPR_USART1_REMAP);
350394
} else {
351-
LL_GPIO_AF_DisableRemap_USART1();
395+
disable_remap(AFIO_MAPR_USART1_REMAP);
352396
}
353397
break;
354398
#endif
355399
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay)
356400
case DT_REG_ADDR(DT_NODELABEL(usart2)):
357401
if (remap == REMAP_1) {
358-
LL_GPIO_AF_EnableRemap_USART2();
402+
enable_remap(AFIO_MAPR_USART2_REMAP);
359403
} else {
360-
LL_GPIO_AF_DisableRemap_USART2();
404+
disable_remap(AFIO_MAPR_USART2_REMAP);
361405
}
362406
break;
363407
#endif
364408
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart3), okay)
365409
case DT_REG_ADDR(DT_NODELABEL(usart3)):
366410
if (remap == REMAP_2) {
367-
LL_GPIO_AF_EnableRemap_USART3();
411+
enable_partial_remap(AFIO_MAPR_USART3_REMAP,
412+
AFIO_MAPR_USART3_REMAP_FULLREMAP);
368413
} else if (remap == REMAP_1) {
369-
LL_GPIO_AF_RemapPartial_USART3();
414+
enable_partial_remap(AFIO_MAPR_USART3_REMAP,
415+
AFIO_MAPR_USART3_REMAP_PARTIALREMAP);
370416
} else {
371-
LL_GPIO_AF_DisableRemap_USART3();
417+
enable_partial_remap(AFIO_MAPR_USART3_REMAP,
418+
AFIO_MAPR_USART3_REMAP_NOREMAP);
372419
}
373420
break;
374421
#endif
375422
#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay)
376423
case DT_REG_ADDR(DT_NODELABEL(spi1)):
377424
if (remap == REMAP_1) {
378-
LL_GPIO_AF_EnableRemap_SPI1();
425+
enable_remap(AFIO_MAPR_SPI1_REMAP);
379426
} else {
380-
LL_GPIO_AF_DisableRemap_SPI1();
427+
disable_remap(AFIO_MAPR_SPI1_REMAP);
381428
}
382429
break;
383430
#endif

0 commit comments

Comments
 (0)