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