Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nfroggy opened this issue Dec 20, 2023 · 0 comments

Comments

@nfroggy
Copy link

nfroggy commented Dec 20, 2023

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
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant