TM STM32Fxxx HAL Libraries  v1.0.0
Libraries for STM32Fxxx (F0, F4 and F7 series) devices based on HAL drivers from ST from Tilen Majerle

Library Functions. More...

Functions

void TM_SPI_Init (SPI_TypeDef *SPIx, TM_SPI_PinsPack_t pinspack)
 Initializes SPIx peripheral with custom pinspack and default other settings. More...
 
void TM_SPI_InitWithMode (SPI_TypeDef *SPIx, TM_SPI_PinsPack_t pinspack, TM_SPI_Mode_t SPI_Mode)
 Initializes SPIx peripheral with custom pinspack and SPI mode and default other settings. More...
 
void TM_SPI_InitFull (SPI_TypeDef *SPIx, TM_SPI_PinsPack_t pinspack, uint16_t SPI_BaudRatePrescaler, TM_SPI_Mode_t SPI_Mode_t, uint16_t SPI_Mode, uint16_t SPI_FirstBit)
 Initializes SPIx peripheral with custom settings. More...
 
uint16_t TM_SPI_GetPrescalerFromMaxFrequency (SPI_TypeDef *SPIx, uint32_t MAX_SPI_Frequency)
 Calculates bits for SPI prescaler register to get minimal prescaler value for SPI peripheral. More...
 
TM_SPI_DataSize_t TM_SPI_SetDataSize (SPI_TypeDef *SPIx, TM_SPI_DataSize_t DataSize)
 Sets data size for SPI at runtime. More...
 
static __INLINE uint8_t TM_SPI_Send (SPI_TypeDef *SPIx, uint8_t data)
 Sends single byte over SPI. More...
 
void TM_SPI_SendMulti (SPI_TypeDef *SPIx, uint8_t *dataOut, uint8_t *dataIn, uint32_t count)
 Sends and receives multiple bytes over SPIx. More...
 
void TM_SPI_WriteMulti (SPI_TypeDef *SPIx, uint8_t *dataOut, uint32_t count)
 Writes multiple bytes over SPI. More...
 
void TM_SPI_ReadMulti (SPI_TypeDef *SPIx, uint8_t *dataIn, uint8_t dummy, uint32_t count)
 Receives multiple data bytes over SPI. More...
 
static __INLINE uint16_t TM_SPI_Send16 (SPI_TypeDef *SPIx, uint8_t data)
 Sends single byte over SPI. More...
 
void TM_SPI_SendMulti16 (SPI_TypeDef *SPIx, uint16_t *dataOut, uint16_t *dataIn, uint32_t count)
 Sends and receives multiple bytes over SPIx in 16-bit SPI mode. More...
 
void TM_SPI_WriteMulti16 (SPI_TypeDef *SPIx, uint16_t *dataOut, uint32_t count)
 Writes multiple data via SPI in 16-bit SPI mode. More...
 
void TM_SPI_ReadMulti16 (SPI_TypeDef *SPIx, uint16_t *dataIn, uint16_t dummy, uint32_t count)
 Receives multiple data bytes over SPI in 16-bit SPI mode. More...
 
void TM_SPI_InitCustomPinsCallback (SPI_TypeDef *SPIx, uint16_t AlternateFunction)
 Init custom SPI pins for your SPIx. This is callback function and will be called from my library if needed. More...
 

Detailed Description

Library Functions.

Function Documentation

uint16_t TM_SPI_GetPrescalerFromMaxFrequency ( SPI_TypeDef *  SPIx,
uint32_t  MAX_SPI_Frequency 
)

Calculates bits for SPI prescaler register to get minimal prescaler value for SPI peripheral.

Note
SPI has 8 prescalers available, 2,4,8,...,128,256
This function will return you a bits you must set in your CR1 register.
Imagine, you can use 20MHz max clock in your system, your system is running on 168MHz, and you use SPI on APB2 bus. On 168 and 180MHz devices, APB2 works on Fclk/2, so 84 and 90MHz. So, if you calculate this, prescaler will need to be 84MHz / 20MHz = 4.xx, but if you use 4 prescaler, then you will be over 20MHz. You need 8 prescaler then. This function will calculate this.
Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6. Different SPIx works on different clock and is important to know for which SPI you need prescaler.
MAX_SPI_FrequencyMax SPI frequency you can use. Function will calculate the minimum prescaler you need for that.
Return values
Bitscombination for SPI_CR1 register, with aligned location already, prepared to set parameter for TM_SPI_InitFull() function.
void TM_SPI_Init ( SPI_TypeDef *  SPIx,
TM_SPI_PinsPack_t  pinspack 
)

Initializes SPIx peripheral with custom pinspack and default other settings.

Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
pinspackPinspack you will use from default SPI table. This parameter can be a value of TM_SPI_PinsPack_t enumeration
Return values
None
void TM_SPI_InitCustomPinsCallback ( SPI_TypeDef *  SPIx,
uint16_t  AlternateFunction 
)

Init custom SPI pins for your SPIx. This is callback function and will be called from my library if needed.

