Skip to content

Commit 333dc8b

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 333dc8b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cores/arduino/HardwareTimer.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,17 @@ 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);
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+
// on F1 family, input alternate function must configure GPIO in input mode
658+
pinMode(pin, INPUT);
659+
} else
660+
#endif
661+
{
662+
/* Configure PWM GPIO pins */
663+
pinmap_pinout(pin, PinMap_PWM);
664+
}
656665
} else {
657666
// Pin doesn't match with timer output channels
658667
Error_Handler();

0 commit comments

Comments
 (0)