Skip to content

HardwareTimer: specific F1 GPIO needs Alternate Function configuration #1039

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 2 commits into from
Apr 21, 2020
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
10 changes: 4 additions & 6 deletions cores/arduino/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,17 +668,15 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)

if (pin != NC) {
if ((int)get_pwm_channel(pin) == timChannel) {
/* Configure PWM GPIO pins */
pinmap_pinout(pin, PinMap_PWM);
#if defined(STM32F1xx)
if ((mode == TIMER_INPUT_CAPTURE_RISING) || (mode == TIMER_INPUT_CAPTURE_FALLING) \
|| (mode == TIMER_INPUT_CAPTURE_BOTHEDGE) || (mode == TIMER_INPUT_FREQ_DUTY_MEASUREMENT)) {
// on F1 family, input alternate function must configure GPIO in input mode
pinMode(pin, INPUT);
} else
#endif
{
/* Configure PWM GPIO pins */
pinmap_pinout(pin, PinMap_PWM);
pinMode(pinNametoDigitalPin(pin), INPUT);
}
#endif
} else {
// Pin doesn't match with timer output channels
Error_Handler();
Expand Down
4 changes: 4 additions & 0 deletions libraries/SrcWrapper/src/stm32/pinmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ void pin_function(PinName pin, int function)
switch (mode) {
case STM_PIN_INPUT:
ll_mode = LL_GPIO_MODE_INPUT;
#if defined(STM32F1xx)
// on F1 family, input mode may be associated with an alternate function
pin_SetAFPin(gpio, pin, afnum);
#endif
break;
case STM_PIN_OUTPUT:
ll_mode = LL_GPIO_MODE_OUTPUT;
Expand Down