Macros | Functions
stm32f30x_spi.c File Reference

This file provides firmware functions to manage the following functionalities of the Serial peripheral interface (SPI): More...

#include "stm32f30x_spi.h"
#include "stm32f30x_rcc.h"
Include dependency graph for stm32f30x_spi.c:

Go to the source code of this file.

Macros

#define CR1_CLEAR_MASK   ((uint16_t)0x3040)
 
#define CR2_LDMA_MASK   ((uint16_t)0x9FFF)
 
#define I2SCFGR_CLEAR_MASK   ((uint16_t)0xF040)
 

Functions

void I2S_Cmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the specified SPI peripheral (in I2S mode). More...
 
void I2S_FullDuplexConfig (SPI_TypeDef *I2Sxext, I2S_InitTypeDef *I2S_InitStruct)
 Configures the full duplex mode for the I2Sx peripheral using its extension I2Sxext according to the specified parameters in the I2S_InitStruct. More...
 
void I2S_Init (SPI_TypeDef *SPIx, I2S_InitTypeDef *I2S_InitStruct)
 Initializes the SPIx peripheral according to the specified parameters in the I2S_InitStruct. More...
 
void I2S_StructInit (I2S_InitTypeDef *I2S_InitStruct)
 Fills each I2S_InitStruct member with its default value. More...
 
void SPI_BiDirectionalLineConfig (SPI_TypeDef *SPIx, uint16_t SPI_Direction)
 Selects the data transfer direction in bidirectional mode for the specified SPI. More...
 
