2019-06-30 11:28 PM
Hi All,
I notice a bug in the HAL_GPIO_TogglePin() when there are two pins with different voltage level. E.g. GPIOF, Pin9 = 1 and Pin 10 = 0. It turns out Pin9 was 1 and Pin10 =0, then Pin9 and 10 = 0 then 1 and so on. Support it should be Pin9 != Pin10 but instead the Pin9=Pin10 and blink together.
Looking to the code, it determine 1 pin only instead of two.
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;
}
}
Compare to the old StandardPeripheral code:
void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
GPIOx->ODR ^= GPIO_Pin;
}
Does anyone spotted this bug before? It HAL codes looks like "kids" level kind of coding. The logic was not well thought.
2020-04-10 08:58 AM
Hello All,
I raised internally the reported GPIO issues for review and fix on HAL and LL drivers.
Thank you for your contribution.
Best Regards,
Imen