stm32l4xx_hal_spi_ex.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "stm32l4xx_hal.h"
  41. /** @addtogroup STM32L4xx_HAL_Driver
  42. * @{
  43. */
  44. /** @defgroup SPIEx SPIEx
  45. * @brief SPI Extended HAL module driver
  46. * @{
  47. */
  48. #ifdef HAL_SPI_MODULE_ENABLED
  49. /* Private typedef -----------------------------------------------------------*/
  50. /* Private defines -----------------------------------------------------------*/
  51. /** @defgroup SPIEx_Private_Constants SPIEx Private Constants
  52. * @{
  53. */
  54. #define SPI_FIFO_SIZE 4
  55. /**
  56. * @}
  57. */
  58. /* Private macros ------------------------------------------------------------*/
  59. /* Private variables ---------------------------------------------------------*/
  60. /* Private function prototypes -----------------------------------------------*/
  61. /* Exported functions --------------------------------------------------------*/
  62. /** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
  63. * @{
  64. */
  65. /** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
  66. * @brief Data transfers functions
  67. *
  68. @verbatim
  69. ==============================================================================
  70. ##### IO operation functions #####
  71. ===============================================================================
  72. [..]
  73. This subsection provides a set of extended functions to manage the SPI
  74. data transfers.
  75. (#) Rx data flush function:
  76. (++) HAL_SPIEx_FlushRxFifo()
  77. @endverbatim
  78. * @{
  79. */
  80. /**
  81. * @brief Flush the RX fifo.
  82. * @param hspi pointer to a SPI_HandleTypeDef structure that contains
  83. * the configuration information for the specified SPI module.
  84. * @retval HAL status
  85. */
  86. HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi)
  87. {
  88. __IO uint32_t tmpreg;
  89. uint8_t count = 0U;
  90. while ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY)
  91. {
  92. count++;
  93. tmpreg = hspi->Instance->DR;
  94. UNUSED(tmpreg); /* To avoid GCC warning */
  95. if (count == SPI_FIFO_SIZE)
  96. {
  97. return HAL_TIMEOUT;
  98. }
  99. }
  100. return HAL_OK;
  101. }
  102. /**
  103. * @}
  104. */
  105. /**
  106. * @}
  107. */
  108. #endif /* HAL_SPI_MODULE_ENABLED */
  109. /**
  110. * @}
  111. */
  112. /**
  113. * @}
  114. */
  115. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/