From 2aa8531e8b51d208a0bcb0db3952e95d72c9d2ac Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Mon, 20 Apr 2020 14:45:22 +0200 Subject: [PATCH 1/2] HardwareTimer: specific F1 GPIO needs Alternate Function configuration Fixes #1036 --- cores/arduino/HardwareTimer.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cores/arduino/HardwareTimer.cpp b/cores/arduino/HardwareTimer.cpp index 4e01e2b7ef..904231e601 100644 --- a/cores/arduino/HardwareTimer.cpp +++ b/cores/arduino/HardwareTimer.cpp @@ -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(); From 8344badcaae7f1d33001f4a235e08994a3984d06 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Tue, 21 Apr 2020 15:53:39 +0200 Subject: [PATCH 2/2] F1 pinmap: input mode may be associated with an alternate function On F1 specifically, input alternate functions must configure GPIO in input mode. Example: on F103 PinMap_UART_RX {PB_7, USART1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_USART1_ENABLE)}, --- libraries/SrcWrapper/src/stm32/pinmap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/SrcWrapper/src/stm32/pinmap.c b/libraries/SrcWrapper/src/stm32/pinmap.c index 2db859c920..d97b234bfc 100644 --- a/libraries/SrcWrapper/src/stm32/pinmap.c +++ b/libraries/SrcWrapper/src/stm32/pinmap.c @@ -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;