Skip to content

Commit 1a8f87a

Browse files
committed
fix: set only AF mode for mcu with single AF
Fixes #1798 Signed-off-by: Frederic Pillon <[email protected]>
1 parent 9482683 commit 1a8f87a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: cores/arduino/stm32/stm32_def.h

+14
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@
9090
#define PinMap_USB PinMap_USB_DRD_FS
9191
#endif
9292

93+
/**
94+
* Some mcu have single AF and thus only AF mode should be configured.
95+
* No AFRL/AFRG registers exists so they should not be configured.
96+
* In that case the AF does not exists so defining the linked AF
97+
* to 0x7F (max value of the AFNUM i.e. STM_PIN_AFNUM_MASK)
98+
* See GitHub issue #1798.
99+
*/
100+
#if defined(STM32F0xx) && !defined(GPIO_AF0_TIM3)
101+
#define GPIO_AF0_TIM3 STM_PIN_AFNUM_MASK
102+
#endif
103+
#if defined(STM32L0xx) && !defined(GPIO_AF1_SPI1)
104+
#define GPIO_AF1_SPI1 STM_PIN_AFNUM_MASK
105+
#endif
106+
93107
/**
94108
* Libc porting layers
95109
*/

Diff for: libraries/SrcWrapper/src/stm32/pinmap.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ void pin_function(PinName pin, int function)
242242
case STM_PIN_ALTERNATE:
243243
ll_mode = LL_GPIO_MODE_ALTERNATE;
244244
/* In case of ALT function, also set the afnum */
245-
pin_SetAFPin(gpio, pin, afnum);
245+
if (afnum != STM_PIN_AFNUM_MASK) {
246+
pin_SetAFPin(gpio, pin, afnum);
247+
}
246248
break;
247249
case STM_PIN_ANALOG:
248250
ll_mode = LL_GPIO_MODE_ANALOG;

0 commit comments

Comments
 (0)