Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_pssi.c
blob11ab361e22eecc93c02be2e56671685544773d98
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_pssi.c
4 * @author MCD Application Team
5 * @brief PSSI HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Parallel Synchronous Slave Interface (PSSI) peripheral:
8 * + Initialization and de-initialization functions
9 * + IO operation functions
10 * + Peripheral State and Errors functions
12 @verbatim
13 ==============================================================================
14 ##### How to use this driver #####
15 ==============================================================================
16 [..]
17 The PSSI HAL driver can be used as follows:
19 (#) Declare a PSSI_HandleTypeDef handle structure, for example:
20 PSSI_HandleTypeDef hpssi;
22 (#) Initialize the PSSI low level resources by implementing the @ref HAL_PSSI_MspInit() API:
23 (##) Enable the PSSIx interface clock
24 (##) PSSI pins configuration
25 (+++) Enable the clock for the PSSI GPIOs
26 (+++) Configure PSSI pins as alternate function open-drain
27 (##) NVIC configuration if you need to use interrupt process
28 (+++) Configure the PSSIx interrupt priority
29 (+++) Enable the NVIC PSSI IRQ Channel
30 (##) DMA Configuration if you need to use DMA process
31 (+++) Declare DMA_HandleTypeDef handles structure for the transmit and receive
32 (+++) Enable the DMAx interface clock
33 (+++) Configure the DMA handle parameters
34 (+++) Configure the DMA Tx and Rx
35 (+++) Associate the initialized DMA handle to the hpssi DMA Tx and Rx handle
36 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
37 the DMA Tx and Rx
39 (#) Configure the Communication Bus Width, Control Signals, Input Polarity and Output Polarity
40 in the hpssi Init structure.
42 (#) Initialize the PSSI registers by calling the @ref HAL_PSSI_Init(), configure also the low level Hardware
43 (GPIO, CLOCK, NVIC...etc) by calling the customized @ref HAL_PSSI_MspInit(&hpssi) API.
46 (#) For PSSI IO operations, two operation modes are available within this driver :
48 *** Polling mode IO operation ***
49 =================================
50 [..]
51 (+) Transmit an amount of data by byte in blocking mode using @ref HAL_PSSI_Transmit()
52 (+) Receive an amount of data by byte in blocking mode using @ref HAL_PSSI_Receive()
54 *** DMA mode IO operation ***
55 ==============================
56 [..]
57 (+) Transmit an amount of data in non-blocking mode (DMA) using
58 @ref HAL_PSSI_Transmit_DMA()
59 (+) At transmission end of transfer, @ref HAL_PSSI_TxCpltCallback() is executed and user can
60 add his own code by customization of function pointer @ref HAL_PSSI_TxCpltCallback()
61 (+) Receive an amount of data in non-blocking mode (DMA) using
62 @ref HAL_PSSI_Receive_DMA()
63 (+) At reception end of transfer, @ref HAL_PSSI_RxCpltCallback() is executed and user can
64 add his own code by customization of function pointer @ref HAL_PSSI_RxCpltCallback()
65 (+) In case of transfer Error, @ref HAL_PSSI_ErrorCallback() function is executed and user can
66 add his own code by customization of function pointer @ref HAL_PSSI_ErrorCallback()
67 (+) Abort a PSSI process communication with Interrupt using @ref HAL_PSSI_Abort_IT()
68 (+) End of abort process, @ref HAL_PSSI_AbortCpltCallback() is executed and user can
69 add his own code by customization of function pointer @ref HAL_PSSI_AbortCpltCallback()
71 *** PSSI HAL driver macros list ***
72 ==================================
73 [..]
74 Below the list of most used macros in PSSI HAL driver.
76 (+) @ref HAL_PSSI_ENABLE : Enable the PSSI peripheral
77 (+) @ref HAL_PSSI_DISABLE : Disable the PSSI peripheral
78 (+) @ref HAL_PSSI_GET_FLAG : Check whether the specified PSSI flag is set or not
79 (+) @ref HAL_PSSI_CLEAR_FLAG : Clear the specified PSSI pending flag
80 (+) @ref HAL_PSSI_ENABLE_IT : Enable the specified PSSI interrupt
81 (+) @ref HAL_PSSI_DISABLE_IT : Disable the specified PSSI interrupt
83 *** Callback registration ***
84 =============================================
85 Use Functions @ref HAL_PSSI_RegisterCallback() or @ref HAL_PSSI_RegisterAddrCallback()
86 to register an interrupt callback.
88 Function @ref HAL_PSSI_RegisterCallback() allows to register following callbacks:
89 (+) TxCpltCallback : callback for transmission end of transfer.
90 (+) RxCpltCallback : callback for reception end of transfer.
91 (+) ErrorCallback : callback for error detection.
92 (+) AbortCpltCallback : callback for abort completion process.
93 (+) MspInitCallback : callback for Msp Init.
94 (+) MspDeInitCallback : callback for Msp DeInit.
95 This function takes as parameters the HAL peripheral handle, the Callback ID
96 and a pointer to the user callback function.
99 Use function @ref HAL_PSSI_UnRegisterCallback to reset a callback to the default
100 weak function.
101 @ref HAL_PSSI_UnRegisterCallback takes as parameters the HAL peripheral handle,
102 and the Callback ID.
103 This function allows to reset following callbacks:
104 (+) TxCpltCallback : callback for transmission end of transfer.
105 (+) RxCpltCallback : callback for reception end of transfer.
106 (+) ErrorCallback : callback for error detection.
107 (+) AbortCpltCallback : callback for abort completion process.
108 (+) MspInitCallback : callback for Msp Init.
109 (+) MspDeInitCallback : callback for Msp DeInit.
112 By default, after the @ref HAL_PSSI_Init() and when the state is @ref HAL_PSSI_STATE_RESET
113 all callbacks are set to the corresponding weak functions:
114 examples @ref HAL_PSSI_TxCpltCallback(), @ref HAL_PSSI_RxCpltCallback().
115 Exception done for MspInit and MspDeInit functions that are
116 reset to the legacy weak functions in the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit() only when
117 these callbacks are null (not registered beforehand).
118 If MspInit or MspDeInit are not null, the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit()
119 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
121 Callbacks can be registered/unregistered in @ref HAL_PSSI_STATE_READY state only.
122 Exception done MspInit/MspDeInit functions that can be registered/unregistered
123 in @ref HAL_PSSI_STATE_READY or @ref HAL_PSSI_STATE_RESET state,
124 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
125 Then, the user first registers the MspInit/MspDeInit user callbacks
126 using @ref HAL_PSSI_RegisterCallback() before calling @ref HAL_PSSI_DeInit()
127 or @ref HAL_PSSI_Init() function.
130 [..]
131 (@) You can refer to the PSSI HAL driver header file for more useful macros
133 @endverbatim
134 ******************************************************************************
135 * @attention
137 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
138 * All rights reserved.</center></h2>
140 * This software component is licensed by ST under BSD 3-Clause license,
141 * the "License"; You may not use this file except in compliance with the
142 * License. You may obtain a copy of the License at:
143 * opensource.org/licenses/BSD-3-Clause
145 ******************************************************************************
148 /* Includes ------------------------------------------------------------------*/
149 #include "stm32h7xx_hal.h"
151 /** @addtogroup STM32H7xx_HAL_Driver
152 * @{
155 /** @defgroup PSSI PSSI
156 * @brief PSSI HAL module driver
157 * @{
160 #ifdef HAL_PSSI_MODULE_ENABLED
161 #if defined(PSSI)
162 /* Private typedef -----------------------------------------------------------*/
163 /* Private define ------------------------------------------------------------*/
165 /** @defgroup PSSI_Private_Define PSSI Private Define
166 * @{
172 * @}
175 /* Private macro -------------------------------------------------------------*/
176 /* Private variables ---------------------------------------------------------*/
177 /* Private function prototypes -----------------------------------------------*/
179 /** @defgroup PSSI_Private_Functions PSSI Private Functions
180 * @{
182 /* Private functions to handle DMA transfer */
183 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
184 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
185 void PSSI_DMAError(DMA_HandleTypeDef *hdma);
186 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma);
188 /* Private functions to handle IT transfer */
189 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode);
191 /* Private functions to handle flags during polling transfer */
192 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart);
195 * @}
198 /* Exported functions --------------------------------------------------------*/
200 /** @defgroup PSSI_Exported_Functions PSSI Exported Functions
201 * @{
204 /** @defgroup PSSI_Exported_Functions_Group1 Initialization and de-initialization functions
205 * @brief Initialization and Configuration functions
207 @verbatim
208 ===============================================================================
209 ##### Initialization and de-initialization functions #####
210 ===============================================================================
211 [..] This subsection provides a set of functions allowing to initialize and
212 deinitialize the PSSIx peripheral:
214 (+) User must implement HAL_PSSI_MspInit() function in which he configures
215 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
217 (+) Call the function HAL_PSSI_Init() to configure the selected device with
218 the selected configuration:
219 (++) Data Width
220 (++) Control Signals
221 (++) Input Clock polarity
222 (++) Output Clock polarity
224 (+) Call the function HAL_PSSI_DeInit() to restore the default configuration
225 of the selected PSSIx peripheral.
227 @endverbatim
228 * @{
232 * @brief Initializes the PSSI according to the specified parameters
233 * in the PSSI_InitTypeDef and initialize the associated handle.
234 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
235 * the configuration information for the specified PSSI.
236 * @retval HAL status
238 HAL_StatusTypeDef HAL_PSSI_Init(PSSI_HandleTypeDef *hpssi)
240 /* Check the PSSI handle allocation */
241 if (hpssi == NULL)
243 return HAL_ERROR;
246 /* Check the parameters */
247 assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
248 assert_param(IS_PSSI_CONTROL_SIGNAL(hpssi->Init.ControlSignal));
249 assert_param(IS_PSSI_BUSWIDTH(hpssi->Init.BusWidth));
250 assert_param(IS_PSSI_CLOCK_POLARITY(hpssi->Init.ClockPolarity));
251 assert_param(IS_PSSI_DE_POLARITY(hpssi->Init.DataEnablePolarity));
252 assert_param(IS_PSSI_RDY_POLARITY(hpssi->Init.ReadyPolarity));
254 if (hpssi->State == HAL_PSSI_STATE_RESET)
256 /* Allocate lock resource and initialize it */
257 hpssi->Lock = HAL_UNLOCKED;
259 /* Init the PSSI Callback settings */
260 hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
261 hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
262 hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
263 hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
265 if (hpssi->MspInitCallback == NULL)
267 hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
270 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
271 hpssi->MspInitCallback(hpssi);
275 hpssi->State = HAL_PSSI_STATE_BUSY;
277 /* Disable the selected PSSI peripheral */
278 HAL_PSSI_DISABLE(hpssi);
280 /*---------------------------- PSSIx CR Configuration ----------------------*/
281 /* Configure PSSIx: Control Signal and Bus Width*/
283 MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DERDYCFG|PSSI_CR_EDM|PSSI_CR_DEPOL|PSSI_CR_RDYPOL,
284 hpssi->Init.ControlSignal|hpssi->Init.DataEnablePolarity|hpssi->Init.ReadyPolarity|hpssi->Init.BusWidth);
286 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
287 hpssi->State = HAL_PSSI_STATE_READY;
289 return HAL_OK;
293 * @brief DeInitialize the PSSI peripheral.
294 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
295 * the configuration information for the specified PSSI.
296 * @retval HAL status
298 HAL_StatusTypeDef HAL_PSSI_DeInit(PSSI_HandleTypeDef *hpssi)
300 /* Check the PSSI handle allocation */
301 if (hpssi == NULL)
303 return HAL_ERROR;
306 /* Check the parameters */
307 assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
309 hpssi->State = HAL_PSSI_STATE_BUSY;
311 /* Disable the PSSI Peripheral Clock */
312 HAL_PSSI_DISABLE(hpssi);
314 if (hpssi->MspDeInitCallback == NULL)
316 hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
319 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
320 hpssi->MspDeInitCallback(hpssi);
322 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
323 hpssi->State = HAL_PSSI_STATE_RESET;
325 /* Release Lock */
326 __HAL_UNLOCK(hpssi);
328 return HAL_OK;
332 * @brief Initialize the PSSI MSP.
333 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
334 * the configuration information for the specified PSSI.
335 * @retval None
337 __weak void HAL_PSSI_MspInit(PSSI_HandleTypeDef *hpssi)
339 /* Prevent unused argument(s) compilation warning */
340 UNUSED(hpssi);
342 /* NOTE : This function should not be modified, when the callback is needed,
343 the HAL_PSSI_MspInit can be implemented in the user file
348 * @brief DeInitialize the PSSI MSP.
349 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
350 * the configuration information for the specified PSSI.
351 * @retval None
353 __weak void HAL_PSSI_MspDeInit(PSSI_HandleTypeDef *hpssi)
355 /* Prevent unused argument(s) compilation warning */
356 UNUSED(hpssi);
358 /* NOTE : This function should not be modified, when the callback is needed,
359 the HAL_PSSI_MspDeInit can be implemented in the user file
364 * @brief Register a User PSSI Callback
365 * To be used instead of the weak predefined callback
366 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
367 * the configuration information for the specified PSSI.
368 * @param CallbackID ID of the callback to be registered
369 * This parameter can be one of the following values:
370 * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
371 * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
372 * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
373 * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
374 * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
375 * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
376 * @param pCallback pointer to the Callback function
377 * @retval HAL status
379 HAL_StatusTypeDef HAL_PSSI_RegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID, pPSSI_CallbackTypeDef pCallback)
381 HAL_StatusTypeDef status = HAL_OK;
383 if (pCallback == NULL)
385 /* Update the error code */
386 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
388 return HAL_ERROR;
390 /* Process locked */
391 __HAL_LOCK(hpssi);
393 if (HAL_PSSI_STATE_READY == hpssi->State)
395 switch (CallbackID)
397 case HAL_PSSI_TX_COMPLETE_CB_ID :
398 hpssi->TxCpltCallback = pCallback;
399 break;
401 case HAL_PSSI_RX_COMPLETE_CB_ID :
402 hpssi->RxCpltCallback = pCallback;
403 break;
405 case HAL_PSSI_ERROR_CB_ID :
406 hpssi->ErrorCallback = pCallback;
407 break;
409 case HAL_PSSI_ABORT_CB_ID :
410 hpssi->AbortCpltCallback = pCallback;
411 break;
413 case HAL_PSSI_MSPINIT_CB_ID :
414 hpssi->MspInitCallback = pCallback;
415 break;
417 case HAL_PSSI_MSPDEINIT_CB_ID :
418 hpssi->MspDeInitCallback = pCallback;
419 break;
421 default :
422 /* Update the error code */
423 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
425 /* Return error status */
426 status = HAL_ERROR;
427 break;
430 else if (HAL_PSSI_STATE_RESET == hpssi->State)
432 switch (CallbackID)
434 case HAL_PSSI_MSPINIT_CB_ID :
435 hpssi->MspInitCallback = pCallback;
436 break;
438 case HAL_PSSI_MSPDEINIT_CB_ID :
439 hpssi->MspDeInitCallback = pCallback;
440 break;
442 default :
443 /* Update the error code */
444 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
446 /* Return error status */
447 status = HAL_ERROR;
448 break;
451 else
453 /* Update the error code */
454 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
456 /* Return error status */
457 status = HAL_ERROR;
460 /* Release Lock */
461 __HAL_UNLOCK(hpssi);
462 return status;
466 * @brief Unregister an PSSI Callback
467 * PSSI callback is redirected to the weak predefined callback
468 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
469 * the configuration information for the specified PSSI.
470 * @param CallbackID ID of the callback to be unregistered
471 * This parameter can be one of the following values:
472 * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
473 * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
474 * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
475 * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
476 * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
477 * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
478 * @retval HAL status
480 HAL_StatusTypeDef HAL_PSSI_UnRegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID)
482 HAL_StatusTypeDef status = HAL_OK;
484 /* Process locked */
485 __HAL_LOCK(hpssi);
487 if (HAL_PSSI_STATE_READY == hpssi->State)
489 switch (CallbackID)
491 case HAL_PSSI_TX_COMPLETE_CB_ID :
492 hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
493 break;
495 case HAL_PSSI_RX_COMPLETE_CB_ID :
496 hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
497 break;
499 case HAL_PSSI_ERROR_CB_ID :
500 hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
501 break;
503 case HAL_PSSI_ABORT_CB_ID :
504 hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
505 break;
507 case HAL_PSSI_MSPINIT_CB_ID :
508 hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
509 break;
511 case HAL_PSSI_MSPDEINIT_CB_ID :
512 hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
513 break;
515 default :
516 /* Update the error code */
517 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
519 /* Return error status */
520 status = HAL_ERROR;
521 break;
524 else if (HAL_PSSI_STATE_RESET == hpssi->State)
526 switch (CallbackID)
528 case HAL_PSSI_MSPINIT_CB_ID :
529 hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
530 break;
532 case HAL_PSSI_MSPDEINIT_CB_ID :
533 hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
534 break;
536 default :
537 /* Update the error code */
538 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
540 /* Return error status */
541 status = HAL_ERROR;
542 break;
545 else
547 /* Update the error code */
548 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
550 /* Return error status */
551 status = HAL_ERROR;
554 /* Release Lock */
555 __HAL_UNLOCK(hpssi);
556 return status;
561 * @}
564 /** @defgroup PSSI_Exported_Functions_Group2 Input and Output operation functions
565 * @brief Data transfers functions
567 @verbatim
568 ===============================================================================
569 ##### IO operation functions #####
570 ===============================================================================
571 [..]
572 This subsection provides a set of functions allowing to manage the PSSI data
573 transfers.
575 (#) There are two modes of transfer:
576 (++) Blocking mode : The communication is performed in the polling mode.
577 The status of all data processing is returned by the same function
578 after finishing transfer.
579 (++) No-Blocking mode : The communication is performed using DMA.
580 These functions return the status of the transfer startup.
581 The end of the data processing will be indicated through the
582 dedicated the DMA IRQ .
584 (#) Blocking mode functions are :
585 (++) HAL_PSSI_Transmit()
586 (++) HAL_PSSI_Receive()
588 (#) No-Blocking mode functions with DMA are :
589 (++) HAL_PSSI_Transmit_DMA()
590 (++) HAL_PSSI_Receive_DMA()
592 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
593 (++) HAL_PSSI_TxCpltCallback()
594 (++) HAL_PSSI_RxCpltCallback()
595 (++) HAL_PSSI_ErrorCallback()
596 (++) HAL_PSSI_AbortCpltCallback()
598 @endverbatim
599 * @{
603 * @brief Transmits in master mode an amount of data in blocking mode.
604 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
605 * the configuration information for the specified PSSI.
606 * @param pData Pointer to data buffer
607 * @param Size Amount of data to be sent (in bytes)
608 * @param Timeout Timeout duration
609 * @retval HAL status
611 HAL_StatusTypeDef HAL_PSSI_Transmit(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
613 uint32_t tickstart;
614 uint32_t transfer_size = Size;
616 if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
617 ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size%2U) != 0U)) ||
618 ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size%4U) != 0U)))
620 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
621 return HAL_ERROR;
623 if (hpssi->State == HAL_PSSI_STATE_READY)
625 /* Process Locked */
626 __HAL_LOCK(hpssi);
628 hpssi->State = HAL_PSSI_STATE_BUSY;
629 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
631 /* Disable the selected PSSI peripheral */
632 HAL_PSSI_DISABLE(hpssi);
634 /* Configure transfer parameters */
635 hpssi->Instance->CR |= PSSI_CR_OUTEN_OUTPUT |
636 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL);
637 /* DMA Disable */
638 hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
640 /* Enable the selected PSSI peripheral */
641 HAL_PSSI_ENABLE(hpssi);
643 if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
645 uint8_t *pbuffer = pData;
646 while (transfer_size > 0U)
648 /* Init tickstart for timeout management*/
649 tickstart = HAL_GetTick();
650 /* Wait until Fifo is ready to transfer one byte flag is set */
651 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
653 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
654 hpssi->State = HAL_PSSI_STATE_READY;
655 /* Process Unlocked */
656 __HAL_UNLOCK(hpssi);
657 return HAL_ERROR;
659 /* Write data to DR */
660 *(__IO uint8_t *)(&hpssi->Instance->DR) = *(uint8_t *)pbuffer;
662 /* Increment Buffer pointer */
663 pbuffer++;
665 transfer_size--;
668 else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
670 uint16_t *pbuffer = (uint16_t *)pData;
671 while (transfer_size > 0U)
673 /* Init tickstart for timeout management*/
674 tickstart = HAL_GetTick();
675 /* Wait until Fifo is ready to transfer four bytes flag is set */
676 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
678 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
679 hpssi->State = HAL_PSSI_STATE_READY;
680 /* Process Unlocked */
681 __HAL_UNLOCK(hpssi);
682 return HAL_ERROR;
684 /* Write data to DR */
685 *(__IO uint16_t *)((uint32_t)(&hpssi->Instance->DR)) = *pbuffer;
687 /* Increment Buffer pointer */
688 pbuffer++;
689 transfer_size -= 2U;
693 else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
695 uint32_t *pbuffer = (uint32_t *)pData;
696 while (transfer_size > 0U)
698 /* Init tickstart for timeout management*/
699 tickstart = HAL_GetTick();
700 /* Wait until Fifo is ready to transfer four bytes flag is set */
701 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
703 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
704 hpssi->State = HAL_PSSI_STATE_READY;
705 /* Process Unlocked */
706 __HAL_UNLOCK(hpssi);
707 return HAL_ERROR;
709 /* Write data to DR */
710 *(__IO uint32_t *)(&hpssi->Instance->DR) = *pbuffer;
712 /* Increment Buffer pointer */
713 pbuffer++;
714 transfer_size -= 4U;
718 else
720 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
721 hpssi->State = HAL_PSSI_STATE_READY;
722 /* Process Unlocked */
723 __HAL_UNLOCK(hpssi);
724 return HAL_ERROR;
727 /* Check Errors Flags */
728 if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
730 HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
731 HAL_PSSI_DISABLE(hpssi);
732 hpssi->ErrorCode = HAL_PSSI_ERROR_UNDER_RUN;
733 hpssi->State = HAL_PSSI_STATE_READY;
734 /* Process Unlocked */
735 __HAL_UNLOCK(hpssi);
736 return HAL_ERROR;
739 hpssi->State = HAL_PSSI_STATE_READY;
741 /* Process Unlocked */
742 __HAL_UNLOCK(hpssi);
744 return HAL_OK;
746 else
748 return HAL_BUSY;
754 * @brief Receives an amount of data in blocking mode.
755 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
756 * the configuration information for the specified PSSI.
757 * @param pData Pointer to data buffer
758 * @param Size Amount of data to be received (in bytes)
759 * @param Timeout Timeout duration
760 * @retval HAL status
762 HAL_StatusTypeDef HAL_PSSI_Receive(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
764 uint32_t tickstart;
765 uint32_t transfer_size = Size;
767 if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
768 ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size%2U) != 0U)) ||
769 ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size%4U) != 0U)))
771 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
772 return HAL_ERROR;
775 if (hpssi->State == HAL_PSSI_STATE_READY)
777 /* Process Locked */
778 __HAL_LOCK(hpssi);
780 hpssi->State = HAL_PSSI_STATE_BUSY;
781 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
783 /* Disable the selected PSSI peripheral */
784 HAL_PSSI_DISABLE(hpssi);
785 /* Configure transfer parameters */
786 hpssi->Instance->CR |= PSSI_CR_OUTEN_INPUT |((hpssi->Init.ClockPolarity == HAL_PSSI_FALLING_EDGE)?0U:PSSI_CR_CKPOL);
789 /* DMA Disable */
790 hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
792 /* Enable the selected PSSI peripheral */
793 HAL_PSSI_ENABLE(hpssi);
794 if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
796 uint8_t *pbuffer = pData;
798 while (transfer_size > 0U)
800 /* Init tickstart for timeout management*/
801 tickstart = HAL_GetTick();
802 /* Wait until Fifo is ready to receive one byte flag is set */
803 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
805 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
806 hpssi->State = HAL_PSSI_STATE_READY;
807 /* Process Unlocked */
808 __HAL_UNLOCK(hpssi);
809 return HAL_ERROR;
811 /* Read data from DR */
812 *pbuffer = *(__IO uint8_t *)(&hpssi->Instance->DR);
813 pbuffer++;
814 transfer_size--;
817 else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
819 uint16_t *pbuffer = (uint16_t *)pData;
821 while (transfer_size > 0U)
823 /* Init tickstart for timeout management*/
824 tickstart = HAL_GetTick();
825 /* Wait until Fifo is ready to receive four bytes flag is set */
826 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
828 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
829 hpssi->State = HAL_PSSI_STATE_READY;
830 /* Process Unlocked */
831 __HAL_UNLOCK(hpssi);
832 return HAL_ERROR;
835 /* Read data from DR */
836 *pbuffer = *(__IO uint16_t *)((uint32_t)&hpssi->Instance->DR);
837 pbuffer++;
838 transfer_size -= 2U;
842 else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
844 uint32_t *pbuffer = (uint32_t *)pData;
846 while (transfer_size > 0U)
848 /* Init tickstart for timeout management*/
849 tickstart = HAL_GetTick();
850 /* Wait until Fifo is ready to receive four bytes flag is set */
851 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
853 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
854 hpssi->State = HAL_PSSI_STATE_READY;
855 /* Process Unlocked */
856 __HAL_UNLOCK(hpssi);
857 return HAL_ERROR;
860 /* Read data from DR */
861 *pbuffer = *(__IO uint32_t *)(&hpssi->Instance->DR);
862 pbuffer++;
863 transfer_size -= 4U;
867 else
869 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
870 hpssi->State = HAL_PSSI_STATE_READY;
871 /* Process Unlocked */
872 __HAL_UNLOCK(hpssi);
873 return HAL_ERROR;
875 /* Check Errors Flags */
877 if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
879 HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
880 hpssi->ErrorCode = HAL_PSSI_ERROR_OVER_RUN;
881 __HAL_UNLOCK(hpssi);
882 return HAL_ERROR;
886 hpssi->State = HAL_PSSI_STATE_READY;
888 /* Process Unlocked */
889 __HAL_UNLOCK(hpssi);
891 return HAL_OK;
893 else
895 return HAL_BUSY;
900 * @brief Transmit an amount of data in non-blocking mode with DMA
901 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
902 * the configuration information for the specified PSSI.
903 * @param pData Pointer to data buffer
904 * @param Size Amount of data to be sent (in bytes)
905 * @retval HAL status
907 HAL_StatusTypeDef HAL_PSSI_Transmit_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
909 HAL_StatusTypeDef dmaxferstatus;
911 if (hpssi->State == HAL_PSSI_STATE_READY)
914 /* Process Locked */
915 __HAL_LOCK(hpssi);
917 hpssi->State = HAL_PSSI_STATE_BUSY_TX;
918 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
920 /* Disable the selected PSSI peripheral */
921 HAL_PSSI_DISABLE(hpssi);
923 /* Prepare transfer parameters */
924 hpssi->pBuffPtr = pData;
925 hpssi->XferCount = Size;
927 if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
929 hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
931 else
933 hpssi->XferSize = hpssi->XferCount;
936 if (hpssi->XferSize > 0U)
938 if (hpssi->hdmatx != NULL)
941 /* Configure BusWidth */
942 if( hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
944 MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | PSSI_CR_OUTEN_OUTPUT |
945 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL));
947 else
949 MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth | PSSI_CR_OUTEN_OUTPUT |
950 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL));
953 /* Set the PSSI DMA transfer complete callback */
954 hpssi->hdmatx->XferCpltCallback = PSSI_DMATransmitCplt;
956 /* Set the DMA error callback */
957 hpssi->hdmatx->XferErrorCallback = PSSI_DMAError;
959 /* Set the unused DMA callbacks to NULL */
960 hpssi->hdmatx->XferHalfCpltCallback = NULL;
961 hpssi->hdmatx->XferAbortCallback = NULL;
963 /* Enable the DMA */
964 dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmatx, (uint32_t)pData, (uint32_t)&hpssi->Instance->DR, hpssi->XferSize);
966 else
968 /* Update PSSI state */
969 hpssi->State = HAL_PSSI_STATE_READY;
971 /* Update PSSI error code */
972 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
974 /* Process Unlocked */
975 __HAL_UNLOCK(hpssi);
977 return HAL_ERROR;
980 if (dmaxferstatus == HAL_OK)
984 /* Update XferCount value */
985 hpssi->XferCount -= hpssi->XferSize;
987 /* Process Unlocked */
988 __HAL_UNLOCK(hpssi);
990 /* Note : The PSSI interrupts must be enabled after unlocking current process
991 to avoid the risk of PSSI interrupt handle execution before current
992 process unlock */
993 /* Enable ERR interrupt */
994 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
996 /* Enable DMA Request */
997 hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
998 /* Enable the selected PSSI peripheral */
999 HAL_PSSI_ENABLE(hpssi);
1001 else
1003 /* Update PSSI state */
1004 hpssi->State = HAL_PSSI_STATE_READY;
1006 /* Update PSSI error code */
1007 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1009 /* Process Unlocked */
1010 __HAL_UNLOCK(hpssi);
1012 return HAL_ERROR;
1015 else
1017 /* Process Unlocked */
1018 __HAL_UNLOCK(hpssi);
1020 /* Note : The PSSI interrupts must be enabled after unlocking current process
1021 to avoid the risk of PSSI interrupt handle execution before current
1022 process unlock */
1023 /* Enable ERRinterrupt */
1024 /* possible to enable all of these */
1026 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1029 return HAL_OK;
1031 else
1033 return HAL_BUSY;
1038 * @brief Receive an amount of data in non-blocking mode with DMA
1039 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1040 * the configuration information for the specified PSSI.
1041 * @param pData Pointer to data buffer
1042 * @param Size Amount of data to be received (in bytes)
1043 * @retval HAL status
1045 HAL_StatusTypeDef HAL_PSSI_Receive_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
1048 HAL_StatusTypeDef dmaxferstatus;
1050 if (hpssi->State == HAL_PSSI_STATE_READY)
1053 /* Disable the selected PSSI peripheral */
1054 HAL_PSSI_DISABLE(hpssi);
1055 /* Process Locked */
1056 __HAL_LOCK(hpssi);
1058 hpssi->State = HAL_PSSI_STATE_BUSY_RX;
1059 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
1061 /* Prepare transfer parameters */
1062 hpssi->pBuffPtr = pData;
1063 hpssi->XferCount = Size;
1065 if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
1067 hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
1069 else
1071 hpssi->XferSize = hpssi->XferCount;
1074 if (hpssi->XferSize > 0U)
1076 if (hpssi->hdmarx != NULL)
1079 /* Configure BusWidth */
1080 if( hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
1082 MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE |
1083 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?PSSI_CR_CKPOL:0U));
1085 else
1087 MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth |
1088 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?PSSI_CR_CKPOL:0U));
1091 /* Set the PSSI DMA transfer complete callback */
1092 hpssi->hdmarx->XferCpltCallback = PSSI_DMAReceiveCplt;
1094 /* Set the DMA error callback */
1095 hpssi->hdmarx->XferErrorCallback = PSSI_DMAError;
1097 /* Set the unused DMA callbacks to NULL */
1098 hpssi->hdmarx->XferHalfCpltCallback = NULL;
1099 hpssi->hdmarx->XferAbortCallback = NULL;
1101 /* Enable the DMA */
1102 dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmarx, (uint32_t)&hpssi->Instance->DR, (uint32_t)pData, hpssi->XferSize);
1104 else
1106 /* Update PSSI state */
1107 hpssi->State = HAL_PSSI_STATE_READY;
1109 /* Update PSSI error code */
1110 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1112 /* Process Unlocked */
1113 __HAL_UNLOCK(hpssi);
1115 return HAL_ERROR;
1118 if (dmaxferstatus == HAL_OK)
1120 /* Update XferCount value */
1121 hpssi->XferCount -= hpssi->XferSize;
1123 /* Process Unlocked */
1124 __HAL_UNLOCK(hpssi);
1126 /* Note : The PSSI interrupts must be enabled after unlocking current process
1127 to avoid the risk of PSSI interrupt handle execution before current
1128 process unlock */
1129 /* Enable ERR interrupt */
1130 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1132 /* Enable DMA Request */
1133 hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
1134 /* Enable the selected PSSI peripheral */
1135 HAL_PSSI_ENABLE(hpssi);
1137 else
1139 /* Update PSSI state */
1140 hpssi->State = HAL_PSSI_STATE_READY;
1142 /* Update PSSI error code */
1143 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1145 /* Process Unlocked */
1146 __HAL_UNLOCK(hpssi);
1148 return HAL_ERROR;
1151 else
1154 /* Process Unlocked */
1155 __HAL_UNLOCK(hpssi);
1157 /* Enable ERR,interrupt */
1158 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1161 return HAL_OK;
1163 else
1165 return HAL_BUSY;
1172 * @brief Abort a DMA process communication with Interrupt.
1173 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1174 * the configuration information for the specified PSSI.
1175 * @retval HAL status
1177 HAL_StatusTypeDef HAL_PSSI_Abort_DMA(PSSI_HandleTypeDef *hpssi)
1180 /* Process Locked */
1181 __HAL_LOCK(hpssi);
1183 /* Disable Interrupts */
1184 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1186 /* Set State at HAL_PSSI_STATE_ABORT */
1187 hpssi->State = HAL_PSSI_STATE_ABORT;
1189 /* Abort DMA TX transfer if any */
1190 if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1192 if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1195 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1197 if (hpssi->hdmatx != NULL)
1199 /* Set the PSSI DMA Abort callback :
1200 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1201 hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1203 /* Abort DMA TX */
1204 if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1206 /* Call Directly XferAbortCallback function in case of error */
1207 hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1212 /* Abort DMA RX transfer if any */
1213 else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1216 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1218 if (hpssi->hdmarx != NULL)
1220 /* Set the PSSI DMA Abort callback :
1221 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1222 hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1224 /* Abort DMA RX */
1225 if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1227 /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1228 hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1232 else
1234 /* Call the error callback */
1235 hpssi->ErrorCallback(hpssi);
1240 /* Process Unlocked */
1241 __HAL_UNLOCK(hpssi);
1243 /* Note : The PSSI interrupts must be enabled after unlocking current process
1244 to avoid the risk of PSSI interrupt handle execution before current
1245 process unlock */
1246 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1248 return HAL_OK;
1253 * @}
1256 /** @defgroup PSSI_Exported_Functions_Group3 IRQ Handler and Callbacks
1257 * @{
1261 * @brief This function handles PSSI event interrupt request.
1262 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1263 * the configuration information for the specified PSSI.
1264 * @retval None
1266 void HAL_PSSI_IRQHandler(PSSI_HandleTypeDef *hpssi)
1268 /* Overrun/ Underrun Errors */
1269 if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_MIS) != 0U)
1271 /* Reset handle parameters */
1273 hpssi->XferCount = 0U;
1275 /* Disable all interrupts */
1276 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1279 /* Abort DMA TX transfer if any */
1280 if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1282 if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1284 /* Set new error code */
1285 hpssi->ErrorCode |= HAL_PSSI_ERROR_UNDER_RUN;
1287 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1289 if (hpssi->hdmatx != NULL)
1291 /* Set the PSSI DMA Abort callback :
1292 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1293 hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1295 /* Process Unlocked */
1296 __HAL_UNLOCK(hpssi);
1298 /* Abort DMA TX */
1299 if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1301 /* Call Directly XferAbortCallback function in case of error */
1302 hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1307 /* Abort DMA RX transfer if any */
1308 else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1310 /* Set new error code */
1311 hpssi->ErrorCode |= HAL_PSSI_ERROR_OVER_RUN;
1313 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1315 if (hpssi->hdmarx != NULL)
1317 /* Set the PSSI DMA Abort callback :
1318 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1319 hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1321 /* Process Unlocked */
1322 __HAL_UNLOCK(hpssi);
1324 /* Abort DMA RX */
1325 if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1327 /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1328 hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1332 else
1334 /* Call the corresponding callback to inform upper layer of the error */
1335 hpssi->ErrorCallback(hpssi);
1339 /* If state is an abort treatment on going, don't change state */
1340 if (hpssi->State == HAL_PSSI_STATE_ABORT)
1342 hpssi->State = HAL_PSSI_STATE_READY;
1344 /* Process Unlocked */
1345 __HAL_UNLOCK(hpssi);
1347 /* Call the corresponding callback to inform upper layer of End of Transfer */
1348 hpssi->AbortCpltCallback(hpssi);
1351 else
1353 /* Set HAL_PSSI_STATE_READY */
1354 hpssi->State = HAL_PSSI_STATE_READY;
1355 /* Process Unlocked */
1356 __HAL_UNLOCK(hpssi);
1358 /* Call the corresponding callback to inform upper layer of End of Transfer */
1359 hpssi->ErrorCallback(hpssi);
1368 * @brief Tx Transfer complete callback.
1369 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1370 * the configuration information for the specified PSSI.
1371 * @retval None
1373 __weak void HAL_PSSI_TxCpltCallback(PSSI_HandleTypeDef *hpssi)
1375 /* Prevent unused argument(s) compilation warning */
1376 UNUSED(hpssi);
1378 /* NOTE : This function should not be modified, when the callback is needed,
1379 the HAL_PSSI_TxCpltCallback can be implemented in the user file
1384 * @brief Rx Transfer complete callback.
1385 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1386 * the configuration information for the specified PSSI.
1387 * @retval None
1389 __weak void HAL_PSSI_RxCpltCallback(PSSI_HandleTypeDef *hpssi)
1391 /* Prevent unused argument(s) compilation warning */
1392 UNUSED(hpssi);
1394 /* NOTE : This function should not be modified, when the callback is needed,
1395 the HAL_PSSI_RxCpltCallback can be implemented in the user file
1401 * @brief PSSI error callback.
1402 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1403 * the configuration information for the specified PSSI.
1404 * @retval None
1406 __weak void HAL_PSSI_ErrorCallback(PSSI_HandleTypeDef *hpssi)
1408 /* Prevent unused argument(s) compilation warning */
1409 UNUSED(hpssi);
1411 /* NOTE : This function should not be modified, when the callback is needed,
1412 the HAL_PSSI_ErrorCallback could be implemented in the user file
1417 * @brief PSSI abort callback.
1418 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1419 * the configuration information for the specified PSSI.
1420 * @retval None
1422 __weak void HAL_PSSI_AbortCpltCallback(PSSI_HandleTypeDef *hpssi)
1424 /* Prevent unused argument(s) compilation warning */
1425 UNUSED(hpssi);
1427 /* NOTE : This function should not be modified, when the callback is needed,
1428 the HAL_PSSI_AbortCpltCallback could be implemented in the user file
1433 * @}
1436 /** @defgroup PSSI_Exported_Functions_Group4 Peripheral State, Mode and Error functions
1437 * @brief Peripheral State, Mode and Error functions
1439 @verbatim
1440 ===============================================================================
1441 ##### Peripheral State, Mode and Error functions #####
1442 ===============================================================================
1443 [..]
1444 This subsection permit to get in run-time the status of the peripheral
1445 and the data flow.
1447 @endverbatim
1448 * @{
1452 * @brief Return the PSSI handle state.
1453 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1454 * the configuration information for the specified PSSI.
1455 * @retval HAL state
1457 HAL_PSSI_StateTypeDef HAL_PSSI_GetState(PSSI_HandleTypeDef *hpssi)
1459 /* Return PSSI handle state */
1460 return hpssi->State;
1465 * @brief Return the PSSI error code.
1466 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1467 * the configuration information for the specified PSSI.
1468 * @retval PSSI Error Code
1470 uint32_t HAL_PSSI_GetError(PSSI_HandleTypeDef *hpssi)
1472 return hpssi->ErrorCode;
1476 * @}
1480 * @}
1483 /** @addtogroup PSSI_Private_Functions
1484 * @{
1488 * @brief PSSI Errors process.
1489 * @param hpssi PSSI handle.
1490 * @param ErrorCode Error code to handle.
1491 * @retval None
1493 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode)
1496 /* Reset handle parameters */
1498 hpssi->XferCount = 0U;
1500 /* Set new error code */
1501 hpssi->ErrorCode |= ErrorCode;
1503 /* Disable all interrupts */
1504 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1507 /* Abort DMA TX transfer if any */
1508 if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1510 if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1512 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1514 if (hpssi->hdmatx != NULL)
1516 /* Set the PSSI DMA Abort callback :
1517 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1518 hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1520 /* Process Unlocked */
1521 __HAL_UNLOCK(hpssi);
1523 /* Abort DMA TX */
1524 if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1526 /* Call Directly XferAbortCallback function in case of error */
1527 hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1532 /* Abort DMA RX transfer if any */
1533 else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1535 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1537 if (hpssi->hdmarx != NULL)
1539 /* Set the PSSI DMA Abort callback :
1540 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1541 hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1543 /* Process Unlocked */
1544 __HAL_UNLOCK(hpssi);
1546 /* Abort DMA RX */
1547 if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1549 /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1550 hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1554 else
1556 /*Nothing to do*/
1560 /* If state is an abort treatment on going, don't change state */
1561 if (hpssi->State == HAL_PSSI_STATE_ABORT)
1563 hpssi->State = HAL_PSSI_STATE_READY;
1565 /* Process Unlocked */
1566 __HAL_UNLOCK(hpssi);
1568 /* Call the corresponding callback to inform upper layer of End of Transfer */
1570 hpssi->AbortCpltCallback(hpssi);
1573 else
1575 /* Set HAL_PSSI_STATE_READY */
1576 hpssi->State = HAL_PSSI_STATE_READY;
1578 /* Process Unlocked */
1579 __HAL_UNLOCK(hpssi);
1581 /* Call the corresponding callback to inform upper layer of End of Transfer */
1582 hpssi->ErrorCallback(hpssi);
1588 * @brief DMA PSSI slave transmit process complete callback.
1589 * @param hdma DMA handle
1590 * @retval None
1592 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
1594 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
1596 uint32_t tmperror;
1599 /* Disable Interrupts */
1600 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1602 /* Store current volatile hpssi->ErrorCode, misra rule */
1603 tmperror = hpssi->ErrorCode;
1605 /* Call the corresponding callback to inform upper layer of End of Transfer */
1606 if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1608 /* Call the corresponding callback to inform upper layer of End of Transfer */
1609 PSSI_Error(hpssi, hpssi->ErrorCode);
1611 /* hpssi->State == HAL_PSSI_STATE_BUSY_TX */
1612 else
1614 hpssi->State = HAL_PSSI_STATE_READY;
1616 /* Process Unlocked */
1617 __HAL_UNLOCK(hpssi);
1619 /* Call the corresponding callback to inform upper layer of End of Transfer */
1621 hpssi->TxCpltCallback(hpssi);
1629 * @brief DMA PSSI master receive process complete callback.
1630 * @param hdma DMA handle
1631 * @retval None
1633 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1635 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
1637 uint32_t tmperror;
1640 /* Disable Interrupts */
1641 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1643 /* Store current volatile hpssi->ErrorCode, misra rule */
1644 tmperror = hpssi->ErrorCode;
1646 /* Call the corresponding callback to inform upper layer of End of Transfer */
1647 if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1649 /* Call the corresponding callback to inform upper layer of End of Transfer */
1650 PSSI_Error(hpssi, hpssi->ErrorCode);
1652 /* hpssi->State == HAL_PSSI_STATE_BUSY_RX */
1653 else
1655 hpssi->State = HAL_PSSI_STATE_READY;
1657 /* Process Unlocked */
1658 __HAL_UNLOCK(hpssi);
1660 /* Call the corresponding callback to inform upper layer of End of Transfer */
1661 hpssi->RxCpltCallback(hpssi);
1669 * @brief DMA PSSI communication abort callback
1670 * (To be called at end of DMA Abort procedure).
1671 * @param hdma DMA handle.
1672 * @retval None
1674 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma)
1676 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
1678 /* Reset AbortCpltCallback */
1679 hpssi->hdmatx->XferAbortCallback = NULL;
1680 hpssi->hdmarx->XferAbortCallback = NULL;
1682 /* Check if come from abort from user */
1683 if (hpssi->State == HAL_PSSI_STATE_ABORT)
1685 hpssi->State = HAL_PSSI_STATE_READY;
1687 /* Call the corresponding callback to inform upper layer of End of Transfer */
1689 hpssi->AbortCpltCallback(hpssi);
1692 else
1694 /* Call the corresponding callback to inform upper layer of End of Transfer */
1695 hpssi->ErrorCallback(hpssi);
1700 * @brief This function handles PSSI Communication Timeout.
1701 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1702 * the configuration information for the specified PSSI.
1703 * @param Flag Specifies the PSSI flag to check.
1704 * @param Status The new Flag status (SET or RESET).
1705 * @param Timeout Timeout duration
1706 * @param Tickstart Tick start value
1707 * @retval HAL status
1709 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
1711 while ((HAL_PSSI_GET_STATUS(hpssi, Flag) & Flag) == (uint32_t)Status)
1713 /* Check for the Timeout */
1714 if (Timeout != HAL_MAX_DELAY)
1716 if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
1718 hpssi->ErrorCode |= HAL_PSSI_ERROR_TIMEOUT;
1719 hpssi->State = HAL_PSSI_STATE_READY;
1721 /* Process Unlocked */
1722 __HAL_UNLOCK(hpssi);
1724 return HAL_ERROR;
1728 return HAL_OK;
1730 void PSSI_DMAError(DMA_HandleTypeDef *hdma)
1732 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
1734 uint32_t tmperror;
1737 /* Disable the selected PSSI peripheral */
1738 HAL_PSSI_DISABLE(hpssi);
1740 /* Disable Interrupts */
1741 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1743 /* Store current volatile hpssi->ErrorCode, misra rule */
1744 tmperror = hpssi->ErrorCode;
1746 /* Call the corresponding callback to inform upper layer of End of Transfer */
1747 if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1749 /* Call the corresponding callback to inform upper layer of End of Transfer */
1750 PSSI_Error(hpssi, hpssi->ErrorCode);
1752 else
1754 hpssi->State = HAL_PSSI_STATE_READY;
1756 /* Process Unlocked */
1757 __HAL_UNLOCK(hpssi);
1759 /* Call the corresponding callback to inform upper layer of End of Transfer */
1760 hpssi->ErrorCallback(hpssi);
1769 * @}
1771 #endif /* PSSI */
1772 #endif /* HAL_PSSI_MODULE_ENABLED */
1774 * @}
1778 * @}
1781 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/