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
11   *
12   ******************************************************************************
13   * @attention
14   *
15   * Copyright (c) 2017 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 PSSI HAL driver can be used as follows:
29 
30     (#) Declare a PSSI_HandleTypeDef handle structure, for example:
31         PSSI_HandleTypeDef  hpssi;
32 
33     (#) Initialize the PSSI low level resources by implementing the @ref HAL_PSSI_MspInit() API:
34         (##) Enable the PSSIx interface clock
35         (##) PSSI pins configuration
36             (+++) Enable the clock for the PSSI GPIOs
37             (+++) Configure PSSI pins as alternate function open-drain
38         (##) NVIC configuration if you need to use interrupt process
39             (+++) Configure the PSSIx interrupt priority
40             (+++) Enable the NVIC PSSI IRQ Channel
41         (##) DMA Configuration if you need to use DMA process
42             (+++) Declare  DMA_HandleTypeDef handles structure for the transmit and receive
43             (+++) Enable the DMAx interface clock
44             (+++) Configure the DMA handle parameters
45             (+++) Configure the DMA Tx and Rx
46             (+++) Associate the initialized DMA handle to the hpssi DMA Tx and Rx handle
47             (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
48                   the DMA Tx and Rx
49 
50     (#) Configure the Communication Bus Width,  Control Signals, Input Polarity and Output Polarity
51          in the hpssi Init structure.
52 
53     (#) Initialize the PSSI registers by calling the @ref HAL_PSSI_Init(), configure also the low level Hardware
54         (GPIO, CLOCK, NVIC...etc) by calling the customized @ref HAL_PSSI_MspInit(&hpssi) API.
55 
56 
57     (#) For PSSI IO operations, two operation modes are available within this driver :
58 
59     *** Polling mode IO operation ***
60     =================================
61     [..]
62       (+) Transmit an amount of data by byte in blocking mode using @ref HAL_PSSI_Transmit()
63       (+) Receive an amount of data by byte in blocking mode using @ref HAL_PSSI_Receive()
64 
65     *** DMA mode IO operation ***
66     ==============================
67     [..]
68       (+) Transmit an amount of data in non-blocking mode (DMA) using
69           @ref HAL_PSSI_Transmit_DMA()
70       (+) At transmission end of transfer, @ref HAL_PSSI_TxCpltCallback() is executed and user can
71            add his own code by customization of function pointer @ref HAL_PSSI_TxCpltCallback()
72       (+) Receive an amount of data in non-blocking mode (DMA) using
73           @ref HAL_PSSI_Receive_DMA()
74       (+) At reception end of transfer, @ref HAL_PSSI_RxCpltCallback() is executed and user can
75            add his own code by customization of function pointer @ref HAL_PSSI_RxCpltCallback()
76       (+) In case of transfer Error, @ref HAL_PSSI_ErrorCallback() function is executed and user can
77            add his own code by customization of function pointer @ref HAL_PSSI_ErrorCallback()
78       (+) Abort a  PSSI process communication with Interrupt using @ref HAL_PSSI_Abort_IT()
79       (+) End of abort process, @ref HAL_PSSI_AbortCpltCallback() is executed and user can
80            add his own code by customization of function pointer @ref HAL_PSSI_AbortCpltCallback()
81 
82      *** PSSI HAL driver macros list ***
83      ==================================
84      [..]
85        Below the list of most used macros in PSSI HAL driver.
86 
87       (+) @ref HAL_PSSI_ENABLE     : Enable the PSSI peripheral
88       (+) @ref HAL_PSSI_DISABLE    : Disable the PSSI peripheral
89       (+) @ref HAL_PSSI_GET_FLAG   : Check whether the specified PSSI flag is set or not
90       (+) @ref HAL_PSSI_CLEAR_FLAG : Clear the specified PSSI pending flag
91       (+) @ref HAL_PSSI_ENABLE_IT  : Enable the specified PSSI interrupt
92       (+) @ref HAL_PSSI_DISABLE_IT : Disable the specified PSSI interrupt
93 
94      *** Callback registration ***
95      =============================================
96      Use Functions @ref HAL_PSSI_RegisterCallback() or @ref HAL_PSSI_RegisterAddrCallback()
97      to register an interrupt callback.
98 
99      Function @ref HAL_PSSI_RegisterCallback() allows to register following callbacks:
100        (+) TxCpltCallback       : callback for transmission end of transfer.
101        (+) RxCpltCallback       : callback for reception end of transfer.
102        (+) ErrorCallback        : callback for error detection.
103        (+) AbortCpltCallback    : callback for abort completion process.
104        (+) MspInitCallback      : callback for Msp Init.
105        (+) MspDeInitCallback    : callback for Msp DeInit.
106      This function takes as parameters the HAL peripheral handle, the Callback ID
107      and a pointer to the user callback function.
108 
109 
110      Use function @ref HAL_PSSI_UnRegisterCallback to reset a callback to the default
111      weak function.
112      @ref HAL_PSSI_UnRegisterCallback takes as parameters the HAL peripheral handle,
113      and the Callback ID.
114      This function allows to reset following callbacks:
115        (+) TxCpltCallback       : callback for transmission end of transfer.
116        (+) RxCpltCallback       : callback for reception end of transfer.
117        (+) ErrorCallback        : callback for error detection.
118        (+) AbortCpltCallback    : callback for abort completion process.
119        (+) MspInitCallback      : callback for Msp Init.
120        (+) MspDeInitCallback    : callback for Msp DeInit.
121 
122 
123      By default, after the @ref HAL_PSSI_Init() and when the state is @ref HAL_PSSI_STATE_RESET
124      all callbacks are set to the corresponding weak functions:
125      examples @ref HAL_PSSI_TxCpltCallback(), @ref HAL_PSSI_RxCpltCallback().
126      Exception done for MspInit and MspDeInit functions that are
127      reset to the legacy weak functions in the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit() only when
128      these callbacks are null (not registered beforehand).
129      If MspInit or MspDeInit are not null, the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit()
130      keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
131 
132      Callbacks can be registered/unregistered in @ref HAL_PSSI_STATE_READY state only.
133      Exception done MspInit/MspDeInit functions that can be registered/unregistered
134      in @ref HAL_PSSI_STATE_READY or @ref HAL_PSSI_STATE_RESET state,
135      thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
136      Then, the user first registers the MspInit/MspDeInit user callbacks
137      using @ref HAL_PSSI_RegisterCallback() before calling @ref HAL_PSSI_DeInit()
138      or @ref HAL_PSSI_Init() function.
139 
140 
141      [..]
142        (@) You can refer to the PSSI HAL driver header file for more useful macros
143 
144   @endverbatim
145   */
146 
147 /* Includes ------------------------------------------------------------------*/
148 #include "stm32h7xx_hal.h"
149 
150 /** @addtogroup STM32H7xx_HAL_Driver
151   * @{
152   */
153 
154 /** @defgroup PSSI PSSI
155   * @brief PSSI HAL module driver
156   * @{
157   */
158 
159 #ifdef HAL_PSSI_MODULE_ENABLED
160 #if defined(PSSI)
161 /* Private typedef -----------------------------------------------------------*/
162 /* Private define ------------------------------------------------------------*/
163 
164 /** @defgroup PSSI_Private_Define PSSI Private Define
165   * @{
166   */
167 
168 
169 
170 /**
171   * @}
172   */
173 
174 /* Private macro -------------------------------------------------------------*/
175 /* Private variables ---------------------------------------------------------*/
176 /* Private function prototypes -----------------------------------------------*/
177 
178 /** @defgroup PSSI_Private_Functions PSSI Private Functions
179   * @{
180   */
181 /* Private functions to handle DMA transfer */
182 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
183 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
184 void PSSI_DMAError(DMA_HandleTypeDef *hdma);
185 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma);
186 
187 
188 /* Private functions to handle IT transfer */
189 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode);
190 
191 
192 /* Private functions for PSSI transfer IRQ handler */
193 
194 
195 /* Private functions to handle flags during polling transfer */
196 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status,
197                                                        uint32_t Timeout, uint32_t Tickstart);
198 
199 /* Private functions to centralize the enable/disable of Interrupts */
200 
201 
202 /**
203   * @}
204   */
205 
206 /* Exported functions --------------------------------------------------------*/
207 
208 /** @defgroup PSSI_Exported_Functions PSSI Exported Functions
209   * @{
210   */
211 
212 /** @defgroup PSSI_Exported_Functions_Group1 Initialization and de-initialization functions
213   *  @brief    Initialization and Configuration functions
214   *
215 @verbatim
216  ===============================================================================
217               ##### Initialization and de-initialization functions #####
218  ===============================================================================
219     [..]  This subsection provides a set of functions allowing to initialize and
220           deinitialize the PSSIx peripheral:
221 
222       (+) User must implement HAL_PSSI_MspInit() function in which he configures
223           all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
224 
225       (+) Call the function HAL_PSSI_Init() to configure the selected device with
226           the selected configuration:
227         (++) Data Width
228         (++) Control Signals
229         (++) Input Clock polarity
230         (++) Output Clock polarity
231 
232       (+) Call the function HAL_PSSI_DeInit() to restore the default configuration
233           of the selected PSSIx peripheral.
234 
235 @endverbatim
236   * @{
237   */
238 
239 /**
240   * @brief  Initializes the PSSI according to the specified parameters
241   *         in the PSSI_InitTypeDef and initialize the associated handle.
242   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
243   *                the configuration information for the specified PSSI.
244   * @retval HAL status
245   */
HAL_PSSI_Init(PSSI_HandleTypeDef * hpssi)246 HAL_StatusTypeDef HAL_PSSI_Init(PSSI_HandleTypeDef *hpssi)
247 {
248   /* Check the PSSI handle allocation */
249   if (hpssi == NULL)
250   {
251     return HAL_ERROR;
252   }
253 
254   /* Check the parameters */
255   assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
256   assert_param(IS_PSSI_CONTROL_SIGNAL(hpssi->Init.ControlSignal));
257   assert_param(IS_PSSI_BUSWIDTH(hpssi->Init.BusWidth));
258   assert_param(IS_PSSI_CLOCK_POLARITY(hpssi->Init.ClockPolarity));
259   assert_param(IS_PSSI_DE_POLARITY(hpssi->Init.DataEnablePolarity));
260   assert_param(IS_PSSI_RDY_POLARITY(hpssi->Init.ReadyPolarity));
261 
262   if (hpssi->State == HAL_PSSI_STATE_RESET)
263   {
264     /* Allocate lock resource and initialize it */
265     hpssi->Lock = HAL_UNLOCKED;
266 
267     /* Init the PSSI Callback settings */
268     hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
269     hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
270     hpssi->ErrorCallback        = HAL_PSSI_ErrorCallback;        /* Legacy weak ErrorCallback        */
271     hpssi->AbortCpltCallback    = HAL_PSSI_AbortCpltCallback;    /* Legacy weak AbortCpltCallback    */
272 
273     if (hpssi->MspInitCallback == NULL)
274     {
275       hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit  */
276     }
277 
278     /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
279     hpssi->MspInitCallback(hpssi);
280 
281   }
282 
283   hpssi->State = HAL_PSSI_STATE_BUSY;
284 
285   /* Disable the selected PSSI peripheral */
286   HAL_PSSI_DISABLE(hpssi);
287 
288   /*---------------------------- PSSIx CR Configuration ----------------------*/
289   /* Configure PSSIx: Control Signal and Bus Width*/
290 
291   MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DERDYCFG | PSSI_CR_EDM | PSSI_CR_DEPOL | PSSI_CR_RDYPOL,
292              hpssi->Init.ControlSignal | hpssi->Init.DataEnablePolarity |
293              hpssi->Init.ReadyPolarity | hpssi->Init.BusWidth);
294 
295   hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
296   hpssi->State = HAL_PSSI_STATE_READY;
297 
298   return HAL_OK;
299 }
300 
301 /**
302   * @brief  DeInitialize the PSSI peripheral.
303   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
304   *                the configuration information for the specified PSSI.
305   * @retval HAL status
306   */
HAL_PSSI_DeInit(PSSI_HandleTypeDef * hpssi)307 HAL_StatusTypeDef HAL_PSSI_DeInit(PSSI_HandleTypeDef *hpssi)
308 {
309   /* Check the PSSI handle allocation */
310   if (hpssi == NULL)
311   {
312     return HAL_ERROR;
313   }
314 
315   /* Check the parameters */
316   assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
317 
318   hpssi->State = HAL_PSSI_STATE_BUSY;
319 
320   /* Disable the PSSI Peripheral Clock */
321   HAL_PSSI_DISABLE(hpssi);
322 
323   if (hpssi->MspDeInitCallback == NULL)
324   {
325     hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit  */
326   }
327 
328   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
329   hpssi->MspDeInitCallback(hpssi);
330 
331   hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
332   hpssi->State = HAL_PSSI_STATE_RESET;
333 
334   /* Release Lock */
335   __HAL_UNLOCK(hpssi);
336 
337   return HAL_OK;
338 }
339 
340 /**
341   * @brief Initialize the PSSI MSP.
342   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
343   *                the configuration information for the specified PSSI.
344   * @retval None
345   */
HAL_PSSI_MspInit(PSSI_HandleTypeDef * hpssi)346 __weak void HAL_PSSI_MspInit(PSSI_HandleTypeDef *hpssi)
347 {
348   /* Prevent unused argument(s) compilation warning */
349   UNUSED(hpssi);
350 
351   /* NOTE : This function should not be modified, when the callback is needed,
352             the HAL_PSSI_MspInit can be implemented in the user file
353    */
354 }
355 
356 /**
357   * @brief DeInitialize the PSSI MSP.
358   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
359   *                the configuration information for the specified PSSI.
360   * @retval None
361   */
HAL_PSSI_MspDeInit(PSSI_HandleTypeDef * hpssi)362 __weak void HAL_PSSI_MspDeInit(PSSI_HandleTypeDef *hpssi)
363 {
364   /* Prevent unused argument(s) compilation warning */
365   UNUSED(hpssi);
366 
367   /* NOTE : This function should not be modified, when the callback is needed,
368             the HAL_PSSI_MspDeInit can be implemented in the user file
369    */
370 }
371 
372 /**
373   * @brief  Register a User PSSI Callback
374   *         To be used instead of the weak predefined callback
375   * @note   The HAL_PSSI_RegisterCallback() may be called before HAL_PSSI_Init() in
376   *         HAL_PSSI_STATE_RESET to register callbacks for HAL_PSSI_MSPINIT_CB_ID
377   *         and HAL_PSSI_MSPDEINIT_CB_ID.
378   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
379   *                the configuration information for the specified PSSI.
380   * @param  CallbackID ID of the callback to be registered
381   *         This parameter can be one of the following values:
382   *          @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID  Tx Transfer completed callback ID
383   *          @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID  Rx Transfer completed callback ID
384   *          @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
385   *          @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
386   *          @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
387   *          @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
388   * @param  pCallback pointer to the Callback function
389   * @retval HAL status
390   */
HAL_PSSI_RegisterCallback(PSSI_HandleTypeDef * hpssi,HAL_PSSI_CallbackIDTypeDef CallbackID,pPSSI_CallbackTypeDef pCallback)391 HAL_StatusTypeDef HAL_PSSI_RegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID,
392                                             pPSSI_CallbackTypeDef pCallback)
393 {
394   HAL_StatusTypeDef status = HAL_OK;
395 
396   if (pCallback == NULL)
397   {
398     /* Update the error code */
399     hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
400 
401     return HAL_ERROR;
402   }
403 
404   if (HAL_PSSI_STATE_READY == hpssi->State)
405   {
406     switch (CallbackID)
407     {
408       case HAL_PSSI_TX_COMPLETE_CB_ID :
409         hpssi->TxCpltCallback = pCallback;
410         break;
411 
412       case HAL_PSSI_RX_COMPLETE_CB_ID :
413         hpssi->RxCpltCallback = pCallback;
414         break;
415 
416       case HAL_PSSI_ERROR_CB_ID :
417         hpssi->ErrorCallback = pCallback;
418         break;
419 
420       case HAL_PSSI_ABORT_CB_ID :
421         hpssi->AbortCpltCallback = pCallback;
422         break;
423 
424       case HAL_PSSI_MSPINIT_CB_ID :
425         hpssi->MspInitCallback = pCallback;
426         break;
427 
428       case HAL_PSSI_MSPDEINIT_CB_ID :
429         hpssi->MspDeInitCallback = pCallback;
430         break;
431 
432       default :
433         /* Update the error code */
434         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
435 
436         /* Return error status */
437         status =  HAL_ERROR;
438         break;
439     }
440   }
441   else if (HAL_PSSI_STATE_RESET == hpssi->State)
442   {
443     switch (CallbackID)
444     {
445       case HAL_PSSI_MSPINIT_CB_ID :
446         hpssi->MspInitCallback = pCallback;
447         break;
448 
449       case HAL_PSSI_MSPDEINIT_CB_ID :
450         hpssi->MspDeInitCallback = pCallback;
451         break;
452 
453       default :
454         /* Update the error code */
455         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
456 
457         /* Return error status */
458         status =  HAL_ERROR;
459         break;
460     }
461   }
462   else
463   {
464     /* Update the error code */
465     hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
466 
467     /* Return error status */
468     status =  HAL_ERROR;
469   }
470 
471   return status;
472 }
473 
474 /**
475   * @brief  Unregister an PSSI Callback
476   *         PSSI callback is redirected to the weak predefined callback
477   * @note   The HAL_PSSI_UnRegisterCallback() may be called before HAL_PSSI_Init() in
478   *         HAL_PSSI_STATE_RESET to un-register callbacks for HAL_PSSI_MSPINIT_CB_ID
479   *         and HAL_PSSI_MSPDEINIT_CB_ID.
480   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
481   *                the configuration information for the specified PSSI.
482   * @param  CallbackID ID of the callback to be unregistered
483   *         This parameter can be one of the following values:
484   *          @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID  Tx Transfer completed callback ID
485   *          @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID  Rx Transfer completed callback ID
486   *          @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
487   *          @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
488   *          @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
489   *          @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
490   * @retval HAL status
491   */
HAL_PSSI_UnRegisterCallback(PSSI_HandleTypeDef * hpssi,HAL_PSSI_CallbackIDTypeDef CallbackID)492 HAL_StatusTypeDef HAL_PSSI_UnRegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID)
493 {
494   HAL_StatusTypeDef status = HAL_OK;
495 
496   if (HAL_PSSI_STATE_READY == hpssi->State)
497   {
498     switch (CallbackID)
499     {
500       case HAL_PSSI_TX_COMPLETE_CB_ID :
501         hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
502         break;
503 
504       case HAL_PSSI_RX_COMPLETE_CB_ID :
505         hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback;   /* Legacy weak RxCpltCallback  */
506         break;
507 
508       case HAL_PSSI_ERROR_CB_ID :
509         hpssi->ErrorCallback = HAL_PSSI_ErrorCallback;               /* Legacy weak ErrorCallback        */
510         break;
511 
512       case HAL_PSSI_ABORT_CB_ID :
513         hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback;       /* Legacy weak AbortCpltCallback    */
514         break;
515 
516       case HAL_PSSI_MSPINIT_CB_ID :
517         hpssi->MspInitCallback = HAL_PSSI_MspInit;                   /* Legacy weak MspInit              */
518         break;
519 
520       case HAL_PSSI_MSPDEINIT_CB_ID :
521         hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit;               /* Legacy weak MspDeInit            */
522         break;
523 
524       default :
525         /* Update the error code */
526         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
527 
528         /* Return error status */
529         status =  HAL_ERROR;
530         break;
531     }
532   }
533   else if (HAL_PSSI_STATE_RESET == hpssi->State)
534   {
535     switch (CallbackID)
536     {
537       case HAL_PSSI_MSPINIT_CB_ID :
538         hpssi->MspInitCallback = HAL_PSSI_MspInit;                   /* Legacy weak MspInit              */
539         break;
540 
541       case HAL_PSSI_MSPDEINIT_CB_ID :
542         hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit;               /* Legacy weak MspDeInit            */
543         break;
544 
545       default :
546         /* Update the error code */
547         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
548 
549         /* Return error status */
550         status =  HAL_ERROR;
551         break;
552     }
553   }
554   else
555   {
556     /* Update the error code */
557     hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
558 
559     /* Return error status */
560     status =  HAL_ERROR;
561   }
562 
563   return status;
564 }
565 
566 
567 /**
568   * @}
569   */
570 
571 /** @defgroup PSSI_Exported_Functions_Group2 Input and Output operation functions
572   *  @brief   Data transfers functions
573   *
574 @verbatim
575  ===============================================================================
576                       ##### IO operation functions #####
577  ===============================================================================
578     [..]
579     This subsection provides a set of functions allowing to manage the PSSI data
580     transfers.
581 
582     (#) There are two modes of transfer:
583        (++) Blocking mode : The communication is performed in the polling mode.
584             The status of all data processing is returned by the same function
585             after finishing transfer.
586        (++) No-Blocking mode : The communication is performed using DMA.
587             These functions return the status of the transfer startup.
588             The end of the data processing will be indicated through the
589             dedicated  the DMA IRQ .
590 
591     (#) Blocking mode functions are :
592         (++) HAL_PSSI_Transmit()
593         (++) HAL_PSSI_Receive()
594 
595     (#) No-Blocking mode functions with DMA are :
596         (++) HAL_PSSI_Transmit_DMA()
597         (++) HAL_PSSI_Receive_DMA()
598 
599     (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
600         (++) HAL_PSSI_TxCpltCallback()
601         (++) HAL_PSSI_RxCpltCallback()
602         (++) HAL_PSSI_ErrorCallback()
603         (++) HAL_PSSI_AbortCpltCallback()
604 
605 @endverbatim
606   * @{
607   */
608 
609 /**
610   * @brief  Transmits in master mode an amount of data in blocking mode.
611   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
612   *                the configuration information for the specified PSSI.
613   * @param  pData Pointer to data buffer
614   * @param  Size Amount of data to be sent (in bytes)
615   * @param  Timeout Timeout duration
616   * @retval HAL status
617   */
HAL_PSSI_Transmit(PSSI_HandleTypeDef * hpssi,uint8_t * pData,uint32_t Size,uint32_t Timeout)618 HAL_StatusTypeDef HAL_PSSI_Transmit(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
619 {
620   uint32_t tickstart;
621   uint32_t  transfer_size = Size;
622 
623   if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
624       ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size % 2U) != 0U)) ||
625       ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size % 4U) != 0U)))
626   {
627     hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
628     return HAL_ERROR;
629   }
630   if (hpssi->State == HAL_PSSI_STATE_READY)
631   {
632     /* Process Locked */
633     __HAL_LOCK(hpssi);
634 
635     hpssi->State     = HAL_PSSI_STATE_BUSY;
636     hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
637 
638     /* Disable the selected PSSI peripheral */
639     HAL_PSSI_DISABLE(hpssi);
640 
641     /* Configure transfer parameters */
642     hpssi->Instance->CR |= PSSI_CR_OUTEN_OUTPUT |
643                            ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL);
644     /* DMA Disable */
645     hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
646 
647     /* Enable the selected PSSI peripheral */
648     HAL_PSSI_ENABLE(hpssi);
649 
650     if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
651     {
652       uint8_t *pbuffer = pData;
653       while (transfer_size > 0U)
654       {
655         /* Init tickstart for timeout management*/
656         tickstart = HAL_GetTick();
657         /* Wait until Fifo is ready to transfer one byte flag is set */
658         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
659         {
660           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
661           hpssi->State = HAL_PSSI_STATE_READY;
662           /* Process Unlocked */
663           __HAL_UNLOCK(hpssi);
664           return HAL_ERROR;
665         }
666         /* Write data to DR */
667         *(__IO uint8_t *)(&hpssi->Instance->DR) = *(uint8_t *)pbuffer;
668 
669         /* Increment Buffer pointer */
670         pbuffer++;
671 
672         transfer_size--;
673       }
674     }
675     else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
676     {
677       uint16_t *pbuffer = (uint16_t *)pData;
678       __IO uint16_t *dr = (__IO uint16_t *)(&hpssi->Instance->DR);
679 
680       while (transfer_size > 0U)
681       {
682         /* Init tickstart for timeout management*/
683         tickstart = HAL_GetTick();
684         /* Wait until Fifo is ready to transfer four bytes flag is set */
685         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
686         {
687           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
688           hpssi->State = HAL_PSSI_STATE_READY;
689           /* Process Unlocked */
690           __HAL_UNLOCK(hpssi);
691           return HAL_ERROR;
692         }
693         /* Write data to DR */
694         *dr = *pbuffer;
695 
696         /* Increment Buffer pointer */
697         pbuffer++;
698         transfer_size -= 2U;
699 
700       }
701     }
702     else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
703     {
704       uint32_t *pbuffer = (uint32_t *)pData;
705       while (transfer_size > 0U)
706       {
707         /* Init tickstart for timeout management*/
708         tickstart = HAL_GetTick();
709         /* Wait until Fifo is ready to transfer four bytes flag is set */
710         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
711         {
712           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
713           hpssi->State = HAL_PSSI_STATE_READY;
714           /* Process Unlocked */
715           __HAL_UNLOCK(hpssi);
716           return HAL_ERROR;
717         }
718         /* Write data to DR */
719         *(__IO uint32_t *)(&hpssi->Instance->DR) = *pbuffer;
720 
721         /* Increment Buffer pointer */
722         pbuffer++;
723         transfer_size -= 4U;
724       }
725 
726     }
727     else
728     {
729       hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
730       hpssi->State = HAL_PSSI_STATE_READY;
731       /* Process Unlocked */
732       __HAL_UNLOCK(hpssi);
733       return HAL_ERROR;
734     }
735 
736     /* Check Errors Flags */
737     if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
738     {
739       HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
740       HAL_PSSI_DISABLE(hpssi);
741       hpssi->ErrorCode = HAL_PSSI_ERROR_UNDER_RUN;
742       hpssi->State = HAL_PSSI_STATE_READY;
743       /* Process Unlocked */
744       __HAL_UNLOCK(hpssi);
745       return HAL_ERROR;
746     }
747 
748     hpssi->State = HAL_PSSI_STATE_READY;
749 
750     /* Process Unlocked */
751     __HAL_UNLOCK(hpssi);
752 
753     return HAL_OK;
754   }
755   else
756   {
757     return HAL_BUSY;
758   }
759 }
760 
761 
762 /**
763   * @brief  Receives an amount of data in blocking mode.
764   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
765   *                the configuration information for the specified PSSI.
766   * @param  pData Pointer to data buffer
767   * @param  Size Amount of data to be received (in bytes)
768   * @param  Timeout Timeout duration
769   * @retval HAL status
770   */
HAL_PSSI_Receive(PSSI_HandleTypeDef * hpssi,uint8_t * pData,uint32_t Size,uint32_t Timeout)771 HAL_StatusTypeDef HAL_PSSI_Receive(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
772 {
773   uint32_t tickstart;
774   uint32_t  transfer_size = Size;
775 
776   if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
777       ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size % 2U) != 0U)) ||
778       ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size % 4U) != 0U)))
779   {
780     hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
781     return HAL_ERROR;
782   }
783 
784   if (hpssi->State == HAL_PSSI_STATE_READY)
785   {
786     /* Process Locked */
787     __HAL_LOCK(hpssi);
788 
789     hpssi->State     = HAL_PSSI_STATE_BUSY;
790     hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
791 
792     /* Disable the selected PSSI peripheral */
793     HAL_PSSI_DISABLE(hpssi);
794     /* Configure transfer parameters */
795     hpssi->Instance->CR |= PSSI_CR_OUTEN_INPUT |
796                            ((hpssi->Init.ClockPolarity == HAL_PSSI_FALLING_EDGE) ? 0U : PSSI_CR_CKPOL);
797 
798     /* DMA Disable */
799     hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
800 
801     /* Enable the selected PSSI peripheral */
802     HAL_PSSI_ENABLE(hpssi);
803     if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
804     {
805       uint8_t *pbuffer = pData;
806 
807       while (transfer_size > 0U)
808       {
809         /* Init tickstart for timeout management*/
810         tickstart = HAL_GetTick();
811         /* Wait until Fifo is ready to receive one byte flag is set */
812         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
813         {
814           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
815           hpssi->State = HAL_PSSI_STATE_READY;
816           /* Process Unlocked */
817           __HAL_UNLOCK(hpssi);
818           return HAL_ERROR;
819         }
820         /* Read data from DR */
821         *pbuffer = *(__IO uint8_t *)(&hpssi->Instance->DR);
822         pbuffer++;
823         transfer_size--;
824       }
825     }
826     else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
827     {
828       uint16_t *pbuffer = (uint16_t *)pData;
829       __IO uint16_t *dr = (__IO uint16_t *)(&hpssi->Instance->DR);
830 
831       while (transfer_size > 0U)
832       {
833         /* Init tickstart for timeout management*/
834         tickstart = HAL_GetTick();
835         /* Wait until Fifo is ready to receive four bytes flag is set */
836         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
837         {
838           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
839           hpssi->State = HAL_PSSI_STATE_READY;
840           /* Process Unlocked */
841           __HAL_UNLOCK(hpssi);
842           return HAL_ERROR;
843         }
844 
845         /* Read data from DR */
846         *pbuffer = *dr;
847         pbuffer++;
848         transfer_size -= 2U;
849 
850       }
851     }
852     else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
853     {
854       uint32_t *pbuffer = (uint32_t *)pData;
855 
856       while (transfer_size > 0U)
857       {
858         /* Init tickstart for timeout management*/
859         tickstart = HAL_GetTick();
860         /* Wait until Fifo is ready to receive four bytes flag is set */
861         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
862         {
863           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
864           hpssi->State = HAL_PSSI_STATE_READY;
865           /* Process Unlocked */
866           __HAL_UNLOCK(hpssi);
867           return HAL_ERROR;
868         }
869 
870         /* Read data from DR */
871         *pbuffer = *(__IO uint32_t *)(&hpssi->Instance->DR);
872         pbuffer++;
873         transfer_size -= 4U;
874 
875       }
876     }
877     else
878     {
879       hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
880       hpssi->State = HAL_PSSI_STATE_READY;
881       /* Process Unlocked */
882       __HAL_UNLOCK(hpssi);
883       return HAL_ERROR;
884     }
885     /* Check Errors Flags */
886 
887     if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
888     {
889       HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
890       hpssi->ErrorCode = HAL_PSSI_ERROR_OVER_RUN;
891       __HAL_UNLOCK(hpssi);
892       return HAL_ERROR;
893     }
894 
895 
896     hpssi->State = HAL_PSSI_STATE_READY;
897 
898     /* Process Unlocked */
899     __HAL_UNLOCK(hpssi);
900 
901     return HAL_OK;
902   }
903   else
904   {
905     return HAL_BUSY;
906   }
907 }
908 
909 /**
910   * @brief  Transmit an amount of data in non-blocking mode with DMA
911   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
912   *                the configuration information for the specified PSSI.
913   * @param  pData Pointer to data buffer
914   * @param  Size Amount of data to be sent (in bytes)
915   * @retval HAL status
916   */
HAL_PSSI_Transmit_DMA(PSSI_HandleTypeDef * hpssi,uint32_t * pData,uint32_t Size)917 HAL_StatusTypeDef HAL_PSSI_Transmit_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
918 {
919   HAL_StatusTypeDef dmaxferstatus;
920 
921   if (hpssi->State == HAL_PSSI_STATE_READY)
922   {
923 
924     /* Process Locked */
925     __HAL_LOCK(hpssi);
926 
927     hpssi->State       = HAL_PSSI_STATE_BUSY_TX;
928     hpssi->ErrorCode   = HAL_PSSI_ERROR_NONE;
929 
930     /* Disable the selected PSSI peripheral */
931     HAL_PSSI_DISABLE(hpssi);
932 
933     /* Prepare transfer parameters */
934     hpssi->pBuffPtr    = pData;
935     hpssi->XferCount   = Size;
936 
937     if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
938     {
939       hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
940     }
941     else
942     {
943       hpssi->XferSize = hpssi->XferCount;
944     }
945 
946     if (hpssi->XferSize > 0U)
947     {
948       if (hpssi->hdmatx != NULL)
949       {
950 
951         /* Configure BusWidth */
952         if (hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
953         {
954           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
955                      PSSI_CR_DMA_ENABLE | PSSI_CR_OUTEN_OUTPUT |
956                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL));
957         }
958         else
959         {
960           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
961                      PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth | PSSI_CR_OUTEN_OUTPUT |
962                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL));
963         }
964 
965         /* Set the PSSI DMA transfer complete callback */
966         hpssi->hdmatx->XferCpltCallback = PSSI_DMATransmitCplt;
967 
968         /* Set the DMA error callback */
969         hpssi->hdmatx->XferErrorCallback = PSSI_DMAError;
970 
971         /* Set the unused DMA callbacks to NULL */
972         hpssi->hdmatx->XferHalfCpltCallback = NULL;
973         hpssi->hdmatx->XferAbortCallback = NULL;
974 
975         /* Enable the DMA  */
976         dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmatx, (uint32_t)pData, (uint32_t)&hpssi->Instance->DR,
977                                          hpssi->XferSize);
978       }
979       else
980       {
981         /* Update PSSI state */
982         hpssi->State     = HAL_PSSI_STATE_READY;
983 
984         /* Update PSSI error code */
985         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
986 
987         /* Process Unlocked */
988         __HAL_UNLOCK(hpssi);
989 
990         return HAL_ERROR;
991       }
992 
993       if (dmaxferstatus == HAL_OK)
994       {
995 
996 
997         /* Update XferCount value */
998         hpssi->XferCount -= hpssi->XferSize;
999 
1000         /* Process Unlocked */
1001         __HAL_UNLOCK(hpssi);
1002 
1003         /* Note : The PSSI interrupts must be enabled after unlocking current process
1004                   to avoid the risk of PSSI interrupt handle execution before current
1005                   process unlock */
1006         /* Enable ERR interrupt */
1007         HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1008 
1009         /* Enable DMA Request */
1010         hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
1011         /* Enable the selected PSSI peripheral */
1012         HAL_PSSI_ENABLE(hpssi);
1013       }
1014       else
1015       {
1016         /* Update PSSI state */
1017         hpssi->State     = HAL_PSSI_STATE_READY;
1018 
1019         /* Update PSSI error code */
1020         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1021 
1022         /* Process Unlocked */
1023         __HAL_UNLOCK(hpssi);
1024 
1025         return HAL_ERROR;
1026       }
1027     }
1028     else
1029     {
1030       /* Process Unlocked */
1031       __HAL_UNLOCK(hpssi);
1032 
1033       /* Note : The PSSI interrupts must be enabled after unlocking current process
1034                 to avoid the risk of PSSI interrupt handle execution before current
1035                 process unlock */
1036       /* Enable ERRinterrupt */
1037       /* possible to enable all of these */
1038 
1039       HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1040     }
1041 
1042     return HAL_OK;
1043   }
1044   else
1045   {
1046     return HAL_BUSY;
1047   }
1048 }
1049 
1050 /**
1051   * @brief  Receive an amount of data in non-blocking mode with DMA
1052   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1053   *                the configuration information for the specified PSSI.
1054   * @param  pData Pointer to data buffer
1055   * @param  Size Amount of data to be received (in bytes)
1056   * @retval HAL status
1057   */
HAL_PSSI_Receive_DMA(PSSI_HandleTypeDef * hpssi,uint32_t * pData,uint32_t Size)1058 HAL_StatusTypeDef HAL_PSSI_Receive_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
1059 {
1060 
1061   HAL_StatusTypeDef dmaxferstatus;
1062 
1063   if (hpssi->State == HAL_PSSI_STATE_READY)
1064   {
1065 
1066     /* Disable the selected PSSI peripheral */
1067     HAL_PSSI_DISABLE(hpssi);
1068     /* Process Locked */
1069     __HAL_LOCK(hpssi);
1070 
1071     hpssi->State       = HAL_PSSI_STATE_BUSY_RX;
1072     hpssi->ErrorCode   = HAL_PSSI_ERROR_NONE;
1073 
1074     /* Prepare transfer parameters */
1075     hpssi->pBuffPtr    = pData;
1076     hpssi->XferCount   = Size;
1077 
1078     if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
1079     {
1080       hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
1081     }
1082     else
1083     {
1084       hpssi->XferSize = hpssi->XferCount;
1085     }
1086 
1087     if (hpssi->XferSize > 0U)
1088     {
1089       if (hpssi->hdmarx != NULL)
1090       {
1091 
1092         /* Configure BusWidth */
1093         if (hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
1094         {
1095           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL, PSSI_CR_DMA_ENABLE |
1096                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? PSSI_CR_CKPOL : 0U));
1097         }
1098         else
1099         {
1100           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
1101                      PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth |
1102                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? PSSI_CR_CKPOL : 0U));
1103         }
1104 
1105         /* Set the PSSI DMA transfer complete callback */
1106         hpssi->hdmarx->XferCpltCallback = PSSI_DMAReceiveCplt;
1107 
1108         /* Set the DMA error callback */
1109         hpssi->hdmarx->XferErrorCallback = PSSI_DMAError;
1110 
1111         /* Set the unused DMA callbacks to NULL */
1112         hpssi->hdmarx->XferHalfCpltCallback = NULL;
1113         hpssi->hdmarx->XferAbortCallback = NULL;
1114 
1115         /* Enable the DMA  */
1116         dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmarx, (uint32_t)&hpssi->Instance->DR, (uint32_t)pData,
1117                                          hpssi->XferSize);
1118       }
1119       else
1120       {
1121         /* Update PSSI state */
1122         hpssi->State     = HAL_PSSI_STATE_READY;
1123 
1124         /* Update PSSI error code */
1125         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1126 
1127         /* Process Unlocked */
1128         __HAL_UNLOCK(hpssi);
1129 
1130         return HAL_ERROR;
1131       }
1132 
1133       if (dmaxferstatus == HAL_OK)
1134       {
1135         /* Update XferCount value */
1136         hpssi->XferCount -= hpssi->XferSize;
1137 
1138         /* Process Unlocked */
1139         __HAL_UNLOCK(hpssi);
1140 
1141         /* Note : The PSSI interrupts must be enabled after unlocking current process
1142                   to avoid the risk of PSSI interrupt handle execution before current
1143                   process unlock */
1144         /* Enable ERR  interrupt */
1145         HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1146 
1147         /* Enable DMA Request */
1148         hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
1149         /* Enable the selected PSSI peripheral */
1150         HAL_PSSI_ENABLE(hpssi);
1151       }
1152       else
1153       {
1154         /* Update PSSI state */
1155         hpssi->State     = HAL_PSSI_STATE_READY;
1156 
1157         /* Update PSSI error code */
1158         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1159 
1160         /* Process Unlocked */
1161         __HAL_UNLOCK(hpssi);
1162 
1163         return HAL_ERROR;
1164       }
1165     }
1166     else
1167     {
1168 
1169       /* Process Unlocked */
1170       __HAL_UNLOCK(hpssi);
1171 
1172       /* Enable ERR,interrupt */
1173       HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1174     }
1175 
1176     return HAL_OK;
1177   }
1178   else
1179   {
1180     return HAL_BUSY;
1181   }
1182 }
1183 
1184 
1185 
1186 /**
1187   * @brief  Abort a DMA process communication with Interrupt.
1188   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1189   *                the configuration information for the specified PSSI.
1190   * @retval HAL status
1191   */
HAL_PSSI_Abort_DMA(PSSI_HandleTypeDef * hpssi)1192 HAL_StatusTypeDef HAL_PSSI_Abort_DMA(PSSI_HandleTypeDef *hpssi)
1193 {
1194 
1195   /* Process Locked */
1196   __HAL_LOCK(hpssi);
1197 
1198   /* Disable Interrupts */
1199   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1200 
1201   /* Set State at HAL_PSSI_STATE_ABORT */
1202   hpssi->State = HAL_PSSI_STATE_ABORT;
1203 
1204   /* Abort DMA TX transfer if any */
1205   if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1206   {
1207     if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1208     {
1209 
1210       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1211 
1212       if (hpssi->hdmatx != NULL)
1213       {
1214         /* Set the PSSI DMA Abort callback :
1215         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1216         hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1217 
1218         /* Abort DMA TX */
1219         if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1220         {
1221           /* Call Directly XferAbortCallback function in case of error */
1222           hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1223         }
1224       }
1225 
1226     }
1227     /* Abort DMA RX transfer if any */
1228     else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1229     {
1230 
1231       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1232 
1233       if (hpssi->hdmarx != NULL)
1234       {
1235         /* Set the PSSI DMA Abort callback :
1236         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1237         hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1238 
1239         /* Abort DMA RX */
1240         if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1241         {
1242           /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1243           hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1244         }
1245       }
1246     }
1247     else
1248     {
1249       /* Call the error callback */
1250       hpssi->ErrorCallback(hpssi);
1251     }
1252   }
1253 
1254 
1255   /* Process Unlocked */
1256   __HAL_UNLOCK(hpssi);
1257 
1258   /* Note : The PSSI interrupts must be enabled after unlocking current process
1259             to avoid the risk of PSSI interrupt handle execution before current
1260             process unlock */
1261   HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1262 
1263   return HAL_OK;
1264 
1265 }
1266 
1267 /**
1268   * @}
1269   */
1270 
1271 /** @defgroup PSSI_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
1272   * @{
1273   */
1274 
1275 /**
1276   * @brief  This function handles PSSI event interrupt request.
1277   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1278   *                the configuration information for the specified PSSI.
1279   * @retval None
1280   */
HAL_PSSI_IRQHandler(PSSI_HandleTypeDef * hpssi)1281 void HAL_PSSI_IRQHandler(PSSI_HandleTypeDef *hpssi)
1282 {
1283   /* Overrun/ Underrun Errors */
1284   if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_MIS) != 0U)
1285   {
1286     /* Reset handle parameters */
1287 
1288     hpssi->XferCount     = 0U;
1289 
1290     /* Disable all interrupts */
1291     HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1292 
1293 
1294     /* Abort DMA TX transfer if any */
1295     if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1296     {
1297       if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1298       {
1299         /* Set new error code */
1300         hpssi->ErrorCode |= HAL_PSSI_ERROR_UNDER_RUN;
1301 
1302         hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1303 
1304         if (hpssi->hdmatx != NULL)
1305         {
1306           /* Set the PSSI DMA Abort callback :
1307           will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1308           hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1309 
1310           /* Process Unlocked */
1311           __HAL_UNLOCK(hpssi);
1312 
1313           /* Abort DMA TX */
1314           if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1315           {
1316             /* Call Directly XferAbortCallback function in case of error */
1317             hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1318           }
1319         }
1320 
1321       }
1322       /* Abort DMA RX transfer if any */
1323       else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1324       {
1325         /* Set new error code */
1326         hpssi->ErrorCode |= HAL_PSSI_ERROR_OVER_RUN;
1327 
1328         hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1329 
1330         if (hpssi->hdmarx != NULL)
1331         {
1332           /* Set the PSSI DMA Abort callback :
1333           will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1334           hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1335 
1336           /* Process Unlocked */
1337           __HAL_UNLOCK(hpssi);
1338 
1339           /* Abort DMA RX */
1340           if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1341           {
1342             /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1343             hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1344           }
1345         }
1346       }
1347       else
1348       {
1349         /* Call the corresponding callback to inform upper layer of the error */
1350         hpssi->ErrorCallback(hpssi);
1351       }
1352     }
1353 
1354     /* If state is an abort treatment on going, don't change state */
1355     if (hpssi->State == HAL_PSSI_STATE_ABORT)
1356     {
1357       hpssi->State = HAL_PSSI_STATE_READY;
1358 
1359       /* Process Unlocked */
1360       __HAL_UNLOCK(hpssi);
1361 
1362       /* Call the corresponding callback to inform upper layer of End of Transfer */
1363       hpssi->AbortCpltCallback(hpssi);
1364 
1365     }
1366     else
1367     {
1368       /* Set HAL_PSSI_STATE_READY */
1369       hpssi->State         = HAL_PSSI_STATE_READY;
1370       /* Process Unlocked */
1371       __HAL_UNLOCK(hpssi);
1372 
1373       /* Call the corresponding callback to inform upper layer of End of Transfer */
1374       hpssi->ErrorCallback(hpssi);
1375 
1376     }
1377 
1378   }
1379 }
1380 
1381 
1382 /**
1383   * @brief   Tx Transfer complete callback.
1384   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1385   *                the configuration information for the specified PSSI.
1386   * @retval None
1387   */
HAL_PSSI_TxCpltCallback(PSSI_HandleTypeDef * hpssi)1388 __weak void HAL_PSSI_TxCpltCallback(PSSI_HandleTypeDef *hpssi)
1389 {
1390   /* Prevent unused argument(s) compilation warning */
1391   UNUSED(hpssi);
1392 
1393   /* NOTE : This function should not be modified, when the callback is needed,
1394             the HAL_PSSI_TxCpltCallback can be implemented in the user file
1395    */
1396 }
1397 
1398 /**
1399   * @brief   Rx Transfer complete callback.
1400   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1401   *                the configuration information for the specified PSSI.
1402   * @retval None
1403   */
HAL_PSSI_RxCpltCallback(PSSI_HandleTypeDef * hpssi)1404 __weak void HAL_PSSI_RxCpltCallback(PSSI_HandleTypeDef *hpssi)
1405 {
1406   /* Prevent unused argument(s) compilation warning */
1407   UNUSED(hpssi);
1408 
1409   /* NOTE : This function should not be modified, when the callback is needed,
1410             the HAL_PSSI_RxCpltCallback can be implemented in the user file
1411    */
1412 }
1413 
1414 
1415 /**
1416   * @brief  PSSI error callback.
1417   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1418   *                the configuration information for the specified PSSI.
1419   * @retval None
1420   */
HAL_PSSI_ErrorCallback(PSSI_HandleTypeDef * hpssi)1421 __weak void HAL_PSSI_ErrorCallback(PSSI_HandleTypeDef *hpssi)
1422 {
1423   /* Prevent unused argument(s) compilation warning */
1424   UNUSED(hpssi);
1425 
1426   /* NOTE : This function should not be modified, when the callback is needed,
1427             the HAL_PSSI_ErrorCallback could be implemented in the user file
1428    */
1429 }
1430 
1431 /**
1432   * @brief  PSSI abort callback.
1433   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1434   *                the configuration information for the specified PSSI.
1435   * @retval None
1436   */
HAL_PSSI_AbortCpltCallback(PSSI_HandleTypeDef * hpssi)1437 __weak void HAL_PSSI_AbortCpltCallback(PSSI_HandleTypeDef *hpssi)
1438 {
1439   /* Prevent unused argument(s) compilation warning */
1440   UNUSED(hpssi);
1441 
1442   /* NOTE : This function should not be modified, when the callback is needed,
1443             the HAL_PSSI_AbortCpltCallback could be implemented in the user file
1444    */
1445 }
1446 
1447 /**
1448   * @}
1449   */
1450 
1451 /** @defgroup PSSI_Exported_Functions_Group3 Peripheral State and Error functions
1452   *  @brief   Peripheral State, Mode and Error functions
1453   *
1454 @verbatim
1455  ===============================================================================
1456             ##### Peripheral State, Mode and Error functions #####
1457  ===============================================================================
1458     [..]
1459     This subsection permit to get in run-time the status of the peripheral
1460     and the data flow.
1461 
1462 @endverbatim
1463   * @{
1464   */
1465 
1466 /**
1467   * @brief  Return the PSSI handle state.
1468   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1469   *                the configuration information for the specified PSSI.
1470   * @retval HAL state
1471   */
HAL_PSSI_GetState(PSSI_HandleTypeDef * hpssi)1472 HAL_PSSI_StateTypeDef HAL_PSSI_GetState(PSSI_HandleTypeDef *hpssi)
1473 {
1474   /* Return PSSI handle state */
1475   return hpssi->State;
1476 }
1477 
1478 
1479 /**
1480   * @brief  Return the PSSI error code.
1481   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1482   *              the configuration information for the specified PSSI.
1483   * @retval PSSI Error Code
1484   */
HAL_PSSI_GetError(PSSI_HandleTypeDef * hpssi)1485 uint32_t HAL_PSSI_GetError(PSSI_HandleTypeDef *hpssi)
1486 {
1487   return hpssi->ErrorCode;
1488 }
1489 
1490 /**
1491   * @}
1492   */
1493 
1494 /**
1495   * @}
1496   */
1497 
1498 /** @addtogroup PSSI_Private_Functions
1499   * @{
1500   */
1501 
1502 /**
1503   * @brief  PSSI Errors process.
1504   * @param  hpssi PSSI handle.
1505   * @param  ErrorCode Error code to handle.
1506   * @retval None
1507   */
PSSI_Error(PSSI_HandleTypeDef * hpssi,uint32_t ErrorCode)1508 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode)
1509 {
1510 
1511   /* Reset handle parameters */
1512 
1513   hpssi->XferCount     = 0U;
1514 
1515   /* Set new error code */
1516   hpssi->ErrorCode |= ErrorCode;
1517 
1518   /* Disable all interrupts */
1519   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1520 
1521 
1522   /* Abort DMA TX transfer if any */
1523   if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1524   {
1525     if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1526     {
1527       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1528 
1529       if (hpssi->hdmatx != NULL)
1530       {
1531         /* Set the PSSI DMA Abort callback :
1532         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1533         hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1534 
1535         /* Process Unlocked */
1536         __HAL_UNLOCK(hpssi);
1537 
1538         /* Abort DMA TX */
1539         if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1540         {
1541           /* Call Directly XferAbortCallback function in case of error */
1542           hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1543         }
1544       }
1545 
1546     }
1547     /* Abort DMA RX transfer if any */
1548     else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1549     {
1550       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1551 
1552       if (hpssi->hdmarx != NULL)
1553       {
1554         /* Set the PSSI DMA Abort callback :
1555         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1556         hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1557 
1558         /* Process Unlocked */
1559         __HAL_UNLOCK(hpssi);
1560 
1561         /* Abort DMA RX */
1562         if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1563         {
1564           /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1565           hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1566         }
1567       }
1568     }
1569     else
1570     {
1571       /*Nothing to do*/
1572     }
1573   }
1574 
1575   /* If state is an abort treatment on going, don't change state */
1576   if (hpssi->State == HAL_PSSI_STATE_ABORT)
1577   {
1578     hpssi->State = HAL_PSSI_STATE_READY;
1579 
1580     /* Process Unlocked */
1581     __HAL_UNLOCK(hpssi);
1582 
1583     /* Call the corresponding callback to inform upper layer of End of Transfer */
1584 
1585     hpssi->AbortCpltCallback(hpssi);
1586 
1587   }
1588   else
1589   {
1590     /* Set HAL_PSSI_STATE_READY */
1591     hpssi->State = HAL_PSSI_STATE_READY;
1592 
1593     /* Process Unlocked */
1594     __HAL_UNLOCK(hpssi);
1595 
1596     /* Call the corresponding callback to inform upper layer of End of Transfer */
1597     hpssi->ErrorCallback(hpssi);
1598 
1599   }
1600 }
1601 
1602 /**
1603   * @brief  DMA PSSI slave transmit process complete callback.
1604   * @param  hdma DMA handle
1605   * @retval None
1606   */
PSSI_DMATransmitCplt(DMA_HandleTypeDef * hdma)1607 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
1608 {
1609   /* Derogation MISRAC2012-Rule-11.5 */
1610   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1611 
1612   uint32_t tmperror;
1613 
1614 
1615   /* Disable Interrupts */
1616   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1617 
1618   /* Store current volatile hpssi->ErrorCode, misra rule */
1619   tmperror = hpssi->ErrorCode;
1620 
1621   /* Call the corresponding callback to inform upper layer of End of Transfer */
1622   if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1623   {
1624     /* Call the corresponding callback to inform upper layer of End of Transfer */
1625     PSSI_Error(hpssi, hpssi->ErrorCode);
1626   }
1627   /* hpssi->State == HAL_PSSI_STATE_BUSY_TX */
1628   else
1629   {
1630     hpssi->State = HAL_PSSI_STATE_READY;
1631 
1632     /* Process Unlocked */
1633     __HAL_UNLOCK(hpssi);
1634 
1635     /* Call the corresponding callback to inform upper layer of End of Transfer */
1636 
1637     hpssi->TxCpltCallback(hpssi);
1638 
1639   }
1640 
1641 
1642 }
1643 
1644 /**
1645   * @brief DMA PSSI master receive process complete callback.
1646   * @param  hdma DMA handle
1647   * @retval None
1648   */
PSSI_DMAReceiveCplt(DMA_HandleTypeDef * hdma)1649 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1650 {
1651   /* Derogation MISRAC2012-Rule-11.5 */
1652   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1653 
1654   uint32_t tmperror;
1655 
1656 
1657   /* Disable Interrupts */
1658   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1659 
1660   /* Store current volatile hpssi->ErrorCode, misra rule */
1661   tmperror = hpssi->ErrorCode;
1662 
1663   /* Call the corresponding callback to inform upper layer of End of Transfer */
1664   if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1665   {
1666     /* Call the corresponding callback to inform upper layer of End of Transfer */
1667     PSSI_Error(hpssi, hpssi->ErrorCode);
1668   }
1669   /* hpssi->State == HAL_PSSI_STATE_BUSY_RX */
1670   else
1671   {
1672     hpssi->State = HAL_PSSI_STATE_READY;
1673 
1674     /* Process Unlocked */
1675     __HAL_UNLOCK(hpssi);
1676 
1677     /* Call the corresponding callback to inform upper layer of End of Transfer */
1678     hpssi->RxCpltCallback(hpssi);
1679 
1680   }
1681 
1682 
1683 }
1684 
1685 /**
1686   * @brief DMA PSSI communication abort callback
1687   *        (To be called at end of DMA Abort procedure).
1688   * @param hdma DMA handle.
1689   * @retval None
1690   */
PSSI_DMAAbort(DMA_HandleTypeDef * hdma)1691 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma)
1692 {
1693   /* Derogation MISRAC2012-Rule-11.5 */
1694   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1695 
1696   /* Reset AbortCpltCallback */
1697   hpssi->hdmatx->XferAbortCallback = NULL;
1698   hpssi->hdmarx->XferAbortCallback = NULL;
1699 
1700   /* Check if come from abort from user */
1701   if (hpssi->State == HAL_PSSI_STATE_ABORT)
1702   {
1703     hpssi->State = HAL_PSSI_STATE_READY;
1704 
1705     /* Call the corresponding callback to inform upper layer of End of Transfer */
1706 
1707     hpssi->AbortCpltCallback(hpssi);
1708 
1709   }
1710   else
1711   {
1712     /* Call the corresponding callback to inform upper layer of End of Transfer */
1713     hpssi->ErrorCallback(hpssi);
1714   }
1715 }
1716 
1717 /**
1718   * @brief  This function handles PSSI Communication Timeout.
1719   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1720   *                the configuration information for the specified PSSI.
1721   * @param  Flag Specifies the PSSI flag to check.
1722   * @param  Status The new Flag status (SET or RESET).
1723   * @param  Timeout Timeout duration
1724   * @param  Tickstart Tick start value
1725   * @retval HAL status
1726   */
PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef * hpssi,uint32_t Flag,FlagStatus Status,uint32_t Timeout,uint32_t Tickstart)1727 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status,
1728                                                        uint32_t Timeout, uint32_t Tickstart)
1729 {
1730   while ((HAL_PSSI_GET_STATUS(hpssi, Flag) & Flag) == (uint32_t)Status)
1731   {
1732     /* Check for the Timeout */
1733     if (Timeout != HAL_MAX_DELAY)
1734     {
1735       if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
1736       {
1737         hpssi->ErrorCode |= HAL_PSSI_ERROR_TIMEOUT;
1738         hpssi->State = HAL_PSSI_STATE_READY;
1739 
1740         /* Process Unlocked */
1741         __HAL_UNLOCK(hpssi);
1742 
1743         return HAL_ERROR;
1744       }
1745     }
1746   }
1747   return HAL_OK;
1748 }
PSSI_DMAError(DMA_HandleTypeDef * hdma)1749 void PSSI_DMAError(DMA_HandleTypeDef *hdma)
1750 {
1751   /* Derogation MISRAC2012-Rule-11.5 */
1752   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1753 
1754   uint32_t tmperror;
1755 
1756 
1757   /* Disable the selected PSSI peripheral */
1758   HAL_PSSI_DISABLE(hpssi);
1759 
1760   /* Disable Interrupts */
1761   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1762 
1763   /* Store current volatile hpssi->ErrorCode, misra rule */
1764   tmperror = hpssi->ErrorCode;
1765 
1766   /* Call the corresponding callback to inform upper layer of End of Transfer */
1767   if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1768   {
1769     /* Call the corresponding callback to inform upper layer of End of Transfer */
1770     PSSI_Error(hpssi, hpssi->ErrorCode);
1771   }
1772   else
1773   {
1774     hpssi->State = HAL_PSSI_STATE_READY;
1775 
1776     /* Process Unlocked */
1777     __HAL_UNLOCK(hpssi);
1778 
1779     /* Call the corresponding callback to inform upper layer of End of Transfer */
1780     hpssi->ErrorCallback(hpssi);
1781 
1782   }
1783 
1784 }
1785 
1786 
1787 
1788 /**
1789   * @}
1790   */
1791 #endif /* PSSI */
1792 #endif /* HAL_PSSI_MODULE_ENABLED */
1793 /**
1794   * @}
1795   */
1796 
1797 /**
1798   * @}
1799   */
1800