Drivers from scratch for STM32F413XX
This was my attempt at writing the drivers of GPIO, I2C, SPI and UART for STM32F413XX containing the ARM Cortex M4 from scratch after completing the Mastering Microcontroller and Embedded Driver Development course by Kiran Nayak. I recommend this course to anyone wanting to learn firmware development.
Driver layer
The driver layer consists of header files for each of the four peripherals which act as an interface for the client (generally, the application layer in an embedded system).
The MCU header file usr_stm32f413xx.h contains:
- Base addresses of flash, SRAM1, ROM, peripheral buses and the various peripherals
- Peripheral register definition structure and peripheral definitions
- System clock and peripheral clock enable/disable
- Peripheral interrupt position number in the vector table
- Bit positions of various registers for all peripherals
The header file of peripheral driver implementation contains:
- Peripheral handle structure
- Peripheral configuration structure
- API prototypes
- And, macros for various modes that need to be configured
Implementation of Driver Layer (APIs) — General Structure
The drivers for the following peripherals in any STM32F413XX are implemented:
- GPIOx (x = A, B, C, D, E, F, G, H)
- SPIx (x = 1, 2, 3, 4)
- I2Cx (x = 1, 2, 3)
- USARTx (x = 1, 2, 3, 6)
- UARTx (x = 4, 5, 7, 8, 9, 10)
The first block from the left indicates the header file in the driver layer containing a list of APIs — the middle block. The third block indicates the implementation of the APIs to be used to interact with the corresponding peripheral in .c files.
For instance, the GPIO driver layer contains a list of APIs implemented in usr_stm32f413xx_gpio_driver.c to control the GPIOx peripheral on the hardware (where x = A, B, C, D, E, F, G, H).
Configurable Items of Each Peripheral
The client/user can configure a list of items for each of the peripheral.
Examples and Other Notes
The drivers were tested on STM32F413ZH Nucleo-144 containing ARM Cortex M4 and the communication protocols were tested with an Arduino Uno Rev3.
This link provides examples that test all the drivers.
The reference manual RM0430 for ARM cortex M4 can be found here.
The links to datasheet and user manual of the board can be found here.
I couldn’t find all the documents on the board’s product page at ST’s official website.