Skip to content

Commit 1f16e5e

Browse files
committed
HardwareTimer: Fix STM32F1 specific gpio configuration is case of input
On F1 family, input alternate function must configure GPIO in input mode (not in alternate function like other STM32 families). Fixes #812
1 parent a7b8969 commit 1f16e5e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cores/arduino/HardwareTimer.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,22 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
651651

652652
if (pin != NC) {
653653
if ((int)get_pwm_channel(pin) == timChannel) {
654-
/* Configure PWM GPIO pins */
655-
pinmap_pinout(pin, PinMap_PWM);
656-
} else {
654+
#if defined(STM32F1xx)
655+
if ((mode == TIMER_INPUT_CAPTURE_RISING) || (mode == TIMER_INPUT_CAPTURE_FALLING) \
656+
|| (mode == TIMER_INPUT_CAPTURE_BOTHEDGE) || (mode == TIMER_INPUT_FREQ_DUTY_MEASUREMENT))
657+
{
658+
// on F1 family, input alternate function must configure GPIO in input mode
659+
pinMode(pin, INPUT);
660+
}
661+
else
662+
#endif
663+
{
664+
/* Configure PWM GPIO pins */
665+
pinmap_pinout(pin, PinMap_PWM);
666+
}
667+
}
668+
else
669+
{
657670
// Pin doesn't match with timer output channels
658671
Error_Handler();
659672
}

0 commit comments

Comments
 (0)