Strange behavior with call to HAL_GPIO_ReadPin()
I am seeing some strange happenings using X-CUBE-MEMS software pack, which generates some code for user buttons, LED outputs, etc.
I noticed the user button was always returning GPIO_PIN_SET even when it should be returning GPIO_PIN_RESET
I make a call like so:
PushButtonState = BSP_PB_GetState(BUTTON_KEY);Which calls this function: (I've added some serial debug output)
int32_t BSP_PB_GetState(Button_TypeDef Button)
{
GPIO_PinState bitstatus;
bitstatus = (int32_t)(HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]) == GPIO_PIN_RESET);
serprintf("After call: %i\n", bitstatus);
return bitstatus;
}Which calls this function (again with debug output added)
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
GPIO_PinState bitstatus;
/* Check the parameters */
assert_param(IS_GPIO_PIN(GPIO_Pin));
if ((GPIOx->IDR & GPIO_Pin) != 0x00u)
{
bitstatus = GPIO_PIN_SET;
}
else
{
bitstatus = GPIO_PIN_RESET;
}
serprintf("Bitstatus: %i\n", bitstatus);
return bitstatus;
}HAL_GPIO_ReadPin is returning GPIO_PIN_RESET as expected, but the calling function doesn't seem to know that. My serial output looks like this:
Bitstatus: 0
After call: 1What is happening here?
