STM32L486xx HAL User Manual
stm32l4xx_hal_spi_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_spi_ex.c
00004   * @author  MCD Application Team
00005   * @brief   Extended SPI HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          SPI peripheral extended functionalities :
00008   *           + IO operation functions
00009   *
00010   ******************************************************************************
00011   * @attention
00012   *
00013   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00014   *
00015   * Redistribution and use in source and binary forms, with or without modification,
00016   * are permitted provided that the following conditions are met:
00017   *   1. Redistributions of source code must retain the above copyright notice,
00018   *      this list of conditions and the following disclaimer.
00019   *   2. Redistributions in binary form must reproduce the above copyright notice,
00020   *      this list of conditions and the following disclaimer in the documentation
00021   *      and/or other materials provided with the distribution.
00022   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00023   *      may be used to endorse or promote products derived from this software
00024   *      without specific prior written permission.
00025   *
00026   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00029   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00030   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00032   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00034   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036   *
00037   ******************************************************************************
00038   */
00039 
00040 /* Includes ------------------------------------------------------------------*/
00041 #include "stm32l4xx_hal.h"
00042 
00043 /** @addtogroup STM32L4xx_HAL_Driver
00044   * @{
00045   */
00046 
00047 /** @defgroup SPIEx SPIEx
00048   * @brief SPI Extended HAL module driver
00049   * @{
00050   */
00051 #ifdef HAL_SPI_MODULE_ENABLED
00052 
00053 /* Private typedef -----------------------------------------------------------*/
00054 /* Private defines -----------------------------------------------------------*/
00055 /** @defgroup SPIEx_Private_Constants SPIEx Private Constants
00056   * @{
00057   */
00058 #define SPI_FIFO_SIZE       4
00059 /**
00060   * @}
00061   */
00062 
00063 /* Private macros ------------------------------------------------------------*/
00064 /* Private variables ---------------------------------------------------------*/
00065 /* Private function prototypes -----------------------------------------------*/
00066 /* Exported functions --------------------------------------------------------*/
00067 
00068 /** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
00069   * @{
00070   */
00071 
00072 /** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
00073   *  @brief   Data transfers functions
00074   *
00075 @verbatim
00076   ==============================================================================
00077                       ##### IO operation functions #####
00078  ===============================================================================
00079  [..]
00080     This subsection provides a set of extended functions to manage the SPI
00081     data transfers.
00082 
00083     (#) Rx data flush function:
00084         (++) HAL_SPIEx_FlushRxFifo()
00085 
00086 @endverbatim
00087   * @{
00088   */
00089 
00090 /**
00091   * @brief  Flush the RX fifo.
00092   * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
00093   *               the configuration information for the specified SPI module.
00094   * @retval HAL status
00095   */
00096 HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi)
00097 {
00098   __IO uint32_t tmpreg;
00099   uint8_t  count = 0U;
00100   while ((hspi->Instance->SR & SPI_FLAG_FRLVL) !=  SPI_FRLVL_EMPTY)
00101   {
00102     count++;
00103     tmpreg = hspi->Instance->DR;
00104     UNUSED(tmpreg); /* To avoid GCC warning */
00105     if (count == SPI_FIFO_SIZE)
00106     {
00107       return HAL_TIMEOUT;
00108     }
00109   }
00110   return HAL_OK;
00111 }
00112 
00113 /**
00114   * @}
00115   */
00116 
00117 /**
00118   * @}
00119   */
00120 
00121 #endif /* HAL_SPI_MODULE_ENABLED */
00122 
00123 /**
00124   * @}
00125   */
00126 
00127 /**
00128   * @}
00129   */
00130 
00131 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/