LoRaMac-node
LoRaMac-node copied to clipboard
GpioMcuRemoveInterrupt sets GPIO pull-up/pull-down registers to random uninitialized memory
This happens at least on the NucleoL476 example board implementation. I had a quick look at the other STM32 examples and it appears to happen there too. The issue is that GpioMcuRemoveInterrupt doesn't initialize the Pull field in the GPIO_InitStructure struct. It then calls HAL_GPIO_Init, which bitwise ORs the uninitialized Pull field with the GPIO PUPDR register, causing random values to be written to the pull-up and pull-down registers.
Our internal fix was to zero-initialize the struct to make sure that nothing was being changed in the PUPDR register:
void GpioMcuRemoveInterrupt( Gpio_t *obj )
{
if( obj->pin < IOE_0 )
{
// Clear callback before changing pin mode
GpioIrq[( obj->pin ) & 0x0F] = NULL;
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Pin = obj->pinIndex ;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init( obj->port, &GPIO_InitStructure );
}
else
{
#if defined( BOARD_IOE_EXT )
// IOExt Pin
GpioIoeRemoveInterrupt( obj );
#endif
}
}