-/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************\r
-* File Name : stm32f10x_spi.c\r
-* Author : MCD Application Team\r
-* Date First Issued : 09/29/2006\r
-* Description : This file provides all the SPI firmware functions.\r
-********************************************************************************\r
-* History:\r
-* 04/02/2007: V0.2\r
-* 02/05/2007: V0.1\r
-* 09/29/2006: V0.01\r
-********************************************************************************\r
-* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.\r
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,\r
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE\r
-* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING\r
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
-*******************************************************************************/\r
+/**\r
+ ******************************************************************************\r
+ * @file stm32f10x_spi.c\r
+ * @author MCD Application Team\r
+ * @version V3.0.0\r
+ * @date 04/06/2009\r
+ * @brief This file provides all the SPI firmware functions.\r
+ ******************************************************************************\r
+ * @copy\r
+ *\r
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
+ *\r
+ * <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2>\r
+ */ \r
\r
/* Includes ------------------------------------------------------------------*/\r
#include "stm32f10x_spi.h"\r
#include "stm32f10x_rcc.h"\r
\r
-/* Private typedef -----------------------------------------------------------*/\r
-/* Private define ------------------------------------------------------------*/\r
+/** @addtogroup StdPeriph_Driver\r
+ * @{\r
+ */\r
+\r
+/** @defgroup SPI \r
+ * @brief SPI driver modules\r
+ * @{\r
+ */ \r
+\r
+/** @defgroup SPI_Private_TypesDefinitions\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */ \r
+\r
+\r
+/** @defgroup SPI_Private_Defines\r
+ * @{\r
+ */\r
+\r
/* SPI SPE mask */\r
-#define CR1_SPE_Set ((u16)0x0040)\r
-#define CR1_SPE_Reset ((u16)0xFFBF)\r
+#define CR1_SPE_Set ((uint16_t)0x0040)\r
+#define CR1_SPE_Reset ((uint16_t)0xFFBF)\r
+\r
+/* I2S I2SE mask */\r
+#define I2SCFGR_I2SE_Set ((uint16_t)0x0400)\r
+#define I2SCFGR_I2SE_Reset ((uint16_t)0xFBFF)\r
\r
/* SPI CRCNext mask */\r
-#define CR1_CRCNext_Set ((u16)0x1000)\r
+#define CR1_CRCNext_Set ((uint16_t)0x1000)\r
\r
/* SPI CRCEN mask */\r
-#define CR1_CRCEN_Set ((u16)0x2000)\r
-#define CR1_CRCEN_Reset ((u16)0xDFFF)\r
+#define CR1_CRCEN_Set ((uint16_t)0x2000)\r
+#define CR1_CRCEN_Reset ((uint16_t)0xDFFF)\r
\r
/* SPI SSOE mask */\r
-#define CR2_SSOE_Set ((u16)0x0004)\r
-#define CR2_SSOE_Reset ((u16)0xFFFB)\r
+#define CR2_SSOE_Set ((uint16_t)0x0004)\r
+#define CR2_SSOE_Reset ((uint16_t)0xFFFB)\r
\r
/* SPI registers Masks */\r
-#define CR1_CLEAR_Mask ((u16)0x3040)\r
-\r
-/* Private macro -------------------------------------------------------------*/\r
-/* Private variables ---------------------------------------------------------*/\r
-/* Private function prototypes -----------------------------------------------*/\r
-/* Private functions ---------------------------------------------------------*/\r
-\r
-/*******************************************************************************\r
-* Function Name : SPI_DeInit\r
-* Description : Deinitializes the SPIx peripheral registers to their default\r
-* reset values.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_DeInit(SPI_TypeDef* SPIx)\r
+#define CR1_CLEAR_Mask ((uint16_t)0x3040)\r
+#define I2SCFGR_CLEAR_Mask ((uint16_t)0xF040)\r
+\r
+/* SPI or I2S mode selection masks */\r
+#define SPI_Mode_Select ((uint16_t)0xF7FF)\r
+#define I2S_Mode_Select ((uint16_t)0x0800) \r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup SPI_Private_Macros\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup SPI_Private_Variables\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup SPI_Private_FunctionPrototypes\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup SPI_Private_Functions\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @brief Deinitializes the SPIx peripheral registers to their default\r
+ * reset values (Affects also the I2Ss).\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @retval : None\r
+ */\r
+void SPI_I2S_DeInit(SPI_TypeDef* SPIx)\r
{\r
- switch (*(u32*)&SPIx)\r
+ /* Check the parameters */\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ \r
+ switch (*(uint32_t*)&SPIx)\r
{\r
case SPI1_BASE:\r
/* Enable SPI1 reset state */\r
/* Release SPI1 from reset state */\r
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);\r
break;\r
-\r
case SPI2_BASE:\r
/* Enable SPI2 reset state */\r
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);\r
/* Release SPI2 from reset state */\r
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);\r
break;\r
-\r
+ case SPI3_BASE:\r
+ /* Enable SPI3 reset state */\r
+ RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);\r
+ /* Release SPI3 from reset state */\r
+ RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);\r
+ break;\r
default:\r
break;\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_Init\r
-* Description : Initializes the SPIx according to the specified parameters\r
-* in the SPI_InitStruct.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_InitStruct: pointer to a SPI_InitTypeDef structure that\r
-* contains the configuration information for the specified\r
-* SPI peripheral.\r
-* Output : None\r
-* Return : None\r
-******************************************************************************/\r
+/**\r
+ * @brief Initializes the SPIx peripheral according to the specified \r
+ * parameters in the SPI_InitStruct.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param SPI_InitStruct: pointer to a SPI_InitTypeDef structure that\r
+ * contains the configuration information for the specified\r
+ * SPI peripheral.\r
+ * @retval : None\r
+ */\r
void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)\r
{\r
- u16 tmpreg = 0;\r
-\r
- /* Check the parameters */\r
- assert(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));\r
- assert(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));\r
- assert(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));\r
- assert(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));\r
- assert(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));\r
- assert(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));\r
- assert(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));\r
- assert(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));\r
- assert(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));\r
-\r
+ uint16_t tmpreg = 0;\r
+ \r
+ /* check the parameters */\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx)); \r
+ \r
+ /* Check the SPI parameters */\r
+ assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));\r
+ assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));\r
+ assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));\r
+ assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));\r
+ assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));\r
+ assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));\r
+ assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));\r
+ assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));\r
+ assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));\r
/*---------------------------- SPIx CR1 Configuration ------------------------*/\r
/* Get the SPIx CR1 value */\r
tmpreg = SPIx->CR1;\r
/* Set BR bits according to SPI_BaudRatePrescaler value */\r
/* Set CPOL bit according to SPI_CPOL value */\r
/* Set CPHA bit according to SPI_CPHA value */\r
- tmpreg |= (u16)((u32)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |\r
+ tmpreg |= (uint16_t)((uint32_t)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |\r
SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL | \r
SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS | \r
SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);\r
/* Write to SPIx CR1 */\r
SPIx->CR1 = tmpreg;\r
-\r
+ \r
+ /* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */\r
+ SPIx->I2SCFGR &= SPI_Mode_Select; \r
/*---------------------------- SPIx CRCPOLY Configuration --------------------*/\r
/* Write to SPIx CRCPOLY */\r
SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_StructInit\r
-* Description : Fills each SPI_InitStruct member with its default value.\r
-* Input : - SPI_InitStruct : pointer to a SPI_InitTypeDef structure\r
-* which will be initialized.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
+/**\r
+ * @brief Initializes the SPIx peripheral according to the specified \r
+ * parameters in the I2S_InitStruct.\r
+ * @param SPIx: where x can be 2 or 3 to select the SPI peripheral\r
+ * (configured in I2S mode).\r
+ * @param I2S_InitStruct: pointer to an I2S_InitTypeDef structure that\r
+ * contains the configuration information for the specified\r
+ * SPI peripheral configured in I2S mode.\r
+ * @retval : None\r
+ */\r
+void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct)\r
+{\r
+ uint16_t tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1;\r
+ uint32_t tmp = 0;\r
+ RCC_ClocksTypeDef RCC_Clocks;\r
+ \r
+ /* Check the I2S parameters */\r
+ assert_param(IS_SPI_23_PERIPH(SPIx));\r
+ assert_param(IS_I2S_MODE(I2S_InitStruct->I2S_Mode));\r
+ assert_param(IS_I2S_STANDARD(I2S_InitStruct->I2S_Standard));\r
+ assert_param(IS_I2S_DATA_FORMAT(I2S_InitStruct->I2S_DataFormat));\r
+ assert_param(IS_I2S_MCLK_OUTPUT(I2S_InitStruct->I2S_MCLKOutput));\r
+ assert_param(IS_I2S_AUDIO_FREQ(I2S_InitStruct->I2S_AudioFreq));\r
+ assert_param(IS_I2S_CPOL(I2S_InitStruct->I2S_CPOL)); \r
+/*----------------------- SPIx I2SCFGR & I2SPR Configuration -----------------*/\r
+ /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */\r
+ SPIx->I2SCFGR &= I2SCFGR_CLEAR_Mask; \r
+ SPIx->I2SPR = 0x0002;\r
+ \r
+ /* Get the I2SCFGR register value */\r
+ tmpreg = SPIx->I2SCFGR;\r
+ \r
+ /* If the default value has to be written, reinitialize i2sdiv and i2sodd*/\r
+ if(I2S_InitStruct->I2S_AudioFreq == I2S_AudioFreq_Default)\r
+ {\r
+ i2sodd = (uint16_t)0;\r
+ i2sdiv = (uint16_t)2; \r
+ }\r
+ /* If the requested audio frequency is not the default, compute the prescaler */\r
+ else\r
+ {\r
+ /* Check the frame length (For the Prescaler computing) */\r
+ if(I2S_InitStruct->I2S_DataFormat == I2S_DataFormat_16b)\r
+ {\r
+ /* Packet length is 16 bits */\r
+ packetlength = 1;\r
+ }\r
+ else\r
+ {\r
+ /* Packet length is 32 bits */\r
+ packetlength = 2;\r
+ }\r
+ /* Get System Clock frequency */\r
+ RCC_GetClocksFreq(&RCC_Clocks);\r
+ \r
+ /* Compute the Real divider depending on the MCLK output state with a flaoting point */\r
+ if(I2S_InitStruct->I2S_MCLKOutput == I2S_MCLKOutput_Enable)\r
+ {\r
+ /* MCLK output is enabled */\r
+ tmp = (uint16_t)(((10 * RCC_Clocks.SYSCLK_Frequency) / (256 * I2S_InitStruct->I2S_AudioFreq)) + 5);\r
+ }\r
+ else\r
+ {\r
+ /* MCLK output is disabled */\r
+ tmp = (uint16_t)(((10 * RCC_Clocks.SYSCLK_Frequency) / (32 * packetlength * I2S_InitStruct->I2S_AudioFreq)) + 5);\r
+ }\r
+ \r
+ /* Remove the flaoting point */\r
+ tmp = tmp/10; \r
+ \r
+ /* Check the parity of the divider */\r
+ i2sodd = (uint16_t)(tmp & (uint16_t)0x0001);\r
+ \r
+ /* Compute the i2sdiv prescaler */\r
+ i2sdiv = (uint16_t)((tmp - i2sodd) / 2);\r
+ \r
+ /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */\r
+ i2sodd = (uint16_t) (i2sodd << 8);\r
+ }\r
+ \r
+ /* Test if the divider is 1 or 0 */\r
+ if ((i2sdiv < 2) || (i2sdiv > 0xFF))\r
+ {\r
+ /* Set the default values */\r
+ i2sdiv = 2;\r
+ i2sodd = 0;\r
+ }\r
+ /* Write to SPIx I2SPR register the computed value */\r
+ SPIx->I2SPR = (uint16_t)(i2sdiv | i2sodd | I2S_InitStruct->I2S_MCLKOutput); \r
+ \r
+ /* Configure the I2S with the SPI_InitStruct values */\r
+ tmpreg |= (uint16_t)(I2S_Mode_Select | I2S_InitStruct->I2S_Mode | \\r
+ I2S_InitStruct->I2S_Standard | I2S_InitStruct->I2S_DataFormat | \\r
+ I2S_InitStruct->I2S_CPOL);\r
+ \r
+ /* Write to SPIx I2SCFGR */\r
+ SPIx->I2SCFGR = tmpreg;\r
+}\r
+\r
+/**\r
+ * @brief Fills each SPI_InitStruct member with its default value.\r
+ * @param SPI_InitStruct : pointer to a SPI_InitTypeDef structure\r
+ * which will be initialized.\r
+ * @retval : None\r
+ */\r
void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)\r
{\r
/*--------------- Reset SPI init structure parameters values -----------------*/\r
/* Initialize the SPI_Direction member */\r
SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;\r
-\r
/* initialize the SPI_Mode member */\r
SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;\r
-\r
/* initialize the SPI_DataSize member */\r
SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;\r
-\r
/* Initialize the SPI_CPOL member */\r
SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;\r
-\r
/* Initialize the SPI_CPHA member */\r
SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;\r
-\r
/* Initialize the SPI_NSS member */\r
SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;\r
-\r
/* Initialize the SPI_BaudRatePrescaler member */\r
SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;\r
-\r
/* Initialize the SPI_FirstBit member */\r
SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;\r
-\r
/* Initialize the SPI_CRCPolynomial member */\r
SPI_InitStruct->SPI_CRCPolynomial = 7;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_Cmd\r
-* Description : Enables or disables the specified SPI peripheral.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - NewState: new state of the SPIx peripheral. \r
-* This parameter can be: ENABLE or DISABLE.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
+/**\r
+ * @brief Fills each I2S_InitStruct member with its default value.\r
+ * @param I2S_InitStruct : pointer to a I2S_InitTypeDef structure\r
+ * which will be initialized.\r
+ * @retval : None\r
+ */\r
+void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct)\r
+{\r
+/*--------------- Reset I2S init structure parameters values -----------------*/\r
+ /* Initialize the I2S_Mode member */\r
+ I2S_InitStruct->I2S_Mode = I2S_Mode_SlaveTx;\r
+ \r
+ /* Initialize the I2S_Standard member */\r
+ I2S_InitStruct->I2S_Standard = I2S_Standard_Phillips;\r
+ \r
+ /* Initialize the I2S_DataFormat member */\r
+ I2S_InitStruct->I2S_DataFormat = I2S_DataFormat_16b;\r
+ \r
+ /* Initialize the I2S_MCLKOutput member */\r
+ I2S_InitStruct->I2S_MCLKOutput = I2S_MCLKOutput_Disable;\r
+ \r
+ /* Initialize the I2S_AudioFreq member */\r
+ I2S_InitStruct->I2S_AudioFreq = I2S_AudioFreq_Default;\r
+ \r
+ /* Initialize the I2S_CPOL member */\r
+ I2S_InitStruct->I2S_CPOL = I2S_CPOL_Low;\r
+}\r
+\r
+/**\r
+ * @brief Enables or disables the specified SPI peripheral.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param NewState: new state of the SPIx peripheral. \r
+ * This parameter can be: ENABLE or DISABLE.\r
+ * @retval : None\r
+ */\r
void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)\r
{\r
/* Check the parameters */\r
- assert(IS_FUNCTIONAL_STATE(NewState));\r
-\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_FUNCTIONAL_STATE(NewState));\r
if (NewState != DISABLE)\r
{\r
/* Enable the selected SPI peripheral */\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_ITConfig\r
-* Description : Enables or disables the specified SPI interrupts.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_IT: specifies the SPI interrupts sources to be enabled\r
-* or disabled. \r
-* This parameter can be one of the following values:\r
-* - SPI_IT_TXE: Tx buffer empty interrupt mask\r
-* - SPI_IT_RXNE: Rx buffer not empty interrupt mask\r
-* - SPI_IT_ERR: Error interrupt mask\r
-* - NewState: new state of the specified SPI interrupts.\r
-* This parameter can be: ENABLE or DISABLE.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_ITConfig(SPI_TypeDef* SPIx, u8 SPI_IT, FunctionalState NewState)\r
+/**\r
+ * @brief Enables or disables the specified SPI peripheral (in I2S mode).\r
+ * @param SPIx: where x can be 2 or 3 to select the SPI peripheral.\r
+ * @param NewState: new state of the SPIx peripheral. \r
+ * This parameter can be: ENABLE or DISABLE.\r
+ * @retval : None\r
+ */\r
+void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)\r
{\r
- u16 itpos = 0, itmask = 0 ;\r
-\r
/* Check the parameters */\r
- assert(IS_FUNCTIONAL_STATE(NewState));\r
- assert(IS_SPI_CONFIG_IT(SPI_IT));\r
+ assert_param(IS_SPI_23_PERIPH(SPIx));\r
+ assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+ if (NewState != DISABLE)\r
+ {\r
+ /* Enable the selected SPI peripheral (in I2S mode) */\r
+ SPIx->I2SCFGR |= I2SCFGR_I2SE_Set;\r
+ }\r
+ else\r
+ {\r
+ /* Disable the selected SPI peripheral (in I2S mode) */\r
+ SPIx->I2SCFGR &= I2SCFGR_I2SE_Reset;\r
+ }\r
+}\r
\r
- /* Get the SPI IT index */\r
- itpos = SPI_IT >> 4;\r
+/**\r
+ * @brief Enables or disables the specified SPI/I2S interrupts.\r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * 2 or 3 in I2S mode\r
+ * @param SPI_I2S_IT: specifies the SPI/I2S interrupt source to be \r
+ * enabled or disabled. \r
+ * This parameter can be one of the following values:\r
+ * @arg SPI_I2S_IT_TXE: Tx buffer empty interrupt mask\r
+ * @arg SPI_I2S_IT_RXNE: Rx buffer not empty interrupt mask\r
+ * @arg SPI_I2S_IT_ERR: Error interrupt mask\r
+ * @param NewState: new state of the specified SPI/I2S interrupt.\r
+ * This parameter can be: ENABLE or DISABLE.\r
+ * @retval : None\r
+ */\r
+void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)\r
+{\r
+ uint16_t itpos = 0, itmask = 0 ;\r
+ /* Check the parameters */\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+ assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT));\r
+ /* Get the SPI/I2S IT index */\r
+ itpos = SPI_I2S_IT >> 4;\r
/* Set the IT mask */\r
- itmask = (u16)((u16)1 << itpos);\r
-\r
+ itmask = (uint16_t)((uint16_t)1 << itpos);\r
if (NewState != DISABLE)\r
{\r
- /* Enable the selected SPI interrupt */\r
+ /* Enable the selected SPI/I2S interrupt */\r
SPIx->CR2 |= itmask;\r
}\r
else\r
{\r
- /* Disable the selected SPI interrupt */\r
- SPIx->CR2 &= (u16)~itmask;\r
+ /* Disable the selected SPI/I2S interrupt */\r
+ SPIx->CR2 &= (uint16_t)~itmask;\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_DMACmd\r
-* Description : Enables or disables the SPIx\92s DMA interface.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_DMAReq: specifies the SPI DMA transfer request to be\r
-* enabled or disabled. \r
-* This parameter can be any combination of the following values:\r
-* - SPI_DMAReq_Tx: Tx buffer DMA transfer request\r
-* - SPI_DMAReq_Rx: Rx buffer DMA transfer request\r
-* - NewState: new state of the selected SPI DMA transfer request.\r
-* This parameter can be: ENABLE or DISABLE.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_DMACmd(SPI_TypeDef* SPIx, u16 SPI_DMAReq, FunctionalState NewState)\r
+/**\r
+ * @brief Enables or disables the SPIx/I2Sx DMA interface.\r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * 2 or 3 in I2S mode\r
+ * @param SPI_I2S_DMAReq: specifies the SPI/I2S DMA transfer request \r
+ * to be enabled or disabled. \r
+ * This parameter can be any combination of the following values:\r
+ * @arg SPI_I2S_DMAReq_Tx: Tx buffer DMA transfer request\r
+ * @arg SPI_I2S_DMAReq_Rx: Rx buffer DMA transfer request\r
+ * @param NewState: new state of the selected SPI/I2S DMA transfer \r
+ * request.\r
+ * This parameter can be: ENABLE or DISABLE.\r
+ * @retval : None\r
+ */\r
+void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)\r
{\r
/* Check the parameters */\r
- assert(IS_FUNCTIONAL_STATE(NewState));\r
- assert(IS_SPI_DMA_REQ(SPI_DMAReq));\r
-\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+ assert_param(IS_SPI_I2S_DMAREQ(SPI_I2S_DMAReq));\r
if (NewState != DISABLE)\r
{\r
- /* Enable the selected SPI DMA requests */\r
- SPIx->CR2 |= SPI_DMAReq;\r
+ /* Enable the selected SPI/I2S DMA requests */\r
+ SPIx->CR2 |= SPI_I2S_DMAReq;\r
}\r
else\r
{\r
- /* Disable the selected SPI DMA requests */\r
- SPIx->CR2 &= (u16)~SPI_DMAReq;\r
+ /* Disable the selected SPI/I2S DMA requests */\r
+ SPIx->CR2 &= (uint16_t)~SPI_I2S_DMAReq;\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_SendData\r
-* Description : Transmits a Data through the SPIx peripheral.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - Data : Data to be transmitted..\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_SendData(SPI_TypeDef* SPIx, u16 Data)\r
+/**\r
+ * @brief Transmits a Data through the SPIx/I2Sx peripheral.\r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * 2 or 3 in I2S mode\r
+ * @param Data : Data to be transmitted..\r
+ * @retval : None\r
+ */\r
+void SPI_I2S_SendData(SPI_TypeDef* SPIx, uint16_t Data)\r
{\r
+ /* Check the parameters */\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ \r
/* Write in the DR register the data to be sent */\r
SPIx->DR = Data;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_ReceiveData\r
-* Description : Returns the most recent received data by the SPIx peripheral.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* Output : None\r
-* Return : The value of the received data.\r
-*******************************************************************************/\r
-u16 SPI_ReceiveData(SPI_TypeDef* SPIx)\r
+/**\r
+ * @brief Returns the most recent received data by the SPIx/I2Sx peripheral. \r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * 2 or 3 in I2S mode\r
+ * @retval : The value of the received data.\r
+ */\r
+uint16_t SPI_I2S_ReceiveData(SPI_TypeDef* SPIx)\r
{\r
+ /* Check the parameters */\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ \r
/* Return the data in the DR register */\r
return SPIx->DR;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_NSSInternalSoftwareConfig\r
-* Description : Configures internally by software the NSS pin for the selected \r
-* SPI.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_NSSInternalSoft: specifies the SPI NSS internal state.\r
-* This parameter can be one of the following values:\r
-* - SPI_NSSInternalSoft_Set: Set NSS pin internally\r
-* - SPI_NSSInternalSoft_Reset: Reset NSS pin internally\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, u16 SPI_NSSInternalSoft)\r
+/**\r
+ * @brief Configures internally by software the NSS pin for the selected \r
+ * SPI.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param SPI_NSSInternalSoft: specifies the SPI NSS internal state.\r
+ * This parameter can be one of the following values:\r
+ * @arg SPI_NSSInternalSoft_Set: Set NSS pin internally\r
+ * @arg SPI_NSSInternalSoft_Reset: Reset NSS pin internally\r
+ * @retval : None\r
+ */\r
+void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft)\r
{\r
/* Check the parameters */\r
- assert(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));\r
-\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));\r
if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)\r
{\r
/* Set NSS pin internally by software */\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_SSOutputCmd\r
-* Description : Enables or disables the SS output for the selected SPI.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - NewState: new state of the SPIx SS output. \r
-* This parameter can be: ENABLE or DISABLE.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
+/**\r
+ * @brief Enables or disables the SS output for the selected SPI.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param NewState: new state of the SPIx SS output. \r
+ * This parameter can be: ENABLE or DISABLE.\r
+ * @retval : None\r
+ */\r
void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)\r
{\r
/* Check the parameters */\r
- assert(IS_FUNCTIONAL_STATE(NewState));\r
-\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_FUNCTIONAL_STATE(NewState));\r
if (NewState != DISABLE)\r
{\r
/* Enable the selected SPI SS output */\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_DataSizeConfig\r
-* Description : Configures the data size for the selected SPI.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_DataSize: specifies the SPI data size.\r
-* This parameter can be one of the following values:\r
-* - SPI_DataSize_16b: Set data frame format to 16bit\r
-* - SPI_DataSize_8b: Set data frame format to 8bit\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_DataSizeConfig(SPI_TypeDef* SPIx, u16 SPI_DataSize)\r
+/**\r
+ * @brief Configures the data size for the selected SPI.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param SPI_DataSize: specifies the SPI data size.\r
+ * This parameter can be one of the following values:\r
+ * @arg SPI_DataSize_16b: Set data frame format to 16bit\r
+ * @arg SPI_DataSize_8b: Set data frame format to 8bit\r
+ * @retval : None\r
+ */\r
+void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize)\r
{\r
/* Check the parameters */\r
- assert(IS_SPI_DATASIZE(SPI_DataSize));\r
-\r
- if (SPI_DataSize != SPI_DataSize_8b)\r
- {\r
- /* Set data frame format to 16bit */\r
- SPIx->CR1 |= SPI_DataSize_16b;\r
- }\r
- else\r
- {\r
- /* Set data frame format to 8bit */\r
- SPIx->CR1 &= SPI_DataSize_8b;\r
- }\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_DATASIZE(SPI_DataSize));\r
+ /* Clear DFF bit */\r
+ SPIx->CR1 &= (uint16_t)~SPI_DataSize_16b;\r
+ /* Set new DFF bit value */\r
+ SPIx->CR1 |= SPI_DataSize;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_TransmitCRC\r
-* Description : Transmit the SPIx CRC value.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
+/**\r
+ * @brief Transmit the SPIx CRC value.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @retval : None\r
+ */\r
void SPI_TransmitCRC(SPI_TypeDef* SPIx)\r
{\r
+ /* Check the parameters */\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ \r
/* Enable the selected SPI CRC transmission */\r
SPIx->CR1 |= CR1_CRCNext_Set;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_CalculateCRC\r
-* Description : Enables or disables the CRC value calculation of the\r
-* transfered bytes.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - NewState: new state of the SPIx CRC value calculation.\r
-* This parameter can be: ENABLE or DISABLE.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
+/**\r
+ * @brief Enables or disables the CRC value calculation of the\r
+ * transfered bytes.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param NewState: new state of the SPIx CRC value calculation.\r
+ * This parameter can be: ENABLE or DISABLE.\r
+ * @retval : None\r
+ */\r
void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)\r
{\r
/* Check the parameters */\r
- assert(IS_FUNCTIONAL_STATE(NewState));\r
-\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_FUNCTIONAL_STATE(NewState));\r
if (NewState != DISABLE)\r
{\r
/* Enable the selected SPI CRC calculation */\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_GetCRC\r
-* Description : Returns the transmit or the receive CRC register value for\r
-* the specified SPI.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_CRC: specifies the CRC register to be read.\r
-* This parameter can be one of the following values:\r
-* - SPI_CRC_Tx: Selects Tx CRC register\r
-* - SPI_CRC_Rx: Selects Rx CRC register\r
-* Output : None\r
-* Return : The selected CRC register value..\r
-*******************************************************************************/\r
-u16 SPI_GetCRC(SPI_TypeDef* SPIx, u8 SPI_CRC)\r
+/**\r
+ * @brief Returns the transmit or the receive CRC register value for\r
+ * the specified SPI.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param SPI_CRC: specifies the CRC register to be read.\r
+ * This parameter can be one of the following values:\r
+ * @arg SPI_CRC_Tx: Selects Tx CRC register\r
+ * @arg SPI_CRC_Rx: Selects Rx CRC register\r
+ * @retval : The selected CRC register value..\r
+ */\r
+uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC)\r
{\r
- u16 crcreg = 0;\r
-\r
+ uint16_t crcreg = 0;\r
/* Check the parameters */\r
- assert(IS_SPI_CRC(SPI_CRC));\r
-\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_CRC(SPI_CRC));\r
if (SPI_CRC != SPI_CRC_Rx)\r
{\r
/* Get the Tx CRC register */\r
/* Get the Rx CRC register */\r
crcreg = SPIx->RXCRCR;\r
}\r
-\r
/* Return the selected CRC register */\r
return crcreg;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_GetCRCPolynomial\r
-* Description : Returns the CRC Polynomial register value for the specified SPI.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* Output : None\r
-* Return : The CRC Polynomial register value.\r
-*******************************************************************************/\r
-u16 SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)\r
+/**\r
+ * @brief Returns the CRC Polynomial register value for the specified SPI.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @retval : The CRC Polynomial register value.\r
+ */\r
+uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)\r
{\r
+ /* Check the parameters */\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ \r
/* Return the CRC polynomial register */\r
return SPIx->CRCPR;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_BiDirectionalLineConfig\r
-* Description : Selects the data transfer direction in bi-directional mode\r
-* for the specified SPI.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_Direction: specifies the data transfer direction in\r
-* bi-directional mode. \r
-* This parameter can be one of the following values:\r
-* - SPI_Direction_Tx: Selects Tx transmission direction\r
-* - SPI_Direction_Rx: Selects Rx receive direction\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, u16 SPI_Direction)\r
+/**\r
+ * @brief Selects the data transfer direction in bi-directional mode\r
+ * for the specified SPI.\r
+ * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.\r
+ * @param SPI_Direction: specifies the data transfer direction in\r
+ * bi-directional mode. \r
+ * This parameter can be one of the following values:\r
+ * @arg SPI_Direction_Tx: Selects Tx transmission direction\r
+ * @arg SPI_Direction_Rx: Selects Rx receive direction\r
+ * @retval : None\r
+ */\r
+void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction)\r
{\r
/* Check the parameters */\r
- assert(IS_SPI_DIRECTION(SPI_Direction));\r
-\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_DIRECTION(SPI_Direction));\r
if (SPI_Direction == SPI_Direction_Tx)\r
{\r
/* Set the Tx only mode */\r
}\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_GetFlagStatus\r
-* Description : Checks whether the specified SPI flag is set or not.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_FLAG: specifies the flag to check. \r
-* This parameter can be one of the following values:\r
-* - SPI_FLAG_BSY: Busy flag.\r
-* - SPI_FLAG_OVR: Overrun flag.\r
-* - SPI_FLAG_MODF: Mode Fault flag.\r
-* - SPI_FLAG_CRCERR: CRC Error flag.\r
-* - SPI_FLAG_TXE: Transmit buffer empty flag.\r
-* - SPI_FLAG_RXNE: Receive buffer not empty flag.\r
-* Output : None\r
-* Return : The new state of SPI_FLAG (SET or RESET).\r
-*******************************************************************************/\r
-FlagStatus SPI_GetFlagStatus(SPI_TypeDef* SPIx, u16 SPI_FLAG)\r
+/**\r
+ * @brief Checks whether the specified SPI/I2S flag is set or not.\r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * 2 or 3 in I2S mode\r
+ * @param SPI_I2S_FLAG: specifies the SPI/I2S flag to check. \r
+ * This parameter can be one of the following values:\r
+ * @arg SPI_I2S_FLAG_TXE: Transmit buffer empty flag.\r
+ * @arg SPI_I2S_FLAG_RXNE: Receive buffer not empty flag.\r
+ * @arg SPI_I2S_FLAG_BSY: Busy flag.\r
+ * @arg SPI_I2S_FLAG_OVR: Overrun flag.\r
+ * @arg SPI_FLAG_MODF: Mode Fault flag.\r
+ * @arg SPI_FLAG_CRCERR: CRC Error flag.\r
+ * @arg I2S_FLAG_UDR: Underrun Error flag.\r
+ * @arg I2S_FLAG_CHSIDE: Channel Side flag.\r
+ * @retval : The new state of SPI_I2S_FLAG (SET or RESET).\r
+ */\r
+FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)\r
{\r
FlagStatus bitstatus = RESET;\r
-\r
/* Check the parameters */\r
- assert(IS_SPI_GET_FLAG(SPI_FLAG));\r
-\r
- /* Check the status of the specified SPI flag */\r
- if ((SPIx->SR & SPI_FLAG) != (u16)RESET)\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG));\r
+ /* Check the status of the specified SPI/I2S flag */\r
+ if ((SPIx->SR & SPI_I2S_FLAG) != (uint16_t)RESET)\r
{\r
- /* SPI_FLAG is set */\r
+ /* SPI_I2S_FLAG is set */\r
bitstatus = SET;\r
}\r
else\r
{\r
- /* SPI_FLAG is reset */\r
+ /* SPI_I2S_FLAG is reset */\r
bitstatus = RESET;\r
}\r
- /* Return the SPI_FLAG status */\r
+ /* Return the SPI_I2S_FLAG status */\r
return bitstatus;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_ClearFlag\r
-* Description : Clears the SPIx's pending flags.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_FLAG: specifies the flag to clear. \r
-* This parameter can be any combination of the following values:\r
-* - SPI_FLAG_OVR: Overrun flag.\r
-* - SPI_FLAG_MODF: Mode Fault flag.\r
-* - SPI_FLAG_CRCERR: CRC Error flag.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_ClearFlag(SPI_TypeDef* SPIx, u16 SPI_FLAG)\r
+/**\r
+ * @brief Clears the SPIx CRC Error (CRCERR) flag.\r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * @param SPI_I2S_FLAG: specifies the SPI flag to clear. \r
+ * This function clears only CRCERR flag.\r
+ * @note\r
+ * - OVR (OverRun error) flag is cleared by software sequence: a read \r
+ * operation to SPI_DR register (SPI_I2S_ReceiveData()) followed by a read \r
+ * operation to SPI_SR register (SPI_I2S_GetFlagStatus()).\r
+ * - UDR (UnderRun error) flag is cleared by a read operation to \r
+ * SPI_SR register (SPI_I2S_GetFlagStatus()).\r
+ * - MODF (Mode Fault) flag is cleared by software sequence: a read/write \r
+ * operation to SPI_SR register (SPI_I2S_GetFlagStatus()) followed by a \r
+ * write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).\r
+ * @retval : None\r
+ */\r
+void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)\r
{\r
/* Check the parameters */\r
- assert(IS_SPI_CLEAR_FLAG(SPI_FLAG));\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));\r
\r
- /* SPI_FLAG_MODF flag clear */\r
- if(SPI_FLAG == SPI_FLAG_MODF)\r
- {\r
- /* Read SR register */\r
- (void)SPIx->SR;\r
- /* Write on CR1 register */\r
- SPIx->CR1 |= CR1_SPE_Set; \r
- }\r
- /* SPI_FLAG_OVR flag clear */\r
- else if(SPI_FLAG == SPI_FLAG_OVR) \r
- {\r
- /* Read SR register */\r
- (void)SPIx->SR;\r
- }\r
- else /* SPI_FLAG_CRCERR flag clear */\r
- {\r
- /* Clear the selected SPI flag */\r
- SPIx->SR &= (u16)~SPI_FLAG;\r
- }\r
+ /* Clear the selected SPI CRC Error (CRCERR) flag */\r
+ SPIx->SR = (uint16_t)~SPI_I2S_FLAG;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_GetITStatus\r
-* Description : Checks whether the specified SPI interrupt has occurred or not.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_IT: specifies the SPI interrupt source to check. \r
-* This parameter can be one of the following values:\r
-* - SPI_IT_OVR: Overrun interrupt.\r
-* - SPI_IT_MODF: Mode Fault interrupt.\r
-* - SPI_IT_CRCERR: CRC Error interrupt.\r
-* - SPI_IT_TXE: Transmit buffer empty interrupt.\r
-* - SPI_IT_RXNE: Receive buffer not empty interrupt.\r
-* Output : None\r
-* Return : The new state of SPI_IT (SET or RESET).\r
-*******************************************************************************/\r
-ITStatus SPI_GetITStatus(SPI_TypeDef* SPIx, u8 SPI_IT)\r
+/**\r
+ * @brief Checks whether the specified SPI/I2S interrupt has occurred or not.\r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * 2 or 3 in I2S mode\r
+ * @param SPI_I2S_IT: specifies the SPI/I2S interrupt source to check. \r
+ * This parameter can be one of the following values:\r
+ * @arg SPI_I2S_IT_TXE: Transmit buffer empty interrupt.\r
+ * @arg SPI_I2S_IT_RXNE: Receive buffer not empty interrupt.\r
+ * @arg SPI_I2S_IT_OVR: Overrun interrupt.\r
+ * @arg SPI_IT_MODF: Mode Fault interrupt.\r
+ * @arg SPI_IT_CRCERR: CRC Error interrupt.\r
+ * @arg I2S_IT_UDR: Underrun Error interrupt.\r
+ * @retval : The new state of SPI_I2S_IT (SET or RESET).\r
+ */\r
+ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)\r
{\r
ITStatus bitstatus = RESET;\r
- u16 itpos = 0, itmask = 0, enablestatus = 0;\r
-\r
+ uint16_t itpos = 0, itmask = 0, enablestatus = 0;\r
/* Check the parameters */\r
- assert(IS_SPI_GET_IT(SPI_IT));\r
-\r
- /* Get the SPI IT index */\r
- itpos = (u16)((u16)0x01 << (SPI_IT & (u8)0x0F));\r
-\r
- /* Get the SPI IT index */\r
- itmask = SPI_IT >> 4;\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT));\r
+ /* Get the SPI/I2S IT index */\r
+ itpos = (uint16_t)((uint16_t)0x01 << (SPI_I2S_IT & (uint8_t)0x0F));\r
+ /* Get the SPI/I2S IT mask */\r
+ itmask = SPI_I2S_IT >> 4;\r
/* Set the IT mask */\r
- itmask = (u16)((u16)0x01 << itmask);\r
- /* Get the SPI_IT enable bit status */\r
+ itmask = (uint16_t)((uint16_t)0x01 << itmask);\r
+ /* Get the SPI_I2S_IT enable bit status */\r
enablestatus = (SPIx->CR2 & itmask) ;\r
-\r
- /* Check the status of the specified SPI interrupt */\r
- if (((SPIx->SR & itpos) != (u16)RESET) && enablestatus)\r
+ /* Check the status of the specified SPI/I2S interrupt */\r
+ if (((SPIx->SR & itpos) != (uint16_t)RESET) && enablestatus)\r
{\r
- /* SPI_IT is set */\r
+ /* SPI_I2S_IT is set */\r
bitstatus = SET;\r
}\r
else\r
{\r
- /* SPI_IT is reset */\r
+ /* SPI_I2S_IT is reset */\r
bitstatus = RESET;\r
}\r
- /* Return the SPI_IT status */\r
+ /* Return the SPI_I2S_IT status */\r
return bitstatus;\r
}\r
\r
-/*******************************************************************************\r
-* Function Name : SPI_ClearITPendingBit\r
-* Description : Clears the SPI\92s interrupt pending bits.\r
-* Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.\r
-* - SPI_IT: specifies the SPI interrupt pending bit to clear.\r
-* This parameter can be one of the following values:\r
-* - SPI_IT_OVR: Overrun interrupt.\r
-* - SPI_IT_MODF: Mode Fault interrupt.\r
-* - SPI_IT_CRCERR: CRC Error interrupt.\r
-* Output : None\r
-* Return : None\r
-*******************************************************************************/\r
-void SPI_ClearITPendingBit(SPI_TypeDef* SPIx, u8 SPI_IT)\r
+/**\r
+ * @brief Clears the SPIx CRC Error (CRCERR) interrupt pending bit.\r
+ * @param SPIx: where x can be :\r
+ * 1, 2 or 3 in SPI mode \r
+ * @param SPI_I2S_IT: specifies the SPI interrupt pending bit to clear.\r
+ * This function clears only CRCERR intetrrupt pending bit. \r
+ * @note\r
+ * - OVR (OverRun Error) interrupt pending bit is cleared by software \r
+ * sequence: a read operation to SPI_DR register (SPI_I2S_ReceiveData()) \r
+ * followed by a read operation to SPI_SR register (SPI_I2S_GetITStatus()).\r
+ * - UDR (UnderRun Error) interrupt pending bit is cleared by a read \r
+ * operation to SPI_SR register (SPI_I2S_GetITStatus()).\r
+ * - MODF (Mode Fault) interrupt pending bit is cleared by software sequence:\r
+ * a read/write operation to SPI_SR register (SPI_I2S_GetITStatus()) \r
+ * followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable \r
+ * the SPI).\r
+ * @retval : None\r
+ */\r
+void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)\r
{\r
- u16 itpos = 0;\r
-\r
+ uint16_t itpos = 0;\r
/* Check the parameters */\r
- assert(IS_SPI_CLEAR_IT(SPI_IT));\r
-\r
- /* SPI_IT_MODF pending bit clear */\r
- if(SPI_IT == SPI_IT_MODF)\r
- {\r
- /* Read SR register */\r
- (void)SPIx->SR;\r
- /* Write on CR1 register */\r
- SPIx->CR1 |= CR1_SPE_Set; \r
- }\r
- else if(SPI_IT == SPI_IT_OVR) /* SPI_IT_OVR pending bit clear */ \r
- {\r
- /* Read SR register */\r
- (void)(SPIx->SR);\r
- }\r
- else /* SPI_IT_CRCERR pending bit clear */\r
- {\r
- /* Get the SPI IT index */\r
- itpos = (u16)((u16)0x01 << (SPI_IT & (u8)0x0F));\r
- /* Clear the selected SPI interrupt pending bits */\r
- SPIx->SR &= (u16)~itpos;\r
- }\r
+ assert_param(IS_SPI_ALL_PERIPH(SPIx));\r
+ assert_param(IS_SPI_I2S_CLEAR_IT(SPI_I2S_IT));\r
+ /* Get the SPI IT index */\r
+ itpos = (uint16_t)((uint16_t)0x01 << (SPI_I2S_IT & (uint8_t)0x0F));\r
+ /* Clear the selected SPI CRC Error (CRCERR) interrupt pending bit */\r
+ SPIx->SR = (uint16_t)~itpos;\r
}\r
+/**\r
+ * @}\r
+ */ \r
+\r
+/**\r
+ * @}\r
+ */ \r
+\r
+/**\r
+ * @}\r
+ */ \r
\r
-/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/\r
+/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/\r