Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

1648 righe
52 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_spdifrx.c
  4. * @author MCD Application Team
  5. * @brief This file provides firmware functions to manage the following
  6. * functionalities of the SPDIFRX audio interface:
  7. * + Initialization and Configuration
  8. * + Data transfers functions
  9. * + DMA transfers management
  10. * + Interrupts and flags management
  11. *
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * Copyright (c) 2016 STMicroelectronics.
  16. * All rights reserved.
  17. *
  18. * This software is licensed under terms that can be found in the LICENSE file
  19. * in the root directory of this software component.
  20. * If no LICENSE file comes with this software, it is provided AS-IS.
  21. *
  22. ******************************************************************************
  23. @verbatim
  24. ===============================================================================
  25. ##### How to use this driver #####
  26. ===============================================================================
  27. [..]
  28. The SPDIFRX HAL driver can be used as follow:
  29. (#) Declare SPDIFRX_HandleTypeDef handle structure.
  30. (#) Initialize the SPDIFRX low level resources by implement the HAL_SPDIFRX_MspInit() API:
  31. (##) Enable the SPDIFRX interface clock.
  32. (##) SPDIFRX pins configuration:
  33. (+++) Enable the clock for the SPDIFRX GPIOs.
  34. (+++) Configure these SPDIFRX pins as alternate function pull-up.
  35. (##) NVIC configuration if you need to use interrupt process (HAL_SPDIFRX_ReceiveControlFlow_IT() and
  36. HAL_SPDIFRX_ReceiveDataFlow_IT() API's).
  37. (+++) Configure the SPDIFRX interrupt priority.
  38. (+++) Enable the NVIC SPDIFRX IRQ handle.
  39. (##) DMA Configuration if you need to use DMA process (HAL_SPDIFRX_ReceiveDataFlow_DMA() and
  40. HAL_SPDIFRX_ReceiveControlFlow_DMA() API's).
  41. (+++) Declare a DMA handle structure for the reception of the Data Flow channel.
  42. (+++) Declare a DMA handle structure for the reception of the Control Flow channel.
  43. (+++) Enable the DMAx interface clock.
  44. (+++) Configure the declared DMA handle structure CtrlRx/DataRx with the required parameters.
  45. (+++) Configure the DMA Channel.
  46. (+++) Associate the initialized DMA handle to the SPDIFRX DMA CtrlRx/DataRx handle.
  47. (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the
  48. DMA CtrlRx/DataRx channel.
  49. (#) Program the input selection, re-tries number, wait for activity, channel status selection, data format,
  50. stereo mode and masking of user bits using HAL_SPDIFRX_Init() function.
  51. -@- The specific SPDIFRX interrupts (RXNE/CSRNE and Error Interrupts) will be managed using the macros
  52. __SPDIFRX_ENABLE_IT() and __SPDIFRX_DISABLE_IT() inside the receive process.
  53. -@- Make sure that ck_spdif clock is configured.
  54. (#) Three operation modes are available within this driver :
  55. *** Polling mode for reception operation (for debug purpose) ***
  56. ================================================================
  57. [..]
  58. (+) Receive data flow in blocking mode using HAL_SPDIFRX_ReceiveDataFlow()
  59. (+) Receive control flow of data in blocking mode using HAL_SPDIFRX_ReceiveControlFlow()
  60. *** Interrupt mode for reception operation ***
  61. =========================================
  62. [..]
  63. (+) Receive an amount of data (Data Flow) in non blocking mode using HAL_SPDIFRX_ReceiveDataFlow_IT()
  64. (+) Receive an amount of data (Control Flow) in non blocking mode using HAL_SPDIFRX_ReceiveControlFlow_IT()
  65. (+) At reception end of half transfer HAL_SPDIFRX_RxHalfCpltCallback is executed and user can
  66. add his own code by customization of function pointer HAL_SPDIFRX_RxHalfCpltCallback
  67. (+) At reception end of transfer HAL_SPDIFRX_RxCpltCallback is executed and user can
  68. add his own code by customization of function pointer HAL_SPDIFRX_RxCpltCallback
  69. (+) In case of transfer Error, HAL_SPDIFRX_ErrorCallback() function is executed and user can
  70. add his own code by customization of function pointer HAL_SPDIFRX_ErrorCallback
  71. *** DMA mode for reception operation ***
  72. ========================================
  73. [..]
  74. (+) Receive an amount of data (Data Flow) in non blocking mode (DMA) using HAL_SPDIFRX_ReceiveDataFlow_DMA()
  75. (+) Receive an amount of data (Control Flow) in non blocking mode (DMA) using HAL_SPDIFRX_ReceiveControlFlow_DMA()
  76. (+) At reception end of half transfer HAL_SPDIFRX_RxHalfCpltCallback is executed and user can
  77. add his own code by customization of function pointer HAL_SPDIFRX_RxHalfCpltCallback
  78. (+) At reception end of transfer HAL_SPDIFRX_RxCpltCallback is executed and user can
  79. add his own code by customization of function pointer HAL_SPDIFRX_RxCpltCallback
  80. (+) In case of transfer Error, HAL_SPDIFRX_ErrorCallback() function is executed and user can
  81. add his own code by customization of function pointer HAL_SPDIFRX_ErrorCallback
  82. (+) Stop the DMA Transfer using HAL_SPDIFRX_DMAStop()
  83. *** SPDIFRX HAL driver macros list ***
  84. =============================================
  85. [..]
  86. Below the list of most used macros in SPDIFRX HAL driver.
  87. (+) __HAL_SPDIFRX_IDLE: Disable the specified SPDIFRX peripheral (IDLE State)
  88. (+) __HAL_SPDIFRX_SYNC: Enable the synchronization state of the specified SPDIFRX peripheral (SYNC State)
  89. (+) __HAL_SPDIFRX_RCV: Enable the receive state of the specified SPDIFRX peripheral (RCV State)
  90. (+) __HAL_SPDIFRX_ENABLE_IT : Enable the specified SPDIFRX interrupts
  91. (+) __HAL_SPDIFRX_DISABLE_IT : Disable the specified SPDIFRX interrupts
  92. (+) __HAL_SPDIFRX_GET_FLAG: Check whether the specified SPDIFRX flag is set or not.
  93. [..]
  94. (@) You can refer to the SPDIFRX HAL driver header file for more useful macros
  95. *** Callback registration ***
  96. =============================================
  97. The compilation define USE_HAL_SPDIFRX_REGISTER_CALLBACKS when set to 1
  98. allows the user to configure dynamically the driver callbacks.
  99. Use HAL_SPDIFRX_RegisterCallback() function to register an interrupt callback.
  100. The HAL_SPDIFRX_RegisterCallback() function allows to register the following callbacks:
  101. (+) RxHalfCpltCallback : SPDIFRX Data flow half completed callback.
  102. (+) RxCpltCallback : SPDIFRX Data flow completed callback.
  103. (+) CxHalfCpltCallback : SPDIFRX Control flow half completed callback.
  104. (+) CxCpltCallback : SPDIFRX Control flow completed callback.
  105. (+) ErrorCallback : SPDIFRX error callback.
  106. (+) MspInitCallback : SPDIFRX MspInit.
  107. (+) MspDeInitCallback : SPDIFRX MspDeInit.
  108. This function takes as parameters the HAL peripheral handle, the Callback ID
  109. and a pointer to the user callback function.
  110. Use HAL_SPDIFRX_UnRegisterCallback() function to reset a callback to the default
  111. weak function.
  112. The HAL_SPDIFRX_UnRegisterCallback() function takes as parameters the HAL peripheral handle,
  113. and the Callback ID.
  114. This function allows to reset the following callbacks:
  115. (+) RxHalfCpltCallback : SPDIFRX Data flow half completed callback.
  116. (+) RxCpltCallback : SPDIFRX Data flow completed callback.
  117. (+) CxHalfCpltCallback : SPDIFRX Control flow half completed callback.
  118. (+) CxCpltCallback : SPDIFRX Control flow completed callback.
  119. (+) ErrorCallback : SPDIFRX error callback.
  120. (+) MspInitCallback : SPDIFRX MspInit.
  121. (+) MspDeInitCallback : SPDIFRX MspDeInit.
  122. By default, after the HAL_SPDIFRX_Init() and when the state is HAL_SPDIFRX_STATE_RESET
  123. all callbacks are set to the corresponding weak functions :
  124. HAL_SPDIFRX_RxHalfCpltCallback() , HAL_SPDIFRX_RxCpltCallback(), HAL_SPDIFRX_CxHalfCpltCallback(),
  125. HAL_SPDIFRX_CxCpltCallback() and HAL_SPDIFRX_ErrorCallback()
  126. Exception done for MspInit and MspDeInit functions that are
  127. reset to the legacy weak function in the HAL_SPDIFRX_Init()/ HAL_SPDIFRX_DeInit() only when
  128. these callbacks pointers are NULL (not registered beforehand).
  129. If not, MspInit or MspDeInit callbacks pointers are not null, the HAL_SPDIFRX_Init() / HAL_SPDIFRX_DeInit()
  130. keep and use the user MspInit/MspDeInit functions (registered beforehand)
  131. Callbacks can be registered/unregistered in HAL_SPDIFRX_STATE_READY state only.
  132. Exception done MspInit/MspDeInit callbacks that can be registered/unregistered
  133. in HAL_SPDIFRX_STATE_READY or HAL_SPDIFRX_STATE_RESET state,
  134. thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  135. In that case first register the MspInit/MspDeInit user callbacks
  136. using HAL_SPDIFRX_RegisterCallback() before calling HAL_SPDIFRX_DeInit()
  137. or HAL_SPDIFRX_Init() function.
  138. When The compilation define USE_HAL_SPDIFRX_REGISTER_CALLBACKS is set to 0 or
  139. not defined, the callback registration feature is not available and all callbacks
  140. are set to the corresponding weak functions.
  141. @endverbatim
  142. */
  143. /* Includes ------------------------------------------------------------------*/
  144. #include "stm32f4xx_hal.h"
  145. /** @addtogroup STM32F4xx_HAL_Driver
  146. * @{
  147. */
  148. /** @defgroup SPDIFRX SPDIFRX
  149. * @brief SPDIFRX HAL module driver
  150. * @{
  151. */
  152. #ifdef HAL_SPDIFRX_MODULE_ENABLED
  153. #if defined (SPDIFRX)
  154. #if defined(STM32F446xx)
  155. /* Private typedef -----------------------------------------------------------*/
  156. /* Private define ------------------------------------------------------------*/
  157. /** @defgroup SPDIFRX_Private_Defines SPDIFRX Private Defines
  158. * @{
  159. */
  160. #define SPDIFRX_TIMEOUT_VALUE 10U
  161. /**
  162. * @}
  163. */
  164. /* Private macro -------------------------------------------------------------*/
  165. /* Private variables ---------------------------------------------------------*/
  166. /* Private function prototypes -----------------------------------------------*/
  167. /** @addtogroup SPDIFRX_Private_Functions
  168. * @{
  169. */
  170. static void SPDIFRX_DMARxCplt(DMA_HandleTypeDef *hdma);
  171. static void SPDIFRX_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
  172. static void SPDIFRX_DMACxCplt(DMA_HandleTypeDef *hdma);
  173. static void SPDIFRX_DMACxHalfCplt(DMA_HandleTypeDef *hdma);
  174. static void SPDIFRX_DMAError(DMA_HandleTypeDef *hdma);
  175. static void SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif);
  176. static void SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif);
  177. static HAL_StatusTypeDef SPDIFRX_WaitOnFlagUntilTimeout(SPDIFRX_HandleTypeDef *hspdif, uint32_t Flag,
  178. FlagStatus Status, uint32_t Timeout, uint32_t tickstart);
  179. /**
  180. * @}
  181. */
  182. /* Exported functions ---------------------------------------------------------*/
  183. /** @defgroup SPDIFRX_Exported_Functions SPDIFRX Exported Functions
  184. * @{
  185. */
  186. /** @defgroup SPDIFRX_Exported_Functions_Group1 Initialization and de-initialization functions
  187. * @brief Initialization and Configuration functions
  188. *
  189. @verbatim
  190. ===============================================================================
  191. ##### Initialization and de-initialization functions #####
  192. ===============================================================================
  193. [..] This subsection provides a set of functions allowing to initialize and
  194. de-initialize the SPDIFRX peripheral:
  195. (+) User must Implement HAL_SPDIFRX_MspInit() function in which he configures
  196. all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
  197. (+) Call the function HAL_SPDIFRX_Init() to configure the SPDIFRX peripheral with
  198. the selected configuration:
  199. (++) Input Selection (IN0, IN1,...)
  200. (++) Maximum allowed re-tries during synchronization phase
  201. (++) Wait for activity on SPDIF selected input
  202. (++) Channel status selection (from channel A or B)
  203. (++) Data format (LSB, MSB, ...)
  204. (++) Stereo mode
  205. (++) User bits masking (PT,C,U,V,...)
  206. (+) Call the function HAL_SPDIFRX_DeInit() to restore the default configuration
  207. of the selected SPDIFRXx peripheral.
  208. @endverbatim
  209. * @{
  210. */
  211. /**
  212. * @brief Initializes the SPDIFRX according to the specified parameters
  213. * in the SPDIFRX_InitTypeDef and create the associated handle.
  214. * @param hspdif SPDIFRX handle
  215. * @retval HAL status
  216. */
  217. HAL_StatusTypeDef HAL_SPDIFRX_Init(SPDIFRX_HandleTypeDef *hspdif)
  218. {
  219. uint32_t tmpreg;
  220. /* Check the SPDIFRX handle allocation */
  221. if (hspdif == NULL)
  222. {
  223. return HAL_ERROR;
  224. }
  225. /* Check the SPDIFRX parameters */
  226. assert_param(IS_STEREO_MODE(hspdif->Init.StereoMode));
  227. assert_param(IS_SPDIFRX_INPUT_SELECT(hspdif->Init.InputSelection));
  228. assert_param(IS_SPDIFRX_MAX_RETRIES(hspdif->Init.Retries));
  229. assert_param(IS_SPDIFRX_WAIT_FOR_ACTIVITY(hspdif->Init.WaitForActivity));
  230. assert_param(IS_SPDIFRX_CHANNEL(hspdif->Init.ChannelSelection));
  231. assert_param(IS_SPDIFRX_DATA_FORMAT(hspdif->Init.DataFormat));
  232. assert_param(IS_PREAMBLE_TYPE_MASK(hspdif->Init.PreambleTypeMask));
  233. assert_param(IS_CHANNEL_STATUS_MASK(hspdif->Init.ChannelStatusMask));
  234. assert_param(IS_VALIDITY_MASK(hspdif->Init.ValidityBitMask));
  235. assert_param(IS_PARITY_ERROR_MASK(hspdif->Init.ParityErrorMask));
  236. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  237. if (hspdif->State == HAL_SPDIFRX_STATE_RESET)
  238. {
  239. /* Allocate lock resource and initialize it */
  240. hspdif->Lock = HAL_UNLOCKED;
  241. hspdif->RxHalfCpltCallback = HAL_SPDIFRX_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
  242. hspdif->RxCpltCallback = HAL_SPDIFRX_RxCpltCallback; /* Legacy weak RxCpltCallback */
  243. hspdif->CxHalfCpltCallback = HAL_SPDIFRX_CxHalfCpltCallback; /* Legacy weak CxHalfCpltCallback */
  244. hspdif->CxCpltCallback = HAL_SPDIFRX_CxCpltCallback; /* Legacy weak CxCpltCallback */
  245. hspdif->ErrorCallback = HAL_SPDIFRX_ErrorCallback; /* Legacy weak ErrorCallback */
  246. if (hspdif->MspInitCallback == NULL)
  247. {
  248. hspdif->MspInitCallback = HAL_SPDIFRX_MspInit; /* Legacy weak MspInit */
  249. }
  250. /* Init the low level hardware */
  251. hspdif->MspInitCallback(hspdif);
  252. }
  253. #else
  254. if (hspdif->State == HAL_SPDIFRX_STATE_RESET)
  255. {
  256. /* Allocate lock resource and initialize it */
  257. hspdif->Lock = HAL_UNLOCKED;
  258. /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
  259. HAL_SPDIFRX_MspInit(hspdif);
  260. }
  261. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  262. /* SPDIFRX peripheral state is BUSY */
  263. hspdif->State = HAL_SPDIFRX_STATE_BUSY;
  264. /* Disable SPDIFRX interface (IDLE State) */
  265. __HAL_SPDIFRX_IDLE(hspdif);
  266. /* Reset the old SPDIFRX CR configuration */
  267. tmpreg = hspdif->Instance->CR;
  268. tmpreg &= ~(SPDIFRX_CR_RXSTEO | SPDIFRX_CR_DRFMT | SPDIFRX_CR_PMSK |
  269. SPDIFRX_CR_VMSK | SPDIFRX_CR_CUMSK | SPDIFRX_CR_PTMSK |
  270. SPDIFRX_CR_CHSEL | SPDIFRX_CR_NBTR | SPDIFRX_CR_WFA |
  271. SPDIFRX_CR_INSEL);
  272. /* Sets the new configuration of the SPDIFRX peripheral */
  273. tmpreg |= (hspdif->Init.StereoMode |
  274. hspdif->Init.InputSelection |
  275. hspdif->Init.Retries |
  276. hspdif->Init.WaitForActivity |
  277. hspdif->Init.ChannelSelection |
  278. hspdif->Init.DataFormat |
  279. hspdif->Init.PreambleTypeMask |
  280. hspdif->Init.ChannelStatusMask |
  281. hspdif->Init.ValidityBitMask |
  282. hspdif->Init.ParityErrorMask
  283. );
  284. hspdif->Instance->CR = tmpreg;
  285. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
  286. /* SPDIFRX peripheral state is READY*/
  287. hspdif->State = HAL_SPDIFRX_STATE_READY;
  288. return HAL_OK;
  289. }
  290. /**
  291. * @brief DeInitializes the SPDIFRX peripheral
  292. * @param hspdif SPDIFRX handle
  293. * @retval HAL status
  294. */
  295. HAL_StatusTypeDef HAL_SPDIFRX_DeInit(SPDIFRX_HandleTypeDef *hspdif)
  296. {
  297. /* Check the SPDIFRX handle allocation */
  298. if (hspdif == NULL)
  299. {
  300. return HAL_ERROR;
  301. }
  302. /* Check the parameters */
  303. assert_param(IS_SPDIFRX_ALL_INSTANCE(hspdif->Instance));
  304. hspdif->State = HAL_SPDIFRX_STATE_BUSY;
  305. /* Disable SPDIFRX interface (IDLE state) */
  306. __HAL_SPDIFRX_IDLE(hspdif);
  307. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  308. if (hspdif->MspDeInitCallback == NULL)
  309. {
  310. hspdif->MspDeInitCallback = HAL_SPDIFRX_MspDeInit; /* Legacy weak MspDeInit */
  311. }
  312. /* DeInit the low level hardware */
  313. hspdif->MspDeInitCallback(hspdif);
  314. #else
  315. /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
  316. HAL_SPDIFRX_MspDeInit(hspdif);
  317. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  318. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
  319. /* SPDIFRX peripheral state is RESET*/
  320. hspdif->State = HAL_SPDIFRX_STATE_RESET;
  321. /* Release Lock */
  322. __HAL_UNLOCK(hspdif);
  323. return HAL_OK;
  324. }
  325. /**
  326. * @brief SPDIFRX MSP Init
  327. * @param hspdif SPDIFRX handle
  328. * @retval None
  329. */
  330. __weak void HAL_SPDIFRX_MspInit(SPDIFRX_HandleTypeDef *hspdif)
  331. {
  332. /* Prevent unused argument(s) compilation warning */
  333. UNUSED(hspdif);
  334. /* NOTE : This function Should not be modified, when the callback is needed,
  335. the HAL_SPDIFRX_MspInit could be implemented in the user file
  336. */
  337. }
  338. /**
  339. * @brief SPDIFRX MSP DeInit
  340. * @param hspdif SPDIFRX handle
  341. * @retval None
  342. */
  343. __weak void HAL_SPDIFRX_MspDeInit(SPDIFRX_HandleTypeDef *hspdif)
  344. {
  345. /* Prevent unused argument(s) compilation warning */
  346. UNUSED(hspdif);
  347. /* NOTE : This function Should not be modified, when the callback is needed,
  348. the HAL_SPDIFRX_MspDeInit could be implemented in the user file
  349. */
  350. }
  351. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  352. /**
  353. * @brief Register a User SPDIFRX Callback
  354. * To be used instead of the weak predefined callback
  355. * @param hspdif SPDIFRX handle
  356. * @param CallbackID ID of the callback to be registered
  357. * This parameter can be one of the following values:
  358. * @arg @ref HAL_SPDIFRX_RX_HALF_CB_ID SPDIFRX Data flow half completed callback ID
  359. * @arg @ref HAL_SPDIFRX_RX_CPLT_CB_ID SPDIFRX Data flow completed callback ID
  360. * @arg @ref HAL_SPDIFRX_CX_HALF_CB_ID SPDIFRX Control flow half completed callback ID
  361. * @arg @ref HAL_SPDIFRX_CX_CPLT_CB_ID SPDIFRX Control flow completed callback ID
  362. * @arg @ref HAL_SPDIFRX_ERROR_CB_ID SPDIFRX error callback ID
  363. * @arg @ref HAL_SPDIFRX_MSPINIT_CB_ID MspInit callback ID
  364. * @arg @ref HAL_SPDIFRX_MSPDEINIT_CB_ID MspDeInit callback ID
  365. * @param pCallback pointer to the Callback function
  366. * @retval HAL status
  367. */
  368. HAL_StatusTypeDef HAL_SPDIFRX_RegisterCallback(SPDIFRX_HandleTypeDef *hspdif, HAL_SPDIFRX_CallbackIDTypeDef CallbackID,
  369. pSPDIFRX_CallbackTypeDef pCallback)
  370. {
  371. HAL_StatusTypeDef status = HAL_OK;
  372. if (pCallback == NULL)
  373. {
  374. /* Update the error code */
  375. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_INVALID_CALLBACK;
  376. return HAL_ERROR;
  377. }
  378. /* Process locked */
  379. __HAL_LOCK(hspdif);
  380. if (HAL_SPDIFRX_STATE_READY == hspdif->State)
  381. {
  382. switch (CallbackID)
  383. {
  384. case HAL_SPDIFRX_RX_HALF_CB_ID :
  385. hspdif->RxHalfCpltCallback = pCallback;
  386. break;
  387. case HAL_SPDIFRX_RX_CPLT_CB_ID :
  388. hspdif->RxCpltCallback = pCallback;
  389. break;
  390. case HAL_SPDIFRX_CX_HALF_CB_ID :
  391. hspdif->CxHalfCpltCallback = pCallback;
  392. break;
  393. case HAL_SPDIFRX_CX_CPLT_CB_ID :
  394. hspdif->CxCpltCallback = pCallback;
  395. break;
  396. case HAL_SPDIFRX_ERROR_CB_ID :
  397. hspdif->ErrorCallback = pCallback;
  398. break;
  399. case HAL_SPDIFRX_MSPINIT_CB_ID :
  400. hspdif->MspInitCallback = pCallback;
  401. break;
  402. case HAL_SPDIFRX_MSPDEINIT_CB_ID :
  403. hspdif->MspDeInitCallback = pCallback;
  404. break;
  405. default :
  406. /* Update the error code */
  407. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_INVALID_CALLBACK;
  408. /* Return error status */
  409. status = HAL_ERROR;
  410. break;
  411. }
  412. }
  413. else if (HAL_SPDIFRX_STATE_RESET == hspdif->State)
  414. {
  415. switch (CallbackID)
  416. {
  417. case HAL_SPDIFRX_MSPINIT_CB_ID :
  418. hspdif->MspInitCallback = pCallback;
  419. break;
  420. case HAL_SPDIFRX_MSPDEINIT_CB_ID :
  421. hspdif->MspDeInitCallback = pCallback;
  422. break;
  423. default :
  424. /* Update the error code */
  425. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_INVALID_CALLBACK;
  426. /* Return error status */
  427. status = HAL_ERROR;
  428. break;
  429. }
  430. }
  431. else
  432. {
  433. /* Update the error code */
  434. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_INVALID_CALLBACK;
  435. /* Return error status */
  436. status = HAL_ERROR;
  437. }
  438. /* Release Lock */
  439. __HAL_UNLOCK(hspdif);
  440. return status;
  441. }
  442. /**
  443. * @brief Unregister a SPDIFRX Callback
  444. * SPDIFRX callback is redirected to the weak predefined callback
  445. * @param hspdif SPDIFRX handle
  446. * @param CallbackID ID of the callback to be unregistered
  447. * This parameter can be one of the following values:
  448. * @arg @ref HAL_SPDIFRX_RX_HALF_CB_ID SPDIFRX Data flow half completed callback ID
  449. * @arg @ref HAL_SPDIFRX_RX_CPLT_CB_ID SPDIFRX Data flow completed callback ID
  450. * @arg @ref HAL_SPDIFRX_CX_HALF_CB_ID SPDIFRX Control flow half completed callback ID
  451. * @arg @ref HAL_SPDIFRX_CX_CPLT_CB_ID SPDIFRX Control flow completed callback ID
  452. * @arg @ref HAL_SPDIFRX_ERROR_CB_ID SPDIFRX error callback ID
  453. * @arg @ref HAL_SPDIFRX_MSPINIT_CB_ID MspInit callback ID
  454. * @arg @ref HAL_SPDIFRX_MSPDEINIT_CB_ID MspDeInit callback ID
  455. * @retval HAL status
  456. */
  457. HAL_StatusTypeDef HAL_SPDIFRX_UnRegisterCallback(SPDIFRX_HandleTypeDef *hspdif,
  458. HAL_SPDIFRX_CallbackIDTypeDef CallbackID)
  459. {
  460. HAL_StatusTypeDef status = HAL_OK;
  461. /* Process locked */
  462. __HAL_LOCK(hspdif);
  463. if (HAL_SPDIFRX_STATE_READY == hspdif->State)
  464. {
  465. switch (CallbackID)
  466. {
  467. case HAL_SPDIFRX_RX_HALF_CB_ID :
  468. hspdif->RxHalfCpltCallback = HAL_SPDIFRX_RxHalfCpltCallback;
  469. break;
  470. case HAL_SPDIFRX_RX_CPLT_CB_ID :
  471. hspdif->RxCpltCallback = HAL_SPDIFRX_RxCpltCallback;
  472. break;
  473. case HAL_SPDIFRX_CX_HALF_CB_ID :
  474. hspdif->CxHalfCpltCallback = HAL_SPDIFRX_CxHalfCpltCallback;
  475. break;
  476. case HAL_SPDIFRX_CX_CPLT_CB_ID :
  477. hspdif->CxCpltCallback = HAL_SPDIFRX_CxCpltCallback;
  478. break;
  479. case HAL_SPDIFRX_ERROR_CB_ID :
  480. hspdif->ErrorCallback = HAL_SPDIFRX_ErrorCallback;
  481. break;
  482. default :
  483. /* Update the error code */
  484. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_INVALID_CALLBACK;
  485. /* Return error status */
  486. status = HAL_ERROR;
  487. break;
  488. }
  489. }
  490. else if (HAL_SPDIFRX_STATE_RESET == hspdif->State)
  491. {
  492. switch (CallbackID)
  493. {
  494. case HAL_SPDIFRX_MSPINIT_CB_ID :
  495. hspdif->MspInitCallback = HAL_SPDIFRX_MspInit; /* Legacy weak MspInit */
  496. break;
  497. case HAL_SPDIFRX_MSPDEINIT_CB_ID :
  498. hspdif->MspDeInitCallback = HAL_SPDIFRX_MspDeInit; /* Legacy weak MspInit */
  499. break;
  500. default :
  501. /* Update the error code */
  502. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_INVALID_CALLBACK;
  503. /* Return error status */
  504. status = HAL_ERROR;
  505. break;
  506. }
  507. }
  508. else
  509. {
  510. /* Update the error code */
  511. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_INVALID_CALLBACK;
  512. /* Return error status */
  513. status = HAL_ERROR;
  514. }
  515. /* Release Lock */
  516. __HAL_UNLOCK(hspdif);
  517. return status;
  518. }
  519. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  520. /**
  521. * @brief Set the SPDIFRX data format according to the specified parameters in the SPDIFRX_InitTypeDef.
  522. * @param hspdif SPDIFRX handle
  523. * @param sDataFormat SPDIFRX data format
  524. * @retval HAL status
  525. */
  526. HAL_StatusTypeDef HAL_SPDIFRX_SetDataFormat(SPDIFRX_HandleTypeDef *hspdif, SPDIFRX_SetDataFormatTypeDef sDataFormat)
  527. {
  528. uint32_t tmpreg;
  529. /* Check the SPDIFRX handle allocation */
  530. if (hspdif == NULL)
  531. {
  532. return HAL_ERROR;
  533. }
  534. /* Check the SPDIFRX parameters */
  535. assert_param(IS_STEREO_MODE(sDataFormat.StereoMode));
  536. assert_param(IS_SPDIFRX_DATA_FORMAT(sDataFormat.DataFormat));
  537. assert_param(IS_PREAMBLE_TYPE_MASK(sDataFormat.PreambleTypeMask));
  538. assert_param(IS_CHANNEL_STATUS_MASK(sDataFormat.ChannelStatusMask));
  539. assert_param(IS_VALIDITY_MASK(sDataFormat.ValidityBitMask));
  540. assert_param(IS_PARITY_ERROR_MASK(sDataFormat.ParityErrorMask));
  541. /* Reset the old SPDIFRX CR configuration */
  542. tmpreg = hspdif->Instance->CR;
  543. if (((tmpreg & SPDIFRX_STATE_RCV) == SPDIFRX_STATE_RCV) &&
  544. (((tmpreg & SPDIFRX_CR_DRFMT) != sDataFormat.DataFormat) ||
  545. ((tmpreg & SPDIFRX_CR_RXSTEO) != sDataFormat.StereoMode)))
  546. {
  547. return HAL_ERROR;
  548. }
  549. tmpreg &= ~(SPDIFRX_CR_RXSTEO | SPDIFRX_CR_DRFMT | SPDIFRX_CR_PMSK |
  550. SPDIFRX_CR_VMSK | SPDIFRX_CR_CUMSK | SPDIFRX_CR_PTMSK);
  551. /* Configure the new data format */
  552. tmpreg |= (sDataFormat.StereoMode |
  553. sDataFormat.DataFormat |
  554. sDataFormat.PreambleTypeMask |
  555. sDataFormat.ChannelStatusMask |
  556. sDataFormat.ValidityBitMask |
  557. sDataFormat.ParityErrorMask);
  558. hspdif->Instance->CR = tmpreg;
  559. return HAL_OK;
  560. }
  561. /**
  562. * @}
  563. */
  564. /** @defgroup SPDIFRX_Exported_Functions_Group2 IO operation functions
  565. * @brief Data transfers functions
  566. *
  567. @verbatim
  568. ===============================================================================
  569. ##### IO operation functions #####
  570. ===============================================================================
  571. [..]
  572. This subsection provides a set of functions allowing to manage the SPDIFRX data
  573. transfers.
  574. (#) There is two mode of transfer:
  575. (++) Blocking mode : The communication is performed in the polling mode.
  576. The status of all data processing is returned by the same function
  577. after finishing transfer.
  578. (++) No-Blocking mode : The communication is performed using Interrupts
  579. or DMA. These functions return the status of the transfer start-up.
  580. The end of the data processing will be indicated through the
  581. dedicated SPDIFRX IRQ when using Interrupt mode or the DMA IRQ when
  582. using DMA mode.
  583. (#) Blocking mode functions are :
  584. (++) HAL_SPDIFRX_ReceiveDataFlow()
  585. (++) HAL_SPDIFRX_ReceiveControlFlow()
  586. (+@) Do not use blocking mode to receive both control and data flow at the same time.
  587. (#) No-Blocking mode functions with Interrupt are :
  588. (++) HAL_SPDIFRX_ReceiveControlFlow_IT()
  589. (++) HAL_SPDIFRX_ReceiveDataFlow_IT()
  590. (#) No-Blocking mode functions with DMA are :
  591. (++) HAL_SPDIFRX_ReceiveControlFlow_DMA()
  592. (++) HAL_SPDIFRX_ReceiveDataFlow_DMA()
  593. (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
  594. (++) HAL_SPDIFRX_RxCpltCallback()
  595. (++) HAL_SPDIFRX_CxCpltCallback()
  596. @endverbatim
  597. * @{
  598. */
  599. /**
  600. * @brief Receives an amount of data (Data Flow) in blocking mode.
  601. * @param hspdif pointer to SPDIFRX_HandleTypeDef structure that contains
  602. * the configuration information for SPDIFRX module.
  603. * @param pData Pointer to data buffer
  604. * @param Size Amount of data to be received
  605. * @param Timeout Timeout duration
  606. * @retval HAL status
  607. */
  608. HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size,
  609. uint32_t Timeout)
  610. {
  611. uint32_t tickstart;
  612. uint16_t sizeCounter = Size;
  613. uint32_t *pTmpBuf = pData;
  614. if ((pData == NULL) || (Size == 0U))
  615. {
  616. return HAL_ERROR;
  617. }
  618. if (hspdif->State == HAL_SPDIFRX_STATE_READY)
  619. {
  620. /* Process Locked */
  621. __HAL_LOCK(hspdif);
  622. hspdif->State = HAL_SPDIFRX_STATE_BUSY;
  623. /* Start synchronisation */
  624. __HAL_SPDIFRX_SYNC(hspdif);
  625. /* Get tick */
  626. tickstart = HAL_GetTick();
  627. /* Wait until SYNCD flag is set */
  628. if (SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, Timeout, tickstart) != HAL_OK)
  629. {
  630. return HAL_TIMEOUT;
  631. }
  632. /* Start reception */
  633. __HAL_SPDIFRX_RCV(hspdif);
  634. /* Receive data flow */
  635. while (sizeCounter > 0U)
  636. {
  637. /* Get tick */
  638. tickstart = HAL_GetTick();
  639. /* Wait until RXNE flag is set */
  640. if (SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_RXNE, RESET, Timeout, tickstart) != HAL_OK)
  641. {
  642. return HAL_TIMEOUT;
  643. }
  644. (*pTmpBuf) = hspdif->Instance->DR;
  645. pTmpBuf++;
  646. sizeCounter--;
  647. }
  648. /* SPDIFRX ready */
  649. hspdif->State = HAL_SPDIFRX_STATE_READY;
  650. /* Process Unlocked */
  651. __HAL_UNLOCK(hspdif);
  652. return HAL_OK;
  653. }
  654. else
  655. {
  656. return HAL_BUSY;
  657. }
  658. }
  659. /**
  660. * @brief Receives an amount of data (Control Flow) in blocking mode.
  661. * @param hspdif pointer to a SPDIFRX_HandleTypeDef structure that contains
  662. * the configuration information for SPDIFRX module.
  663. * @param pData Pointer to data buffer
  664. * @param Size Amount of data to be received
  665. * @param Timeout Timeout duration
  666. * @retval HAL status
  667. */
  668. HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size,
  669. uint32_t Timeout)
  670. {
  671. uint32_t tickstart;
  672. uint16_t sizeCounter = Size;
  673. uint32_t *pTmpBuf = pData;
  674. if ((pData == NULL) || (Size == 0U))
  675. {
  676. return HAL_ERROR;
  677. }
  678. if (hspdif->State == HAL_SPDIFRX_STATE_READY)
  679. {
  680. /* Process Locked */
  681. __HAL_LOCK(hspdif);
  682. hspdif->State = HAL_SPDIFRX_STATE_BUSY;
  683. /* Start synchronization */
  684. __HAL_SPDIFRX_SYNC(hspdif);
  685. /* Get tick */
  686. tickstart = HAL_GetTick();
  687. /* Wait until SYNCD flag is set */
  688. if (SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, Timeout, tickstart) != HAL_OK)
  689. {
  690. return HAL_TIMEOUT;
  691. }
  692. /* Start reception */
  693. __HAL_SPDIFRX_RCV(hspdif);
  694. /* Receive control flow */
  695. while (sizeCounter > 0U)
  696. {
  697. /* Get tick */
  698. tickstart = HAL_GetTick();
  699. /* Wait until CSRNE flag is set */
  700. if (SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_CSRNE, RESET, Timeout, tickstart) != HAL_OK)
  701. {
  702. return HAL_TIMEOUT;
  703. }
  704. (*pTmpBuf) = hspdif->Instance->CSR;
  705. pTmpBuf++;
  706. sizeCounter--;
  707. }
  708. /* SPDIFRX ready */
  709. hspdif->State = HAL_SPDIFRX_STATE_READY;
  710. /* Process Unlocked */
  711. __HAL_UNLOCK(hspdif);
  712. return HAL_OK;
  713. }
  714. else
  715. {
  716. return HAL_BUSY;
  717. }
  718. }
  719. /**
  720. * @brief Receive an amount of data (Data Flow) in non-blocking mode with Interrupt
  721. * @param hspdif SPDIFRX handle
  722. * @param pData a 32-bit pointer to the Receive data buffer.
  723. * @param Size number of data sample to be received .
  724. * @retval HAL status
  725. */
  726. HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
  727. {
  728. uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
  729. const HAL_SPDIFRX_StateTypeDef tempState = hspdif->State;
  730. if ((tempState == HAL_SPDIFRX_STATE_READY) || (tempState == HAL_SPDIFRX_STATE_BUSY_CX))
  731. {
  732. if ((pData == NULL) || (Size == 0U))
  733. {
  734. return HAL_ERROR;
  735. }
  736. /* Process Locked */
  737. __HAL_LOCK(hspdif);
  738. hspdif->pRxBuffPtr = pData;
  739. hspdif->RxXferSize = Size;
  740. hspdif->RxXferCount = Size;
  741. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
  742. /* Check if a receive process is ongoing or not */
  743. hspdif->State = HAL_SPDIFRX_STATE_BUSY_RX;
  744. /* Enable the SPDIFRX PE Error Interrupt */
  745. __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
  746. /* Enable the SPDIFRX OVR Error Interrupt */
  747. __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
  748. /* Enable the SPDIFRX RXNE interrupt */
  749. __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_RXNE);
  750. if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_RCV)
  751. {
  752. /* Start synchronization */
  753. __HAL_SPDIFRX_SYNC(hspdif);
  754. /* Wait until SYNCD flag is set */
  755. do
  756. {
  757. if (count == 0U)
  758. {
  759. /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt
  760. process */
  761. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
  762. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
  763. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
  764. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
  765. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
  766. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
  767. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
  768. hspdif->State = HAL_SPDIFRX_STATE_READY;
  769. /* Process Unlocked */
  770. __HAL_UNLOCK(hspdif);
  771. return HAL_TIMEOUT;
  772. }
  773. count--;
  774. } while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
  775. /* Start reception */
  776. __HAL_SPDIFRX_RCV(hspdif);
  777. }
  778. /* Process Unlocked */
  779. __HAL_UNLOCK(hspdif);
  780. return HAL_OK;
  781. }
  782. else
  783. {
  784. return HAL_BUSY;
  785. }
  786. }
  787. /**
  788. * @brief Receive an amount of data (Control Flow) with Interrupt
  789. * @param hspdif SPDIFRX handle
  790. * @param pData a 32-bit pointer to the Receive data buffer.
  791. * @param Size number of data sample (Control Flow) to be received
  792. * @retval HAL status
  793. */
  794. HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
  795. {
  796. uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
  797. const HAL_SPDIFRX_StateTypeDef tempState = hspdif->State;
  798. if ((tempState == HAL_SPDIFRX_STATE_READY) || (tempState == HAL_SPDIFRX_STATE_BUSY_RX))
  799. {
  800. if ((pData == NULL) || (Size == 0U))
  801. {
  802. return HAL_ERROR;
  803. }
  804. /* Process Locked */
  805. __HAL_LOCK(hspdif);
  806. hspdif->pCsBuffPtr = pData;
  807. hspdif->CsXferSize = Size;
  808. hspdif->CsXferCount = Size;
  809. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
  810. /* Check if a receive process is ongoing or not */
  811. hspdif->State = HAL_SPDIFRX_STATE_BUSY_CX;
  812. /* Enable the SPDIFRX PE Error Interrupt */
  813. __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
  814. /* Enable the SPDIFRX OVR Error Interrupt */
  815. __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
  816. /* Enable the SPDIFRX CSRNE interrupt */
  817. __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
  818. if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_RCV)
  819. {
  820. /* Start synchronization */
  821. __HAL_SPDIFRX_SYNC(hspdif);
  822. /* Wait until SYNCD flag is set */
  823. do
  824. {
  825. if (count == 0U)
  826. {
  827. /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt
  828. process */
  829. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
  830. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
  831. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
  832. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
  833. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
  834. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
  835. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
  836. hspdif->State = HAL_SPDIFRX_STATE_READY;
  837. /* Process Unlocked */
  838. __HAL_UNLOCK(hspdif);
  839. return HAL_TIMEOUT;
  840. }
  841. count--;
  842. } while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
  843. /* Start reception */
  844. __HAL_SPDIFRX_RCV(hspdif);
  845. }
  846. /* Process Unlocked */
  847. __HAL_UNLOCK(hspdif);
  848. return HAL_OK;
  849. }
  850. else
  851. {
  852. return HAL_BUSY;
  853. }
  854. }
  855. /**
  856. * @brief Receive an amount of data (Data Flow) mode with DMA
  857. * @param hspdif SPDIFRX handle
  858. * @param pData a 32-bit pointer to the Receive data buffer.
  859. * @param Size number of data sample to be received
  860. * @retval HAL status
  861. */
  862. HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow_DMA(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
  863. {
  864. uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
  865. const HAL_SPDIFRX_StateTypeDef tempState = hspdif->State;
  866. if ((pData == NULL) || (Size == 0U))
  867. {
  868. return HAL_ERROR;
  869. }
  870. if ((tempState == HAL_SPDIFRX_STATE_READY) || (tempState == HAL_SPDIFRX_STATE_BUSY_CX))
  871. {
  872. /* Process Locked */
  873. __HAL_LOCK(hspdif);
  874. hspdif->pRxBuffPtr = pData;
  875. hspdif->RxXferSize = Size;
  876. hspdif->RxXferCount = Size;
  877. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
  878. hspdif->State = HAL_SPDIFRX_STATE_BUSY_RX;
  879. /* Set the SPDIFRX Rx DMA Half transfer complete callback */
  880. hspdif->hdmaDrRx->XferHalfCpltCallback = SPDIFRX_DMARxHalfCplt;
  881. /* Set the SPDIFRX Rx DMA transfer complete callback */
  882. hspdif->hdmaDrRx->XferCpltCallback = SPDIFRX_DMARxCplt;
  883. /* Set the DMA error callback */
  884. hspdif->hdmaDrRx->XferErrorCallback = SPDIFRX_DMAError;
  885. /* Enable the DMA request */
  886. if (HAL_DMA_Start_IT(hspdif->hdmaDrRx, (uint32_t)&hspdif->Instance->DR, (uint32_t)hspdif->pRxBuffPtr, Size) !=
  887. HAL_OK)
  888. {
  889. /* Set SPDIFRX error */
  890. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_DMA;
  891. /* Set SPDIFRX state */
  892. hspdif->State = HAL_SPDIFRX_STATE_ERROR;
  893. /* Process Unlocked */
  894. __HAL_UNLOCK(hspdif);
  895. return HAL_ERROR;
  896. }
  897. /* Enable RXDMAEN bit in SPDIFRX CR register for data flow reception*/
  898. hspdif->Instance->CR |= SPDIFRX_CR_RXDMAEN;
  899. if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_RCV)
  900. {
  901. /* Start synchronization */
  902. __HAL_SPDIFRX_SYNC(hspdif);
  903. /* Wait until SYNCD flag is set */
  904. do
  905. {
  906. if (count == 0U)
  907. {
  908. /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt
  909. process */
  910. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
  911. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
  912. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
  913. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
  914. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
  915. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
  916. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
  917. hspdif->State = HAL_SPDIFRX_STATE_READY;
  918. /* Process Unlocked */
  919. __HAL_UNLOCK(hspdif);
  920. return HAL_TIMEOUT;
  921. }
  922. count--;
  923. } while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
  924. /* Start reception */
  925. __HAL_SPDIFRX_RCV(hspdif);
  926. }
  927. /* Process Unlocked */
  928. __HAL_UNLOCK(hspdif);
  929. return HAL_OK;
  930. }
  931. else
  932. {
  933. return HAL_BUSY;
  934. }
  935. }
  936. /**
  937. * @brief Receive an amount of data (Control Flow) with DMA
  938. * @param hspdif SPDIFRX handle
  939. * @param pData a 32-bit pointer to the Receive data buffer.
  940. * @param Size number of data (Control Flow) sample to be received
  941. * @retval HAL status
  942. */
  943. HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow_DMA(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
  944. {
  945. uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
  946. const HAL_SPDIFRX_StateTypeDef tempState = hspdif->State;
  947. if ((pData == NULL) || (Size == 0U))
  948. {
  949. return HAL_ERROR;
  950. }
  951. if ((tempState == HAL_SPDIFRX_STATE_READY) || (tempState == HAL_SPDIFRX_STATE_BUSY_RX))
  952. {
  953. hspdif->pCsBuffPtr = pData;
  954. hspdif->CsXferSize = Size;
  955. hspdif->CsXferCount = Size;
  956. /* Process Locked */
  957. __HAL_LOCK(hspdif);
  958. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
  959. hspdif->State = HAL_SPDIFRX_STATE_BUSY_CX;
  960. /* Set the SPDIFRX Rx DMA Half transfer complete callback */
  961. hspdif->hdmaCsRx->XferHalfCpltCallback = SPDIFRX_DMACxHalfCplt;
  962. /* Set the SPDIFRX Rx DMA transfer complete callback */
  963. hspdif->hdmaCsRx->XferCpltCallback = SPDIFRX_DMACxCplt;
  964. /* Set the DMA error callback */
  965. hspdif->hdmaCsRx->XferErrorCallback = SPDIFRX_DMAError;
  966. /* Enable the DMA request */
  967. if (HAL_DMA_Start_IT(hspdif->hdmaCsRx, (uint32_t)&hspdif->Instance->CSR, (uint32_t)hspdif->pCsBuffPtr, Size) !=
  968. HAL_OK)
  969. {
  970. /* Set SPDIFRX error */
  971. hspdif->ErrorCode = HAL_SPDIFRX_ERROR_DMA;
  972. /* Set SPDIFRX state */
  973. hspdif->State = HAL_SPDIFRX_STATE_ERROR;
  974. /* Process Unlocked */
  975. __HAL_UNLOCK(hspdif);
  976. return HAL_ERROR;
  977. }
  978. /* Enable CBDMAEN bit in SPDIFRX CR register for control flow reception*/
  979. hspdif->Instance->CR |= SPDIFRX_CR_CBDMAEN;
  980. if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_RCV)
  981. {
  982. /* Start synchronization */
  983. __HAL_SPDIFRX_SYNC(hspdif);
  984. /* Wait until SYNCD flag is set */
  985. do
  986. {
  987. if (count == 0U)
  988. {
  989. /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt
  990. process */
  991. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
  992. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
  993. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
  994. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
  995. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
  996. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
  997. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
  998. hspdif->State = HAL_SPDIFRX_STATE_READY;
  999. /* Process Unlocked */
  1000. __HAL_UNLOCK(hspdif);
  1001. return HAL_TIMEOUT;
  1002. }
  1003. count--;
  1004. } while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
  1005. /* Start reception */
  1006. __HAL_SPDIFRX_RCV(hspdif);
  1007. }
  1008. /* Process Unlocked */
  1009. __HAL_UNLOCK(hspdif);
  1010. return HAL_OK;
  1011. }
  1012. else
  1013. {
  1014. return HAL_BUSY;
  1015. }
  1016. }
  1017. /**
  1018. * @brief stop the audio stream receive from the Media.
  1019. * @param hspdif SPDIFRX handle
  1020. * @retval None
  1021. */
  1022. HAL_StatusTypeDef HAL_SPDIFRX_DMAStop(SPDIFRX_HandleTypeDef *hspdif)
  1023. {
  1024. /* Process Locked */
  1025. __HAL_LOCK(hspdif);
  1026. /* Disable the SPDIFRX DMA requests */
  1027. hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_RXDMAEN);
  1028. hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_CBDMAEN);
  1029. /* Disable the SPDIFRX DMA channel */
  1030. if (hspdif->hdmaDrRx != NULL)
  1031. {
  1032. __HAL_DMA_DISABLE(hspdif->hdmaDrRx);
  1033. }
  1034. if (hspdif->hdmaCsRx != NULL)
  1035. {
  1036. __HAL_DMA_DISABLE(hspdif->hdmaCsRx);
  1037. }
  1038. /* Disable SPDIFRX peripheral */
  1039. __HAL_SPDIFRX_IDLE(hspdif);
  1040. hspdif->State = HAL_SPDIFRX_STATE_READY;
  1041. /* Process Unlocked */
  1042. __HAL_UNLOCK(hspdif);
  1043. return HAL_OK;
  1044. }
  1045. /**
  1046. * @brief This function handles SPDIFRX interrupt request.
  1047. * @param hspdif SPDIFRX handle
  1048. * @retval HAL status
  1049. */
  1050. void HAL_SPDIFRX_IRQHandler(SPDIFRX_HandleTypeDef *hspdif)
  1051. {
  1052. uint32_t itFlag = hspdif->Instance->SR;
  1053. uint32_t itSource = hspdif->Instance->IMR;
  1054. /* SPDIFRX in mode Data Flow Reception */
  1055. if (((itFlag & SPDIFRX_FLAG_RXNE) == SPDIFRX_FLAG_RXNE) && ((itSource & SPDIFRX_IT_RXNE) == SPDIFRX_IT_RXNE))
  1056. {
  1057. __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_RXNE);
  1058. SPDIFRX_ReceiveDataFlow_IT(hspdif);
  1059. }
  1060. /* SPDIFRX in mode Control Flow Reception */
  1061. if (((itFlag & SPDIFRX_FLAG_CSRNE) == SPDIFRX_FLAG_CSRNE) && ((itSource & SPDIFRX_IT_CSRNE) == SPDIFRX_IT_CSRNE))
  1062. {
  1063. __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_CSRNE);
  1064. SPDIFRX_ReceiveControlFlow_IT(hspdif);
  1065. }
  1066. /* SPDIFRX Overrun error interrupt occurred */
  1067. if (((itFlag & SPDIFRX_FLAG_OVR) == SPDIFRX_FLAG_OVR) && ((itSource & SPDIFRX_IT_OVRIE) == SPDIFRX_IT_OVRIE))
  1068. {
  1069. __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_OVRIE);
  1070. /* Change the SPDIFRX error code */
  1071. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_OVR;
  1072. /* the transfer is not stopped */
  1073. HAL_SPDIFRX_ErrorCallback(hspdif);
  1074. }
  1075. /* SPDIFRX Parity error interrupt occurred */
  1076. if (((itFlag & SPDIFRX_FLAG_PERR) == SPDIFRX_FLAG_PERR) && ((itSource & SPDIFRX_IT_PERRIE) == SPDIFRX_IT_PERRIE))
  1077. {
  1078. __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_PERRIE);
  1079. /* Change the SPDIFRX error code */
  1080. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_PE;
  1081. /* the transfer is not stopped */
  1082. HAL_SPDIFRX_ErrorCallback(hspdif);
  1083. }
  1084. }
  1085. /**
  1086. * @brief Rx Transfer (Data flow) half completed callbacks
  1087. * @param hspdif SPDIFRX handle
  1088. * @retval None
  1089. */
  1090. __weak void HAL_SPDIFRX_RxHalfCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
  1091. {
  1092. /* Prevent unused argument(s) compilation warning */
  1093. UNUSED(hspdif);
  1094. /* NOTE : This function Should not be modified, when the callback is needed,
  1095. the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
  1096. */
  1097. }
  1098. /**
  1099. * @brief Rx Transfer (Data flow) completed callbacks
  1100. * @param hspdif SPDIFRX handle
  1101. * @retval None
  1102. */
  1103. __weak void HAL_SPDIFRX_RxCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
  1104. {
  1105. /* Prevent unused argument(s) compilation warning */
  1106. UNUSED(hspdif);
  1107. /* NOTE : This function Should not be modified, when the callback is needed,
  1108. the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
  1109. */
  1110. }
  1111. /**
  1112. * @brief Rx (Control flow) Transfer half completed callbacks
  1113. * @param hspdif SPDIFRX handle
  1114. * @retval None
  1115. */
  1116. __weak void HAL_SPDIFRX_CxHalfCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
  1117. {
  1118. /* Prevent unused argument(s) compilation warning */
  1119. UNUSED(hspdif);
  1120. /* NOTE : This function Should not be modified, when the callback is needed,
  1121. the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
  1122. */
  1123. }
  1124. /**
  1125. * @brief Rx Transfer (Control flow) completed callbacks
  1126. * @param hspdif SPDIFRX handle
  1127. * @retval None
  1128. */
  1129. __weak void HAL_SPDIFRX_CxCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
  1130. {
  1131. /* Prevent unused argument(s) compilation warning */
  1132. UNUSED(hspdif);
  1133. /* NOTE : This function Should not be modified, when the callback is needed,
  1134. the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
  1135. */
  1136. }
  1137. /**
  1138. * @brief SPDIFRX error callbacks
  1139. * @param hspdif SPDIFRX handle
  1140. * @retval None
  1141. */
  1142. __weak void HAL_SPDIFRX_ErrorCallback(SPDIFRX_HandleTypeDef *hspdif)
  1143. {
  1144. /* Prevent unused argument(s) compilation warning */
  1145. UNUSED(hspdif);
  1146. /* NOTE : This function Should not be modified, when the callback is needed,
  1147. the HAL_SPDIFRX_ErrorCallback could be implemented in the user file
  1148. */
  1149. }
  1150. /**
  1151. * @}
  1152. */
  1153. /** @defgroup SPDIFRX_Exported_Functions_Group3 Peripheral State and Errors functions
  1154. * @brief Peripheral State functions
  1155. *
  1156. @verbatim
  1157. ===============================================================================
  1158. ##### Peripheral State and Errors functions #####
  1159. ===============================================================================
  1160. [..]
  1161. This subsection permit to get in run-time the status of the peripheral
  1162. and the data flow.
  1163. @endverbatim
  1164. * @{
  1165. */
  1166. /**
  1167. * @brief Return the SPDIFRX state
  1168. * @param hspdif SPDIFRX handle
  1169. * @retval HAL state
  1170. */
  1171. HAL_SPDIFRX_StateTypeDef HAL_SPDIFRX_GetState(SPDIFRX_HandleTypeDef const *const hspdif)
  1172. {
  1173. return hspdif->State;
  1174. }
  1175. /**
  1176. * @brief Return the SPDIFRX error code
  1177. * @param hspdif SPDIFRX handle
  1178. * @retval SPDIFRX Error Code
  1179. */
  1180. uint32_t HAL_SPDIFRX_GetError(SPDIFRX_HandleTypeDef const *const hspdif)
  1181. {
  1182. return hspdif->ErrorCode;
  1183. }
  1184. /**
  1185. * @}
  1186. */
  1187. /**
  1188. * @brief DMA SPDIFRX receive process (Data flow) complete callback
  1189. * @param hdma DMA handle
  1190. * @retval None
  1191. */
  1192. static void SPDIFRX_DMARxCplt(DMA_HandleTypeDef *hdma)
  1193. {
  1194. SPDIFRX_HandleTypeDef *hspdif = (SPDIFRX_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  1195. /* Disable Rx DMA Request */
  1196. if (hdma->Init.Mode != DMA_CIRCULAR)
  1197. {
  1198. hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_RXDMAEN);
  1199. hspdif->RxXferCount = 0;
  1200. hspdif->State = HAL_SPDIFRX_STATE_READY;
  1201. }
  1202. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  1203. hspdif->RxCpltCallback(hspdif);
  1204. #else
  1205. HAL_SPDIFRX_RxCpltCallback(hspdif);
  1206. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  1207. }
  1208. /**
  1209. * @brief DMA SPDIFRX receive process (Data flow) half complete callback
  1210. * @param hdma DMA handle
  1211. * @retval None
  1212. */
  1213. static void SPDIFRX_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
  1214. {
  1215. SPDIFRX_HandleTypeDef *hspdif = (SPDIFRX_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  1216. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  1217. hspdif->RxHalfCpltCallback(hspdif);
  1218. #else
  1219. HAL_SPDIFRX_RxHalfCpltCallback(hspdif);
  1220. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  1221. }
  1222. /**
  1223. * @brief DMA SPDIFRX receive process (Control flow) complete callback
  1224. * @param hdma DMA handle
  1225. * @retval None
  1226. */
  1227. static void SPDIFRX_DMACxCplt(DMA_HandleTypeDef *hdma)
  1228. {
  1229. SPDIFRX_HandleTypeDef *hspdif = (SPDIFRX_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  1230. /* Disable Cb DMA Request */
  1231. hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_CBDMAEN);
  1232. hspdif->CsXferCount = 0;
  1233. hspdif->State = HAL_SPDIFRX_STATE_READY;
  1234. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  1235. hspdif->CxCpltCallback(hspdif);
  1236. #else
  1237. HAL_SPDIFRX_CxCpltCallback(hspdif);
  1238. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  1239. }
  1240. /**
  1241. * @brief DMA SPDIFRX receive process (Control flow) half complete callback
  1242. * @param hdma DMA handle
  1243. * @retval None
  1244. */
  1245. static void SPDIFRX_DMACxHalfCplt(DMA_HandleTypeDef *hdma)
  1246. {
  1247. SPDIFRX_HandleTypeDef *hspdif = (SPDIFRX_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  1248. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  1249. hspdif->CxHalfCpltCallback(hspdif);
  1250. #else
  1251. HAL_SPDIFRX_CxHalfCpltCallback(hspdif);
  1252. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  1253. }
  1254. /**
  1255. * @brief DMA SPDIFRX communication error callback
  1256. * @param hdma DMA handle
  1257. * @retval None
  1258. */
  1259. static void SPDIFRX_DMAError(DMA_HandleTypeDef *hdma)
  1260. {
  1261. SPDIFRX_HandleTypeDef *hspdif = (SPDIFRX_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  1262. /* Disable Rx and Cb DMA Request */
  1263. hspdif->Instance->CR &= (uint16_t)(~(SPDIFRX_CR_RXDMAEN | SPDIFRX_CR_CBDMAEN));
  1264. hspdif->RxXferCount = 0;
  1265. hspdif->State = HAL_SPDIFRX_STATE_READY;
  1266. /* Set the error code and execute error callback*/
  1267. hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_DMA;
  1268. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  1269. /* The transfer is not stopped */
  1270. hspdif->ErrorCallback(hspdif);
  1271. #else
  1272. /* The transfer is not stopped */
  1273. HAL_SPDIFRX_ErrorCallback(hspdif);
  1274. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  1275. }
  1276. /**
  1277. * @brief Receive an amount of data (Data Flow) with Interrupt
  1278. * @param hspdif SPDIFRX handle
  1279. * @retval None
  1280. */
  1281. static void SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif)
  1282. {
  1283. /* Receive data */
  1284. (*hspdif->pRxBuffPtr) = hspdif->Instance->DR;
  1285. hspdif->pRxBuffPtr++;
  1286. hspdif->RxXferCount--;
  1287. if (hspdif->RxXferCount == 0U)
  1288. {
  1289. /* Disable RXNE/PE and OVR interrupts */
  1290. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE | SPDIFRX_IT_PERRIE | SPDIFRX_IT_RXNE);
  1291. hspdif->State = HAL_SPDIFRX_STATE_READY;
  1292. /* Process Unlocked */
  1293. __HAL_UNLOCK(hspdif);
  1294. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  1295. hspdif->RxCpltCallback(hspdif);
  1296. #else
  1297. HAL_SPDIFRX_RxCpltCallback(hspdif);
  1298. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  1299. }
  1300. }
  1301. /**
  1302. * @brief Receive an amount of data (Control Flow) with Interrupt
  1303. * @param hspdif SPDIFRX handle
  1304. * @retval None
  1305. */
  1306. static void SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif)
  1307. {
  1308. /* Receive data */
  1309. (*hspdif->pCsBuffPtr) = hspdif->Instance->CSR;
  1310. hspdif->pCsBuffPtr++;
  1311. hspdif->CsXferCount--;
  1312. if (hspdif->CsXferCount == 0U)
  1313. {
  1314. /* Disable CSRNE interrupt */
  1315. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
  1316. hspdif->State = HAL_SPDIFRX_STATE_READY;
  1317. /* Process Unlocked */
  1318. __HAL_UNLOCK(hspdif);
  1319. #if (USE_HAL_SPDIFRX_REGISTER_CALLBACKS == 1)
  1320. hspdif->CxCpltCallback(hspdif);
  1321. #else
  1322. HAL_SPDIFRX_CxCpltCallback(hspdif);
  1323. #endif /* USE_HAL_SPDIFRX_REGISTER_CALLBACKS */
  1324. }
  1325. }
  1326. /**
  1327. * @brief This function handles SPDIFRX Communication Timeout.
  1328. * @param hspdif SPDIFRX handle
  1329. * @param Flag Flag checked
  1330. * @param Status Value of the flag expected
  1331. * @param Timeout Duration of the timeout
  1332. * @param tickstart Tick start value
  1333. * @retval HAL status
  1334. */
  1335. static HAL_StatusTypeDef SPDIFRX_WaitOnFlagUntilTimeout(SPDIFRX_HandleTypeDef *hspdif, uint32_t Flag,
  1336. FlagStatus Status, uint32_t Timeout, uint32_t tickstart)
  1337. {
  1338. /* Wait until flag is set */
  1339. while (__HAL_SPDIFRX_GET_FLAG(hspdif, Flag) == Status)
  1340. {
  1341. /* Check for the Timeout */
  1342. if (Timeout != HAL_MAX_DELAY)
  1343. {
  1344. if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
  1345. {
  1346. /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt
  1347. process */
  1348. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
  1349. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
  1350. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
  1351. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
  1352. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
  1353. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
  1354. __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
  1355. hspdif->State = HAL_SPDIFRX_STATE_READY;
  1356. /* Process Unlocked */
  1357. __HAL_UNLOCK(hspdif);
  1358. return HAL_TIMEOUT;
  1359. }
  1360. }
  1361. }
  1362. return HAL_OK;
  1363. }
  1364. /**
  1365. * @}
  1366. */
  1367. #endif /* STM32F446xx */
  1368. #endif /* SPDIFRX */
  1369. #endif /* HAL_SPDIFRX_MODULE_ENABLED */
  1370. /**
  1371. * @}
  1372. */
  1373. /**
  1374. * @}
  1375. */