训练营PLSR题目
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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