From b95577991ef8891c62c41e0845903e182cdf60d3 Mon Sep 17 00:00:00 2001 From: Tom Vajzovic Date: Sat, 10 Oct 2020 19:50:25 +0100 Subject: [PATCH] Fix HAL_GPIO_TogglePin if more than one bit is set in argument --- Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c b/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c index 89090d6d9..4b11e868e 100644 --- a/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c +++ b/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c @@ -437,14 +437,9 @@ void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) /* Check the parameters */ assert_param(IS_GPIO_PIN(GPIO_Pin)); - if ((GPIOx->ODR & GPIO_Pin) == GPIO_Pin) - { - GPIOx->BSRR = (uint32_t)GPIO_Pin << GPIO_NUMBER; - } - else - { - GPIOx->BSRR = GPIO_Pin; - } + uint16_t tmp = GPIOx->ODR; + + GPIOx->BSRR = ((((uint32_t)GPIO_Pin & tmp) << GPIO_NUMBER) | (GPIO_Pin & ~tmp)); } /**