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