PER Firmware
Loading...
Searching...
No Matches
spi.h File Reference
#include <stddef.h>
#include "common/phal_F4/dma/dma.h"
#include "common/phal_F4/gpio/gpio.h"
#include "common/phal_F4/phal_F4.h"
#include "common/phal_F4/rcc/rcc.h"
Include dependency graph for spi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SPI_InitConfig_t
 Configuration entry for SPI initilization. More...
 

Macros

#define SPI1_RXDMA_CONT_CONFIG(rx_addr_, priority_)
 
#define SPI1_TXDMA_CONT_CONFIG(tx_addr_, priority_)
 
#define SPI2_TXDMA_CONT_CONFIG(tx_addr_, priority_)
 
#define SPI2_RXDMA_CONT_CONFIG(rx_addr_, priority_)
 

Functions

bool PHAL_SPI_init (SPI_InitConfig_t *handle)
 Initilize SPI peripheral with the configuired structure.
 
bool PHAL_SPI_transfer (SPI_InitConfig_t *spi, const uint8_t *out_data, const uint32_t data_len, const uint8_t *in_data)
 Transfer data_len bytes from out_data to SPI device and place MISO data in in_data This function just starts the DMA transfer,.
 
bool PHAL_SPI_transfer_noDMA (SPI_InitConfig_t *spi, const uint8_t *out_data, uint32_t txlen, uint32_t rxlen, uint8_t *in_data)
 SPI handle.
 
bool PHAL_SPI_busy (SPI_InitConfig_t *cfg)
 Check for current SPI transaction to complete.
 
uint8_t PHAL_SPI_writeByte (SPI_InitConfig_t *spi, uint8_t address, uint8_t writeDat)
 Blocking function to write a single byte to a SPI device. Useful for Initilization functions that just need to write a single byte in a blocking function.
 
uint8_t PHAL_SPI_readByte (SPI_InitConfig_t *spi, uint8_t address, bool skipDummy)
 Blocking function to read a single byte from a SPI device. Useful for Initilization functions that just need to read a single byte in a blocking function.
 
void PHAL_SPI_ForceReset (SPI_InitConfig_t *spi)
 

Detailed Description

Author
Aditya Anand (anand.nosp@m.89@p.nosp@m.urdue.nosp@m..edu)
Version
0.1
Date
2024-12-4

Macro Definition Documentation

◆ SPI1_RXDMA_CONT_CONFIG

#define SPI1_RXDMA_CONT_CONFIG ( rx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(SPI1->DR), \
.mem_addr = (uint32_t)(rx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b0, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = false, \
.dma_chan_request = 0b0011, \
.stream_idx = 2, \
.periph = DMA2, \
.stream = DMA2_Stream2}

◆ SPI1_TXDMA_CONT_CONFIG

#define SPI1_TXDMA_CONT_CONFIG ( tx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(SPI1->DR), \
.mem_addr = (uint32_t)(tx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b1, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0011, \
.stream_idx = 3, \
.periph = DMA2, \
.stream = DMA2_Stream3}

◆ SPI2_RXDMA_CONT_CONFIG

#define SPI2_RXDMA_CONT_CONFIG ( rx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(SPI2->DR), \
.mem_addr = (uint32_t)(rx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b0, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = false, \
.dma_chan_request = 0b0000, \
.stream_idx = 3, \
.periph = DMA1, \
.stream = DMA1_Stream3}

◆ SPI2_TXDMA_CONT_CONFIG

#define SPI2_TXDMA_CONT_CONFIG ( tx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(SPI2->DR), \
.mem_addr = (uint32_t)(tx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b1, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0000, \
.stream_idx = 4, \
.periph = DMA1, \
.stream = DMA1_Stream4}

Function Documentation

◆ PHAL_SPI_busy()

bool PHAL_SPI_busy ( SPI_InitConfig_t * cfg)

Check for current SPI transaction to complete.

Parameters
cfgSpi config
Returns
true
false
Here is the caller graph for this function:

◆ PHAL_SPI_ForceReset()

void PHAL_SPI_ForceReset ( SPI_InitConfig_t * spi)

◆ PHAL_SPI_init()

bool PHAL_SPI_init ( SPI_InitConfig_t * handle)

Initilize SPI peripheral with the configuired structure.

Parameters
handleSPI handle to configure.
Returns
true
false

Peripheral configuration (See RM0440 42.5.7 Configuration of SPI section)

◆ PHAL_SPI_readByte()

uint8_t PHAL_SPI_readByte ( SPI_InitConfig_t * spi,
uint8_t address,
bool skipDummy )

Blocking function to read a single byte from a SPI device. Useful for Initilization functions that just need to read a single byte in a blocking function.

Parameters
spiSpi handle
addressAddress of data to read
skipDummyReturn the 3rd byte read instead of the 2nd byte
Here is the call graph for this function:

◆ PHAL_SPI_transfer()

bool PHAL_SPI_transfer ( SPI_InitConfig_t * spi,
const uint8_t * out_data,
const uint32_t data_len,
const uint8_t * in_data )

Transfer data_len bytes from out_data to SPI device and place MISO data in in_data This function just starts the DMA transfer,.

Parameters
spiSPI handle
out_dataAddress of data buffer to put on MOSI line
data_lenNumber of SPI packets to send
in_dataAddress of data buffer to put data coming in MISO line
Returns
true Able to start DMA transaction
false Unable to start DMA transaction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_SPI_transfer_noDMA()

bool PHAL_SPI_transfer_noDMA ( SPI_InitConfig_t * spi,
const uint8_t * out_data,
uint32_t txlen,
uint32_t rxlen,
uint8_t * in_data )

SPI handle.

Parameters
spiSPI handle
out_dataAddress of data buffer to put on MOSI line
txlenNumber of SPI Packets to Send
rxlenNumber of SPI Packets to Receive
in_dataAddress of data buffer to put data coming in MISO line
Returns
true Successfully completed non-DMA SPI transaction
false Unable to complete non-DMA SPI transaction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_SPI_writeByte()

uint8_t PHAL_SPI_writeByte ( SPI_InitConfig_t * spi,
uint8_t address,
uint8_t writeDat )

Blocking function to write a single byte to a SPI device. Useful for Initilization functions that just need to write a single byte in a blocking function.

Parameters
spiSpi handle
addressAddress of data to read
writeDatData to write to address
Here is the call graph for this function: