STM32L443xx 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   * Copyright (c) 2017 STMicroelectronics.
00014   * All rights reserved.
00015   *
00016   * This software is licensed under terms that can be found in the LICENSE file
00017   * in the root directory of this software component.
00018   * If no LICENSE file comes with this software, it is provided AS-IS.
00019   *
00020   ******************************************************************************
00021   */
00022 
00023 /* Includes ------------------------------------------------------------------*/
00024 #include "stm32l4xx_hal.h"
00025 
00026 /** @addtogroup STM32L4xx_HAL_Driver
00027   * @{
00028   */
00029 
00030 /** @defgroup SPIEx SPIEx
00031   * @brief SPI Extended HAL module driver
00032   * @{
00033   */
00034 #ifdef HAL_SPI_MODULE_ENABLED
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private defines -----------------------------------------------------------*/
00038 /** @defgroup SPIEx_Private_Constants SPIEx Private Constants
00039   * @{
00040   */
00041 #define SPI_FIFO_SIZE       4UL
00042 /**
00043   * @}
00044   */
00045 
00046 /* Private macros ------------------------------------------------------------*/
00047 /* Private variables ---------------------------------------------------------*/
00048 /* Private function prototypes -----------------------------------------------*/
00049 /* Exported functions --------------------------------------------------------*/
00050 
00051 /** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
00052   * @{
00053   */
00054 
00055 /** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
00056   *  @brief   Data transfers functions
00057   *
00058 @verbatim
00059   ==============================================================================
00060                       ##### IO operation functions #####
00061  ===============================================================================
00062  [..]
00063     This subsection provides a set of extended functions to manage the SPI
00064     data transfers.
00065 
00066     (#) Rx data flush function:
00067         (++) HAL_SPIEx_FlushRxFifo()
00068 
00069 @endverbatim
00070   * @{
00071   */
00072 
00073 /**
00074   * @brief  Flush the RX fifo.
00075   * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
00076   *               the configuration information for the specified SPI module.
00077   * @retval HAL status
00078   */
00079 HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi)
00080 {
00081   __IO uint32_t tmpreg;
00082   uint8_t  count = 0U;
00083   while ((hspi->Instance->SR & SPI_FLAG_FRLVL) !=  SPI_FRLVL_EMPTY)
00084   {
00085     count++;
00086     tmpreg = hspi->Instance->DR;
00087     UNUSED(tmpreg); /* To avoid GCC warning */
00088     if (count == SPI_FIFO_SIZE)
00089     {
00090       return HAL_TIMEOUT;
00091     }
00092   }
00093   return HAL_OK;
00094 }
00095 
00096 /**
00097   * @}
00098   */
00099 
00100 /**
00101   * @}
00102   */
00103 
00104 #endif /* HAL_SPI_MODULE_ENABLED */
00105 
00106 /**
00107   * @}
00108   */
00109 
00110 /**
00111   * @}
00112   */