void SPI_CalculateCRC (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the CRC value calculation of the transferred bytes. More...
 
void SPI_Cmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the specified SPI peripheral. More...
 
void SPI_CRCLengthConfig (SPI_TypeDef *SPIx, uint16_t SPI_CRCLength)
 Configures the CRC calculation length for the selected SPI. More...
 
void SPI_DataSizeConfig (SPI_TypeDef *SPIx, uint16_t SPI_DataSize)
 Configures the data size for the selected SPI. More...
 
uint16_t SPI_GetCRC (SPI_TypeDef *SPIx, uint8_t SPI_CRC)
 Returns the transmit or the receive CRC register value for the specified SPI. More...
 
uint16_t SPI_GetCRCPolynomial (SPI_TypeDef *SPIx)
 Returns the CRC Polynomial register value for the specified SPI. More...
 
uint16_t SPI_GetReceptionFIFOStatus (SPI_TypeDef *SPIx)
 Returns the current SPIx Reception FIFO filled level. More...
 
uint16_t SPI_GetTransmissionFIFOStatus (SPI_TypeDef *SPIx)
 Returns the current SPIx Transmission FIFO filled level. More...
 
void SPI_I2S_ClearFlag (SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
 Clears the SPIx CRC Error (CRCERR) flag. More...
 
void SPI_I2S_DeInit (SPI_TypeDef *SPIx)
 De-initialize the SPIx peripheral registers to their default reset values. More...
 
void SPI_I2S_DMACmd (SPI_TypeDef *SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
 Enables or disables the SPIx/I2Sx DMA interface. More...
 
FlagStatus SPI_I2S_GetFlagStatus (SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
 Checks whether the specified SPIx/I2Sx flag is set or not. More...
 
ITStatus SPI_I2S_GetITStatus (SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
 Checks whether the specified SPIx/I2Sx interrupt has occurred or not. More...
 
void SPI_I2S_ITConfig (SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
 Enables or disables the specified SPI/I2S interrupts. More...
 
uint16_t SPI_I2S_ReceiveData16 (SPI_TypeDef *SPIx)
 Returns the most recent received data by the SPIx peripheral. More...
 
void SPI_I2S_SendData16 (SPI_TypeDef *SPIx, uint16_t Data)
 Transmits a Data through the SPIx/I2Sx peripheral. More...
 
void SPI_Init (SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
 Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct. More...
 
void SPI_LastDMATransferCmd (SPI_TypeDef *SPIx, uint16_t SPI_LastDMATransfer)
 Configures the number of data to transfer type(Even/Odd) for the DMA last transfers and for the selected SPI. More...
 
void SPI_NSSInternalSoftwareConfig (SPI_TypeDef *SPIx, uint16_t SPI_NSSInternalSoft)
 Configures internally by software the NSS pin for the selected SPI. More...
 
void SPI_NSSPulseModeCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the NSS pulse management mode. More...
 
uint8_t SPI_ReceiveData8 (SPI_TypeDef *SPIx)
 Returns the most recent received data by the SPIx peripheral. More...
 
void SPI_RxFIFOThresholdConfig (SPI_TypeDef *SPIx, uint16_t SPI_RxFIFOThreshold)
 Configures the FIFO reception threshold for the selected SPI. More...
 
void SPI_SendData8 (SPI_TypeDef *SPIx, uint8_t Data)
 Transmits a Data through the SPIx peripheral. More...
 
void SPI_SSOutputCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the SS output for the selected SPI. More...
 
void SPI_StructInit (SPI_InitTypeDef *SPI_InitStruct)
 Fills each SPI_InitStruct member with its default value. More...
 
void SPI_TIModeCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the SPIx/I2Sx DMA interface. More...
 
void SPI_TransmitCRC (SPI_TypeDef *SPIx)
 Transmit the SPIx CRC value. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Serial peripheral interface (SPI):

Author
MCD Application Team
Version
V1.1.1
Date
04-April-2014
  • Initialization and Configuration
  • Data transfers functions
  • Hardware CRC Calculation
  • DMA transfers management
  • Interrupts and flags management
===============================================================================
                     ##### How to use this driver #####
===============================================================================
   [..]
       (#) Enable peripheral clock using RCC_APBPeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE)
           function for SPI1 or using RCC_APBPeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE)
           function for SPI2.
       (#) Enable SCK, MOSI, MISO and NSS GPIO clocks using RCC_AHBPeriphClockCmd()
           function. 
       (#) Peripherals alternate function: 
           (++) Connect the pin to the desired peripherals' Alternate 
                Function (AF) using GPIO_PinAFConfig() function.
           (++) Configure the desired pin in alternate function by:
                GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF.
           (++) Select the type, pull-up/pull-down and output speed via 
                GPIO_PuPd, GPIO_OType and GPIO_Speed members.
           (++) Call GPIO_Init() function.
       (#) Program the Polarity, Phase, First Data, Baud Rate Prescaler, Slave 
           Management, Peripheral Mode and CRC Polynomial values using the SPI_Init()
           function in SPI mode. In I2S mode, program the Mode, Standard, Data Format,
           MCLK Output, Audio frequency and Polarity using I2S_Init() function.
       (#) Configure the FIFO threshold using SPI_RxFIFOThresholdConfig() to select 
           at which threshold the RXNE event is generated.     
       (#) Enable the NVIC and the corresponding interrupt using the function 
           SPI_I2S_ITConfig() if you need to use interrupt mode. 
       (#) When using the DMA mode 
           (++) Configure the DMA using DMA_Init() function.
           (++) Active the needed channel Request using SPI_I2S_DMACmd() function.
       (#) Enable the SPI using the SPI_Cmd() function or enable the I2S using
           I2S_Cmd().
       (#) Enable the DMA using the DMA_Cmd() function when using DMA mode. 
       (#) Optionally you can enable/configure the following parameters without
           re-initialization (i.e there is no need to call again SPI_Init() function):
           (++) When bidirectional mode (SPI_Direction_1Line_Rx or SPI_Direction_1Line_Tx)
                is programmed as Data direction parameter using the SPI_Init() function
                it can be possible to switch between SPI_Direction_Tx or SPI_Direction_Rx
                using the SPI_BiDirectionalLineConfig() function.
           (++) When SPI_NSS_Soft is selected as Slave Select Management parameter 
                using the SPI_Init() function it can be possible to manage the 
                NSS internal signal using the SPI_NSSInternalSoftwareConfig() function.
           (++) Reconfigure the data size using the SPI_DataSizeConfig() function.  
           (++) Enable or disable the SS output using the SPI_SSOutputCmd() function.
       (#) To use the CRC Hardware calculation feature refer to the Peripheral 
           CRC hardware Calculation subsection.
   [..] It is possible to use SPI in I2S full duplex mode, in this case, each SPI 
        peripheral is able to manage sending and receiving data simultaneously
        using two data lines. Each SPI peripheral has an extended block called I2Sxext
        (ie. I2S2ext for SPI2 and I2S3ext for SPI3).
        The extension block is not a full SPI IP, it is used only as I2S slave to
        implement full duplex mode. The extension block uses the same clock sources
        as its master.          
        To configure I2S full duplex you have to:
       (#) Configure SPIx in I2S mode (I2S_Init() function) as described above. 
       (#) Call the I2S_FullDuplexConfig() function using the same strucutre passed to  
           I2S_Init() function.
       (#) Call I2S_Cmd() for SPIx then for its extended block.
       (#) Configure interrupts or DMA requests and to get/clear flag status, 
           use I2Sxext instance for the extension block.
       [..] Functions that can be called with I2Sxext instances are:
            I2S_Cmd(), I2S_FullDuplexConfig(), SPI_I2S_ReceiveData16(), SPI_I2S_SendData16(), 
            SPI_I2S_DMACmd(), SPI_I2S_ITConfig(), SPI_I2S_GetFlagStatus(), SPI_I2S_ClearFlag(),
            SPI_I2S_GetITStatus() and SPI_I2S_ClearITPendingBit().
       [..] Example: To use SPI3 in Full duplex mode (SPI3 is Master Tx, I2S3ext is Slave Rx):
       [..] RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);   
            I2S_StructInit(&I2SInitStruct);
            I2SInitStruct.Mode = I2S_Mode_MasterTx;     
            I2S_Init(SPI3, &I2SInitStruct);
            I2S_FullDuplexConfig(SPI3ext, &I2SInitStruct)
            I2S_Cmd(SPI3, ENABLE);
            I2S_Cmd(SPI3ext, ENABLE);
            ...
            while (SPI_I2S_GetFlagStatus(SPI2, SPI_FLAG_TXE) == RESET)
            {}
            SPI_I2S_SendData16(SPI3, txdata[i]);
            ...  
            while (SPI_I2S_GetFlagStatus(I2S3ext, SPI_FLAG_RXNE) == RESET)
            {}
            rxdata[i] = SPI_I2S_ReceiveData16(I2S3ext);
            ...          
   [..]
   (@) In SPI mode: To use the SPI TI mode, call the function SPI_TIModeCmd() 
       just after calling the function SPI_Init().  
Attention

© COPYRIGHT 2014 STMicroelectronics

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at:

   http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file stm32f30x_spi.c.



rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:27