You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

134 lines
4.4 KiB

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