Issues with GPIO Configuration and Button Functionality on STM32

So guys,
In my setup, I’ve configured the GPIO pins as follows:

RCC->AHBENR |= RCC_AHBENR_GPIOAEN; // Enable the bus for port IOPA.

GPIOA->MODER |= 0x400; // Set MODER5 (PA5) for LD2,
GPIOA->MODER |= 0x100000; // Set MODER10 (PA10) for LED

GPIOC->PUPDR |= 0x2000000; // Configure PC13 for B1
GPIOA->PUPDR |= 0x20; // Configure PA2 for B2


In the main loop:

while (1)
{
    if(GPIOA->IDR |= 0x4){
        GPIOA->BSRR = 0x400;
        HAL_Delay(1000);
        GPIOA->BRR = 0x400;
        HAL_Delay(1000);
    }

    if(GPIOC->IDR &= 0x2000){
        GPIOA->BRR = 0x20;
    }
    else{
        GPIOA->BSRR = 0x20;
    }
}

The LED is being toggled solely by the initial if statement, and there appears to be no response from the button. The second if statement is accurate but needs to operate in parallel similar to how millis() works within the Arduino IDE.

I have some questions:

  • Have I overlooked any configurations for the button and what steps shall I take to make it function?
  • What steps do I need to take in order for it to work simultaneously?
Was this page helpful?