LEVEL 03 / LESSON 11

Practical Project — GPIO Driver

Apply Embedded C concepts by structuring a register-level GPIO driver for STM32F103C6T6A.

01 / PRACTICAL LAB

STM32F103C6T6A register-level GPIO driver

Apply Embedded C concepts by structuring a register-level GPIO driver for STM32F103C6T6A.

ARCHITECTURE

Header → register definitions → driver API → application.

LOW LEVEL

Use documented peripheral base addresses and register offsets.

SAFE UPDATE

Use masks so unrelated configuration bits remain unchanged.

VERIFY

Flash the firmware and observe the GPIO pin on hardware.

  1. Identify the RCC clock-control register for the GPIO port.
  2. Enable the peripheral clock.
  3. Configure the GPIO pin mode and output configuration.
  4. Implement set, clear and read APIs.
  5. Build ELF/HEX and flash the board.
  6. Measure the pin and debug register state if it fails.
GPIO_Driver.c
/* Register-level driver skeleton */
volatile uint32_t *gpio_reg;

void GPIO_SetPin(uint32_t mask)
{
    *gpio_reg |= mask;
}

void GPIO_ClearPin(uint32_t mask)
{
    *gpio_reg &= ~mask;
}
KEY TAKEAWAY

Define register addresses, masks, initialization and read/write APIs, then verify behavior on hardware.