Skip to content

Commit b955779

Browse files
tcv-gitALABSTM
authored andcommitted
Fix HAL_GPIO_TogglePin if more than one bit is set in argument
1 parent 2d5b78e commit b955779

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,9 @@ void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
437437
/* Check the parameters */
438438
assert_param(IS_GPIO_PIN(GPIO_Pin));
439439

440-
if ((GPIOx->ODR & GPIO_Pin) == GPIO_Pin)
441-
{
442-
GPIOx->BSRR = (uint32_t)GPIO_Pin << GPIO_NUMBER;
443-
}
444-
else
445-
{
446-
GPIOx->BSRR = GPIO_Pin;
447-
}
440+
uint16_t tmp = GPIOx->ODR;
441+
442+
GPIOx->BSRR = ((((uint32_t)GPIO_Pin & tmp) << GPIO_NUMBER) | (GPIO_Pin & ~tmp));
448443
}
449444

450445
/**

0 commit comments

Comments
 (0)