Skip to content

GpioMcuRemoveInterrupt sets GPIO pull-up/pull-down registers to random uninitialized memory #1590

Open
@nfroggy

Description

@nfroggy

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
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions