1 /**
2 ******************************************************************************
3 * @file stm32f0xx_hal_spi_ex.c
4 * @author MCD Application Team
5 * @brief Extended SPI HAL module driver.
6 * This file provides firmware functions to manage the following
7 * SPI peripheral extended functionalities :
8 * + IO operation functions
9 *
10 ******************************************************************************
11 * @attention
12 *
13 * Copyright (c) 2016 STMicroelectronics.
14 * All rights reserved.
15 *
16 * This software is licensed under terms that can be found in the LICENSE file
17 * in the root directory of this software component.
18 * If no LICENSE file comes with this software, it is provided AS-IS.
19 *
20 ******************************************************************************
21 */
22
23 /* Includes ------------------------------------------------------------------*/
24 #include "stm32f0xx_hal.h"
25
26 /** @addtogroup STM32F0xx_HAL_Driver
27 * @{
28 */
29
30 /** @defgroup SPIEx SPIEx
31 * @brief SPI Extended HAL module driver
32 * @{
33 */
34 #ifdef HAL_SPI_MODULE_ENABLED
35
36 /* Private typedef -----------------------------------------------------------*/
37 /* Private defines -----------------------------------------------------------*/
38 /** @defgroup SPIEx_Private_Constants SPIEx Private Constants
39 * @{
40 */
41 #define SPI_FIFO_SIZE 4UL
42 /**
43 * @}
44 */
45
46 /* Private macros ------------------------------------------------------------*/
47 /* Private variables ---------------------------------------------------------*/
48 /* Private function prototypes -----------------------------------------------*/
49 /* Exported functions --------------------------------------------------------*/
50
51 /** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
52 * @{
53 */
54
55 /** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
56 * @brief Data transfers functions
57 *
58 @verbatim
59 ==============================================================================
60 ##### IO operation functions #####
61 ===============================================================================
62 [..]
63 This subsection provides a set of extended functions to manage the SPI
64 data transfers.
65
66 (#) Rx data flush function:
67 (++) HAL_SPIEx_FlushRxFifo()
68
69 @endverbatim
70 * @{
71 */
72
73 /**
74 * @brief Flush the RX fifo.
75 * @param hspi pointer to a SPI_HandleTypeDef structure that contains
76 * the configuration information for the specified SPI module.
77 * @retval HAL status
78 */
HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef * hspi)79 HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi)
80 {
81 __IO uint32_t tmpreg;
82 uint8_t count = 0U;
83 while ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY)
84 {
85 count++;
86 tmpreg = hspi->Instance->DR;
87 UNUSED(tmpreg); /* To avoid GCC warning */
88 if (count == SPI_FIFO_SIZE)
89 {
90 return HAL_TIMEOUT;
91 }
92 }
93 return HAL_OK;
94 }
95
96 /**
97 * @}
98 */
99
100 /**
101 * @}
102 */
103
104 #endif /* HAL_SPI_MODULE_ENABLED */
105
106 /**
107 * @}
108 */
109
110 /**
111 * @}
112 */
113