Note
When you call TM_SPI_Init() function, and if you pass TM_SPI_PinsPack_Custom to function, then this function will be called where you can initialize custom pins for SPI peripheral
You have to initialize MOSI, MISO and SCK pin
Parameters
*SPIxPointer to SPIx peripheral for which you have to set your custom pin settings
AlternateFunctionAlternate function number which should be used for GPIO pins
Return values
None
Note
With __weak parameter to prevent link errors if not defined by user
void TM_SPI_InitFull ( SPI_TypeDef *  SPIx,
TM_SPI_PinsPack_t  pinspack,
uint16_t  SPI_BaudRatePrescaler,
TM_SPI_Mode_t  SPI_Mode_t,
uint16_t  SPI_Mode,
uint16_t  SPI_FirstBit 
)

Initializes SPIx peripheral with custom settings.

Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
pinspackPinspack you will use from default SPI table. This parameter can be a value of TM_SPI_PinsPack_t enumeration
SPI_BaudRatePrescalerSPI baudrate prescaler. This parameter can be a value of SPI_BaudRatePrescaler
SPI_Mode_tSPI mode you will use. This parameter can be a value of TM_SPI_Mode_t enumeration
SPI_ModeSPI mode you will use:
  • SPI_MODE_MASTER: SPI in master mode (default)
  • SPI_MODE_SLAVE: SPI in slave mode
SPI_FirstBitselect first bit for SPI
  • SPI_FIRSTBIT_MSB: MSB is first bit (default)
  • SPI_FIRSTBIT_LSB: LSB is first bit
Return values
None
void TM_SPI_InitWithMode ( SPI_TypeDef *  SPIx,
TM_SPI_PinsPack_t  pinspack,
TM_SPI_Mode_t  SPI_Mode 
)

Initializes SPIx peripheral with custom pinspack and SPI mode and default other settings.

Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
pinspackPinspack you will use from default SPI table. This parameter can be a value of TM_SPI_PinsPack_t enumeration
SPI_ModeSPI mode you will use. This parameter can be a value of TM_SPI_Mode_t enumeration
Return values
None
void TM_SPI_ReadMulti ( SPI_TypeDef *  SPIx,
uint8_t *  dataIn,
uint8_t  dummy,
uint32_t  count 
)

Receives multiple data bytes over SPI.

Note
Selected SPI must be set in 16-bit mode
Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
*dataInPointer to 8-bit array to save data into
dummyDummy byte to be sent over SPI, to receive data back. In most cases 0x00 or 0xFF
countNumber of bytes you want read from device
Return values
None
void TM_SPI_ReadMulti16 ( SPI_TypeDef *  SPIx,
uint16_t *  dataIn,
uint16_t  dummy,
uint32_t  count 
)

Receives multiple data bytes over SPI in 16-bit SPI mode.

Note
Selected SPI must be set in 16-bit mode
Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
*dataInPointer to 16-bit array to save data into
dummyDummy 16-bit value to be sent over SPI, to receive data back. In most cases 0x00 or 0xFF
countNumber of 16-bit values you want read from device
Return values
None
static __INLINE uint8_t TM_SPI_Send ( SPI_TypeDef *  SPIx,
uint8_t  data 
)
static

Sends single byte over SPI.

Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
data8-bit data size to send over SPI
Return values
Receivedbyte from slave device
static __INLINE uint16_t TM_SPI_Send16 ( SPI_TypeDef *  SPIx,
uint8_t  data 
)
static

Sends single byte over SPI.

Note
Selected SPI must be set in 16-bit mode
Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
data16-bit data size to send over SPI
Return values
Received16-bit value from slave device
void TM_SPI_SendMulti ( SPI_TypeDef *  SPIx,
uint8_t *  dataOut,
uint8_t *  dataIn,
uint32_t  count 
)

Sends and receives multiple bytes over SPIx.

Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
*dataOutPointer to array with data to send over SPI
*dataInPointer to array to to save incoming data
countNumber of bytes to send/receive over SPI
Return values
None
void TM_SPI_SendMulti16 ( SPI_TypeDef *  SPIx,
uint16_t *  dataOut,
uint16_t *  dataIn,
uint32_t  count 
)

Sends and receives multiple bytes over SPIx in 16-bit SPI mode.

Note
Selected SPI must be set in 16-bit mode
Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
*dataOutPointer to array with data to send over SPI
*dataInPointer to array to to save incoming data
countNumber of 16-bit values to send/receive over SPI
Return values
None
TM_SPI_DataSize_t TM_SPI_SetDataSize ( SPI_TypeDef *  SPIx,
TM_SPI_DataSize_t  DataSize 
)

Sets data size for SPI at runtime.

Note
You can select either 8 or 16 bits data array.
Parameters
*SPIxPointer to SPIx peripheral where data size will be set
DataSizeDatasize which will be used. This parameter can be a value of TM_SPI_DataSize_t enumeration
Return values
Statusof data size before changes happen
void TM_SPI_WriteMulti ( SPI_TypeDef *  SPIx,
uint8_t *  dataOut,
uint32_t  count 
)

Writes multiple bytes over SPI.

Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
*dataOutPointer to array with data to send over SPI
countNumber of elements to send over SPI
Return values
None
void TM_SPI_WriteMulti16 ( SPI_TypeDef *  SPIx,
uint16_t *  dataOut,
uint32_t  count 
)

Writes multiple data via SPI in 16-bit SPI mode.

Note
Selected SPI must be set in 16-bit mode
Parameters
*SPIxPointer to SPIx peripheral you will use, where x is between 1 to 6
*dataOutPointer to 16-bit array with data to send over SPI
countNumber of elements to send over SPI
Return values
None