Skip to content

Commit

Permalink
fix: set only AF mode for mcu with single AF
Browse files Browse the repository at this point in the history
Fixes #1798

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Sep 2, 2022
1 parent 9482683 commit 1a8f87a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cores/arduino/stm32/stm32_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 3 additions & 1 deletion libraries/SrcWrapper/src/stm32/pinmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a8f87a

Please sign in to comment.