stm32g0xx_hal_spi_ex.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_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) 2018 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. /* Includes ------------------------------------------------------------------*/
  23. #include "stm32g0xx_hal.h"
  24. /** @addtogroup STM32G0xx_HAL_Driver
  25. * @{
  26. */
  27. /** @defgroup SPIEx SPIEx
  28. * @brief SPI Extended HAL module driver
  29. * @{
  30. */
  31. #ifdef HAL_SPI_MODULE_ENABLED
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* Private defines -----------------------------------------------------------*/
  34. /** @defgroup SPIEx_Private_Constants SPIEx Private Constants
  35. * @{
  36. */
  37. #define SPI_FIFO_SIZE 4UL
  38. /**
  39. * @}
  40. */
  41. /* Private macros ------------------------------------------------------------*/
  42. /* Private variables ---------------------------------------------------------*/
  43. /* Private function prototypes -----------------------------------------------*/
  44. /* Exported functions --------------------------------------------------------*/
  45. /** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
  46. * @{
  47. */
  48. /** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
  49. * @brief Data transfers functions
  50. *
  51. @verbatim
  52. ==============================================================================
  53. ##### IO operation functions #####
  54. ===============================================================================
  55. [..]
  56. This subsection provides a set of extended functions to manage the SPI
  57. data transfers.
  58. (#) Rx data flush function:
  59. (++) HAL_SPIEx_FlushRxFifo()
  60. @endverbatim
  61. * @{
  62. */
  63. /**
  64. * @brief Flush the RX fifo.
  65. * @param hspi pointer to a SPI_HandleTypeDef structure that contains
  66. * the configuration information for the specified SPI module.
  67. * @retval HAL status
  68. */
  69. HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(const SPI_HandleTypeDef *hspi)
  70. {
  71. __IO uint32_t tmpreg;
  72. uint8_t count = 0U;
  73. while ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY)
  74. {
  75. count++;
  76. tmpreg = hspi->Instance->DR;
  77. UNUSED(tmpreg); /* To avoid GCC warning */
  78. if (count == SPI_FIFO_SIZE)
  79. {
  80. return HAL_TIMEOUT;
  81. }
  82. }
  83. return HAL_OK;
  84. }
  85. /**
  86. * @}
  87. */
  88. /**
  89. * @}
  90. */
  91. #endif /* HAL_SPI_MODULE_ENABLED */
  92. /**
  93. * @}
  94. */
  95. /**
  96. * @}
  97. */