Posts

Showing posts from August, 2025

How to Write a (GPIO_reg.h) File for STM32F401 GPIO

Image
Introduction When you’re working close to the hardware, you need a way to talk to registers without memorizing their hex addresses. That’s where the reg.h file comes in!!! a small header that connects register addresses from the datasheet to something you can use in C.   1. Where to Start Everything begins with the reference manual for the STM32F401. Two places in it matter the most: Memory map → gives you the starting address for each peripheral. Peripheral section → shows the registers, their offsets, and their bit fields.   Examples: [1] GPIO Driver (Step 1, Get the Base Address) ·          GPIOA Base address: 0x40020000 ·          GPIOB Base address: 0x40020400 ·          GPIOC Base address: 0x40020800     ·          Registers: MODER:   ...