STM32 Example

STM32 Button Input Example

Read push button and toggle LED.

Code Example

while (1)
{
  if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0))
  {
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
  }
  else
  {
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
  }
}

How it works

This STM32 example demonstrates basic peripheral configuration and HAL usage.

Frequently asked questions

Can I use STM32CubeIDE?

Yes. These examples are intended for STM32CubeIDE and STM32 HAL drivers.

Can I modify the GPIO pins?

Yes. Update GPIO pin definitions according to your board schematic.