EMBEDDED SYSTEMS · LAB NOTE 001

From a blinking LED
to reading silicon.

A hands-on STM32 Black Pill learning log, from the first ST-LINK connection to stepping through code and watching a hardware register change.

18 OCT 2026STM32F401 FAMILYFIRST-HAND EXPERIMENT
Close-up photograph of the actual STM32 Black Pill development board used in the experiment
FIG. 01 The board on the workbench PHOTOGRAPH / ORIGINAL

01 / THE QUESTION

What is actually happening inside the microcontroller?

The goal began simply: make the onboard blue LED blink. But once the firmware worked, the interesting part was no longer the LED. It was seeing a C statement turn into a change in bit 13 of a real peripheral register.

02 / THE BUILD LOG

Seven steps from blank project to working hardware.

A complete record of what worked, including the mistakes that taught us something.

01WIRESWD / ST-LINK
02CONFIGUREPC13 / CubeMX
03CODEmain.c / HAL
04FLASHBuild / verify
05INSPECTF6 / ODR13
  1. 01

    Wire the programmer

    ST-LINK V2 through SWDIO, SWCLK and common GND, with an appropriate target-voltage reference.

    CONNECTED ✓
  2. 02

    Configure the MCU

    STM32CubeMX: PC13 as push-pull GPIO output, initial HIGH; SYS Debug set to Serial Wire.

    CONFIGURED ✓
  3. 03

    Generate the HAL project

    Project BlackPill_LED_Blink, generated for STM32CubeIDE with startup and driver files.

    GENERATED ✓
  4. 04

    Write the application loop

    Two lines in main(): toggle PC13, then delay. We corrected an initial placement inside Error_Handler().

    CORRECTED ✓
  5. 05

    Compile the firmware

    STM32CubeIDE compiled the corrected source with 0 errors and 0 warnings.

    BUILT ✓
  6. 06

    Flash and run

    ST-LINK reported Download verified successfully. The onboard LED blinked as expected.

    VERIFIED ✓
  7. 07

    Halt and inspect

    Breakpoint at main.c:97. Step Over moved execution to line 98 and changed GPIOC ODR13.

    OBSERVED ✓

Identification note: The working project selected STM32F401CCUx. ST-LINK detected the STM32F401xB/C family but previously reported 128 KB flash; the exact package marking and available flash still require verification.

03 / THE FIRMWARE

Two lines.
Real hardware.

This was the complete application logic inside the CubeMX-generated while(1). The HAL and GPIO setup were generated separately.

STM32 HALCGPIOC / PC13
Core/Src/main.c
/* USER CODE BEGIN WHILE */
while (1)
{
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
    HAL_Delay(100);

    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
500ms

Initial half-period
1 blink / second

100ms

Updated half-period
5 blinks / second

STM32CubeIDE screenshot showing HAL_GPIO_TogglePin and HAL_Delay(100) in main while loop
FIG. 02 The compiled application loop, captured in STM32CubeIDE.

04 / DEBUGGING

Stop the processor.
See the system.

A breakpoint at main.c:97 halted the Cortex-M4 just before toggling PC13. The LED stopped blinking because the CPU stopped running the application.

F6Step over
F8Resume
F5Step into
F7Step return
STM32CubeIDE debugger screenshot paused at a breakpoint on the LED toggle line
FIG. 03 Breakpoint hit at the source instruction.

05 / THE HARDWARE REGISTER

One bit changed.
We watched it happen.

In the debugger's SFR view, GPIOC ODR changed from 0x00000000 to 0x00002000 after the toggle operation was stepped over.

INTERACTIVE REGISTER EXPLORER

GPIOC / ODR

Memory-mapped address 0x40020814

32-BIT VALUE0x00000000
OUTPUT FIELDODR13 = 0PC13 LOW · LED ON (active-low)

This is an interactive illustration of the observed register states, not a live connection to your microcontroller. Other bits are held at zero for clarity.

First STM32CubeIDE SFR screenshot showing GPIOC ODR13 equal to 0
FIG. 04 / BEFORE ODR = 0x0 · ODR13 = 0. Running-state snapshot, not synchronized to a particular instruction.
Second STM32CubeIDE SFR screenshot showing GPIOC ODR equal to 0x2000 and ODR13 equal to 1
FIG. 05 / AFTER ODR = 0x2000 · ODR13 = 1. CPU suspended at main.c:98.
BINARY WEIGHT213 = 8192DECIMAL 8192 = HEX 0x2000

How one bit becomes a physical output

Bit 13 of the GPIOC output latch controls PC13. On this active-low LED circuit, 0 turns the LED on and 1 turns it off. The HAL toggle uses GPIO peripheral register operations; the resulting output state is visible in ODR.

LSB and MSB: bit 0 is the least significant bit of the word, and bit 31 is the most significant position in a 32-bit value. The ODR register's bits 16–31 are reserved. The selected ODR13 field itself contains one bit.

06 / BENCH REFERENCE

The connections and registers worth keeping.

SWD programming connections

ST-LINK V2Black Pill
SWDIOPA13 / SWDIO
SWCLKPA14 / SWCLK
GNDGND
3.3 V / VTref3V3 as applicable*

* Verify your programmer's voltage reference versus power output before wiring; do not directly tie two independent power outputs together.

GPIOC register map

RegisterAddress
MODER0x40020800
IDR0x40020810
ODR0x40020814
BSRR0x40020818

BSRR supports atomic bit set/reset operations; ODR reports the output latch state.

CONTINUE THE SERIES

Next: blink without HAL GPIO calls.

Compare direct register access, ODR and BSRR, then move on to inputs, interrupts, and hardware timers.

Keep this lab note