Skip to content
UPEEC

Memory-Mapped I/O

Peripherals are controlled by reading and writing special memory addresses called registers.

Advanced
Comments 0

On ARM Cortex-M, a GPIO port's output register might live at address 0x40020014:

#define GPIOA_ODR (*(volatile uint32_t *)0x40020014u)

GPIOA_ODR |= (1u << 5);     // set pin PA5 high

Vendor headers (CMSIS) wrap these addresses in structs — GPIOA->ODR |= GPIO_ODR_OD5; — and HAL libraries wrap them in functions. Always read the microcontroller's reference manual to know what each bit does.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.