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