Merge maintenance-8.x.x fixes into master
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_pssi.c
blob7824ebb05d609b4f4e4a11a8d37d37fcd05c9f5b
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_pssi.c
4 * @author MCD Application Team
5 * @brief PSSI HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Parallel Synchronous Slave Interface (PSSI) peripheral:
8 * + Initialization and de-initialization functions
9 * + IO operation functions
10 * + Peripheral State and Errors functions
12 ******************************************************************************
13 * @attention
15 * Copyright (c) 2019 STMicroelectronics.
16 * All rights reserved.
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.
22 ******************************************************************************
23 @verbatim
24 ==============================================================================
25 ##### How to use this driver #####
26 ==============================================================================
27 [..]
28 The PSSI HAL driver can be used as follows:
30 (#) Declare a PSSI_HandleTypeDef handle structure, for example:
31 PSSI_HandleTypeDef hpssi;
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
50 (#) Configure the Communication Bus Width, Control Signals, Input Polarity and Output Polarity
51 in the hpssi Init structure.
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.
56 (#) For PSSI IO operations, two operation modes are available within this driver :
58 *** Polling mode IO operation ***
59 =================================
60 [..]
61 (+) Transmit an amount of data by byte in blocking mode using @ref HAL_PSSI_Transmit()
62 (+) Receive an amount of data by byte in blocking mode using @ref HAL_PSSI_Receive()
64 *** DMA mode IO operation ***
65 ==============================
66 [..]
67 (+) Transmit an amount of data in non-blocking mode (DMA) using
68 @ref HAL_PSSI_Transmit_DMA()
69 (+) At transmission end of transfer, @ref HAL_PSSI_TxCpltCallback() is executed and user can
70 add his own code by customization of function pointer @ref HAL_PSSI_TxCpltCallback()
71 (+) Receive an amount of data in non-blocking mode (DMA) using
72 @ref HAL_PSSI_Receive_DMA()
73 (+) At reception end of transfer, @ref HAL_PSSI_RxCpltCallback() is executed and user can
74 add his own code by customization of function pointer @ref HAL_PSSI_RxCpltCallback()
75 (+) In case of transfer Error, @ref HAL_PSSI_ErrorCallback() function is executed and user can
76 add his own code by customization of function pointer @ref HAL_PSSI_ErrorCallback()
77 (+) Abort a PSSI process communication with Interrupt using @ref HAL_PSSI_Abort_IT()
78 (+) End of abort process, @ref HAL_PSSI_AbortCpltCallback() is executed and user can
79 add his own code by customization of function pointer @ref HAL_PSSI_AbortCpltCallback()
81 *** PSSI HAL driver macros list ***
82 ==================================
83 [..]
84 Below the list of most used macros in PSSI HAL driver.
86 (+) @ref HAL_PSSI_ENABLE : Enable the PSSI peripheral
87 (+) @ref HAL_PSSI_DISABLE : Disable the PSSI peripheral
88 (+) @ref HAL_PSSI_GET_FLAG : Check whether the specified PSSI flag is set or not
89 (+) @ref HAL_PSSI_CLEAR_FLAG : Clear the specified PSSI pending flag
90 (+) @ref HAL_PSSI_ENABLE_IT : Enable the specified PSSI interrupt
91 (+) @ref HAL_PSSI_DISABLE_IT : Disable the specified PSSI interrupt
93 *** Callback registration ***
94 =============================================
95 Use Functions @ref HAL_PSSI_RegisterCallback() or @ref HAL_PSSI_RegisterAddrCallback()
96 to register an interrupt callback.
98 Function @ref HAL_PSSI_RegisterCallback() allows to register following callbacks:
99 (+) TxCpltCallback : callback for transmission end of transfer.
100 (+) RxCpltCallback : callback for reception end of transfer.
101 (+) ErrorCallback : callback for error detection.
102 (+) AbortCpltCallback : callback for abort completion process.
103 (+) MspInitCallback : callback for Msp Init.
104 (+) MspDeInitCallback : callback for Msp DeInit.
105 This function takes as parameters the HAL peripheral handle, the Callback ID
106 and a pointer to the user callback function.
109 Use function @ref HAL_PSSI_UnRegisterCallback to reset a callback to the default
110 weak function.
111 @ref HAL_PSSI_UnRegisterCallback takes as parameters the HAL peripheral handle,
112 and the Callback ID.
113 This function allows to reset following callbacks:
114 (+) TxCpltCallback : callback for transmission end of transfer.
115 (+) RxCpltCallback : callback for reception end of transfer.
116 (+) ErrorCallback : callback for error detection.
117 (+) AbortCpltCallback : callback for abort completion process.
118 (+) MspInitCallback : callback for Msp Init.
119 (+) MspDeInitCallback : callback for Msp DeInit.
122 By default, after the @ref HAL_PSSI_Init() and when the state is @ref HAL_PSSI_STATE_RESET
123 all callbacks are set to the corresponding weak functions:
124 examples @ref HAL_PSSI_TxCpltCallback(), @ref HAL_PSSI_RxCpltCallback().
125 Exception done for MspInit and MspDeInit functions that are
126 reset to the legacy weak functions in the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit() only when
127 these callbacks are null (not registered beforehand).
128 If MspInit or MspDeInit are not null, the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit()
129 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
131 Callbacks can be registered/unregistered in @ref HAL_PSSI_STATE_READY state only.
132 Exception done MspInit/MspDeInit functions that can be registered/unregistered
133 in @ref HAL_PSSI_STATE_READY or @ref HAL_PSSI_STATE_RESET state,
134 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
135 Then, the user first registers the MspInit/MspDeInit user callbacks
136 using @ref HAL_PSSI_RegisterCallback() before calling @ref HAL_PSSI_DeInit()
137 or @ref HAL_PSSI_Init() function.
140 [..]
141 (@) You can refer to the PSSI HAL driver header file for more useful macros
143 @endverbatim
146 /* Includes ------------------------------------------------------------------*/
147 #include "stm32h7xx_hal.h"
149 /** @addtogroup STM32H7xx_HAL_Driver
150 * @{
153 /** @defgroup PSSI PSSI
154 * @brief PSSI HAL module driver
155 * @{
158 #ifdef HAL_PSSI_MODULE_ENABLED
159 #if defined(PSSI)
160 /* Private typedef -----------------------------------------------------------*/
161 /* Private define ------------------------------------------------------------*/
163 /** @defgroup PSSI_Private_Define PSSI Private Define
164 * @{
170 * @}
173 /* Private macro -------------------------------------------------------------*/
174 /* Private variables ---------------------------------------------------------*/
175 /* Private function prototypes -----------------------------------------------*/
177 /** @defgroup PSSI_Private_Functions PSSI Private Functions
178 * @{
180 /* Private functions to handle DMA transfer */
181 #if defined(HAL_DMA_MODULE_ENABLED)
182 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
183 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
184 void PSSI_DMAError(DMA_HandleTypeDef *hdma);
185 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma);
186 #endif /*HAL_DMA_MODULE_ENABLED*/
188 /* Private functions to handle IT transfer */
189 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode);
192 /* Private functions for PSSI transfer IRQ handler */
195 /* Private functions to handle flags during polling transfer */
196 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status,
197 uint32_t Timeout, uint32_t Tickstart);
199 /* Private functions to centralize the enable/disable of Interrupts */
203 * @}
206 /* Exported functions --------------------------------------------------------*/
208 /** @defgroup PSSI_Exported_Functions PSSI Exported Functions
209 * @{
212 /** @defgroup PSSI_Exported_Functions_Group1 Initialization and de-initialization functions
213 * @brief Initialization and Configuration functions
215 @verbatim
216 ===============================================================================
217 ##### Initialization and de-initialization functions #####
218 ===============================================================================
219 [..] This subsection provides a set of functions allowing to initialize and
220 deinitialize the PSSIx peripheral:
222 (+) User must implement HAL_PSSI_MspInit() function in which he configures
223 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
225 (+) Call the function HAL_PSSI_Init() to configure the selected device with
226 the selected configuration:
227 (++) Data Width
228 (++) Control Signals
229 (++) Input Clock polarity
230 (++) Output Clock polarity
232 (+) Call the function HAL_PSSI_DeInit() to restore the default configuration
233 of the selected PSSIx peripheral.
235 @endverbatim
236 * @{
240 * @brief Initializes the PSSI according to the specified parameters
241 * in the PSSI_InitTypeDef and initialize the associated handle.
242 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
243 * the configuration information for the specified PSSI.
244 * @retval HAL status
246 HAL_StatusTypeDef HAL_PSSI_Init(PSSI_HandleTypeDef *hpssi)
248 /* Check the PSSI handle allocation */
249 if (hpssi == NULL)
251 return HAL_ERROR;
254 /* Check the parameters */
255 assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
256 assert_param(IS_PSSI_CONTROL_SIGNAL(hpssi->Init.ControlSignal));
257 assert_param(IS_PSSI_BUSWIDTH(hpssi->Init.BusWidth));
258 assert_param(IS_PSSI_CLOCK_POLARITY(hpssi->Init.ClockPolarity));
259 assert_param(IS_PSSI_DE_POLARITY(hpssi->Init.DataEnablePolarity));
260 assert_param(IS_PSSI_RDY_POLARITY(hpssi->Init.ReadyPolarity));
262 if (hpssi->State == HAL_PSSI_STATE_RESET)
264 /* Allocate lock resource and initialize it */
265 hpssi->Lock = HAL_UNLOCKED;
267 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
268 /* Init the PSSI Callback settings */
269 hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
270 hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
271 hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
272 hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
274 if (hpssi->MspInitCallback == NULL)
276 hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
279 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
280 hpssi->MspInitCallback(hpssi);
281 #else
282 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
283 HAL_PSSI_MspInit(hpssi);
284 #endif /*USE_HAL_PSSI_REGISTER_CALLBACKS*/
287 hpssi->State = HAL_PSSI_STATE_BUSY;
289 /* Disable the selected PSSI peripheral */
290 HAL_PSSI_DISABLE(hpssi);
292 /*---------------------------- PSSIx CR Configuration ----------------------*/
293 /* Configure PSSIx: Control Signal and Bus Width*/
295 MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DERDYCFG | PSSI_CR_EDM | PSSI_CR_DEPOL | PSSI_CR_RDYPOL,
296 hpssi->Init.ControlSignal | hpssi->Init.DataEnablePolarity |
297 hpssi->Init.ReadyPolarity | hpssi->Init.BusWidth);
299 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
300 hpssi->State = HAL_PSSI_STATE_READY;
302 return HAL_OK;
306 * @brief DeInitialize the PSSI peripheral.
307 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
308 * the configuration information for the specified PSSI.
309 * @retval HAL status
311 HAL_StatusTypeDef HAL_PSSI_DeInit(PSSI_HandleTypeDef *hpssi)
313 /* Check the PSSI handle allocation */
314 if (hpssi == NULL)
316 return HAL_ERROR;
319 /* Check the parameters */
320 assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
322 hpssi->State = HAL_PSSI_STATE_BUSY;
324 /* Disable the PSSI Peripheral Clock */
325 HAL_PSSI_DISABLE(hpssi);
327 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
328 if (hpssi->MspDeInitCallback == NULL)
330 hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
333 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
334 hpssi->MspDeInitCallback(hpssi);
335 #else
336 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
337 HAL_PSSI_MspDeInit(hpssi);
338 #endif /*USE_HAL_PSSI_REGISTER_CALLBACKS*/
340 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
341 hpssi->State = HAL_PSSI_STATE_RESET;
343 /* Release Lock */
344 __HAL_UNLOCK(hpssi);
346 return HAL_OK;
350 * @brief Initialize the PSSI MSP.
351 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
352 * the configuration information for the specified PSSI.
353 * @retval None
355 __weak void HAL_PSSI_MspInit(PSSI_HandleTypeDef *hpssi)
357 /* Prevent unused argument(s) compilation warning */
358 UNUSED(hpssi);
360 /* NOTE : This function should not be modified, when the callback is needed,
361 the HAL_PSSI_MspInit can be implemented in the user file
366 * @brief De-Initialize the PSSI MSP.
367 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
368 * the configuration information for the specified PSSI.
369 * @retval None
371 __weak void HAL_PSSI_MspDeInit(PSSI_HandleTypeDef *hpssi)
373 /* Prevent unused argument(s) compilation warning */
374 UNUSED(hpssi);
376 /* NOTE : This function should not be modified; when the callback is needed,
377 the HAL_PSSI_MspDeInit can be implemented in the user file
381 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
383 * @brief Register a User PSSI Callback
384 * To be used instead of the weak predefined callback
385 * @note The HAL_PSSI_RegisterCallback() may be called before HAL_PSSI_Init() in
386 * HAL_PSSI_STATE_RESET to register callbacks for HAL_PSSI_MSPINIT_CB_ID
387 * and HAL_PSSI_MSPDEINIT_CB_ID.
388 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
389 * the configuration information for the specified PSSI.
390 * @param CallbackID ID of the callback to be registered
391 * This parameter can be one of the following values:
392 * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
393 * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
394 * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
395 * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
396 * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
397 * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
398 * @param pCallback pointer to the Callback function
399 * @retval HAL status
401 HAL_StatusTypeDef HAL_PSSI_RegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID,
402 pPSSI_CallbackTypeDef pCallback)
404 HAL_StatusTypeDef status = HAL_OK;
406 if (pCallback == NULL)
408 /* Update the error code */
409 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
411 return HAL_ERROR;
414 if (HAL_PSSI_STATE_READY == hpssi->State)
416 switch (CallbackID)
418 case HAL_PSSI_TX_COMPLETE_CB_ID :
419 hpssi->TxCpltCallback = pCallback;
420 break;
422 case HAL_PSSI_RX_COMPLETE_CB_ID :
423 hpssi->RxCpltCallback = pCallback;
424 break;
426 case HAL_PSSI_ERROR_CB_ID :
427 hpssi->ErrorCallback = pCallback;
428 break;
430 case HAL_PSSI_ABORT_CB_ID :
431 hpssi->AbortCpltCallback = pCallback;
432 break;
434 case HAL_PSSI_MSPINIT_CB_ID :
435 hpssi->MspInitCallback = pCallback;
436 break;
438 case HAL_PSSI_MSPDEINIT_CB_ID :
439 hpssi->MspDeInitCallback = pCallback;
440 break;
442 default :
443 /* Update the error code */
444 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
446 /* Return error status */
447 status = HAL_ERROR;
448 break;
451 else if (HAL_PSSI_STATE_RESET == hpssi->State)
453 switch (CallbackID)
455 case HAL_PSSI_MSPINIT_CB_ID :
456 hpssi->MspInitCallback = pCallback;
457 break;
459 case HAL_PSSI_MSPDEINIT_CB_ID :
460 hpssi->MspDeInitCallback = pCallback;
461 break;
463 default :
464 /* Update the error code */
465 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
467 /* Return error status */
468 status = HAL_ERROR;
469 break;
472 else
474 /* Update the error code */
475 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
477 /* Return error status */
478 status = HAL_ERROR;
481 return status;
485 * @brief Unregister an PSSI Callback
486 * PSSI callback is redirected to the weak predefined callback
487 * @note The HAL_PSSI_UnRegisterCallback() may be called before HAL_PSSI_Init() in
488 * HAL_PSSI_STATE_RESET to un-register callbacks for HAL_PSSI_MSPINIT_CB_ID
489 * and HAL_PSSI_MSPDEINIT_CB_ID.
490 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
491 * the configuration information for the specified PSSI.
492 * @param CallbackID ID of the callback to be unregistered
493 * This parameter can be one of the following values:
494 * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
495 * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
496 * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
497 * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
498 * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
499 * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
500 * @retval HAL status
502 HAL_StatusTypeDef HAL_PSSI_UnRegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID)
504 HAL_StatusTypeDef status = HAL_OK;
506 if (HAL_PSSI_STATE_READY == hpssi->State)
508 switch (CallbackID)
510 case HAL_PSSI_TX_COMPLETE_CB_ID :
511 hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
512 break;
514 case HAL_PSSI_RX_COMPLETE_CB_ID :
515 hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
516 break;
518 case HAL_PSSI_ERROR_CB_ID :
519 hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
520 break;
522 case HAL_PSSI_ABORT_CB_ID :
523 hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
524 break;
526 case HAL_PSSI_MSPINIT_CB_ID :
527 hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
528 break;
530 case HAL_PSSI_MSPDEINIT_CB_ID :
531 hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
532 break;
534 default :
535 /* Update the error code */
536 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
538 /* Return error status */
539 status = HAL_ERROR;
540 break;
543 else if (HAL_PSSI_STATE_RESET == hpssi->State)
545 switch (CallbackID)
547 case HAL_PSSI_MSPINIT_CB_ID :
548 hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
549 break;
551 case HAL_PSSI_MSPDEINIT_CB_ID :
552 hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
553 break;
555 default :
556 /* Update the error code */
557 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
559 /* Return error status */
560 status = HAL_ERROR;
561 break;
564 else
566 /* Update the error code */
567 hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
569 /* Return error status */
570 status = HAL_ERROR;
573 return status;
576 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
579 * @}
582 /** @defgroup PSSI_Exported_Functions_Group2 Input and Output operation functions
583 * @brief Data transfers functions
585 @verbatim
586 ===============================================================================
587 ##### IO operation functions #####
588 ===============================================================================
589 [..]
590 This subsection provides a set of functions allowing to manage the PSSI data
591 transfers.
593 (#) There are two modes of transfer:
594 (++) Blocking mode : The communication is performed in the polling mode.
595 The status of all data processing is returned by the same function
596 after finishing transfer.
597 (++) No-Blocking mode : The communication is performed using DMA.
598 These functions return the status of the transfer startup.
599 The end of the data processing will be indicated through the
600 dedicated the DMA IRQ .
602 (#) Blocking mode functions are :
603 (++) HAL_PSSI_Transmit()
604 (++) HAL_PSSI_Receive()
606 (#) No-Blocking mode functions with DMA are :
607 (++) HAL_PSSI_Transmit_DMA()
608 (++) HAL_PSSI_Receive_DMA()
610 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
611 (++) HAL_PSSI_TxCpltCallback()
612 (++) HAL_PSSI_RxCpltCallback()
613 (++) HAL_PSSI_ErrorCallback()
614 (++) HAL_PSSI_AbortCpltCallback()
616 @endverbatim
617 * @{
621 * @brief Transmits in master mode an amount of data in blocking mode.
622 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
623 * the configuration information for the specified PSSI.
624 * @param pData Pointer to data buffer
625 * @param Size Amount of data to be sent (in bytes)
626 * @param Timeout Timeout duration
627 * @retval HAL status
629 HAL_StatusTypeDef HAL_PSSI_Transmit(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
631 uint32_t tickstart;
632 uint32_t transfer_size = Size;
634 if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
635 ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size % 2U) != 0U)) ||
636 ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size % 4U) != 0U)))
638 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
639 return HAL_ERROR;
641 if (hpssi->State == HAL_PSSI_STATE_READY)
643 /* Process Locked */
644 __HAL_LOCK(hpssi);
646 hpssi->State = HAL_PSSI_STATE_BUSY;
647 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
649 /* Disable the selected PSSI peripheral */
650 HAL_PSSI_DISABLE(hpssi);
652 /* Configure transfer parameters */
653 MODIFY_REG(hpssi->Instance->CR, (PSSI_CR_OUTEN | PSSI_CR_CKPOL),
654 (PSSI_CR_OUTEN_OUTPUT |((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL)));
656 #if defined(HAL_DMA_MODULE_ENABLED)
657 /* DMA Disable */
658 hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
659 #endif /*HAL_DMA_MODULE_ENABLED*/
661 /* Enable the selected PSSI peripheral */
662 HAL_PSSI_ENABLE(hpssi);
664 if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
666 uint8_t *pbuffer = pData;
667 while (transfer_size > 0U)
669 /* Init tickstart for timeout management*/
670 tickstart = HAL_GetTick();
671 /* Wait until Fifo is ready to transfer one byte flag is set */
672 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
674 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
675 hpssi->State = HAL_PSSI_STATE_READY;
676 /* Process Unlocked */
677 __HAL_UNLOCK(hpssi);
678 return HAL_ERROR;
680 /* Write data to DR */
681 *(__IO uint8_t *)(&hpssi->Instance->DR) = *(uint8_t *)pbuffer;
683 /* Increment Buffer pointer */
684 pbuffer++;
686 transfer_size--;
689 else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
691 uint16_t *pbuffer = (uint16_t *)pData;
692 __IO uint16_t *dr = (__IO uint16_t *)(&hpssi->Instance->DR);
694 while (transfer_size > 0U)
696 /* Init tickstart for timeout management*/
697 tickstart = HAL_GetTick();
698 /* Wait until Fifo is ready to transfer four bytes flag is set */
699 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
701 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
702 hpssi->State = HAL_PSSI_STATE_READY;
703 /* Process Unlocked */
704 __HAL_UNLOCK(hpssi);
705 return HAL_ERROR;
707 /* Write data to DR */
708 *dr = *pbuffer;
710 /* Increment Buffer pointer */
711 pbuffer++;
712 transfer_size -= 2U;
715 else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
717 uint32_t *pbuffer = (uint32_t *)pData;
718 while (transfer_size > 0U)
720 /* Init tickstart for timeout management*/
721 tickstart = HAL_GetTick();
722 /* Wait until Fifo is ready to transfer four bytes flag is set */
723 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
725 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
726 hpssi->State = HAL_PSSI_STATE_READY;
727 /* Process Unlocked */
728 __HAL_UNLOCK(hpssi);
729 return HAL_ERROR;
731 /* Write data to DR */
732 *(__IO uint32_t *)(&hpssi->Instance->DR) = *pbuffer;
734 /* Increment Buffer pointer */
735 pbuffer++;
736 transfer_size -= 4U;
739 else
741 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
742 hpssi->State = HAL_PSSI_STATE_READY;
743 /* Process Unlocked */
744 __HAL_UNLOCK(hpssi);
745 return HAL_ERROR;
748 /* Check Errors Flags */
749 if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
751 HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
752 HAL_PSSI_DISABLE(hpssi);
753 hpssi->ErrorCode = HAL_PSSI_ERROR_UNDER_RUN;
754 hpssi->State = HAL_PSSI_STATE_READY;
755 /* Process Unlocked */
756 __HAL_UNLOCK(hpssi);
757 return HAL_ERROR;
760 hpssi->State = HAL_PSSI_STATE_READY;
762 /* Process Unlocked */
763 __HAL_UNLOCK(hpssi);
765 return HAL_OK;
767 else
769 return HAL_BUSY;
774 * @brief Receives an amount of data in blocking mode.
775 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
776 * the configuration information for the specified PSSI.
777 * @param pData Pointer to data buffer
778 * @param Size Amount of data to be received (in bytes)
779 * @param Timeout Timeout duration
780 * @retval HAL status
782 HAL_StatusTypeDef HAL_PSSI_Receive(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
784 uint32_t tickstart;
785 uint32_t transfer_size = Size;
787 if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
788 ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size % 2U) != 0U)) ||
789 ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size % 4U) != 0U)))
791 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
792 return HAL_ERROR;
795 if (hpssi->State == HAL_PSSI_STATE_READY)
797 /* Process Locked */
798 __HAL_LOCK(hpssi);
800 hpssi->State = HAL_PSSI_STATE_BUSY;
801 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
803 /* Disable the selected PSSI peripheral */
804 HAL_PSSI_DISABLE(hpssi);
805 /* Configure transfer parameters */
806 MODIFY_REG(hpssi->Instance->CR, (PSSI_CR_OUTEN | PSSI_CR_CKPOL),
807 (PSSI_CR_OUTEN_INPUT | ((hpssi->Init.ClockPolarity == HAL_PSSI_FALLING_EDGE) ? 0U : PSSI_CR_CKPOL)));
809 #if defined(HAL_DMA_MODULE_ENABLED)
810 /* DMA Disable */
811 hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
812 #endif /*HAL_DMA_MODULE_ENABLED*/
814 /* Enable the selected PSSI peripheral */
815 HAL_PSSI_ENABLE(hpssi);
816 if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
818 uint8_t *pbuffer = pData;
820 while (transfer_size > 0U)
822 /* Init tickstart for timeout management*/
823 tickstart = HAL_GetTick();
824 /* Wait until Fifo is ready to receive one byte flag is set */
825 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
827 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
828 hpssi->State = HAL_PSSI_STATE_READY;
829 /* Process Unlocked */
830 __HAL_UNLOCK(hpssi);
831 return HAL_ERROR;
833 /* Read data from DR */
834 *pbuffer = *(__IO uint8_t *)(&hpssi->Instance->DR);
835 pbuffer++;
836 transfer_size--;
839 else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
841 uint16_t *pbuffer = (uint16_t *)pData;
842 __IO uint16_t *dr = (__IO uint16_t *)(&hpssi->Instance->DR);
844 while (transfer_size > 0U)
846 /* Init tickstart for timeout management*/
847 tickstart = HAL_GetTick();
848 /* Wait until Fifo is ready to receive four bytes flag is set */
849 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
851 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
852 hpssi->State = HAL_PSSI_STATE_READY;
853 /* Process Unlocked */
854 __HAL_UNLOCK(hpssi);
855 return HAL_ERROR;
858 /* Read data from DR */
859 *pbuffer = *dr;
860 pbuffer++;
861 transfer_size -= 2U;
864 else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
866 uint32_t *pbuffer = (uint32_t *)pData;
868 while (transfer_size > 0U)
870 /* Init tickstart for timeout management*/
871 tickstart = HAL_GetTick();
872 /* Wait until Fifo is ready to receive four bytes flag is set */
873 if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
875 hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
876 hpssi->State = HAL_PSSI_STATE_READY;
877 /* Process Unlocked */
878 __HAL_UNLOCK(hpssi);
879 return HAL_ERROR;
882 /* Read data from DR */
883 *pbuffer = *(__IO uint32_t *)(&hpssi->Instance->DR);
884 pbuffer++;
885 transfer_size -= 4U;
888 else
890 hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
891 hpssi->State = HAL_PSSI_STATE_READY;
892 /* Process Unlocked */
893 __HAL_UNLOCK(hpssi);
894 return HAL_ERROR;
896 /* Check Errors Flags */
898 if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
900 HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
901 hpssi->ErrorCode = HAL_PSSI_ERROR_OVER_RUN;
902 __HAL_UNLOCK(hpssi);
903 return HAL_ERROR;
906 hpssi->State = HAL_PSSI_STATE_READY;
908 /* Process Unlocked */
909 __HAL_UNLOCK(hpssi);
911 return HAL_OK;
913 else
915 return HAL_BUSY;
919 #if defined(HAL_DMA_MODULE_ENABLED)
921 * @brief Transmit an amount of data in non-blocking mode with DMA
922 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
923 * the configuration information for the specified PSSI.
924 * @param pData Pointer to data buffer
925 * @param Size Amount of data to be sent (in bytes)
926 * @retval HAL status
928 HAL_StatusTypeDef HAL_PSSI_Transmit_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
930 HAL_StatusTypeDef dmaxferstatus;
932 if (hpssi->State == HAL_PSSI_STATE_READY)
935 /* Process Locked */
936 __HAL_LOCK(hpssi);
938 hpssi->State = HAL_PSSI_STATE_BUSY_TX;
939 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
941 /* Disable the selected PSSI peripheral */
942 HAL_PSSI_DISABLE(hpssi);
944 /* Prepare transfer parameters */
945 hpssi->pBuffPtr = pData;
946 hpssi->XferCount = Size;
948 if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
950 hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
952 else
954 hpssi->XferSize = hpssi->XferCount;
957 if (hpssi->XferSize > 0U)
959 if (hpssi->hdmatx != NULL)
962 /* Configure BusWidth */
963 if (hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
965 MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
966 PSSI_CR_DMA_ENABLE | PSSI_CR_OUTEN_OUTPUT |
967 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL));
969 else
971 MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
972 PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth | PSSI_CR_OUTEN_OUTPUT |
973 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? 0U : PSSI_CR_CKPOL));
976 /* Set the PSSI DMA transfer complete callback */
977 hpssi->hdmatx->XferCpltCallback = PSSI_DMATransmitCplt;
979 /* Set the DMA error callback */
980 hpssi->hdmatx->XferErrorCallback = PSSI_DMAError;
982 /* Set the unused DMA callbacks to NULL */
983 hpssi->hdmatx->XferHalfCpltCallback = NULL;
984 hpssi->hdmatx->XferAbortCallback = NULL;
986 /* Enable the DMA */
987 dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmatx, (uint32_t)pData, (uint32_t)&hpssi->Instance->DR,
988 hpssi->XferSize);
990 else
992 /* Update PSSI state */
993 hpssi->State = HAL_PSSI_STATE_READY;
995 /* Update PSSI error code */
996 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
998 /* Process Unlocked */
999 __HAL_UNLOCK(hpssi);
1001 return HAL_ERROR;
1004 if (dmaxferstatus == HAL_OK)
1006 /* Update XferCount value */
1007 hpssi->XferCount -= hpssi->XferSize;
1009 /* Process Unlocked */
1010 __HAL_UNLOCK(hpssi);
1012 /* Note : The PSSI interrupts must be enabled after unlocking current process
1013 to avoid the risk of PSSI interrupt handle execution before current
1014 process unlock */
1015 /* Enable ERR interrupt */
1016 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1018 /* Enable DMA Request */
1019 hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
1020 /* Enable the selected PSSI peripheral */
1021 HAL_PSSI_ENABLE(hpssi);
1023 else
1025 /* Update PSSI state */
1026 hpssi->State = HAL_PSSI_STATE_READY;
1028 /* Update PSSI error code */
1029 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1031 /* Process Unlocked */
1032 __HAL_UNLOCK(hpssi);
1034 return HAL_ERROR;
1037 else
1039 /* Process Unlocked */
1040 __HAL_UNLOCK(hpssi);
1042 /* Note : The PSSI interrupts must be enabled after unlocking current process
1043 to avoid the risk of PSSI interrupt handle execution before current
1044 process unlock */
1045 /* Enable ERRinterrupt */
1046 /* possible to enable all of these */
1048 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1050 return HAL_OK;
1052 else
1054 return HAL_BUSY;
1059 * @brief Receive an amount of data in non-blocking mode with DMA
1060 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1061 * the configuration information for the specified PSSI.
1062 * @param pData Pointer to data buffer
1063 * @param Size Amount of data to be received (in bytes)
1064 * @retval HAL status
1066 HAL_StatusTypeDef HAL_PSSI_Receive_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
1069 HAL_StatusTypeDef dmaxferstatus;
1071 if (hpssi->State == HAL_PSSI_STATE_READY)
1074 /* Disable the selected PSSI peripheral */
1075 HAL_PSSI_DISABLE(hpssi);
1076 /* Process Locked */
1077 __HAL_LOCK(hpssi);
1079 hpssi->State = HAL_PSSI_STATE_BUSY_RX;
1080 hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
1082 /* Prepare transfer parameters */
1083 hpssi->pBuffPtr = pData;
1084 hpssi->XferCount = Size;
1086 if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
1088 hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
1090 else
1092 hpssi->XferSize = hpssi->XferCount;
1095 if (hpssi->XferSize > 0U)
1097 if (hpssi->hdmarx != NULL)
1099 /* Configure BusWidth */
1100 if (hpssi->hdmarx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
1102 MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL, PSSI_CR_DMA_ENABLE |
1103 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? PSSI_CR_CKPOL : 0U));
1105 else
1107 MODIFY_REG(hpssi->Instance->CR, PSSI_CR_DMAEN | PSSI_CR_OUTEN | PSSI_CR_CKPOL,
1108 PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth |
1109 ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE) ? PSSI_CR_CKPOL : 0U));
1112 /* Set the PSSI DMA transfer complete callback */
1113 hpssi->hdmarx->XferCpltCallback = PSSI_DMAReceiveCplt;
1115 /* Set the DMA error callback */
1116 hpssi->hdmarx->XferErrorCallback = PSSI_DMAError;
1118 /* Set the unused DMA callbacks to NULL */
1119 hpssi->hdmarx->XferHalfCpltCallback = NULL;
1120 hpssi->hdmarx->XferAbortCallback = NULL;
1122 /* Enable the DMA */
1123 dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmarx, (uint32_t)&hpssi->Instance->DR, (uint32_t)pData,
1124 hpssi->XferSize);
1126 else
1128 /* Update PSSI state */
1129 hpssi->State = HAL_PSSI_STATE_READY;
1131 /* Update PSSI error code */
1132 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1134 /* Process Unlocked */
1135 __HAL_UNLOCK(hpssi);
1137 return HAL_ERROR;
1140 if (dmaxferstatus == HAL_OK)
1142 /* Update XferCount value */
1143 hpssi->XferCount -= hpssi->XferSize;
1145 /* Process Unlocked */
1146 __HAL_UNLOCK(hpssi);
1148 /* Note : The PSSI interrupts must be enabled after unlocking current process
1149 to avoid the risk of PSSI interrupt handle execution before current
1150 process unlock */
1151 /* Enable ERR interrupt */
1152 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1154 /* Enable DMA Request */
1155 hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
1156 /* Enable the selected PSSI peripheral */
1157 HAL_PSSI_ENABLE(hpssi);
1159 else
1161 /* Update PSSI state */
1162 hpssi->State = HAL_PSSI_STATE_READY;
1164 /* Update PSSI error code */
1165 hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
1167 /* Process Unlocked */
1168 __HAL_UNLOCK(hpssi);
1170 return HAL_ERROR;
1173 else
1175 /* Process Unlocked */
1176 __HAL_UNLOCK(hpssi);
1178 /* Enable ERR,interrupt */
1179 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1182 return HAL_OK;
1184 else
1186 return HAL_BUSY;
1191 * @brief Abort a DMA process communication with Interrupt.
1192 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1193 * the configuration information for the specified PSSI.
1194 * @retval HAL status
1196 HAL_StatusTypeDef HAL_PSSI_Abort_DMA(PSSI_HandleTypeDef *hpssi)
1198 /* Process Locked */
1199 __HAL_LOCK(hpssi);
1201 /* Disable Interrupts */
1202 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1204 /* Set State at HAL_PSSI_STATE_ABORT */
1205 hpssi->State = HAL_PSSI_STATE_ABORT;
1207 /* Abort DMA TX transfer if any */
1208 if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1210 if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1212 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1214 if (hpssi->hdmatx != NULL)
1216 /* Set the PSSI DMA Abort callback :
1217 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1218 hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1220 /* Abort DMA TX */
1221 if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1223 /* Call Directly XferAbortCallback function in case of error */
1224 hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1228 /* Abort DMA RX transfer if any */
1229 else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1231 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1233 if (hpssi->hdmarx != NULL)
1235 /* Set the PSSI DMA Abort callback :
1236 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1237 hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1239 /* Abort DMA RX */
1240 if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1242 /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1243 hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1247 else
1250 /* Call the error callback */
1251 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1252 hpssi->ErrorCallback(hpssi);
1253 #else
1254 HAL_PSSI_ErrorCallback(hpssi);
1255 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1259 /* Process Unlocked */
1260 __HAL_UNLOCK(hpssi);
1262 /* Note : The PSSI interrupts must be enabled after unlocking current process
1263 to avoid the risk of PSSI interrupt handle execution before current
1264 process unlock */
1265 HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1267 return HAL_OK;
1269 #endif /*HAL_DMA_MODULE_ENABLED*/
1272 * @}
1275 /** @addtogroup PSSI_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
1276 * @{
1280 * @brief This function handles PSSI event interrupt request.
1281 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1282 * the configuration information for the specified PSSI.
1283 * @retval None
1285 void HAL_PSSI_IRQHandler(PSSI_HandleTypeDef *hpssi)
1287 /* Overrun/ Underrun Errors */
1288 if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_MIS) != 0U)
1290 /* Reset handle parameters */
1291 hpssi->XferCount = 0U;
1293 /* Disable all interrupts */
1294 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1296 #if defined(HAL_DMA_MODULE_ENABLED)
1297 /* Abort DMA TX transfer if any */
1298 if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1300 if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1302 /* Set new error code */
1303 hpssi->ErrorCode |= HAL_PSSI_ERROR_UNDER_RUN;
1305 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1307 if (hpssi->hdmatx != NULL)
1309 /* Set the PSSI DMA Abort callback :
1310 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1311 hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1313 /* Process Unlocked */
1314 __HAL_UNLOCK(hpssi);
1316 /* Abort DMA TX */
1317 if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1319 /* Call Directly XferAbortCallback function in case of error */
1320 hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1324 /* Abort DMA RX transfer if any */
1325 else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1327 /* Set new error code */
1328 hpssi->ErrorCode |= HAL_PSSI_ERROR_OVER_RUN;
1330 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1332 if (hpssi->hdmarx != NULL)
1334 /* Set the PSSI DMA Abort callback :
1335 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1336 hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1338 /* Process Unlocked */
1339 __HAL_UNLOCK(hpssi);
1341 /* Abort DMA RX */
1342 if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1344 /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1345 hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1349 else
1351 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1352 /* Call the corresponding callback to inform upper layer of the error */
1353 hpssi->ErrorCallback(hpssi);
1354 #else
1355 HAL_PSSI_ErrorCallback(hpssi);
1356 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1359 #endif /*HAL_DMA_MODULE_ENABLED*/
1361 /* If state is an abort treatment on going, don't change state */
1362 if (hpssi->State == HAL_PSSI_STATE_ABORT)
1364 hpssi->State = HAL_PSSI_STATE_READY;
1366 /* Process Unlocked */
1367 __HAL_UNLOCK(hpssi);
1369 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1370 /* Call the corresponding callback to inform upper layer of End of Transfer */
1371 hpssi->AbortCpltCallback(hpssi);
1372 #else
1373 HAL_PSSI_AbortCpltCallback(hpssi);
1374 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1376 else
1378 /* Set HAL_PSSI_STATE_READY */
1379 hpssi->State = HAL_PSSI_STATE_READY;
1380 /* Process Unlocked */
1381 __HAL_UNLOCK(hpssi);
1383 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1384 /* Call the corresponding callback to inform upper layer of End of Transfer */
1385 hpssi->ErrorCallback(hpssi);
1386 #else
1387 HAL_PSSI_ErrorCallback(hpssi);
1388 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1394 * @brief Tx Transfer complete callback.
1395 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1396 * the configuration information for the specified PSSI.
1397 * @retval None
1399 __weak void HAL_PSSI_TxCpltCallback(PSSI_HandleTypeDef *hpssi)
1401 /* Prevent unused argument(s) compilation warning */
1402 UNUSED(hpssi);
1404 /* NOTE : This function should not be modified, when the callback is needed,
1405 the HAL_PSSI_TxCpltCallback can be implemented in the user file
1410 * @brief Rx Transfer complete callback.
1411 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1412 * the configuration information for the specified PSSI.
1413 * @retval None
1415 __weak void HAL_PSSI_RxCpltCallback(PSSI_HandleTypeDef *hpssi)
1417 /* Prevent unused argument(s) compilation warning */
1418 UNUSED(hpssi);
1420 /* NOTE : This function should not be modified, when the callback is needed,
1421 the HAL_PSSI_RxCpltCallback can be implemented in the user file
1426 * @brief PSSI error callback.
1427 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1428 * the configuration information for the specified PSSI.
1429 * @retval None
1431 __weak void HAL_PSSI_ErrorCallback(PSSI_HandleTypeDef *hpssi)
1433 /* Prevent unused argument(s) compilation warning */
1434 UNUSED(hpssi);
1436 /* NOTE : This function should not be modified, when the callback is needed,
1437 the HAL_PSSI_ErrorCallback could be implemented in the user file
1442 * @brief PSSI abort callback.
1443 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1444 * the configuration information for the specified PSSI.
1445 * @retval None
1447 __weak void HAL_PSSI_AbortCpltCallback(PSSI_HandleTypeDef *hpssi)
1449 /* Prevent unused argument(s) compilation warning */
1450 UNUSED(hpssi);
1452 /* NOTE : This function should not be modified, when the callback is needed,
1453 the HAL_PSSI_AbortCpltCallback could be implemented in the user file
1458 * @}
1461 /** @defgroup PSSI_Exported_Functions_Group3 Peripheral State and Error functions
1462 * @brief Peripheral State, Mode and Error functions
1464 @verbatim
1465 ===============================================================================
1466 ##### Peripheral State, Mode and Error functions #####
1467 ===============================================================================
1468 [..]
1469 This subsection permit to get in run-time the status of the peripheral
1470 and the data flow.
1472 @endverbatim
1473 * @{
1477 * @brief Return the PSSI handle state.
1478 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1479 * the configuration information for the specified PSSI.
1480 * @retval HAL state
1482 HAL_PSSI_StateTypeDef HAL_PSSI_GetState(const PSSI_HandleTypeDef *hpssi)
1484 /* Return PSSI handle state */
1485 return hpssi->State;
1489 * @brief Return the PSSI error code.
1490 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1491 * the configuration information for the specified PSSI.
1492 * @retval PSSI Error Code
1494 uint32_t HAL_PSSI_GetError(const PSSI_HandleTypeDef *hpssi)
1496 return hpssi->ErrorCode;
1500 * @}
1504 * @}
1507 /** @addtogroup PSSI_Private_Functions
1508 * @{
1512 * @brief PSSI Errors process.
1513 * @param hpssi PSSI handle.
1514 * @param ErrorCode Error code to handle.
1515 * @retval None
1517 static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode)
1519 /* Reset handle parameters */
1520 hpssi->XferCount = 0U;
1522 /* Set new error code */
1523 hpssi->ErrorCode |= ErrorCode;
1525 /* Disable all interrupts */
1526 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1528 #if defined(HAL_DMA_MODULE_ENABLED)
1529 /* Abort DMA TX transfer if any */
1530 if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
1532 if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
1534 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1536 if (hpssi->hdmatx != NULL)
1538 /* Set the PSSI DMA Abort callback :
1539 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1540 hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
1542 /* Process Unlocked */
1543 __HAL_UNLOCK(hpssi);
1545 /* Abort DMA TX */
1546 if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
1548 /* Call Directly XferAbortCallback function in case of error */
1549 hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
1553 /* Abort DMA RX transfer if any */
1554 else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
1556 hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
1558 if (hpssi->hdmarx != NULL)
1560 /* Set the PSSI DMA Abort callback :
1561 will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
1562 hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
1564 /* Process Unlocked */
1565 __HAL_UNLOCK(hpssi);
1567 /* Abort DMA RX */
1568 if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
1570 /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
1571 hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
1575 else
1577 /*Nothing to do*/
1580 #endif /*HAL_DMA_MODULE_ENABLED*/
1582 /* If state is an abort treatment on going, don't change state */
1583 if (hpssi->State == HAL_PSSI_STATE_ABORT)
1585 hpssi->State = HAL_PSSI_STATE_READY;
1587 /* Process Unlocked */
1588 __HAL_UNLOCK(hpssi);
1590 /* Call the corresponding callback to inform upper layer of End of Transfer */
1591 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1592 hpssi->AbortCpltCallback(hpssi);
1593 #else
1594 HAL_PSSI_AbortCpltCallback(hpssi);
1595 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1597 else
1599 /* Set HAL_PSSI_STATE_READY */
1600 hpssi->State = HAL_PSSI_STATE_READY;
1602 /* Process Unlocked */
1603 __HAL_UNLOCK(hpssi);
1605 /* Call the corresponding callback to inform upper layer of End of Transfer */
1606 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1607 hpssi->ErrorCallback(hpssi);
1608 #else
1609 HAL_PSSI_ErrorCallback(hpssi);
1610 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1614 #if defined(HAL_DMA_MODULE_ENABLED)
1616 * @brief DMA PSSI slave transmit process complete callback.
1617 * @param hdma DMA handle
1618 * @retval None
1620 void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
1622 /* Derogation MISRAC2012-Rule-11.5 */
1623 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1625 uint32_t tmperror;
1627 /* Disable Interrupts */
1628 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1630 /* Store current volatile hpssi->ErrorCode, misra rule */
1631 tmperror = hpssi->ErrorCode;
1633 /* Call the corresponding callback to inform upper layer of End of Transfer */
1634 if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1636 /* Call the corresponding callback to inform upper layer of End of Transfer */
1637 PSSI_Error(hpssi, hpssi->ErrorCode);
1639 /* hpssi->State == HAL_PSSI_STATE_BUSY_TX */
1640 else
1642 hpssi->State = HAL_PSSI_STATE_READY;
1644 /* Process Unlocked */
1645 __HAL_UNLOCK(hpssi);
1647 /* Call the corresponding callback to inform upper layer of End of Transfer */
1648 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1649 hpssi->TxCpltCallback(hpssi);
1650 #else
1651 HAL_PSSI_TxCpltCallback(hpssi);
1652 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1657 * @brief DMA PSSI master receive process complete callback.
1658 * @param hdma DMA handle
1659 * @retval None
1661 void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1663 /* Derogation MISRAC2012-Rule-11.5 */
1664 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1666 uint32_t tmperror;
1668 /* Disable Interrupts */
1669 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1671 /* Store current volatile hpssi->ErrorCode, misra rule */
1672 tmperror = hpssi->ErrorCode;
1674 /* Call the corresponding callback to inform upper layer of End of Transfer */
1675 if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1677 /* Call the corresponding callback to inform upper layer of End of Transfer */
1678 PSSI_Error(hpssi, hpssi->ErrorCode);
1680 /* hpssi->State == HAL_PSSI_STATE_BUSY_RX */
1681 else
1683 hpssi->State = HAL_PSSI_STATE_READY;
1685 /* Process Unlocked */
1686 __HAL_UNLOCK(hpssi);
1688 /* Call the corresponding callback to inform upper layer of End of Transfer */
1689 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1690 hpssi->RxCpltCallback(hpssi);
1691 #else
1692 HAL_PSSI_RxCpltCallback(hpssi);
1693 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1698 * @brief DMA PSSI communication abort callback
1699 * (To be called at end of DMA Abort procedure).
1700 * @param hdma DMA handle.
1701 * @retval None
1703 void PSSI_DMAAbort(DMA_HandleTypeDef *hdma)
1705 /* Derogation MISRAC2012-Rule-11.5 */
1706 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1708 /* Reset AbortCpltCallback */
1709 hpssi->hdmatx->XferAbortCallback = NULL;
1710 hpssi->hdmarx->XferAbortCallback = NULL;
1712 /* Check if come from abort from user */
1713 if (hpssi->State == HAL_PSSI_STATE_ABORT)
1715 hpssi->State = HAL_PSSI_STATE_READY;
1717 /* Call the corresponding callback to inform upper layer of End of Transfer */
1718 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1719 hpssi->AbortCpltCallback(hpssi);
1720 #else
1721 HAL_PSSI_AbortCpltCallback(hpssi);
1722 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1724 else
1726 /* Call the corresponding callback to inform upper layer of End of Transfer */
1727 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1728 hpssi->ErrorCallback(hpssi);
1729 #else
1730 HAL_PSSI_ErrorCallback(hpssi);
1731 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1734 #endif /*HAL_DMA_MODULE_ENABLED*/
1737 * @brief This function handles PSSI Communication Timeout.
1738 * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
1739 * the configuration information for the specified PSSI.
1740 * @param Flag Specifies the PSSI flag to check.
1741 * @param Status The new Flag status (SET or RESET).
1742 * @param Timeout Timeout duration
1743 * @param Tickstart Tick start value
1744 * @retval HAL status
1746 static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status,
1747 uint32_t Timeout, uint32_t Tickstart)
1749 while ((HAL_PSSI_GET_STATUS(hpssi, Flag) & Flag) == (uint32_t)Status)
1751 /* Check for the Timeout */
1752 if (Timeout != HAL_MAX_DELAY)
1754 if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
1756 hpssi->ErrorCode |= HAL_PSSI_ERROR_TIMEOUT;
1757 hpssi->State = HAL_PSSI_STATE_READY;
1759 /* Process Unlocked */
1760 __HAL_UNLOCK(hpssi);
1762 return HAL_ERROR;
1766 return HAL_OK;
1769 #if defined(HAL_DMA_MODULE_ENABLED)
1770 void PSSI_DMAError(DMA_HandleTypeDef *hdma)
1772 /* Derogation MISRAC2012-Rule-11.5 */
1773 PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent);
1775 uint32_t tmperror;
1777 /* Disable the selected PSSI peripheral */
1778 HAL_PSSI_DISABLE(hpssi);
1780 /* Disable Interrupts */
1781 HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
1783 /* Store current volatile hpssi->ErrorCode, misra rule */
1784 tmperror = hpssi->ErrorCode;
1786 /* Call the corresponding callback to inform upper layer of End of Transfer */
1787 if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
1789 /* Call the corresponding callback to inform upper layer of End of Transfer */
1790 PSSI_Error(hpssi, hpssi->ErrorCode);
1792 else
1794 hpssi->State = HAL_PSSI_STATE_READY;
1796 /* Process Unlocked */
1797 __HAL_UNLOCK(hpssi);
1799 /* Call the corresponding callback to inform upper layer of End of Transfer */
1800 #if (USE_HAL_PSSI_REGISTER_CALLBACKS == 1)
1801 hpssi->ErrorCallback(hpssi);
1802 #else
1803 HAL_PSSI_ErrorCallback(hpssi);
1804 #endif /* USE_HAL_PSSI_REGISTER_CALLBACKS */
1807 #endif /*HAL_DMA_MODULE_ENABLED*/
1811 * @}
1813 #endif /* PSSI */
1814 #endif /* HAL_PSSI_MODULE_ENABLED */
1816 * @}
1820 * @}