STM32 Example

STM32 Blink LED Example

Blink onboard LED using STM32 HAL.

Code Example

#include "main.h"

int main(void)
{
  HAL_Init();

  __HAL_RCC_GPIOC_CLK_ENABLE();

  GPIO_InitTypeDef GPIO_InitStruct = {0};
  GPIO_InitStruct.Pin = GPIO_PIN_13;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  while (1)
  {
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
    HAL_Delay(500);
  }
}

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.