Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:08

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_pssi.c
0004   * @author  MCD Application Team
0005   * @brief   PSSI HAL module driver.
0006   *          This file provides firmware functions to manage the following
0007   *          functionalities of the Parallel Synchronous Slave Interface (PSSI) peripheral:
0008   *           + Initialization and de-initialization functions
0009   *           + IO operation functions
0010   *           + Peripheral State and Errors functions
0011   *
0012   ******************************************************************************
0013   * @attention
0014   *
0015   * Copyright (c) 2019 STMicroelectronics.
0016   * All rights reserved.
0017   *
0018   * This software is licensed under terms that can be found in the LICENSE file
0019   * in the root directory of this software component.
0020   * If no LICENSE file comes with this software, it is provided AS-IS.
0021   *
0022   ******************************************************************************
0023   @verbatim
0024   ==============================================================================
0025                         ##### How to use this driver #####
0026   ==============================================================================
0027     [..]
0028     The PSSI HAL driver can be used as follows:
0029 
0030     (#) Declare a PSSI_HandleTypeDef handle structure, for example:
0031         PSSI_HandleTypeDef  hpssi;
0032 
0033     (#) Initialize the PSSI low level resources by implementing the @ref HAL_PSSI_MspInit() API:
0034         (##) Enable the PSSIx interface clock
0035         (##) PSSI pins configuration
0036             (+++) Enable the clock for the PSSI GPIOs
0037             (+++) Configure PSSI pins as alternate function open-drain
0038         (##) NVIC configuration if you need to use interrupt process
0039             (+++) Configure the PSSIx interrupt priority
0040             (+++) Enable the NVIC PSSI IRQ Channel
0041         (##) DMA Configuration if you need to use DMA process
0042             (+++) Declare  DMA_HandleTypeDef handles structure for the transmit and receive
0043             (+++) Enable the DMAx interface clock
0044             (+++) Configure the DMA handle parameters
0045             (+++) Configure the DMA Tx and Rx
0046             (+++) Associate the initialized DMA handle to the hpssi DMA Tx and Rx handle
0047             (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
0048                   the DMA Tx and Rx
0049 
0050     (#) Configure the Communication Bus Width,  Control Signals, Input Polarity and Output Polarity
0051          in the hpssi Init structure.
0052 
0053     (#) Initialize the PSSI registers by calling the @ref HAL_PSSI_Init(), configure also the low level Hardware
0054         (GPIO, CLOCK, NVIC...etc) by calling the customized @ref HAL_PSSI_MspInit(&hpssi) API.
0055 
0056     (#) For PSSI IO operations, two operation modes are available within this driver :
0057 
0058     *** Polling mode IO operation ***
0059     =================================
0060     [..]
0061       (+) Transmit an amount of data by byte in blocking mode using @ref HAL_PSSI_Transmit()
0062       (+) Receive an amount of data by byte in blocking mode using @ref HAL_PSSI_Receive()
0063 
0064     *** DMA mode IO operation ***
0065     ==============================
0066     [..]
0067       (+) Transmit an amount of data in non-blocking mode (DMA) using
0068           @ref HAL_PSSI_Transmit_DMA()
0069       (+) At transmission end of transfer, @ref HAL_PSSI_TxCpltCallback() is executed and user can
0070            add his own code by customization of function pointer @ref HAL_PSSI_TxCpltCallback()
0071       (+) Receive an amount of data in non-blocking mode (DMA) using
0072           @ref HAL_PSSI_Receive_DMA()
0073       (+) At reception end of transfer, @ref HAL_PSSI_RxCpltCallback() is executed and user can
0074            add his own code by customization of function pointer @ref HAL_PSSI_RxCpltCallback()
0075       (+) In case of transfer Error, @ref HAL_PSSI_ErrorCallback() function is executed and user can
0076            add his own code by customization of function pointer @ref HAL_PSSI_ErrorCallback()
0077       (+) Abort a  PSSI process communication with Interrupt using @ref HAL_PSSI_Abort_IT()
0078       (+) End of abort process, @ref HAL_PSSI_AbortCpltCallback() is executed and user can
0079            add his own code by customization of function pointer @ref HAL_PSSI_AbortCpltCallback()
0080 
0081      *** PSSI HAL driver macros list ***
0082      ==================================
0083      [..]
0084        Below the list of most used macros in PSSI HAL driver.
0085 
0086       (+) @ref HAL_PSSI_ENABLE     : Enable the PSSI peripheral
0087       (+) @ref HAL_PSSI_DISABLE    : Disable the PSSI peripheral
0088       (+) @ref HAL_PSSI_GET_FLAG   : Check whether the specified PSSI flag is set or not
0089       (+) @ref HAL_PSSI_CLEAR_FLAG : Clear the specified PSSI pending flag
0090       (+) @ref HAL_PSSI_ENABLE_IT  : Enable the specified PSSI interrupt
0091       (+) @ref HAL_PSSI_DISABLE_IT : Disable the specified PSSI interrupt
0092 
0093      *** Callback registration ***
0094      =============================================
0095      Use Functions @ref HAL_PSSI_RegisterCallback() or @ref HAL_PSSI_RegisterAddrCallback()
0096      to register an interrupt callback.
0097 
0098      Function @ref HAL_PSSI_RegisterCallback() allows to register following callbacks:
0099        (+) TxCpltCallback       : callback for transmission end of transfer.
0100        (+) RxCpltCallback       : callback for reception end of transfer.
0101        (+) ErrorCallback        : callback for error detection.
0102        (+) AbortCpltCallback    : callback for abort completion process.
0103        (+) MspInitCallback      : callback for Msp Init.
0104        (+) MspDeInitCallback    : callback for Msp DeInit.
0105      This function takes as parameters the HAL peripheral handle, the Callback ID
0106      and a pointer to the user callback function.
0107 
0108 
0109      Use function @ref HAL_PSSI_UnRegisterCallback to reset a callback to the default
0110      weak function.
0111      @ref HAL_PSSI_UnRegisterCallback takes as parameters the HAL peripheral handle,
0112      and the Callback ID.
0113      This function allows to reset following callbacks:
0114        (+) TxCpltCallback       : callback for transmission end of transfer.
0115        (+) RxCpltCallback       : callback for reception end of transfer.
0116        (+) ErrorCallback        : callback for error detection.
0117        (+) AbortCpltCallback    : callback for abort completion process.
0118        (+) MspInitCallback      : callback for Msp Init.
0119        (+) MspDeInitCallback    : callback for Msp DeInit.
0120 
0121 
0122      By default, after the @ref HAL_PSSI_Init() and when the state is @ref HAL_PSSI_STATE_RESET
0123      all callbacks are set to the corresponding weak functions:
0124      examples @ref HAL_PSSI_TxCpltCallback(), @ref HAL_PSSI_RxCpltCallback().
0125      Exception done for MspInit and MspDeInit functions that are
0126      reset to the legacy weak functions in the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit() only when
0127      these callbacks are null (not registered beforehand).
0128      If MspInit or MspDeInit are not null, the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit()
0129      keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
0130 
0131      Callbacks can be registered/unregistered in @ref HAL_PSSI_STATE_READY state only.
0132      Exception done MspInit/MspDeInit functions that can be registered/unregistered
0133      in @ref HAL_PSSI_STATE_READY or @ref HAL_PSSI_STATE_RESET state,
0134      thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
0135      Then, the user first registers the MspInit/MspDeInit user callbacks
0136      using @ref HAL_PSSI_RegisterCallback() before calling @ref HAL_PSSI_DeInit()
0137      or @ref HAL_PSSI_Init() function.
0138 
0139 
0140      [..]
0141        (@) You can refer to the PSSI HAL driver header file for more useful macros
0142 
0143   @endverbatim
0144   */
0145 
0146 /* Includes ------------------------------------------------------------------*/
0147 #include "stm32h7xx_hal.h"
0148 
0149 /** @addtogroup STM32H7xx_HAL_Driver
0150   * @{
0151   */
0152 
0153 /** @defgroup PSSI PSSI
0154   * @ingroup RTEMSBSPsARMSTM32H7
0155   * @brief PSSI HAL module driver
0156   * @{
0157   */
0158 
0159 #ifdef HAL_PSSI_MODULE_ENABLED
0160 #if defined(PSSI)
0161 /* Private typedef -----------------------------------------------------------*/
0162 /* Private define ------------------------------------------------------------*/
0163 
0164 /** @defgroup PSSI_Private_Define PSSI Private Define
0165   * @ingroup RTEMSBSPsARMSTM32H7
0166   * @{
0167   */
0168 
0169 
0170 
0171 /**
0172   * @}
0173   */
0174 
0175 /* Private macro -------------------------------------------------------------*/
0176 /* Private variables ---------------------------------------------------------*/
0177 /* Private function prototypes -----------------------------------------------*/
0178 
0179 /** @defgroup PSSI_Private_Functions PSSI Private Functions
0180   * @ingroup RTEMSBSPsARMSTM32H7
0181   * @{
0182   */
0183 /* Private functions to handle DMA transfer */
0184 #if defined(HAL_DMA_MODULE_ENABLED)
0185 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
0186 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
0187 void PSSI_DMAError(DMA_HandleTypeDef *hdma);
0188 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma);
0189 #endif /*HAL_DMA_MODULE_ENABLED*/
0190 
0191 /* Private functions to handle IT transfer */
0192 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode);
0193 
0194 
0195 /* Private functions for PSSI transfer IRQ handler */
0196 
0197 
0198 /* Private functions to handle flags during polling transfer */
0199 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status,
0200                                                        uint32_t Timeout, uint32_t Tickstart);
0201 
0202 /* Private functions to centralize the enable/disable of Interrupts */
0203 
0204 
0205 /**
0206   * @}
0207   */
0208 
0209 /* Exported functions --------------------------------------------------------*/
0210 
0211 /** @defgroup PSSI_Exported_Functions PSSI Exported Functions
0212   * @ingroup RTEMSBSPsARMSTM32H7
0213   * @{
0214   */
0215 
0216 /** @defgroup PSSI_Exported_Functions_Group1 Initialization and de-initialization functions
0217   * @ingroup RTEMSBSPsARMSTM32H7
0218   *  @brief    Initialization and Configuration functions
0219   *
0220 @verbatim
0221  ===============================================================================
0222               ##### Initialization and de-initialization functions #####
0223  ===============================================================================
0224     [..]  This subsection provides a set of functions allowing to initialize and
0225           deinitialize the PSSIx peripheral:
0226 
0227       (+) User must implement HAL_PSSI_MspInit() function in which he configures
0228           all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
0229 
0230       (+) Call the function HAL_PSSI_Init() to configure the selected device with
0231           the selected configuration:
0232         (++) Data Width
0233         (++) Control Signals
0234         (++) Input Clock polarity
0235         (++) Output Clock polarity
0236 
0237       (+) Call the function HAL_PSSI_DeInit() to restore the default configuration
0238           of the selected PSSIx peripheral.
0239 
0240 @endverbatim
0241   * @{
0242   */
0243 
0244 /**
0245   * @brief  Initializes the PSSI according to the specified parameters
0246   *         in the PSSI_InitTypeDef and initialize the associated handle.
0247   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0248   *                the configuration information for the specified PSSI.
0249   * @retval HAL status
0250   */
0251 HAL_StatusTypeDef HAL_PSSI_Init(PSSI_HandleTypeDef *hpssi)
0252 {
0253   /* Check the PSSI handle allocation */
0254   if (hpssi == NULL)
0255   {
0256     return HAL_ERROR;
0257   }
0258 
0259   /* Check the parameters */
0260   assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
0261   assert_param(IS_PSSI_CONTROL_SIGNAL(hpssi->Init.ControlSignal));
0262   assert_param(IS_PSSI_BUSWIDTH(hpssi->Init.BusWidth));
0263   assert_param(IS_PSSI_CLOCK_POLARITY(hpssi->Init.ClockPolarity));
0264   assert_param(IS_PSSI_DE_POLARITY(hpssi->Init.DataEnablePolarity));
0265   assert_param(IS_PSSI_RDY_POLARITY(hpssi->Init.ReadyPolarity));
0266 
0267   if (hpssi->State == HAL_PSSI_STATE_RESET)
0268   {
0269     /* Allocate lock resource and initialize it */
0270     hpssi->Lock = HAL_UNLOCKED;
0271 
0272 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
0273     /* Init the PSSI Callback settings */
0274     hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
0275     hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
0276     hpssi->ErrorCallback        = HAL_PSSI_ErrorCallback;        /* Legacy weak ErrorCallback        */
0277     hpssi->AbortCpltCallback    = HAL_PSSI_AbortCpltCallback;    /* Legacy weak AbortCpltCallback    */
0278 
0279     if (hpssi->MspInitCallback == NULL)
0280     {
0281       hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit  */
0282     }
0283 
0284     /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
0285     hpssi->MspInitCallback(hpssi);
0286 #else
0287     /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
0288     HAL_PSSI_MspInit(hpssi);
0289 #endif /*USE_HAL_PSSI_REGISTER_CALLBACKS*/
0290   }
0291 
0292   hpssi->State = HAL_PSSI_STATE_BUSY;
0293 
0294   /* Disable the selected PSSI peripheral */
0295   HAL_PSSI_DISABLE(hpssi);
0296 
0297   /*---------------------------- PSSIx CR Configuration ----------------------*/
0298   /* Configure PSSIx: Control Signal and Bus Width*/
0299 
0300   MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DERDYCFG | PSSI_CR_EDM | PSSI_CR_DEPOL | PSSI_CR_RDYPOL,
0301              hpssi->Init.ControlSignal | hpssi->Init.DataEnablePolarity |
0302              hpssi->Init.ReadyPolarity | hpssi->Init.BusWidth);
0303 
0304   hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
0305   hpssi->State = HAL_PSSI_STATE_READY;
0306 
0307   return HAL_OK;
0308 }
0309 
0310 /**
0311   * @brief  DeInitialize the PSSI peripheral.
0312   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0313   *                the configuration information for the specified PSSI.
0314   * @retval HAL status
0315   */
0316 HAL_StatusTypeDef HAL_PSSI_DeInit(PSSI_HandleTypeDef *hpssi)
0317 {
0318   /* Check the PSSI handle allocation */
0319   if (hpssi == NULL)
0320   {
0321     return HAL_ERROR;
0322   }
0323 
0324   /* Check the parameters */
0325   assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
0326 
0327   hpssi->State = HAL_PSSI_STATE_BUSY;
0328 
0329   /* Disable the PSSI Peripheral Clock */
0330   HAL_PSSI_DISABLE(hpssi);
0331 
0332 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
0333   if (hpssi->MspDeInitCallback == NULL)
0334   {
0335     hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit  */
0336   }
0337 
0338   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
0339   hpssi->MspDeInitCallback(hpssi);
0340 #else
0341   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
0342   HAL_PSSI_MspDeInit(hpssi);
0343 #endif /*USE_HAL_PSSI_REGISTER_CALLBACKS*/
0344 
0345   hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
0346   hpssi->State = HAL_PSSI_STATE_RESET;
0347 
0348   /* Release Lock */
0349   __HAL_UNLOCK(hpssi);
0350 
0351   return HAL_OK;
0352 }
0353 
0354 /**
0355   * @brief Initialize the PSSI MSP.
0356   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0357   *                the configuration information for the specified PSSI.
0358   * @retval None
0359   */
0360 __weak void HAL_PSSI_MspInit(PSSI_HandleTypeDef *hpssi)
0361 {
0362   /* Prevent unused argument(s) compilation warning */
0363   UNUSED(hpssi);
0364 
0365   /* NOTE : This function should not be modified, when the callback is needed,
0366             the HAL_PSSI_MspInit can be implemented in the user file
0367    */
0368 }
0369 
0370 /**
0371   * @brief De-Initialize the PSSI MSP.
0372   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0373   *                the configuration information for the specified PSSI.
0374   * @retval None
0375   */
0376 __weak void HAL_PSSI_MspDeInit(PSSI_HandleTypeDef *hpssi)
0377 {
0378   /* Prevent unused argument(s) compilation warning */
0379   UNUSED(hpssi);
0380 
0381   /* NOTE : This function should not be modified; when the callback is needed,
0382             the HAL_PSSI_MspDeInit can be implemented in the user file
0383    */
0384 }
0385 
0386 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
0387 /**
0388   * @brief  Register a User PSSI Callback
0389   *         To be used instead of the weak predefined callback
0390   * @note   The HAL_PSSI_RegisterCallback() may be called before HAL_PSSI_Init() in
0391   *         HAL_PSSI_STATE_RESET to register callbacks for HAL_PSSI_MSPINIT_CB_ID
0392   *         and HAL_PSSI_MSPDEINIT_CB_ID.
0393   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0394   *                the configuration information for the specified PSSI.
0395   * @param  CallbackID ID of the callback to be registered
0396   *         This parameter can be one of the following values:
0397   *          @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID  Tx Transfer completed callback ID
0398   *          @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID  Rx Transfer completed callback ID
0399   *          @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
0400   *          @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
0401   *          @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
0402   *          @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
0403   * @param  pCallback pointer to the Callback function
0404   * @retval HAL status
0405   */
0406 HAL_StatusTypeDef HAL_PSSI_RegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID,
0407                                             pPSSI_CallbackTypeDef pCallback)
0408 {
0409   HAL_StatusTypeDef status = HAL_OK;
0410 
0411   if (pCallback == NULL)
0412   {
0413     /* Update the error code */
0414     hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
0415 
0416     return HAL_ERROR;
0417   }
0418 
0419   if (HAL_PSSI_STATE_READY == hpssi->State)
0420   {
0421     switch (CallbackID)
0422     {
0423       case HAL_PSSI_TX_COMPLETE_CB_ID :
0424         hpssi->TxCpltCallback = pCallback;
0425         break;
0426 
0427       case HAL_PSSI_RX_COMPLETE_CB_ID :
0428         hpssi->RxCpltCallback = pCallback;
0429         break;
0430 
0431       case HAL_PSSI_ERROR_CB_ID :
0432         hpssi->ErrorCallback = pCallback;
0433         break;
0434 
0435       case HAL_PSSI_ABORT_CB_ID :
0436         hpssi->AbortCpltCallback = pCallback;
0437         break;
0438 
0439       case HAL_PSSI_MSPINIT_CB_ID :
0440         hpssi->MspInitCallback = pCallback;
0441         break;
0442 
0443       case HAL_PSSI_MSPDEINIT_CB_ID :
0444         hpssi->MspDeInitCallback = pCallback;
0445         break;
0446 
0447       default :
0448         /* Update the error code */
0449         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
0450 
0451         /* Return error status */
0452         status =  HAL_ERROR;
0453         break;
0454     }
0455   }
0456   else if (HAL_PSSI_STATE_RESET == hpssi->State)
0457   {
0458     switch (CallbackID)
0459     {
0460       case HAL_PSSI_MSPINIT_CB_ID :
0461         hpssi->MspInitCallback = pCallback;
0462         break;
0463 
0464       case HAL_PSSI_MSPDEINIT_CB_ID :
0465         hpssi->MspDeInitCallback = pCallback;
0466         break;
0467 
0468       default :
0469         /* Update the error code */
0470         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
0471 
0472         /* Return error status */
0473         status =  HAL_ERROR;
0474         break;
0475     }
0476   }
0477   else
0478   {
0479     /* Update the error code */
0480     hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
0481 
0482     /* Return error status */
0483     status =  HAL_ERROR;
0484   }
0485 
0486   return status;
0487 }
0488 
0489 /**
0490   * @brief  Unregister an PSSI Callback
0491   *         PSSI callback is redirected to the weak predefined callback
0492   * @note   The HAL_PSSI_UnRegisterCallback() may be called before HAL_PSSI_Init() in
0493   *         HAL_PSSI_STATE_RESET to un-register callbacks for HAL_PSSI_MSPINIT_CB_ID
0494   *         and HAL_PSSI_MSPDEINIT_CB_ID.
0495   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0496   *                the configuration information for the specified PSSI.
0497   * @param  CallbackID ID of the callback to be unregistered
0498   *         This parameter can be one of the following values:
0499   *          @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID  Tx Transfer completed callback ID
0500   *          @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID  Rx Transfer completed callback ID
0501   *          @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
0502   *          @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
0503   *          @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
0504   *          @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
0505   * @retval HAL status
0506   */
0507 HAL_StatusTypeDef HAL_PSSI_UnRegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID)
0508 {
0509   HAL_StatusTypeDef status = HAL_OK;
0510 
0511   if (HAL_PSSI_STATE_READY == hpssi->State)
0512   {
0513     switch (CallbackID)
0514     {
0515       case HAL_PSSI_TX_COMPLETE_CB_ID :
0516         hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback;             /* Legacy weak TxCpltCallback     */
0517         break;
0518 
0519       case HAL_PSSI_RX_COMPLETE_CB_ID :
0520         hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback;             /* Legacy weak RxCpltCallback     */
0521         break;
0522 
0523       case HAL_PSSI_ERROR_CB_ID :
0524         hpssi->ErrorCallback = HAL_PSSI_ErrorCallback;               /* Legacy weak ErrorCallback      */
0525         break;
0526 
0527       case HAL_PSSI_ABORT_CB_ID :
0528         hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback;       /* Legacy weak AbortCpltCallback  */
0529         break;
0530 
0531       case HAL_PSSI_MSPINIT_CB_ID :
0532         hpssi->MspInitCallback = HAL_PSSI_MspInit;                   /* Legacy weak MspInit            */
0533         break;
0534 
0535       case HAL_PSSI_MSPDEINIT_CB_ID :
0536         hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit;               /* Legacy weak MspDeInit          */
0537         break;
0538 
0539       default :
0540         /* Update the error code */
0541         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
0542 
0543         /* Return error status */
0544         status =  HAL_ERROR;
0545         break;
0546     }
0547   }
0548   else if (HAL_PSSI_STATE_RESET == hpssi->State)
0549   {
0550     switch (CallbackID)
0551     {
0552       case HAL_PSSI_MSPINIT_CB_ID :
0553         hpssi->MspInitCallback = HAL_PSSI_MspInit;                   /* Legacy weak MspInit            */
0554         break;
0555 
0556       case HAL_PSSI_MSPDEINIT_CB_ID :
0557         hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit;               /* Legacy weak MspDeInit          */
0558         break;
0559 
0560       default :
0561         /* Update the error code */
0562         hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
0563 
0564         /* Return error status */
0565         status =  HAL_ERROR;
0566         break;
0567     }
0568   }
0569   else
0570   {
0571     /* Update the error code */
0572     hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
0573 
0574     /* Return error status */
0575     status =  HAL_ERROR;
0576   }
0577 
0578   return status;
0579 }
0580 
0581 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
0582 
0583 /**
0584   * @}
0585   */
0586 
0587 /** @defgroup PSSI_Exported_Functions_Group2 Input and Output operation functions
0588   * @ingroup RTEMSBSPsARMSTM32H7
0589   *  @brief   Data transfers functions
0590   *
0591 @verbatim
0592  ===============================================================================
0593                       ##### IO operation functions #####
0594  ===============================================================================
0595     [..]
0596     This subsection provides a set of functions allowing to manage the PSSI data
0597     transfers.
0598 
0599     (#) There are two modes of transfer:
0600        (++) Blocking mode : The communication is performed in the polling mode.
0601             The status of all data processing is returned by the same function
0602             after finishing transfer.
0603        (++) No-Blocking mode : The communication is performed using DMA.
0604             These functions return the status of the transfer startup.
0605             The end of the data processing will be indicated through the
0606             dedicated  the DMA IRQ .
0607 
0608     (#) Blocking mode functions are :
0609         (++) HAL_PSSI_Transmit()
0610         (++) HAL_PSSI_Receive()
0611 
0612     (#) No-Blocking mode functions with DMA are :
0613         (++) HAL_PSSI_Transmit_DMA()
0614         (++) HAL_PSSI_Receive_DMA()
0615 
0616     (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
0617         (++) HAL_PSSI_TxCpltCallback()
0618         (++) HAL_PSSI_RxCpltCallback()
0619         (++) HAL_PSSI_ErrorCallback()
0620         (++) HAL_PSSI_AbortCpltCallback()
0621 
0622 @endverbatim
0623   * @{
0624   */
0625 
0626 /**
0627   * @brief  Transmits in master mode an amount of data in blocking mode.
0628   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0629   *                the configuration information for the specified PSSI.
0630   * @param  pData Pointer to data buffer
0631   * @param  Size Amount of data to be sent (in bytes)
0632   * @param  Timeout Timeout duration
0633   * @retval HAL status
0634   */
0635 HAL_StatusTypeDef HAL_PSSI_Transmit(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
0636 {
0637   uint32_t tickstart;
0638   uint32_t  transfer_size = Size;
0639 
0640   if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
0641       ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size % 2U) != 0U)) ||
0642       ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size % 4U) != 0U)))
0643   {
0644     hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
0645     return HAL_ERROR;
0646   }
0647   if (hpssi->State == HAL_PSSI_STATE_READY)
0648   {
0649     /* Process Locked */
0650     __HAL_LOCK(hpssi);
0651 
0652     hpssi->State     = HAL_PSSI_STATE_BUSY;
0653     hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
0654 
0655     /* Disable the selected PSSI peripheral */
0656     HAL_PSSI_DISABLE(hpssi);
0657 
0658     /* Configure transfer parameters */
0659     MODIFY_REG(hpssi->Instance->CR, (PSSI_CR_OUTEN | PSSI_CR_CKPOL),
0660               (PSSI_CR_OUTEN_OUTPUT |((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL)));
0661 
0662 #if defined(HAL_DMA_MODULE_ENABLED)
0663     /* DMA Disable */
0664     hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
0665 #endif /*HAL_DMA_MODULE_ENABLED*/
0666 
0667     /* Enable the selected PSSI peripheral */
0668     HAL_PSSI_ENABLE(hpssi);
0669 
0670     if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
0671     {
0672       uint8_t *pbuffer = pData;
0673       while (transfer_size > 0U)
0674       {
0675         /* Init tickstart for timeout management*/
0676         tickstart = HAL_GetTick();
0677         /* Wait until Fifo is ready to transfer one byte flag is set */
0678         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
0679         {
0680           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
0681           hpssi->State = HAL_PSSI_STATE_READY;
0682           /* Process Unlocked */
0683           __HAL_UNLOCK(hpssi);
0684           return HAL_ERROR;
0685         }
0686         /* Write data to DR */
0687         *(__IO uint8_t *)(&hpssi->Instance->DR) = *(uint8_t *)pbuffer;
0688 
0689         /* Increment Buffer pointer */
0690         pbuffer++;
0691 
0692         transfer_size--;
0693       }
0694     }
0695     else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
0696     {
0697       uint16_t *pbuffer = (uint16_t *)pData;
0698       __IO uint16_t *dr = (__IO uint16_t *)(&hpssi->Instance->DR);
0699 
0700       while (transfer_size > 0U)
0701       {
0702         /* Init tickstart for timeout management*/
0703         tickstart = HAL_GetTick();
0704         /* Wait until Fifo is ready to transfer four bytes flag is set */
0705         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
0706         {
0707           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
0708           hpssi->State = HAL_PSSI_STATE_READY;
0709           /* Process Unlocked */
0710           __HAL_UNLOCK(hpssi);
0711           return HAL_ERROR;
0712         }
0713         /* Write data to DR */
0714         *dr = *pbuffer;
0715 
0716         /* Increment Buffer pointer */
0717         pbuffer++;
0718         transfer_size -= 2U;
0719       }
0720     }
0721     else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
0722     {
0723       uint32_t *pbuffer = (uint32_t *)pData;
0724       while (transfer_size > 0U)
0725       {
0726         /* Init tickstart for timeout management*/
0727         tickstart = HAL_GetTick();
0728         /* Wait until Fifo is ready to transfer four bytes flag is set */
0729         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
0730         {
0731           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
0732           hpssi->State = HAL_PSSI_STATE_READY;
0733           /* Process Unlocked */
0734           __HAL_UNLOCK(hpssi);
0735           return HAL_ERROR;
0736         }
0737         /* Write data to DR */
0738         *(__IO uint32_t *)(&hpssi->Instance->DR) = *pbuffer;
0739 
0740         /* Increment Buffer pointer */
0741         pbuffer++;
0742         transfer_size -= 4U;
0743       }
0744     }
0745     else
0746     {
0747       hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
0748       hpssi->State = HAL_PSSI_STATE_READY;
0749       /* Process Unlocked */
0750       __HAL_UNLOCK(hpssi);
0751       return HAL_ERROR;
0752     }
0753 
0754     /* Check Errors Flags */
0755     if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
0756     {
0757       HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
0758       HAL_PSSI_DISABLE(hpssi);
0759       hpssi->ErrorCode = HAL_PSSI_ERROR_UNDER_RUN;
0760       hpssi->State = HAL_PSSI_STATE_READY;
0761       /* Process Unlocked */
0762       __HAL_UNLOCK(hpssi);
0763       return HAL_ERROR;
0764     }
0765 
0766     hpssi->State = HAL_PSSI_STATE_READY;
0767 
0768     /* Process Unlocked */
0769     __HAL_UNLOCK(hpssi);
0770 
0771     return HAL_OK;
0772   }
0773   else
0774   {
0775     return HAL_BUSY;
0776   }
0777 }
0778 
0779 /**
0780   * @brief  Receives an amount of data in blocking mode.
0781   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0782   *                the configuration information for the specified PSSI.
0783   * @param  pData Pointer to data buffer
0784   * @param  Size Amount of data to be received (in bytes)
0785   * @param  Timeout Timeout duration
0786   * @retval HAL status
0787   */
0788 HAL_StatusTypeDef HAL_PSSI_Receive(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
0789 {
0790   uint32_t tickstart;
0791   uint32_t  transfer_size = Size;
0792 
0793   if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
0794       ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size % 2U) != 0U)) ||
0795       ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size % 4U) != 0U)))
0796   {
0797     hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
0798     return HAL_ERROR;
0799   }
0800 
0801   if (hpssi->State == HAL_PSSI_STATE_READY)
0802   {
0803     /* Process Locked */
0804     __HAL_LOCK(hpssi);
0805 
0806     hpssi->State     = HAL_PSSI_STATE_BUSY;
0807     hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
0808 
0809     /* Disable the selected PSSI peripheral */
0810     HAL_PSSI_DISABLE(hpssi);
0811     /* Configure transfer parameters */
0812     MODIFY_REG(hpssi->Instance->CR, (PSSI_CR_OUTEN | PSSI_CR_CKPOL),
0813               (PSSI_CR_OUTEN_INPUT | ((hpssi->Init.ClockPolarity == HAL_PSSI_FALLING_EDGE) ? 0U : PSSI_CR_CKPOL)));
0814 
0815 #if defined(HAL_DMA_MODULE_ENABLED)
0816     /* DMA Disable */
0817     hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
0818 #endif /*HAL_DMA_MODULE_ENABLED*/
0819 
0820     /* Enable the selected PSSI peripheral */
0821     HAL_PSSI_ENABLE(hpssi);
0822     if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
0823     {
0824       uint8_t *pbuffer = pData;
0825 
0826       while (transfer_size > 0U)
0827       {
0828         /* Init tickstart for timeout management*/
0829         tickstart = HAL_GetTick();
0830         /* Wait until Fifo is ready to receive one byte flag is set */
0831         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
0832         {
0833           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
0834           hpssi->State = HAL_PSSI_STATE_READY;
0835           /* Process Unlocked */
0836           __HAL_UNLOCK(hpssi);
0837           return HAL_ERROR;
0838         }
0839         /* Read data from DR */
0840         *pbuffer = *(__IO uint8_t *)(&hpssi->Instance->DR);
0841         pbuffer++;
0842         transfer_size--;
0843       }
0844     }
0845     else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
0846     {
0847       uint16_t *pbuffer = (uint16_t *)pData;
0848       __IO uint16_t *dr = (__IO uint16_t *)(&hpssi->Instance->DR);
0849 
0850       while (transfer_size > 0U)
0851       {
0852         /* Init tickstart for timeout management*/
0853         tickstart = HAL_GetTick();
0854         /* Wait until Fifo is ready to receive four bytes flag is set */
0855         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
0856         {
0857           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
0858           hpssi->State = HAL_PSSI_STATE_READY;
0859           /* Process Unlocked */
0860           __HAL_UNLOCK(hpssi);
0861           return HAL_ERROR;
0862         }
0863 
0864         /* Read data from DR */
0865         *pbuffer = *dr;
0866         pbuffer++;
0867         transfer_size -= 2U;
0868       }
0869     }
0870     else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
0871     {
0872       uint32_t *pbuffer = (uint32_t *)pData;
0873 
0874       while (transfer_size > 0U)
0875       {
0876         /* Init tickstart for timeout management*/
0877         tickstart = HAL_GetTick();
0878         /* Wait until Fifo is ready to receive four bytes flag is set */
0879         if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
0880         {
0881           hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
0882           hpssi->State = HAL_PSSI_STATE_READY;
0883           /* Process Unlocked */
0884           __HAL_UNLOCK(hpssi);
0885           return HAL_ERROR;
0886         }
0887 
0888         /* Read data from DR */
0889         *pbuffer = *(__IO uint32_t *)(&hpssi->Instance->DR);
0890         pbuffer++;
0891         transfer_size -= 4U;
0892       }
0893     }
0894     else
0895     {
0896       hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
0897       hpssi->State = HAL_PSSI_STATE_READY;
0898       /* Process Unlocked */
0899       __HAL_UNLOCK(hpssi);
0900       return HAL_ERROR;
0901     }
0902     /* Check Errors Flags */
0903 
0904     if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
0905     {
0906       HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
0907       hpssi->ErrorCode = HAL_PSSI_ERROR_OVER_RUN;
0908       __HAL_UNLOCK(hpssi);
0909       return HAL_ERROR;
0910     }
0911 
0912     hpssi->State = HAL_PSSI_STATE_READY;
0913 
0914     /* Process Unlocked */
0915     __HAL_UNLOCK(hpssi);
0916 
0917     return HAL_OK;
0918   }
0919   else
0920   {
0921     return HAL_BUSY;
0922   }
0923 }
0924 
0925 #if defined(HAL_DMA_MODULE_ENABLED)
0926 /**
0927   * @brief  Transmit an amount of data in non-blocking mode with DMA
0928   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
0929   *                the configuration information for the specified PSSI.
0930   * @param  pData Pointer to data buffer
0931   * @param  Size Amount of data to be sent (in bytes)
0932   * @retval HAL status
0933   */
0934 HAL_StatusTypeDef HAL_PSSI_Transmit_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
0935 {
0936   HAL_StatusTypeDef dmaxferstatus;
0937 
0938   if (hpssi->State == HAL_PSSI_STATE_READY)
0939   {
0940 
0941     /* Process Locked */
0942     __HAL_LOCK(hpssi);
0943 
0944     hpssi->State       = HAL_PSSI_STATE_BUSY_TX;
0945     hpssi->ErrorCode   = HAL_PSSI_ERROR_NONE;
0946 
0947     /* Disable the selected PSSI peripheral */
0948     HAL_PSSI_DISABLE(hpssi);
0949 
0950     /* Prepare transfer parameters */
0951     hpssi->pBuffPtr    = pData;
0952     hpssi->XferCount   = Size;
0953 
0954     if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
0955     {
0956       hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
0957     }
0958     else
0959     {
0960       hpssi->XferSize = hpssi->XferCount;
0961     }
0962 
0963     if (hpssi->XferSize > 0U)
0964     {
0965       if (hpssi->hdmatx != NULL)
0966       {
0967 
0968         /* Configure BusWidth */
0969         if (hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
0970         {
0971           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
0972                      PSSI_CR_DMA_ENABLE | PSSI_CR_OUTEN_OUTPUT |
0973                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL));
0974         }
0975         else
0976         {
0977           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
0978                      PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth | PSSI_CR_OUTEN_OUTPUT |
0979                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL));
0980         }
0981 
0982         /* Set the PSSI DMA transfer complete callback */
0983         hpssi->hdmatx->XferCpltCallback = PSSI_DMATransmitCplt;
0984 
0985         /* Set the DMA error callback */
0986         hpssi->hdmatx->XferErrorCallback = PSSI_DMAError;
0987 
0988         /* Set the unused DMA callbacks to NULL */
0989         hpssi->hdmatx->XferHalfCpltCallback = NULL;
0990         hpssi->hdmatx->XferAbortCallback = NULL;
0991 
0992         /* Enable the DMA  */
0993         dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmatx, (uint32_t)pData, (uint32_t)&hpssi->Instance->DR,
0994                                          hpssi->XferSize);
0995       }
0996       else
0997       {
0998         /* Update PSSI state */
0999         hpssi->State     = HAL_PSSI_STATE_READY;
1000 
1001         /* Update PSSI error code */
1002         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1003 
1004         /* Process Unlocked */
1005         __HAL_UNLOCK(hpssi);
1006 
1007         return HAL_ERROR;
1008       }
1009 
1010       if (dmaxferstatus == HAL_OK)
1011       {
1012         /* Update XferCount value */
1013         hpssi->XferCount -= hpssi->XferSize;
1014 
1015         /* Process Unlocked */
1016         __HAL_UNLOCK(hpssi);
1017 
1018         /* Note : The PSSI interrupts must be enabled after unlocking current process
1019                   to avoid the risk of PSSI interrupt handle execution before current
1020                   process unlock */
1021         /* Enable ERR interrupt */
1022         HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1023 
1024         /* Enable DMA Request */
1025         hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
1026         /* Enable the selected PSSI peripheral */
1027         HAL_PSSI_ENABLE(hpssi);
1028       }
1029       else
1030       {
1031         /* Update PSSI state */
1032         hpssi->State     = HAL_PSSI_STATE_READY;
1033 
1034         /* Update PSSI error code */
1035         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1036 
1037         /* Process Unlocked */
1038         __HAL_UNLOCK(hpssi);
1039 
1040         return HAL_ERROR;
1041       }
1042     }
1043     else
1044     {
1045       /* Process Unlocked */
1046       __HAL_UNLOCK(hpssi);
1047 
1048       /* Note : The PSSI interrupts must be enabled after unlocking current process
1049                 to avoid the risk of PSSI interrupt handle execution before current
1050                 process unlock */
1051       /* Enable ERRinterrupt */
1052       /* possible to enable all of these */
1053 
1054       HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1055     }
1056     return HAL_OK;
1057   }
1058   else
1059   {
1060     return HAL_BUSY;
1061   }
1062 }
1063 
1064 /**
1065   * @brief  Receive an amount of data in non-blocking mode with DMA
1066   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1067   *                the configuration information for the specified PSSI.
1068   * @param  pData Pointer to data buffer
1069   * @param  Size Amount of data to be received (in bytes)
1070   * @retval HAL status
1071   */
1072 HAL_StatusTypeDef HAL_PSSI_Receive_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
1073 {
1074 
1075   HAL_StatusTypeDef dmaxferstatus;
1076 
1077   if (hpssi->State == HAL_PSSI_STATE_READY)
1078   {
1079 
1080     /* Disable the selected PSSI peripheral */
1081     HAL_PSSI_DISABLE(hpssi);
1082     /* Process Locked */
1083     __HAL_LOCK(hpssi);
1084 
1085     hpssi->State       = HAL_PSSI_STATE_BUSY_RX;
1086     hpssi->ErrorCode   = HAL_PSSI_ERROR_NONE;
1087 
1088     /* Prepare transfer parameters */
1089     hpssi->pBuffPtr    = pData;
1090     hpssi->XferCount   = Size;
1091 
1092     if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
1093     {
1094       hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
1095     }
1096     else
1097     {
1098       hpssi->XferSize = hpssi->XferCount;
1099     }
1100 
1101     if (hpssi->XferSize > 0U)
1102     {
1103       if (hpssi->hdmarx != NULL)
1104       {
1105         /* Configure BusWidth */
1106         if (hpssi->hdmarx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
1107         {
1108           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL, PSSI_CR_DMA_ENABLE |
1109                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? PSSI_CR_CKPOL : 0U));
1110         }
1111         else
1112         {
1113           MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
1114                      PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth |
1115                      ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? PSSI_CR_CKPOL : 0U));
1116         }
1117 
1118         /* Set the PSSI DMA transfer complete callback */
1119         hpssi->hdmarx->XferCpltCallback = PSSI_DMAReceiveCplt;
1120 
1121         /* Set the DMA error callback */
1122         hpssi->hdmarx->XferErrorCallback = PSSI_DMAError;
1123 
1124         /* Set the unused DMA callbacks to NULL */
1125         hpssi->hdmarx->XferHalfCpltCallback = NULL;
1126         hpssi->hdmarx->XferAbortCallback = NULL;
1127 
1128         /* Enable the DMA  */
1129         dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmarx, (uint32_t)&hpssi->Instance->DR, (uint32_t)pData,
1130                                          hpssi->XferSize);
1131       }
1132       else
1133       {
1134         /* Update PSSI state */
1135         hpssi->State     = HAL_PSSI_STATE_READY;
1136 
1137         /* Update PSSI error code */
1138         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1139 
1140         /* Process Unlocked */
1141         __HAL_UNLOCK(hpssi);
1142 
1143         return HAL_ERROR;
1144       }
1145 
1146       if (dmaxferstatus == HAL_OK)
1147       {
1148         /* Update XferCount value */
1149         hpssi->XferCount -= hpssi->XferSize;
1150 
1151         /* Process Unlocked */
1152         __HAL_UNLOCK(hpssi);
1153 
1154         /* Note : The PSSI interrupts must be enabled after unlocking current process
1155                   to avoid the risk of PSSI interrupt handle execution before current
1156                   process unlock */
1157         /* Enable ERR  interrupt */
1158         HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1159 
1160         /* Enable DMA Request */
1161         hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
1162         /* Enable the selected PSSI peripheral */
1163         HAL_PSSI_ENABLE(hpssi);
1164       }
1165       else
1166       {
1167         /* Update PSSI state */
1168         hpssi->State     = HAL_PSSI_STATE_READY;
1169 
1170         /* Update PSSI error code */
1171         hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1172 
1173         /* Process Unlocked */
1174         __HAL_UNLOCK(hpssi);
1175 
1176         return HAL_ERROR;
1177       }
1178     }
1179     else
1180     {
1181       /* Process Unlocked */
1182       __HAL_UNLOCK(hpssi);
1183 
1184       /* Enable ERR,interrupt */
1185       HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1186     }
1187 
1188     return HAL_OK;
1189   }
1190   else
1191   {
1192     return HAL_BUSY;
1193   }
1194 }
1195 
1196 /**
1197   * @brief  Abort a DMA process communication with Interrupt.
1198   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1199   *                the configuration information for the specified PSSI.
1200   * @retval HAL status
1201   */
1202 HAL_StatusTypeDef HAL_PSSI_Abort_DMA(PSSI_HandleTypeDef *hpssi)
1203 {
1204   /* Process Locked */
1205   __HAL_LOCK(hpssi);
1206 
1207   /* Disable Interrupts */
1208   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1209 
1210   /* Set State at HAL_PSSI_STATE_ABORT */
1211   hpssi->State = HAL_PSSI_STATE_ABORT;
1212 
1213   /* Abort DMA TX transfer if any */
1214   if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1215   {
1216     if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1217     {
1218       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1219 
1220       if (hpssi->hdmatx != NULL)
1221       {
1222         /* Set the PSSI DMA Abort callback :
1223         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1224         hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1225 
1226         /* Abort DMA TX */
1227         if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1228         {
1229           /* Call Directly XferAbortCallback function in case of error */
1230           hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1231         }
1232       }
1233     }
1234     /* Abort DMA RX transfer if any */
1235     else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1236     {
1237       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1238 
1239       if (hpssi->hdmarx != NULL)
1240       {
1241         /* Set the PSSI DMA Abort callback :
1242         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1243         hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1244 
1245         /* Abort DMA RX */
1246         if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1247         {
1248           /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1249           hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1250         }
1251       }
1252     }
1253     else
1254     {
1255 
1256       /* Call the error callback */
1257 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1258       hpssi->ErrorCallback(hpssi);
1259 #else
1260       HAL_PSSI_ErrorCallback(hpssi);
1261 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1262     }
1263   }
1264 
1265   /* Process Unlocked */
1266   __HAL_UNLOCK(hpssi);
1267 
1268   /* Note : The PSSI interrupts must be enabled after unlocking current process
1269             to avoid the risk of PSSI interrupt handle execution before current
1270             process unlock */
1271   HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1272 
1273   return HAL_OK;
1274 }
1275 #endif /*HAL_DMA_MODULE_ENABLED*/
1276 
1277 /**
1278   * @}
1279   */
1280 
1281 /** @addtogroup PSSI_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
1282   * @ingroup RTEMSBSPsARMSTM32H7
1283   * @{
1284   */
1285 
1286 /**
1287   * @brief  This function handles PSSI event interrupt request.
1288   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1289   *                the configuration information for the specified PSSI.
1290   * @retval None
1291   */
1292 void HAL_PSSI_IRQHandler(PSSI_HandleTypeDef *hpssi)
1293 {
1294   /* Overrun/ Underrun Errors */
1295   if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_MIS) != 0U)
1296   {
1297     /* Reset handle parameters */
1298     hpssi->XferCount     = 0U;
1299 
1300     /* Disable all interrupts */
1301     HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1302 
1303 #if defined(HAL_DMA_MODULE_ENABLED)
1304     /* Abort DMA TX transfer if any */
1305     if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1306     {
1307       if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1308       {
1309         /* Set new error code */
1310         hpssi->ErrorCode |= HAL_PSSI_ERROR_UNDER_RUN;
1311 
1312         hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1313 
1314         if (hpssi->hdmatx != NULL)
1315         {
1316           /* Set the PSSI DMA Abort callback :
1317           will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1318           hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1319 
1320           /* Process Unlocked */
1321           __HAL_UNLOCK(hpssi);
1322 
1323           /* Abort DMA TX */
1324           if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1325           {
1326             /* Call Directly XferAbortCallback function in case of error */
1327             hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1328           }
1329         }
1330       }
1331       /* Abort DMA RX transfer if any */
1332       else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1333       {
1334         /* Set new error code */
1335         hpssi->ErrorCode |= HAL_PSSI_ERROR_OVER_RUN;
1336 
1337         hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1338 
1339         if (hpssi->hdmarx != NULL)
1340         {
1341           /* Set the PSSI DMA Abort callback :
1342           will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1343           hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1344 
1345           /* Process Unlocked */
1346           __HAL_UNLOCK(hpssi);
1347 
1348           /* Abort DMA RX */
1349           if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1350           {
1351             /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1352             hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1353           }
1354         }
1355       }
1356       else
1357       {
1358 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1359         /* Call the corresponding callback to inform upper layer of the error */
1360         hpssi->ErrorCallback(hpssi);
1361 #else
1362         HAL_PSSI_ErrorCallback(hpssi);
1363 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1364       }
1365     }
1366 #endif /*HAL_DMA_MODULE_ENABLED*/
1367 
1368     /* If state is an abort treatment on going, don't change state */
1369     if (hpssi->State == HAL_PSSI_STATE_ABORT)
1370     {
1371       hpssi->State = HAL_PSSI_STATE_READY;
1372 
1373       /* Process Unlocked */
1374       __HAL_UNLOCK(hpssi);
1375 
1376 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1377       /* Call the corresponding callback to inform upper layer of End of Transfer */
1378       hpssi->AbortCpltCallback(hpssi);
1379 #else
1380       HAL_PSSI_AbortCpltCallback(hpssi);
1381 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1382     }
1383     else
1384     {
1385       /* Set HAL_PSSI_STATE_READY */
1386       hpssi->State         = HAL_PSSI_STATE_READY;
1387       /* Process Unlocked */
1388       __HAL_UNLOCK(hpssi);
1389 
1390 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1391       /* Call the corresponding callback to inform upper layer of End of Transfer */
1392       hpssi->ErrorCallback(hpssi);
1393 #else
1394       HAL_PSSI_ErrorCallback(hpssi);
1395 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1396     }
1397   }
1398 }
1399 
1400 /**
1401   * @brief   Tx Transfer complete callback.
1402   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1403   *                the configuration information for the specified PSSI.
1404   * @retval None
1405   */
1406 __weak void HAL_PSSI_TxCpltCallback(PSSI_HandleTypeDef *hpssi)
1407 {
1408   /* Prevent unused argument(s) compilation warning */
1409   UNUSED(hpssi);
1410 
1411   /* NOTE : This function should not be modified, when the callback is needed,
1412             the HAL_PSSI_TxCpltCallback can be implemented in the user file
1413    */
1414 }
1415 
1416 /**
1417   * @brief   Rx Transfer complete callback.
1418   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1419   *                the configuration information for the specified PSSI.
1420   * @retval None
1421   */
1422 __weak void HAL_PSSI_RxCpltCallback(PSSI_HandleTypeDef *hpssi)
1423 {
1424   /* Prevent unused argument(s) compilation warning */
1425   UNUSED(hpssi);
1426 
1427   /* NOTE : This function should not be modified, when the callback is needed,
1428             the HAL_PSSI_RxCpltCallback can be implemented in the user file
1429    */
1430 }
1431 
1432 /**
1433   * @brief  PSSI error callback.
1434   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1435   *                the configuration information for the specified PSSI.
1436   * @retval None
1437   */
1438 __weak void HAL_PSSI_ErrorCallback(PSSI_HandleTypeDef *hpssi)
1439 {
1440   /* Prevent unused argument(s) compilation warning */
1441   UNUSED(hpssi);
1442 
1443   /* NOTE : This function should not be modified, when the callback is needed,
1444             the HAL_PSSI_ErrorCallback could be implemented in the user file
1445    */
1446 }
1447 
1448 /**
1449   * @brief  PSSI abort callback.
1450   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1451   *                the configuration information for the specified PSSI.
1452   * @retval None
1453   */
1454 __weak void HAL_PSSI_AbortCpltCallback(PSSI_HandleTypeDef *hpssi)
1455 {
1456   /* Prevent unused argument(s) compilation warning */
1457   UNUSED(hpssi);
1458 
1459   /* NOTE : This function should not be modified, when the callback is needed,
1460             the HAL_PSSI_AbortCpltCallback could be implemented in the user file
1461    */
1462 }
1463 
1464 /**
1465   * @}
1466   */
1467 
1468 /** @defgroup PSSI_Exported_Functions_Group3 Peripheral State and Error functions
1469   * @ingroup RTEMSBSPsARMSTM32H7
1470   *  @brief   Peripheral State, Mode and Error functions
1471   *
1472 @verbatim
1473  ===============================================================================
1474             ##### Peripheral State, Mode and Error functions #####
1475  ===============================================================================
1476     [..]
1477     This subsection permit to get in run-time the status of the peripheral
1478     and the data flow.
1479 
1480 @endverbatim
1481   * @{
1482   */
1483 
1484 /**
1485   * @brief  Return the PSSI handle state.
1486   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1487   *                the configuration information for the specified PSSI.
1488   * @retval HAL state
1489   */
1490 HAL_PSSI_StateTypeDef HAL_PSSI_GetState(const PSSI_HandleTypeDef *hpssi)
1491 {
1492   /* Return PSSI handle state */
1493   return hpssi->State;
1494 }
1495 
1496 /**
1497   * @brief  Return the PSSI error code.
1498   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1499   *              the configuration information for the specified PSSI.
1500   * @retval PSSI Error Code
1501   */
1502 uint32_t HAL_PSSI_GetError(const PSSI_HandleTypeDef *hpssi)
1503 {
1504   return hpssi->ErrorCode;
1505 }
1506 
1507 /**
1508   * @}
1509   */
1510 
1511 /**
1512   * @}
1513   */
1514 
1515 /** @addtogroup PSSI_Private_Functions
1516   * @{
1517   */
1518 
1519 /**
1520   * @brief  PSSI Errors process.
1521   * @param  hpssi PSSI handle.
1522   * @param  ErrorCode Error code to handle.
1523   * @retval None
1524   */
1525 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode)
1526 {
1527   /* Reset handle parameters */
1528   hpssi->XferCount     = 0U;
1529 
1530   /* Set new error code */
1531   hpssi->ErrorCode |= ErrorCode;
1532 
1533   /* Disable all interrupts */
1534   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1535 
1536 #if defined(HAL_DMA_MODULE_ENABLED)
1537   /* Abort DMA TX transfer if any */
1538   if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1539   {
1540     if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1541     {
1542       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1543 
1544       if (hpssi->hdmatx != NULL)
1545       {
1546         /* Set the PSSI DMA Abort callback :
1547         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1548         hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1549 
1550         /* Process Unlocked */
1551         __HAL_UNLOCK(hpssi);
1552 
1553         /* Abort DMA TX */
1554         if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1555         {
1556           /* Call Directly XferAbortCallback function in case of error */
1557           hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1558         }
1559       }
1560     }
1561     /* Abort DMA RX transfer if any */
1562     else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1563     {
1564       hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1565 
1566       if (hpssi->hdmarx != NULL)
1567       {
1568         /* Set the PSSI DMA Abort callback :
1569         will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1570         hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1571 
1572         /* Process Unlocked */
1573         __HAL_UNLOCK(hpssi);
1574 
1575         /* Abort DMA RX */
1576         if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1577         {
1578           /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1579           hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1580         }
1581       }
1582     }
1583     else
1584     {
1585       /*Nothing to do*/
1586     }
1587   }
1588 #endif /*HAL_DMA_MODULE_ENABLED*/
1589 
1590   /* If state is an abort treatment on going, don't change state */
1591   if (hpssi->State == HAL_PSSI_STATE_ABORT)
1592   {
1593     hpssi->State = HAL_PSSI_STATE_READY;
1594 
1595     /* Process Unlocked */
1596     __HAL_UNLOCK(hpssi);
1597 
1598     /* Call the corresponding callback to inform upper layer of End of Transfer */
1599 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1600     hpssi->AbortCpltCallback(hpssi);
1601 #else
1602     HAL_PSSI_AbortCpltCallback(hpssi);
1603 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1604   }
1605   else
1606   {
1607     /* Set HAL_PSSI_STATE_READY */
1608     hpssi->State = HAL_PSSI_STATE_READY;
1609 
1610     /* Process Unlocked */
1611     __HAL_UNLOCK(hpssi);
1612 
1613     /* Call the corresponding callback to inform upper layer of End of Transfer */
1614 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1615     hpssi->ErrorCallback(hpssi);
1616 #else
1617     HAL_PSSI_ErrorCallback(hpssi);
1618 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1619   }
1620 }
1621 
1622 #if defined(HAL_DMA_MODULE_ENABLED)
1623 /**
1624   * @brief  DMA PSSI slave transmit process complete callback.
1625   * @param  hdma DMA handle
1626   * @retval None
1627   */
1628 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
1629 {
1630   /* Derogation MISRAC2012-Rule-11.5 */
1631   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1632 
1633   uint32_t tmperror;
1634 
1635   /* Disable Interrupts */
1636   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1637 
1638   /* Store current volatile hpssi->ErrorCode, misra rule */
1639   tmperror = hpssi->ErrorCode;
1640 
1641   /* Call the corresponding callback to inform upper layer of End of Transfer */
1642   if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1643   {
1644     /* Call the corresponding callback to inform upper layer of End of Transfer */
1645     PSSI_Error(hpssi, hpssi->ErrorCode);
1646   }
1647   /* hpssi->State == HAL_PSSI_STATE_BUSY_TX */
1648   else
1649   {
1650     hpssi->State = HAL_PSSI_STATE_READY;
1651 
1652     /* Process Unlocked */
1653     __HAL_UNLOCK(hpssi);
1654 
1655     /* Call the corresponding callback to inform upper layer of End of Transfer */
1656 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1657     hpssi->TxCpltCallback(hpssi);
1658 #else
1659     HAL_PSSI_TxCpltCallback(hpssi);
1660 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1661   }
1662 }
1663 
1664 /**
1665   * @brief DMA PSSI master receive process complete callback.
1666   * @param  hdma DMA handle
1667   * @retval None
1668   */
1669 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1670 {
1671   /* Derogation MISRAC2012-Rule-11.5 */
1672   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1673 
1674   uint32_t tmperror;
1675 
1676   /* Disable Interrupts */
1677   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1678 
1679   /* Store current volatile hpssi->ErrorCode, misra rule */
1680   tmperror = hpssi->ErrorCode;
1681 
1682   /* Call the corresponding callback to inform upper layer of End of Transfer */
1683   if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1684   {
1685     /* Call the corresponding callback to inform upper layer of End of Transfer */
1686     PSSI_Error(hpssi, hpssi->ErrorCode);
1687   }
1688   /* hpssi->State == HAL_PSSI_STATE_BUSY_RX */
1689   else
1690   {
1691     hpssi->State = HAL_PSSI_STATE_READY;
1692 
1693     /* Process Unlocked */
1694     __HAL_UNLOCK(hpssi);
1695 
1696     /* Call the corresponding callback to inform upper layer of End of Transfer */
1697 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1698     hpssi->RxCpltCallback(hpssi);
1699 #else
1700     HAL_PSSI_RxCpltCallback(hpssi);
1701 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1702   }
1703 }
1704 
1705 /**
1706   * @brief DMA PSSI communication abort callback
1707   *        (To be called at end of DMA Abort procedure).
1708   * @param hdma DMA handle.
1709   * @retval None
1710   */
1711 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma)
1712 {
1713   /* Derogation MISRAC2012-Rule-11.5 */
1714   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1715 
1716   /* Reset AbortCpltCallback */
1717   hpssi->hdmatx->XferAbortCallback = NULL;
1718   hpssi->hdmarx->XferAbortCallback = NULL;
1719 
1720   /* Check if come from abort from user */
1721   if (hpssi->State == HAL_PSSI_STATE_ABORT)
1722   {
1723     hpssi->State = HAL_PSSI_STATE_READY;
1724 
1725     /* Call the corresponding callback to inform upper layer of End of Transfer */
1726 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1727     hpssi->AbortCpltCallback(hpssi);
1728 #else
1729     HAL_PSSI_AbortCpltCallback(hpssi);
1730 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1731   }
1732   else
1733   {
1734     /* Call the corresponding callback to inform upper layer of End of Transfer */
1735 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1736     hpssi->ErrorCallback(hpssi);
1737 #else
1738     HAL_PSSI_ErrorCallback(hpssi);
1739 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1740   }
1741 }
1742 #endif /*HAL_DMA_MODULE_ENABLED*/
1743 
1744 /**
1745   * @brief  This function handles PSSI Communication Timeout.
1746   * @param  hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1747   *                the configuration information for the specified PSSI.
1748   * @param  Flag Specifies the PSSI flag to check.
1749   * @param  Status The new Flag status (SET or RESET).
1750   * @param  Timeout Timeout duration
1751   * @param  Tickstart Tick start value
1752   * @retval HAL status
1753   */
1754 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status,
1755                                                        uint32_t Timeout, uint32_t Tickstart)
1756 {
1757   while ((HAL_PSSI_GET_STATUS(hpssi, Flag) & Flag) == (uint32_t)Status)
1758   {
1759     /* Check for the Timeout */
1760     if (Timeout != HAL_MAX_DELAY)
1761     {
1762       if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
1763       {
1764         hpssi->ErrorCode |= HAL_PSSI_ERROR_TIMEOUT;
1765         hpssi->State = HAL_PSSI_STATE_READY;
1766 
1767         /* Process Unlocked */
1768         __HAL_UNLOCK(hpssi);
1769 
1770         return HAL_ERROR;
1771       }
1772     }
1773   }
1774   return HAL_OK;
1775 }
1776 
1777 #if defined(HAL_DMA_MODULE_ENABLED)
1778 void PSSI_DMAError(DMA_HandleTypeDef *hdma)
1779 {
1780   /* Derogation MISRAC2012-Rule-11.5 */
1781   PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1782 
1783   uint32_t tmperror;
1784 
1785   /* Disable the selected PSSI peripheral */
1786   HAL_PSSI_DISABLE(hpssi);
1787 
1788   /* Disable Interrupts */
1789   HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1790 
1791   /* Store current volatile hpssi->ErrorCode, misra rule */
1792   tmperror = hpssi->ErrorCode;
1793 
1794   /* Call the corresponding callback to inform upper layer of End of Transfer */
1795   if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1796   {
1797     /* Call the corresponding callback to inform upper layer of End of Transfer */
1798     PSSI_Error(hpssi, hpssi->ErrorCode);
1799   }
1800   else
1801   {
1802     hpssi->State = HAL_PSSI_STATE_READY;
1803 
1804     /* Process Unlocked */
1805     __HAL_UNLOCK(hpssi);
1806 
1807     /* Call the corresponding callback to inform upper layer of End of Transfer */
1808 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1809     hpssi->ErrorCallback(hpssi);
1810 #else
1811     HAL_PSSI_ErrorCallback(hpssi);
1812 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1813   }
1814 }
1815 #endif /*HAL_DMA_MODULE_ENABLED*/
1816 
1817 
1818 /**
1819   * @}
1820   */
1821 #endif /* PSSI */
1822 #endif /* HAL_PSSI_MODULE_ENABLED */
1823 /**
1824   * @}
1825   */
1826 
1827 /**
1828   * @}
1829   */