Skip to content

Commit 4f134ae

Browse files
committed
HardwareTimer: Keep alternate function for F1 family
For the F1 family the GPIO pin associated with a capturing timer not only has to be forced to input mode, but its alternate function still has to be set according to PinMap_PWM.
1 parent a8b0838 commit 4f134ae

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cores/arduino/HardwareTimer.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,12 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
672672
if ((mode == TIMER_INPUT_CAPTURE_RISING) || (mode == TIMER_INPUT_CAPTURE_FALLING) \
673673
|| (mode == TIMER_INPUT_CAPTURE_BOTHEDGE) || (mode == TIMER_INPUT_FREQ_DUTY_MEASUREMENT)) {
674674
// on F1 family, input alternate function must configure GPIO in input mode
675-
pinMode(pin, INPUT);
675+
uint32_t function = pinmap_find_function(pin, PinMap_PWM);
676+
if (function != (uint32_t)NC) {
677+
// force input mode
678+
function = (function & ~STM_PIN_FUNCTION_BITS) | (STM_MODE_INPUT << STM_PIN_FUNCTION_SHIFT);
679+
pin_function(pin, function);
680+
}
676681
} else
677682
#endif
678683
{

libraries/SrcWrapper/src/stm32/pinmap.c

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ void pin_function(PinName pin, int function)
121121
switch (mode) {
122122
case STM_PIN_INPUT:
123123
ll_mode = LL_GPIO_MODE_INPUT;
124+
#if defined(STM32F1xx)
125+
// on F1 family, input mode may be associated with an alternate function
126+
pin_SetAFPin(gpio, pin, afnum);
127+
#endif
124128
break;
125129
case STM_PIN_OUTPUT:
126130
ll_mode = LL_GPIO_MODE_OUTPUT;

0 commit comments

Comments
 (0)