From 5b674530b345905c5fd715d11c58a4acf3da77cc Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 8 Dec 2020 13:49:25 +0100 Subject: [PATCH] Remap pin management Fix #1180 Signed-off-by: Frederic Pillon --- libraries/SrcWrapper/src/stm32/pinmap.c | 51 ++++++++++++++++--------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/libraries/SrcWrapper/src/stm32/pinmap.c b/libraries/SrcWrapper/src/stm32/pinmap.c index 5dac46f6ff..cd3f14b19b 100644 --- a/libraries/SrcWrapper/src/stm32/pinmap.c +++ b/libraries/SrcWrapper/src/stm32/pinmap.c @@ -73,25 +73,42 @@ void pin_function(PinName pin, int function) } /* Handle pin remap if any */ -#if defined(LL_SYSCFG_PIN_RMP_PA11) && defined(LL_SYSCFG_PIN_RMP_PA12) - if ((pin >= PA_9) && (pin <= PA_12)) { - __HAL_RCC_SYSCFG_CLK_ENABLE(); - switch ((int)pin) { - case PA_9: +#if defined(LL_SYSCFG_PIN_RMP_PA11) && defined(LL_SYSCFG_PIN_RMP_PA12) || defined(SYSCFG_CFGR1_PA11_PA12_RMP) + __HAL_RCC_SYSCFG_CLK_ENABLE(); + switch (pin & PNAME_MASK) { +#if defined(SYSCFG_CFGR1_PA11_PA12_RMP) + /* Disable PIN pair PA11/12 mapped instead of PA9/10 */ + case PA_9: + case PA_10: + LL_SYSCFG_DisablePinRemap(); + break; + /* Enable PIN pair PA11/12 mapped instead of PA9/10 */ + case PA_11: + case PA_12: + if ((pin & PREMAP) == PREMAP) { + LL_SYSCFG_EnablePinRemap(); + } + break; +#else + case PA_9: + if ((pin & PREMAP) == PREMAP) { LL_SYSCFG_EnablePinRemap(LL_SYSCFG_PIN_RMP_PA11); - break; - case PA_11: - LL_SYSCFG_DisablePinRemap(LL_SYSCFG_PIN_RMP_PA11); - break; - case PA_10: + } + break; + case PA_10: + if ((pin & PREMAP) == PREMAP) { LL_SYSCFG_EnablePinRemap(LL_SYSCFG_PIN_RMP_PA12); - break; - case PA_12: - LL_SYSCFG_DisablePinRemap(LL_SYSCFG_PIN_RMP_PA12); - break; - default: - break; - } + } + break; + case PA_11: + LL_SYSCFG_DisablePinRemap(LL_SYSCFG_PIN_RMP_PA11); + break; + case PA_12: + LL_SYSCFG_DisablePinRemap(LL_SYSCFG_PIN_RMP_PA12); + break; +#endif + default: + break; } #endif