From deca336aedab4cdd8f5d84ee5e3877977d525fdd Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 1 Sep 2022 18:49:14 +0200 Subject: [PATCH] fix: set only AF mode for mcu with single AF Fixes #1798 Signed-off-by: Frederic Pillon --- cores/arduino/stm32/stm32_def.h | 14 ++++++++++++++ libraries/SrcWrapper/src/stm32/pinmap.c | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cores/arduino/stm32/stm32_def.h b/cores/arduino/stm32/stm32_def.h index 407274c6ec..cb4c63c87b 100644 --- a/cores/arduino/stm32/stm32_def.h +++ b/cores/arduino/stm32/stm32_def.h @@ -90,6 +90,20 @@ #define PinMap_USB PinMap_USB_DRD_FS #endif +/** + * Some mcu have single AF and thus only AF mode should be configured. + * No AFRL/AFRG registers exists so they should not be configured. + * In that case the AF does not exists so defining the linked AF + * to 0x7F (max value of the AFNUM i.e. STM_PIN_AFNUM_MASK) + * See GitHub issue #1798. + */ +#if defined(STM32F0xx) && !defined(GPIO_AF0_TIM3) + #define GPIO_AF0_TIM3 STM_PIN_AFNUM_MASK +#endif +#if defined(STM32L0xx) && !defined(GPIO_AF1_SPI1) + #define GPIO_AF1_SPI1 STM_PIN_AFNUM_MASK +#endif + /** * Libc porting layers */ diff --git a/libraries/SrcWrapper/src/stm32/pinmap.c b/libraries/SrcWrapper/src/stm32/pinmap.c index 2ffbfcb425..faa04a8da8 100644 --- a/libraries/SrcWrapper/src/stm32/pinmap.c +++ b/libraries/SrcWrapper/src/stm32/pinmap.c @@ -242,7 +242,9 @@ void pin_function(PinName pin, int function) case STM_PIN_ALTERNATE: ll_mode = LL_GPIO_MODE_ALTERNATE; /* In case of ALT function, also set the afnum */ - pin_SetAFPin(gpio, pin, afnum); + if (afnum != STM_PIN_AFNUM_MASK) { + pin_SetAFPin(gpio, pin, afnum); + } break; case STM_PIN_ANALOG: ll_mode = LL_GPIO_MODE_ANALOG; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy