GPS Device
Loading...
Searching...
No Matches
stm32f401re_spi.h File Reference

STM32F401RE SPI driver public API. More...

#include "stm32f401re.h"
#include "common.h"
Include dependency graph for stm32f401re_spi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SPI_CFG_ts
 Configuration structure for initializing an SPI peripheral. More...

Enumerations

enum  SPI_MODE_te { SPI_MODE_SLAVE , SPI_MODE_MASTER }
 SPI operating mode. More...
enum  SPI_DATA_FRAME_FORMAT_te { SPI_DATA_FRAME_FORMATE_8_BIT , SPI_DATA_FRAME_FORMAT_16_BIT }
 SPI data frame size. More...
enum  SPI_CLOCK_POLARITY_te { SPI_CLOCK_POLARITY_0_IDLE , SPI_CLOCK_POLARITY_1_IDLE }
 SPI clock polarity (CPOL). More...
enum  SPI_CLOCK_PHASE_te { SPI_CLOCK_PHASE_FIRST_TRANSITION , SPI_CLOCK_PHASE_SECOND_TRANSITION }
 SPI clock phase (CPHA). More...
enum  SPI_BIT_FIRST_te { SPI_BIT_FIRST_MSB , SPI_BIT_FIRST_LSB }
 SPI frame bit order. More...
enum  SPI_SLAVE_SELECT_MODE_te { SPI_SLAVE_SELECT_MODE_HW , SPI_SLAVE_SELECT_MODE_SW }
 SPI slave select (NSS) management mode. More...
enum  SPI_MASTER_SCLK_SPEED_te {
  SPI_MASTER_SCLK_SPEED_PCLK_DIV_2 , SPI_MASTER_SCLK_SPEED_PCLK_DIV_4 , SPI_MASTER_SCLK_SPEED_PCLK_DIV_8 , SPI_MASTER_SCLK_SPEED_PCLK_DIV_16 ,
  SPI_MASTER_SCLK_SPEED_PCLK_DIV_32 , SPI_MASTER_SCLK_SPEED_PCLK_DIV_64 , SPI_MASTER_SCLK_SPEED_PCLK_DIV_128 , SPI_MASTER_SCLK_SPEED_PCLK_DIV_256
}
 SPI master clock speed as a division of the peripheral clock (PCLK). More...

Functions

void spi_init (SPI_CFG_ts *spi_cfg)
 Initializes the SPI peripheral with the given configuration.
void spi_deinit (SPI_REGDEF_ts const *spi_instance)
 Deinitializes the SPI peripheral and disables its clock.
void spi_send (SPI_REGDEF_ts *spi_instance, uint8_t *tx_buffer, uint32_t len)
 Blocking SPI transmit. Sends len bytes from tx_buffer.
void spi_receive (SPI_REGDEF_ts *spi_instance, uint8_t *rx_buffer, uint32_t len)
 Blocking SPI receive. Reads len bytes into rx_buffer.
void spi_set_pclk_div (SPI_REGDEF_ts *spi_instance, SPI_MASTER_SCLK_SPEED_te pclk_div)
 Changes the SPI master clock speed divisor at runtime.
void spi_set_comm (SPI_REGDEF_ts *spi_instance, EN_STATUS_te en_status)
 Enables or disables the SPI peripheral (SPE bit).

Detailed Description

STM32F401RE SPI driver public API.

Author
github.com/Baksi675

This module provides a blocking full-duplex SPI driver for the STM32F401RE, supporting master and slave modes, 8-bit and 16-bit data frames, hardware and software slave select, and all four SPI clock modes (CPOL/CPHA).

All transfer functions are blocking — they poll status flags and return only after the transfer completes. Peripheral clock management is handled internally.

The driver separates peripheral configuration from bus enablement:

  • spi_init configures the peripheral registers but does not enable it.
  • spi_set_comm enables (SPE = 1) or disables (waits for BSY, then SPE = 0) the peripheral, controlling bus ownership.

Typical usage:

Version
0.1
Date
2026-01-30

Definition in file stm32f401re_spi.h.