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;
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: