MCUs GPIO modules have at least 2 registers :
Direction Register (called: Mode register by st)
Set pin as input or output
Data Register
Write to pin or read from pin
#include "stm32f4xx.h"
#define GPIOAEN (1U<<0)
#define GPIOCEN (1U<<2)
#define LED_PIN (1U<<5)
#define BTN_PIN (1U<<13)
int main(void)
{
/*Enable clock access to GPIOA and GPIOC*/
RCC->AHB1ENR |= GPIOAEN;
RCC->AHB1ENR |= GPIOCEN;
/*Set PA5 as output pin*/
GPIOA->MODER |= (1U<<10);
GPIOA->MODER &= ~(1U<<11);
/*Set PC13 as input pin*/
GPIOC->MODER &= ~(1U<<26);
GPIOC->MODER &= ~(1U<<27);
while(1)
{
/*Check if BTN is pressed*/
if(GPIOC->IDR & BTN_PIN)
{
/*Turn on led*/
GPIOA->BSRR = LED_PIN;
}
else
{
/*Turn off led*/
GPIOA->BSRR = (1U<<21); // Reset PA5
}
}
}




