Skip to content

Commit 6f32b49

Browse files
authored
Merge pull request #1039 from ABOSTM/HT_F1_AF_CONFIG
HardwareTimer: specific F1 GPIO needs Alternate Function configuration
2 parents 7f68be4 + 8344bad commit 6f32b49

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Diff for: cores/arduino/HardwareTimer.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,15 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
668668

669669
if (pin != NC) {
670670
if ((int)get_pwm_channel(pin) == timChannel) {
671+
/* Configure PWM GPIO pins */
672+
pinmap_pinout(pin, PinMap_PWM);
671673
#if defined(STM32F1xx)
672674
if ((mode == TIMER_INPUT_CAPTURE_RISING) || (mode == TIMER_INPUT_CAPTURE_FALLING) \
673675
|| (mode == TIMER_INPUT_CAPTURE_BOTHEDGE) || (mode == TIMER_INPUT_FREQ_DUTY_MEASUREMENT)) {
674676
// on F1 family, input alternate function must configure GPIO in input mode
675-
pinMode(pin, INPUT);
676-
} else
677-
#endif
678-
{
679-
/* Configure PWM GPIO pins */
680-
pinmap_pinout(pin, PinMap_PWM);
677+
pinMode(pinNametoDigitalPin(pin), INPUT);
681678
}
679+
#endif
682680
} else {
683681
// Pin doesn't match with timer output channels
684682
Error_Handler();

Diff for: 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)