Skip to content

fix: set only AF mode for mcu with single AF #1824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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