Create release.yml
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_swpmi.c
blobf90aec773f7e20a09ebe0eea21315bf1b58de706
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_swpmi.c
4 * @author MCD Application Team
5 * @brief SWPMI HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Single Wire Protocol Master Interface (SWPMI).
8 * + Initialization and Configuration
9 * + Data transfers functions
10 * + DMA transfers management
11 * + Interrupts and flags management
12 @verbatim
13 ===============================================================================
14 ##### How to use this driver #####
15 ===============================================================================
16 [..]
17 The SWPMI HAL driver can be used as follows:
19 (#) Declare a SWPMI_HandleTypeDef handle structure (eg. SWPMI_HandleTypeDef hswpmi).
21 (#) Initialize the SWPMI low level resources by implementing the HAL_SWPMI_MspInit() API:
22 (##) Enable the SWPMIx interface clock with __HAL_RCC_SWPMIx_CLK_ENABLE().
23 (##) SWPMI IO configuration:
24 (+++) Enable the clock for the SWPMI GPIO.
25 (+++) Configure these SWPMI pins as alternate function pull-up.
26 (##) NVIC configuration if you need to use interrupt process (HAL_SWPMI_Transmit_IT()
27 and HAL_SWPMI_Receive_IT() APIs):
28 (+++) Configure the SWPMIx interrupt priority with HAL_NVIC_SetPriority().
29 (+++) Enable the NVIC SWPMI IRQ handle with HAL_NVIC_EnableIRQ().
31 (##) DMA Configuration if you need to use DMA process (HAL_SWPMI_Transmit_DMA()
32 and HAL_SWPMI_Receive_DMA() APIs):
33 (+++) Declare a DMA handle structure for the Tx/Rx streams.
34 (+++) Enable the DMAx interface clock.
35 (+++) Configure the declared DMA handle structure with the required
36 Tx/Rx parameters.
37 (+++) Configure the DMA Tx/Rx streams and requests.
38 (+++) Associate the initialized DMA handle to the SWPMI DMA Tx/Rx handle.
39 (+++) Configure the priority and enable the NVIC for the transfer complete
40 interrupt on the DMA Tx/Rx streams.
42 (#) Program the Bite Rate, Tx Buffering mode, Rx Buffering mode in the Init structure.
44 (#) Enable the SWPMI peripheral by calling the HAL_SWPMI_Init() function.
46 [..]
47 Three operation modes are available within this driver :
49 *** Polling mode IO operation ***
50 =================================
51 [..]
52 (+) Send an amount of data in blocking mode using HAL_SWPMI_Transmit()
53 (+) Receive an amount of data in blocking mode using HAL_SWPMI_Receive()
55 *** Interrupt mode IO operation ***
56 ===================================
57 [..]
58 (+) Send an amount of data in non-blocking mode using HAL_SWPMI_Transmit_IT()
59 (+) At transmission end of transfer HAL_SWPMI_TxCpltCallback() is executed and user can
60 add his own code by customization of function pointer HAL_SWPMI_TxCpltCallback()
61 (+) Receive an amount of data in non-blocking mode using HAL_SWPMI_Receive_IT()
62 (+) At reception end of transfer HAL_SWPMI_RxCpltCallback() is executed and user can
63 add his own code by customization of function pointer HAL_SWPMI_RxCpltCallback()
64 (+) In case of flag error, HAL_SWPMI_ErrorCallback() function is executed and user can
65 add his own code by customization of function pointer HAL_SWPMI_ErrorCallback()
67 *** DMA mode IO operation ***
68 =============================
69 [..]
70 (+) Send an amount of data in non-blocking mode (DMA) using HAL_SWPMI_Transmit_DMA()
71 (+) At transmission end of transfer HAL_SWPMI_TxCpltCallback() is executed and user can
72 add his own code by customization of function pointer HAL_SWPMI_TxCpltCallback()
73 (+) Receive an amount of data in non-blocking mode (DMA) using HAL_SWPMI_Receive_DMA()
74 (+) At reception end of transfer HAL_SWPMI_RxCpltCallback() is executed and user can
75 add his own code by customization of function pointer HAL_SWPMI_RxCpltCallback()
76 (+) In case of flag error, HAL_SWPMI_ErrorCallback() function is executed and user can
77 add his own code by customization of function pointer HAL_SWPMI_ErrorCallback()
78 (+) Stop the DMA Transfer using HAL_SWPMI_DMAStop()
80 *** SWPMI HAL driver additional function list ***
81 ===============================================
82 [..]
83 Below the list the others API available SWPMI HAL driver :
85 (+) HAL_SWPMI_EnableLoopback(): Enable the loopback mode for test purpose only
86 (+) HAL_SWPMI_DisableLoopback(): Disable the loopback mode
88 *** SWPMI HAL driver macros list ***
89 ==================================
90 [..]
91 Below the list of most used macros in SWPMI HAL driver :
93 (+) __HAL_SWPMI_ENABLE(): Enable the SWPMI peripheral
94 (+) __HAL_SWPMI_DISABLE(): Disable the SWPMI peripheral
95 (+) __HAL_SWPMI_TRANSCEIVER_ENABLE(): Enable the SWPMI peripheral transceiver
96 (+) __HAL_SWPMI_TRANSCEIVER_DISABLE(): Disable the SWPMI peripheral transceiver
97 (+) __HAL_SWPMI_ENABLE_IT(): Enable the specified SWPMI interrupts
98 (+) __HAL_SWPMI_DISABLE_IT(): Disable the specified SWPMI interrupts
99 (+) __HAL_SWPMI_GET_IT_SOURCE(): Check if the specified SWPMI interrupt source is
100 enabled or disabled
101 (+) __HAL_SWPMI_GET_FLAG(): Check whether the specified SWPMI flag is set or not
103 *** Callback registration ***
104 =============================
105 [..]
106 The compilation define USE_HAL_SWPMI_REGISTER_CALLBACKS when set to 1
107 allows the user to configure dynamically the driver callbacks.
108 [..]
109 Use function HAL_SWPMI_RegisterCallback() to register a user callback. It allows
110 to register the following callbacks:
111 (+) RxCpltCallback : SWPMI receive complete.
112 (+) RxHalfCpltCallback : SWPMI receive half complete.
113 (+) TxCpltCallback : SWPMI transmit complete.
114 (+) TxHalfCpltCallback : SWPMI transmit half complete.
115 (+) ErrorCallback : SWPMI error.
116 (+) MspInitCallback : SWPMI MspInit.
117 (+) MspDeInitCallback : SWPMI MspDeInit.
118 [..]
119 This function takes as parameters the HAL peripheral handle, the callback ID
120 and a pointer to the user callback function.
121 [..]
122 Use function HAL_SWPMI_UnRegisterCallback() to reset a callback to the default
123 weak (surcharged) function.
124 HAL_SWPMI_UnRegisterCallback() takes as parameters the HAL peripheral handle,
125 and the callback ID.
126 This function allows to reset following callbacks:
127 (+) RxCpltCallback : SWPMI receive complete.
128 (+) RxHalfCpltCallback : SWPMI receive half complete.
129 (+) TxCpltCallback : SWPMI transmit complete.
130 (+) TxHalfCpltCallback : SWPMI transmit half complete.
131 (+) ErrorCallback : SWPMI error.
132 (+) MspInitCallback : SWPMI MspInit.
133 (+) MspDeInitCallback : SWPMI MspDeInit.
134 [..]
135 By default, after the HAL_SWPMI_Init and if the state is HAL_SWPMI_STATE_RESET
136 all callbacks are reset to the corresponding legacy weak (surcharged) functions:
137 examples HAL_SWPMI_RxCpltCallback(), HAL_SWPMI_ErrorCallback().
138 Exception done for MspInit and MspDeInit callbacks that are respectively
139 reset to the legacy weak (surcharged) functions in the HAL_SWPMI_Init
140 and HAL_SWPMI_DeInit only when these callbacks are null (not registered beforehand).
141 If not, MspInit or MspDeInit are not null, the HAL_SWPMI_Init and HAL_SWPMI_DeInit
142 keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
143 [..]
144 Callbacks can be registered/unregistered in READY state only.
145 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
146 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
147 during the Init/DeInit.
148 In that case first register the MspInit/MspDeInit user callbacks
149 using HAL_SWPMI_RegisterCallback before calling @ref HAL_SWPMI_DeInit
150 or HAL_SWPMI_Init function.
151 [..]
152 When the compilation define USE_HAL_SWPMI_REGISTER_CALLBACKS is set to 0 or
153 not defined, the callback registering feature is not available
154 and weak (surcharged) callbacks are used.
156 @endverbatim
157 ******************************************************************************
158 * @attention
160 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
161 * All rights reserved.</center></h2>
163 * This software component is licensed by ST under BSD 3-Clause license,
164 * the "License"; You may not use this file except in compliance with the
165 * License. You may obtain a copy of the License at:
166 * opensource.org/licenses/BSD-3-Clause
168 ******************************************************************************
171 /* Includes ------------------------------------------------------------------*/
172 #include "stm32h7xx_hal.h"
174 /** @addtogroup STM32H7xx_HAL_Driver
175 * @{
179 /** @defgroup SWPMI SWPMI
180 * @brief HAL SWPMI module driver
181 * @{
183 #ifdef HAL_SWPMI_MODULE_ENABLED
185 /* Private typedef -----------------------------------------------------------*/
186 /* Private define ------------------------------------------------------------*/
187 /* Private constants ---------------------------------------------------------*/
188 /** @addtogroup SWPMI_Private_Constants SWPMI Private Constants
189 * @{
191 #define SWPMI_TIMEOUT_VALUE 22000U /* End of transmission timeout */
192 #define SWPMI_TRANSCEIVER_RDY_TIMEOUT_VALUE 2000U /* Transceiver ready timeout */
195 * @}
198 /* Private macros ------------------------------------------------------------*/
199 /* Private variables ---------------------------------------------------------*/
200 /* Private function prototypes -----------------------------------------------*/
201 static void SWPMI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
202 static void SWPMI_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
203 static void SWPMI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
204 static void SWPMI_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
205 static void SWPMI_DMAError(DMA_HandleTypeDef *hdma);
206 static void SWPMI_DMAAbortOnError(DMA_HandleTypeDef *hdma);
207 static void SWPMI_Transmit_IT(SWPMI_HandleTypeDef *hswpmi);
208 static void SWPMI_EndTransmit_IT(SWPMI_HandleTypeDef *hswpmi);
209 static void SWPMI_Receive_IT(SWPMI_HandleTypeDef *hswpmi);
210 static void SWPMI_EndReceive_IT(SWPMI_HandleTypeDef *hswpmi);
211 static void SWPMI_EndTransmitReceive_IT(SWPMI_HandleTypeDef *hswpmi);
212 static HAL_StatusTypeDef SWPMI_WaitOnFlagSetUntilTimeout(SWPMI_HandleTypeDef *hswpmi, uint32_t Flag, uint32_t Tickstart, uint32_t Timeout);
214 /* Exported functions --------------------------------------------------------*/
216 /** @defgroup SWPMI_Exported_Functions SWPMI Exported Functions
217 * @{
220 /** @defgroup SWPMI_Exported_Group1 Initialization/de-initialization methods
221 * @brief Initialization and Configuration functions
223 @verbatim
224 ===============================================================================
225 ##### Initialization and Configuration functions #####
226 ===============================================================================
227 [..] This section provides functions allowing to:
228 (+) Initialize and configure the SWPMI peripheral.
229 (+) De-initialize the SWPMI peripheral.
231 @endverbatim
232 * @{
236 * @brief Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitTypeDef.
237 * @param hswpmi SWPMI handle
238 * @retval HAL status
240 HAL_StatusTypeDef HAL_SWPMI_Init(SWPMI_HandleTypeDef *hswpmi)
242 HAL_StatusTypeDef status = HAL_OK;
243 uint32_t tickstart = HAL_GetTick();
245 /* Check the SWPMI handle allocation */
246 if(hswpmi == NULL)
248 status = HAL_ERROR;
250 else
252 /* Check the parameters */
253 assert_param(IS_SWPMI_VOLTAGE_CLASS(hswpmi->Init.VoltageClass));
254 assert_param(IS_SWPMI_BITRATE_VALUE(hswpmi->Init.BitRate));
255 assert_param(IS_SWPMI_TX_BUFFERING_MODE(hswpmi->Init.TxBufferingMode));
256 assert_param(IS_SWPMI_RX_BUFFERING_MODE(hswpmi->Init.RxBufferingMode));
258 if(hswpmi->State == HAL_SWPMI_STATE_RESET)
260 /* Allocate lock resource and initialize it */
261 hswpmi->Lock = HAL_UNLOCKED;
263 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
264 /* Reset callback pointers to the weak predefined callbacks */
265 hswpmi->RxCpltCallback = HAL_SWPMI_RxCpltCallback;
266 hswpmi->RxHalfCpltCallback = HAL_SWPMI_RxHalfCpltCallback;
267 hswpmi->TxCpltCallback = HAL_SWPMI_TxCpltCallback;
268 hswpmi->TxHalfCpltCallback = HAL_SWPMI_TxHalfCpltCallback;
269 hswpmi->ErrorCallback = HAL_SWPMI_ErrorCallback;
271 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
272 if(hswpmi->MspInitCallback == NULL)
274 hswpmi->MspInitCallback = HAL_SWPMI_MspInit;
276 hswpmi->MspInitCallback(hswpmi);
277 #else
278 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
279 HAL_SWPMI_MspInit(hswpmi);
280 #endif
283 hswpmi->State = HAL_SWPMI_STATE_BUSY;
285 /* Disable SWPMI interface */
286 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
288 /* Clear all SWPMI interface flags */
289 WRITE_REG(hswpmi->Instance->ICR, 0x099F);
291 /* Apply Voltage class selection */
292 MODIFY_REG(hswpmi->Instance->OR, SWPMI_OR_CLASS, hswpmi->Init.VoltageClass);
295 /* Configure the BRR register (Bitrate) */
296 WRITE_REG(hswpmi->Instance->BRR, hswpmi->Init.BitRate);
298 /* Apply SWPMI CR configuration */
299 MODIFY_REG(hswpmi->Instance->CR, \
300 SWPMI_CR_RXDMA | SWPMI_CR_TXDMA | SWPMI_CR_RXMODE | SWPMI_CR_TXMODE, \
301 hswpmi->Init.TxBufferingMode | hswpmi->Init.RxBufferingMode);
303 /* Enable the SWPMI transceiver */
304 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPEN);
305 /* Wait on RDYF flag to activate SWPMI */
306 if(SWPMI_WaitOnFlagSetUntilTimeout(hswpmi, SWPMI_FLAG_RDYF, tickstart, SWPMI_TRANSCEIVER_RDY_TIMEOUT_VALUE) != HAL_OK)
308 status = HAL_TIMEOUT;
311 if(status == HAL_OK)
313 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
314 hswpmi->State = HAL_SWPMI_STATE_READY;
316 /* Enable SWPMI peripheral */
317 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
319 else
321 hswpmi->ErrorCode = HAL_SWPMI_ERROR_TRANSCEIVER_NOT_READY;
322 hswpmi->State = HAL_SWPMI_STATE_ERROR;
326 return status;
330 * @brief De-initialize the SWPMI peripheral.
331 * @param hswpmi SWPMI handle
332 * @retval HAL status
334 HAL_StatusTypeDef HAL_SWPMI_DeInit(SWPMI_HandleTypeDef *hswpmi)
336 HAL_StatusTypeDef status = HAL_OK;
338 /* Check the SWPMI handle allocation */
339 if(hswpmi == NULL)
341 status = HAL_ERROR;
343 else
345 /* Check the parameters */
346 assert_param(IS_SWPMI_INSTANCE(hswpmi->Instance));
348 hswpmi->State = HAL_SWPMI_STATE_BUSY;
350 /* Disable SWPMI interface */
351 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
353 /* Disable Loopback mode */
354 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_LPBK);
356 /* Disable SWPMI transceiver */
357 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPEN);
360 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
361 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
362 if(hswpmi->MspDeInitCallback == NULL)
364 hswpmi->MspDeInitCallback = HAL_SWPMI_MspDeInit;
366 hswpmi->MspDeInitCallback(hswpmi);
367 #else
368 HAL_SWPMI_MspDeInit(hswpmi);
369 #endif
371 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
372 hswpmi->State = HAL_SWPMI_STATE_RESET;
374 /* Release Lock */
375 __HAL_UNLOCK(hswpmi);
378 return status;
382 * @brief Initialize the SWPMI MSP.
383 * @param hswpmi SWPMI handle
384 * @retval None
386 __weak void HAL_SWPMI_MspInit(SWPMI_HandleTypeDef *hswpmi)
388 /* Prevent unused argument(s) compilation warning */
389 UNUSED(hswpmi);
391 /* NOTE : This function should not be modified, when the callback is needed,
392 the HAL_SWPMI_MspInit can be implemented in the user file
397 * @brief DeInitialize the SWPMI MSP.
398 * @param hswpmi SWPMI handle
399 * @retval None
401 __weak void HAL_SWPMI_MspDeInit(SWPMI_HandleTypeDef *hswpmi)
403 /* Prevent unused argument(s) compilation warning */
404 UNUSED(hswpmi);
406 /* NOTE : This function should not be modified, when the callback is needed,
407 the HAL_SWPMI_MspDeInit can be implemented in the user file
411 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
413 * @brief Register a user SWPMI callback
414 * to be used instead of the weak predefined callback.
415 * @param hswpmi SWPMI handle.
416 * @param CallbackID ID of the callback to be registered.
417 * This parameter can be one of the following values:
418 * @arg @ref HAL_SWPMI_RX_COMPLETE_CB_ID receive complete callback ID.
419 * @arg @ref HAL_SWPMI_RX_HALFCOMPLETE_CB_ID receive half complete callback ID.
420 * @arg @ref HAL_SWPMI_TX_COMPLETE_CB_ID transmit complete callback ID.
421 * @arg @ref HAL_SWPMI_TX_HALFCOMPLETE_CB_ID transmit half complete callback ID.
422 * @arg @ref HAL_SWPMI_ERROR_CB_ID error callback ID.
423 * @arg @ref HAL_SWPMI_MSPINIT_CB_ID MSP init callback ID.
424 * @arg @ref HAL_SWPMI_MSPDEINIT_CB_ID MSP de-init callback ID.
425 * @param pCallback pointer to the callback function.
426 * @retval HAL status.
428 HAL_StatusTypeDef HAL_SWPMI_RegisterCallback(SWPMI_HandleTypeDef *hswpmi,
429 HAL_SWPMI_CallbackIDTypeDef CallbackID,
430 pSWPMI_CallbackTypeDef pCallback)
432 HAL_StatusTypeDef status = HAL_OK;
434 if(pCallback == NULL)
436 /* update the error code */
437 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_INVALID_CALLBACK;
438 /* update return status */
439 status = HAL_ERROR;
441 else
443 if(hswpmi->State == HAL_SWPMI_STATE_READY)
445 switch (CallbackID)
447 case HAL_SWPMI_RX_COMPLETE_CB_ID :
448 hswpmi->RxCpltCallback = pCallback;
449 break;
450 case HAL_SWPMI_RX_HALFCOMPLETE_CB_ID :
451 hswpmi->RxHalfCpltCallback = pCallback;
452 break;
453 case HAL_SWPMI_TX_COMPLETE_CB_ID :
454 hswpmi->TxCpltCallback = pCallback;
455 break;
456 case HAL_SWPMI_TX_HALFCOMPLETE_CB_ID :
457 hswpmi->TxHalfCpltCallback = pCallback;
458 break;
459 case HAL_SWPMI_ERROR_CB_ID :
460 hswpmi->ErrorCallback = pCallback;
461 break;
462 case HAL_SWPMI_MSPINIT_CB_ID :
463 hswpmi->MspInitCallback = pCallback;
464 break;
465 case HAL_SWPMI_MSPDEINIT_CB_ID :
466 hswpmi->MspDeInitCallback = pCallback;
467 break;
468 default :
469 /* update the error code */
470 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_INVALID_CALLBACK;
471 /* update return status */
472 status = HAL_ERROR;
473 break;
476 else if(hswpmi->State == HAL_SWPMI_STATE_RESET)
478 switch (CallbackID)
480 case HAL_SWPMI_MSPINIT_CB_ID :
481 hswpmi->MspInitCallback = pCallback;
482 break;
483 case HAL_SWPMI_MSPDEINIT_CB_ID :
484 hswpmi->MspDeInitCallback = pCallback;
485 break;
486 default :
487 /* update the error code */
488 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_INVALID_CALLBACK;
489 /* update return status */
490 status = HAL_ERROR;
491 break;
494 else
496 /* update the error code */
497 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_INVALID_CALLBACK;
498 /* update return status */
499 status = HAL_ERROR;
502 return status;
506 * @brief Unregister a user SWPMI callback.
507 * SWPMI callback is redirected to the weak predefined callback.
508 * @param hswpmi SWPMI handle.
509 * @param CallbackID ID of the callback to be unregistered.
510 * This parameter can be one of the following values:
511 * @arg @ref HAL_SWPMI_RX_COMPLETE_CB_ID receive complete callback ID.
512 * @arg @ref HAL_SWPMI_RX_HALFCOMPLETE_CB_ID receive half complete callback ID.
513 * @arg @ref HAL_SWPMI_TX_COMPLETE_CB_ID transmit complete callback ID.
514 * @arg @ref HAL_SWPMI_TX_HALFCOMPLETE_CB_ID transmit half complete callback ID.
515 * @arg @ref HAL_SWPMI_ERROR_CB_ID error callback ID.
516 * @arg @ref HAL_SWPMI_MSPINIT_CB_ID MSP init callback ID.
517 * @arg @ref HAL_SWPMI_MSPDEINIT_CB_ID MSP de-init callback ID.
518 * @retval HAL status.
520 HAL_StatusTypeDef HAL_SWPMI_UnRegisterCallback(SWPMI_HandleTypeDef *hswpmi,
521 HAL_SWPMI_CallbackIDTypeDef CallbackID)
523 HAL_StatusTypeDef status = HAL_OK;
525 if(hswpmi->State == HAL_SWPMI_STATE_READY)
527 switch (CallbackID)
529 case HAL_SWPMI_RX_COMPLETE_CB_ID :
530 hswpmi->RxCpltCallback = HAL_SWPMI_RxCpltCallback;
531 break;
532 case HAL_SWPMI_RX_HALFCOMPLETE_CB_ID :
533 hswpmi->RxHalfCpltCallback = HAL_SWPMI_RxHalfCpltCallback;
534 break;
535 case HAL_SWPMI_TX_COMPLETE_CB_ID :
536 hswpmi->TxCpltCallback = HAL_SWPMI_TxCpltCallback;
537 break;
538 case HAL_SWPMI_TX_HALFCOMPLETE_CB_ID :
539 hswpmi->TxHalfCpltCallback = HAL_SWPMI_TxHalfCpltCallback;
540 break;
541 case HAL_SWPMI_ERROR_CB_ID :
542 hswpmi->ErrorCallback = HAL_SWPMI_ErrorCallback;
543 break;
544 case HAL_SWPMI_MSPINIT_CB_ID :
545 hswpmi->MspInitCallback = HAL_SWPMI_MspInit;
546 break;
547 case HAL_SWPMI_MSPDEINIT_CB_ID :
548 hswpmi->MspDeInitCallback = HAL_SWPMI_MspDeInit;
549 break;
550 default :
551 /* update the error code */
552 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_INVALID_CALLBACK;
553 /* update return status */
554 status = HAL_ERROR;
555 break;
558 else if(hswpmi->State == HAL_SWPMI_STATE_RESET)
560 switch (CallbackID)
562 case HAL_SWPMI_MSPINIT_CB_ID :
563 hswpmi->MspInitCallback = HAL_SWPMI_MspInit;
564 break;
565 case HAL_SWPMI_MSPDEINIT_CB_ID :
566 hswpmi->MspDeInitCallback = HAL_SWPMI_MspDeInit;
567 break;
568 default :
569 /* update the error code */
570 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_INVALID_CALLBACK;
571 /* update return status */
572 status = HAL_ERROR;
573 break;
576 else
578 /* update the error code */
579 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_INVALID_CALLBACK;
580 /* update return status */
581 status = HAL_ERROR;
583 return status;
585 #endif /* USE_HAL_SWPMI_REGISTER_CALLBACKS */
588 * @}
591 /** @defgroup SWPMI_Exported_Group2 IO operation methods
592 * @brief SWPMI Transmit/Receive functions
594 @verbatim
595 ===============================================================================
596 ##### IO operation methods #####
597 ===============================================================================
598 [..]
599 This subsection provides a set of functions allowing to manage the SWPMI
600 data transfers.
602 (#) There are two modes of transfer:
603 (++) Blocking mode: The communication is performed in polling mode.
604 The HAL status of all data processing is returned by the same function
605 after finishing transfer.
606 (++) Non-Blocking mode: The communication is performed using Interrupts
607 or DMA. The end of the data processing will be indicated through the
608 dedicated SWPMI Interrupt handler (HAL_SWPMI_IRQHandler()) when using Interrupt mode or
609 the selected DMA stream interrupt handler when using DMA mode.
610 The HAL_SWPMI_TxCpltCallback(), HAL_SWPMI_RxCpltCallback() user callbacks
611 will be executed respectively at the end of the transmit or receive process.
612 The HAL_SWPMI_ErrorCallback() user callback will be executed when a communication error is detected.
614 (#) Blocking mode API's are:
615 (++) HAL_SWPMI_Transmit()
616 (++) HAL_SWPMI_Receive()
618 (#) Non-Blocking mode API's with Interrupt are:
619 (++) HAL_SWPMI_Transmit_IT()
620 (++) HAL_SWPMI_Receive_IT()
621 (++) HAL_SWPMI_IRQHandler()
623 (#) Non-Blocking mode API's with DMA are:
624 (++) HAL_SWPMI_Transmit_DMA()
625 (++) HAL_SWPMI_Receive_DMA()
626 (++) HAL_SWPMI_DMAPause()
627 (++) HAL_SWPMI_DMAResume()
628 (++) HAL_SWPMI_DMAStop()
630 (#) A set of Transfer Complete Callbacks are provided in Non-Blocking mode:
631 (++) HAL_SWPMI_TxHalfCpltCallback()
632 (++) HAL_SWPMI_TxCpltCallback()
633 (++) HAL_SWPMI_RxHalfCpltCallback()
634 (++) HAL_SWPMI_RxCpltCallback()
635 (++) HAL_SWPMI_ErrorCallback()
637 (#) The capability to launch the above IO operations in loopback mode for
638 user application verification:
639 (++) HAL_SWPMI_EnableLoopback()
640 (++) HAL_SWPMI_DisableLoopback()
642 @endverbatim
643 * @{
647 * @brief Transmit an amount of data in blocking mode.
648 * @param hswpmi pointer to a SWPMI_HandleTypeDef structure that contains
649 * the configuration information for SWPMI module.
650 * @param pData Pointer to data buffer
651 * @param Size Amount of data to be sent
652 * @param Timeout Timeout duration
653 * @retval HAL status
655 HAL_StatusTypeDef HAL_SWPMI_Transmit(SWPMI_HandleTypeDef *hswpmi, uint32_t* pData, uint16_t Size, uint32_t Timeout)
657 uint32_t tickstart = HAL_GetTick();
658 HAL_StatusTypeDef status = HAL_OK;
659 HAL_SWPMI_StateTypeDef tmp_state;
660 uint32_t *ptmp_data;
661 uint32_t tmp_size;
663 if((pData == NULL ) || (Size == 0U))
665 status = HAL_ERROR;
667 else
669 /* Process Locked */
670 __HAL_LOCK(hswpmi);
672 tmp_state = hswpmi->State;
673 if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_RX))
675 /* Check if a non-blocking receive process is ongoing or not */
676 if(tmp_state == HAL_SWPMI_STATE_READY)
678 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
680 /* Disable any transmitter interrupts */
681 __HAL_SWPMI_DISABLE_IT(hswpmi, SWPMI_IT_TCIE | SWPMI_IT_TIE | SWPMI_IT_TXUNRIE | SWPMI_IT_TXBEIE);
683 /* Disable any transmitter flags */
684 __HAL_SWPMI_CLEAR_FLAG(hswpmi, SWPMI_FLAG_TXBEF | SWPMI_FLAG_TXUNRF | SWPMI_FLAG_TCF);
686 /* Enable SWPMI peripheral if not */
687 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
689 else
691 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
694 ptmp_data = pData;
695 tmp_size = Size;
698 /* Wait the TXE to write data */
699 if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_TXE))
701 hswpmi->Instance->TDR = *ptmp_data;
702 ptmp_data++;
703 tmp_size--;
705 else
707 /* Check for the Timeout */
708 if(Timeout != HAL_MAX_DELAY)
710 if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
712 status = HAL_TIMEOUT;
713 break;
717 } while(tmp_size != 0U);
719 /* Wait on TXBEF flag to be able to start a second transfer */
720 if(SWPMI_WaitOnFlagSetUntilTimeout(hswpmi, SWPMI_FLAG_TXBEF, tickstart, Timeout) != HAL_OK)
722 /* Timeout occurred */
723 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_TXBEF_TIMEOUT;
725 status = HAL_TIMEOUT;
728 if(status == HAL_OK)
730 /* Check if a non-blocking receive Process is ongoing or not */
731 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
733 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
735 else
737 hswpmi->State = HAL_SWPMI_STATE_READY;
741 else
743 status = HAL_BUSY;
747 if((status != HAL_OK) && (status != HAL_BUSY))
749 hswpmi->State = HAL_SWPMI_STATE_READY;
751 /* Process Unlocked */
752 __HAL_UNLOCK(hswpmi);
754 return status;
758 * @brief Receive an amount of data in blocking mode.
759 * @param hswpmi pointer to a SWPMI_HandleTypeDef structure that contains
760 * the configuration information for SWPMI module.
761 * @param pData Pointer to data buffer
762 * @param Size Amount of data to be received
763 * @param Timeout Timeout duration
764 * @retval HAL status
766 HAL_StatusTypeDef HAL_SWPMI_Receive(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size, uint32_t Timeout)
768 uint32_t tickstart = HAL_GetTick();
769 HAL_StatusTypeDef status = HAL_OK;
770 HAL_SWPMI_StateTypeDef tmp_state;
771 uint32_t *ptmp_data;
772 uint32_t tmp_size;
774 if((pData == NULL ) || (Size == 0U))
776 status = HAL_ERROR;
778 else
780 /* Process Locked */
781 __HAL_LOCK(hswpmi);
783 tmp_state = hswpmi->State;
784 if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX))
786 /* Check if a non-blocking transmit process is ongoing or not */
787 if(tmp_state == HAL_SWPMI_STATE_READY)
789 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
791 /* Disable any receiver interrupts */
792 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_SRIE | SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
794 /* Enable SWPMI peripheral if not */
795 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
797 else
799 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
802 ptmp_data = pData;
803 tmp_size = Size;
806 /* Wait the RXNE to read data */
807 if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_RXNE))
809 *ptmp_data = hswpmi->Instance->RDR;
810 ptmp_data++;
811 tmp_size--;
813 else
815 /* Check for the Timeout */
816 if(Timeout != HAL_MAX_DELAY)
818 if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
820 status = HAL_TIMEOUT;
821 break;
825 } while(tmp_size != 0U);
827 if(status == HAL_OK)
829 if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_RXBFF))
831 /* Clear RXBFF at end of reception */
832 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXBFF);
835 /* Check if a non-blocking transmit Process is ongoing or not */
836 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
838 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
840 else
842 hswpmi->State = HAL_SWPMI_STATE_READY;
846 else
848 status = HAL_BUSY;
852 if((status != HAL_OK) && (status != HAL_BUSY))
854 hswpmi->State = HAL_SWPMI_STATE_READY;
856 /* Process Unlocked */
857 __HAL_UNLOCK(hswpmi);
859 return status;
863 * @brief Transmit an amount of data in non-blocking mode with interrupt.
864 * @param hswpmi pointer to a SWPMI_HandleTypeDef structure that contains
865 * the configuration information for SWPMI module.
866 * @param pData Pointer to data buffer
867 * @param Size Amount of data to be sent
868 * @retval HAL status
870 HAL_StatusTypeDef HAL_SWPMI_Transmit_IT(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
872 HAL_StatusTypeDef status = HAL_OK;
873 HAL_SWPMI_StateTypeDef tmp_state;
875 if((pData == NULL ) || (Size == 0U))
877 status = HAL_ERROR;
879 else
881 /* Process Locked */
882 __HAL_LOCK(hswpmi);
884 tmp_state = hswpmi->State;
885 if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_RX))
887 /* Update handle */
888 hswpmi->pTxBuffPtr = pData;
889 hswpmi->TxXferSize = Size;
890 hswpmi->TxXferCount = Size;
891 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
893 /* Check if a receive process is ongoing or not */
894 if(tmp_state == HAL_SWPMI_STATE_READY)
896 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
898 /* Enable SWPMI peripheral if not */
899 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
901 else
903 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
906 /* Enable the SWPMI transmit underrun error */
907 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TXUNRIE);
909 /* Process Unlocked */
910 __HAL_UNLOCK(hswpmi);
912 /* Enable the SWPMI interrupts: */
913 /* - Transmit data register empty */
914 /* - Transmit buffer empty */
915 /* - Transmit/Reception completion */
916 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TIE | SWPMI_IT_TXBEIE | SWPMI_IT_TCIE);
918 else
920 status = HAL_BUSY;
922 /* Process Unlocked */
923 __HAL_UNLOCK(hswpmi);
927 return status;
931 * @brief Receive an amount of data in non-blocking mode with interrupt.
932 * @param hswpmi SWPMI handle
933 * @param pData Pointer to data buffer
934 * @param Size Amount of data to be received
935 * @retval HAL status
937 HAL_StatusTypeDef HAL_SWPMI_Receive_IT(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
939 HAL_StatusTypeDef status = HAL_OK;
940 HAL_SWPMI_StateTypeDef tmp_state;
942 if((pData == NULL ) || (Size == 0U))
944 status = HAL_ERROR;
946 else
948 /* Process Locked */
949 __HAL_LOCK(hswpmi);
951 tmp_state = hswpmi->State;
952 if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX))
954 /* Update handle */
955 hswpmi->pRxBuffPtr = pData;
956 hswpmi->RxXferSize = Size;
957 hswpmi->RxXferCount = Size;
958 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
960 /* Check if a transmit process is ongoing or not */
961 if(tmp_state == HAL_SWPMI_STATE_READY)
963 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
965 /* Enable SWPMI peripheral if not */
966 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
968 else
970 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
973 /* Process Unlocked */
974 __HAL_UNLOCK(hswpmi);
976 /* Enable the SWPMI slave resume */
977 /* Enable the SWPMI Data Register not empty Interrupt, receive CRC Error, receive overrun and RxBuf Interrupt */
978 /* Enable the SWPMI Transmit/Reception completion */
979 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
981 else
983 status = HAL_BUSY;
985 /* Process Unlocked */
986 __HAL_UNLOCK(hswpmi);
990 return status;
994 * @brief Transmit an amount of data in non-blocking mode with DMA interrupt.
995 * @param hswpmi SWPMI handle
996 * @param pData Pointer to data buffer
997 * @param Size Amount of data to be sent
998 * @retval HAL status
1000 HAL_StatusTypeDef HAL_SWPMI_Transmit_DMA(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
1002 HAL_StatusTypeDef status = HAL_OK;
1003 HAL_SWPMI_StateTypeDef tmp_state;
1005 if((pData == NULL ) || (Size == 0U))
1007 status = HAL_ERROR;
1009 else
1011 /* Process Locked */
1012 __HAL_LOCK(hswpmi);
1014 tmp_state = hswpmi->State;
1015 if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_RX))
1017 /* Update handle */
1018 hswpmi->pTxBuffPtr = pData;
1019 hswpmi->TxXferSize = Size;
1020 hswpmi->TxXferCount = Size;
1021 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
1023 /* Check if a receive process is ongoing or not */
1024 if(tmp_state == HAL_SWPMI_STATE_READY)
1026 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
1028 /* Enable SWPMI peripheral if not */
1029 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1031 else
1033 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
1036 /* Set the SWPMI DMA transfer complete callback */
1037 hswpmi->hdmatx->XferCpltCallback = SWPMI_DMATransmitCplt;
1039 /* Set the SWPMI DMA Half transfer complete callback */
1040 hswpmi->hdmatx->XferHalfCpltCallback = SWPMI_DMATxHalfCplt;
1042 /* Set the DMA error callback */
1043 hswpmi->hdmatx->XferErrorCallback = SWPMI_DMAError;
1045 /* Enable the SWPMI transmit DMA stream */
1046 if(HAL_DMA_Start_IT(hswpmi->hdmatx, (uint32_t)hswpmi->pTxBuffPtr, (uint32_t)&hswpmi->Instance->TDR, Size) != HAL_OK)
1048 hswpmi->State = tmp_state; /* Back to previous state */
1049 hswpmi->ErrorCode = HAL_SWPMI_ERROR_DMA;
1050 status = HAL_ERROR;
1052 /* Process Unlocked */
1053 __HAL_UNLOCK(hswpmi);
1055 else
1057 /* Process Unlocked */
1058 __HAL_UNLOCK(hswpmi);
1060 /* Enable the SWPMI transmit underrun error */
1061 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TXUNRIE);
1063 /* Enable the DMA transfer for transmit request by setting the TXDMA bit
1064 in the SWPMI CR register */
1065 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_TXDMA);
1068 else
1070 status = HAL_BUSY;
1072 /* Process Unlocked */
1073 __HAL_UNLOCK(hswpmi);
1077 return status;
1081 * @brief Receive an amount of data in non-blocking mode with DMA interrupt.
1082 * @param hswpmi SWPMI handle
1083 * @param pData Pointer to data buffer
1084 * @param Size Amount of data to be received
1085 * @retval HAL status
1087 HAL_StatusTypeDef HAL_SWPMI_Receive_DMA(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
1089 HAL_StatusTypeDef status = HAL_OK;
1090 HAL_SWPMI_StateTypeDef tmp_state;
1092 if((pData == NULL ) || (Size == 0U))
1094 status = HAL_ERROR;
1096 else
1098 /* Process Locked */
1099 __HAL_LOCK(hswpmi);
1101 tmp_state = hswpmi->State;
1102 if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX))
1104 /* Update handle */
1105 hswpmi->pRxBuffPtr = pData;
1106 hswpmi->RxXferSize = Size;
1107 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
1109 /* Check if a transmit process is ongoing or not */
1110 if(tmp_state == HAL_SWPMI_STATE_READY)
1112 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
1114 /* Enable SWPMI peripheral if not */
1115 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1117 else
1119 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
1122 /* Set the SWPMI DMA transfer complete callback */
1123 hswpmi->hdmarx->XferCpltCallback = SWPMI_DMAReceiveCplt;
1125 /* Set the SWPMI DMA Half transfer complete callback */
1126 hswpmi->hdmarx->XferHalfCpltCallback = SWPMI_DMARxHalfCplt;
1128 /* Set the DMA error callback */
1129 hswpmi->hdmarx->XferErrorCallback = SWPMI_DMAError;
1131 /* Enable the DMA request */
1132 if(HAL_DMA_Start_IT(hswpmi->hdmarx, (uint32_t)&hswpmi->Instance->RDR, (uint32_t)hswpmi->pRxBuffPtr, Size) != HAL_OK)
1134 hswpmi->State = tmp_state; /* Back to previous state */
1135 hswpmi->ErrorCode = HAL_SWPMI_ERROR_DMA;
1136 status = HAL_ERROR;
1138 /* Process Unlocked */
1139 __HAL_UNLOCK(hswpmi);
1141 else
1143 /* Process Unlocked */
1144 __HAL_UNLOCK(hswpmi);
1146 /* Enable the SWPMI receive CRC Error and receive overrun interrupts */
1147 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE);
1149 /* Enable the DMA transfer for the receiver request by setting the RXDMA bit
1150 in the SWPMI CR register */
1151 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_RXDMA);
1154 else
1156 status = HAL_BUSY;
1158 /* Process Unlocked */
1159 __HAL_UNLOCK(hswpmi);
1163 return status;
1167 * @brief Stop all DMA transfers.
1168 * @param hswpmi SWPMI handle
1169 * @retval HAL status
1171 HAL_StatusTypeDef HAL_SWPMI_DMAStop(SWPMI_HandleTypeDef *hswpmi)
1173 HAL_StatusTypeDef status = HAL_OK;
1175 /* Process Locked */
1176 __HAL_LOCK(hswpmi);
1178 /* Disable the SWPMI Tx/Rx DMA requests */
1179 CLEAR_BIT(hswpmi->Instance->CR, (SWPMI_CR_TXDMA | SWPMI_CR_RXDMA));
1181 /* Abort the SWPMI DMA tx stream */
1182 if(hswpmi->hdmatx != NULL)
1184 if(HAL_DMA_Abort(hswpmi->hdmatx) != HAL_OK)
1186 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_DMA;
1187 status = HAL_ERROR;
1190 /* Abort the SWPMI DMA rx stream */
1191 if(hswpmi->hdmarx != NULL)
1193 if(HAL_DMA_Abort(hswpmi->hdmarx) != HAL_OK)
1195 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_DMA;
1196 status = HAL_ERROR;
1200 /* Disable SWPMI interface */
1201 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1203 hswpmi->State = HAL_SWPMI_STATE_READY;
1205 /* Process Unlocked */
1206 __HAL_UNLOCK(hswpmi);
1208 return status;
1213 * @brief Enable the Loopback mode.
1214 * @param hswpmi SWPMI handle
1215 * @note Loopback mode is to be used only for test purposes
1216 * @retval HAL_OK / HAL_BUSY
1218 HAL_StatusTypeDef HAL_SWPMI_EnableLoopback(SWPMI_HandleTypeDef *hswpmi)
1220 HAL_StatusTypeDef status = HAL_OK;
1222 /* Process Locked */
1223 __HAL_LOCK(hswpmi);
1225 /* Make sure the SWPMI interface is not enabled to set the loopback mode */
1226 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1228 /* Set Loopback */
1229 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_LPBK);
1231 /* Enable SWPMI interface in loopback mode */
1232 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1234 /* Process Unlocked */
1235 __HAL_UNLOCK(hswpmi);
1237 return status;
1241 * @brief Disable the Loopback mode.
1242 * @param hswpmi SWPMI handle
1243 * @note Loopback mode is to be used only for test purposes
1244 * @retval HAL_OK / HAL_BUSY
1246 HAL_StatusTypeDef HAL_SWPMI_DisableLoopback(SWPMI_HandleTypeDef *hswpmi)
1248 HAL_StatusTypeDef status = HAL_OK;
1250 /* Process Locked */
1251 __HAL_LOCK(hswpmi);
1253 /* Make sure the SWPMI interface is not enabled to reset the loopback mode */
1254 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1256 /* Reset Loopback */
1257 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_LPBK);
1259 /* Re-enable SWPMI interface in normal mode */
1260 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1262 /* Process Unlocked */
1263 __HAL_UNLOCK(hswpmi);
1265 return status;
1269 * @}
1272 /** @defgroup SWPMI_Exported_Group3 SWPMI IRQ handler and callbacks
1273 * @brief SWPMI IRQ handler.
1275 @verbatim
1276 ==============================================================================
1277 ##### SWPMI IRQ handler and callbacks #####
1278 ==============================================================================
1279 [..] This section provides SWPMI IRQ handler and callback functions called within
1280 the IRQ handler.
1282 @endverbatim
1283 * @{
1287 * @brief Handle SWPMI interrupt request.
1288 * @param hswpmi SWPMI handle
1289 * @retval None
1291 void HAL_SWPMI_IRQHandler(SWPMI_HandleTypeDef *hswpmi)
1293 uint32_t regisr = READ_REG(hswpmi->Instance->ISR);
1294 uint32_t regier = READ_REG(hswpmi->Instance->IER);
1295 uint32_t errcode = HAL_SWPMI_ERROR_NONE;
1297 /* SWPMI CRC error interrupt occurred --------------------------------------*/
1298 if(((regisr & SWPMI_FLAG_RXBERF) != 0U) && ((regier & SWPMI_IT_RXBERIE) != 0U))
1300 /* Disable Receive CRC interrupt */
1301 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_RXBERIE | SWPMI_IT_RXBFIE);
1302 /* Clear Receive CRC and Receive buffer full flag */
1303 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXBERF | SWPMI_FLAG_RXBFF);
1305 errcode |= HAL_SWPMI_ERROR_CRC;
1308 /* SWPMI Over-Run interrupt occurred -----------------------------------------*/
1309 if(((regisr & SWPMI_FLAG_RXOVRF) != 0U) && ((regier & SWPMI_IT_RXOVRIE) != 0U))
1311 /* Disable Receive overrun interrupt */
1312 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_RXOVRIE);
1313 /* Clear Receive overrun flag */
1314 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXOVRF);
1316 errcode |= HAL_SWPMI_ERROR_OVR;
1319 /* SWPMI Under-Run interrupt occurred -----------------------------------------*/
1320 if(((regisr & SWPMI_FLAG_TXUNRF) != 0U) && ((regier & SWPMI_IT_TXUNRIE) != 0U))
1322 /* Disable Transmit under run interrupt */
1323 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_TXUNRIE);
1324 /* Clear Transmit under run flag */
1325 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_TXUNRF);
1327 errcode |= HAL_SWPMI_ERROR_UDR;
1330 /* Call SWPMI Error Call back function if needed --------------------------*/
1331 if(errcode != HAL_SWPMI_ERROR_NONE)
1333 hswpmi->ErrorCode |= errcode;
1335 if((errcode & HAL_SWPMI_ERROR_UDR) != 0U)
1337 /* Check TXDMA transfer to abort */
1338 if(HAL_IS_BIT_SET(hswpmi->Instance->CR, SWPMI_CR_TXDMA))
1340 /* Disable DMA TX at SWPMI level */
1341 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_TXDMA);
1343 /* Abort the USART DMA Tx stream */
1344 if(hswpmi->hdmatx != NULL)
1346 /* Set the SWPMI Tx DMA Abort callback :
1347 will lead to call HAL_SWPMI_ErrorCallback() at end of DMA abort procedure */
1348 hswpmi->hdmatx->XferAbortCallback = SWPMI_DMAAbortOnError;
1349 /* Abort DMA TX */
1350 if(HAL_DMA_Abort_IT(hswpmi->hdmatx) != HAL_OK)
1352 /* Call Directly hswpmi->hdmatx->XferAbortCallback function in case of error */
1353 hswpmi->hdmatx->XferAbortCallback(hswpmi->hdmatx);
1356 else
1358 /* Set the SWPMI state ready to be able to start again the process */
1359 hswpmi->State = HAL_SWPMI_STATE_READY;
1361 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1362 hswpmi->ErrorCallback(hswpmi);
1363 #else
1364 HAL_SWPMI_ErrorCallback(hswpmi);
1365 #endif
1368 else
1370 /* Set the SWPMI state ready to be able to start again the process */
1371 hswpmi->State = HAL_SWPMI_STATE_READY;
1373 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1374 hswpmi->ErrorCallback(hswpmi);
1375 #else
1376 HAL_SWPMI_ErrorCallback(hswpmi);
1377 #endif
1380 else
1382 /* Check RXDMA transfer to abort */
1383 if(HAL_IS_BIT_SET(hswpmi->Instance->CR, SWPMI_CR_RXDMA))
1385 /* Disable DMA RX at SWPMI level */
1386 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_RXDMA);
1388 /* Abort the USART DMA Rx stream */
1389 if(hswpmi->hdmarx != NULL)
1391 /* Set the SWPMI Rx DMA Abort callback :
1392 will lead to call HAL_SWPMI_ErrorCallback() at end of DMA abort procedure */
1393 hswpmi->hdmarx->XferAbortCallback = SWPMI_DMAAbortOnError;
1394 /* Abort DMA RX */
1395 if(HAL_DMA_Abort_IT(hswpmi->hdmarx) != HAL_OK)
1397 /* Call Directly hswpmi->hdmarx->XferAbortCallback function in case of error */
1398 hswpmi->hdmarx->XferAbortCallback(hswpmi->hdmarx);
1401 else
1403 /* Set the SWPMI state ready to be able to start again the process */
1404 hswpmi->State = HAL_SWPMI_STATE_READY;
1406 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1407 hswpmi->ErrorCallback(hswpmi);
1408 #else
1409 HAL_SWPMI_ErrorCallback(hswpmi);
1410 #endif
1413 else
1415 /* Set the SWPMI state ready to be able to start again the process */
1416 hswpmi->State = HAL_SWPMI_STATE_READY;
1418 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1419 hswpmi->ErrorCallback(hswpmi);
1420 #else
1421 HAL_SWPMI_ErrorCallback(hswpmi);
1422 #endif
1427 /* SWPMI in mode Receiver ---------------------------------------------------*/
1428 if(((regisr & SWPMI_FLAG_RXNE) != 0U) && ((regier & SWPMI_IT_RIE) != 0U))
1430 SWPMI_Receive_IT(hswpmi);
1433 /* SWPMI in mode Transmitter ------------------------------------------------*/
1434 if(((regisr & SWPMI_FLAG_TXE) != 0U) && ((regier & SWPMI_IT_TIE) != 0U))
1436 SWPMI_Transmit_IT(hswpmi);
1439 /* SWPMI in mode Transmitter (Transmit buffer empty) ------------------------*/
1440 if(((regisr & SWPMI_FLAG_TXBEF) != 0U) && ((regier & SWPMI_IT_TXBEIE) != 0U))
1442 SWPMI_EndTransmit_IT(hswpmi);
1445 /* SWPMI in mode Receiver (Receive buffer full) -----------------------------*/
1446 if(((regisr & SWPMI_FLAG_RXBFF) != 0U) && ((regier & SWPMI_IT_RXBFIE) != 0U))
1448 SWPMI_EndReceive_IT(hswpmi);
1451 /* Both Transmission and reception complete ---------------------------------*/
1452 if(((regisr & SWPMI_FLAG_TCF) != 0U) && ((regier & SWPMI_IT_TCIE) != 0U))
1454 SWPMI_EndTransmitReceive_IT(hswpmi);
1459 * @brief Tx Transfer completed callback.
1460 * @param hswpmi SWPMI handle
1461 * @retval None
1463 __weak void HAL_SWPMI_TxCpltCallback(SWPMI_HandleTypeDef *hswpmi)
1465 /* Prevent unused argument(s) compilation warning */
1466 UNUSED(hswpmi);
1468 /* NOTE : This function should not be modified, when the callback is needed,
1469 the HAL_SWPMI_TxCpltCallback is to be implemented in the user file
1474 * @brief Tx Half Transfer completed callback.
1475 * @param hswpmi SWPMI handle
1476 * @retval None
1478 __weak void HAL_SWPMI_TxHalfCpltCallback(SWPMI_HandleTypeDef *hswpmi)
1480 /* Prevent unused argument(s) compilation warning */
1481 UNUSED(hswpmi);
1483 /* NOTE: This function should not be modified, when the callback is needed,
1484 the HAL_SWPMI_TxHalfCpltCallback is to be implemented in the user file
1489 * @brief Rx Transfer completed callback.
1490 * @param hswpmi SWPMI handle
1491 * @retval None
1493 __weak void HAL_SWPMI_RxCpltCallback(SWPMI_HandleTypeDef *hswpmi)
1495 /* Prevent unused argument(s) compilation warning */
1496 UNUSED(hswpmi);
1498 /* NOTE : This function should not be modified, when the callback is needed,
1499 the HAL_SWPMI_RxCpltCallback is to be implemented in the user file
1504 * @brief Rx Half Transfer completed callback.
1505 * @param hswpmi SWPMI handle
1506 * @retval None
1508 __weak void HAL_SWPMI_RxHalfCpltCallback(SWPMI_HandleTypeDef *hswpmi)
1510 /* Prevent unused argument(s) compilation warning */
1511 UNUSED(hswpmi);
1513 /* NOTE: This function should not be modified, when the callback is needed,
1514 the HAL_SWPMI_RxHalfCpltCallback is to be implemented in the user file
1519 * @brief SWPMI error callback.
1520 * @param hswpmi SWPMI handle
1521 * @retval None
1523 __weak void HAL_SWPMI_ErrorCallback(SWPMI_HandleTypeDef *hswpmi)
1525 /* Prevent unused argument(s) compilation warning */
1526 UNUSED(hswpmi);
1528 /* NOTE : This function should not be modified, when the callback is needed,
1529 the HAL_SWPMI_ErrorCallback is to be implemented in the user file
1534 * @}
1537 /** @defgroup SWPMI_Exported_Group4 Peripheral Control methods
1538 * @brief SWPMI control functions
1540 @verbatim
1541 ===============================================================================
1542 ##### Peripheral Control methods #####
1543 ===============================================================================
1544 [..]
1545 This subsection provides a set of functions allowing to control the SWPMI.
1546 (+) HAL_SWPMI_GetState() API is helpful to check in run-time the state of the SWPMI peripheral
1547 (+) HAL_SWPMI_GetError() API is helpful to check in run-time the error state of the SWPMI peripheral
1548 @endverbatim
1549 * @{
1553 * @brief Return the SWPMI handle state.
1554 * @param hswpmi SWPMI handle
1555 * @retval HAL state
1557 HAL_SWPMI_StateTypeDef HAL_SWPMI_GetState(SWPMI_HandleTypeDef *hswpmi)
1559 /* Return SWPMI handle state */
1560 return hswpmi->State;
1564 * @brief Return the SWPMI error code.
1565 * @param hswpmi : pointer to a SWPMI_HandleTypeDef structure that contains
1566 * the configuration information for the specified SWPMI.
1567 * @retval SWPMI Error Code
1569 uint32_t HAL_SWPMI_GetError(SWPMI_HandleTypeDef *hswpmi)
1571 return hswpmi->ErrorCode;
1575 * @}
1579 * @}
1582 /* Private functions ---------------------------------------------------------*/
1584 /** @defgroup SWPMI_Private_Functions SWPMI Private Functions
1585 * @{
1589 * @brief Transmit an amount of data in interrupt mode.
1590 * @note Function called under interruption only, once interruptions have been enabled by HAL_SWPMI_Transmit_IT()
1591 * @param hswpmi SWPMI handle
1592 * @retval None
1594 static void SWPMI_Transmit_IT(SWPMI_HandleTypeDef *hswpmi)
1596 HAL_SWPMI_StateTypeDef tmp_state = hswpmi->State;
1598 if ((tmp_state == HAL_SWPMI_STATE_BUSY_TX) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX_RX))
1600 if(hswpmi->TxXferCount == 0U)
1602 /* Disable the SWPMI TXE and Underrun Interrupts */
1603 CLEAR_BIT(hswpmi->Instance->IER, (SWPMI_IT_TIE | SWPMI_IT_TXUNRIE));
1605 else
1607 hswpmi->Instance->TDR = (uint32_t)*hswpmi->pTxBuffPtr;
1608 hswpmi->pTxBuffPtr++;
1609 hswpmi->TxXferCount--;
1612 else
1614 /* nothing to do */
1619 * @brief Wraps up transmission in non-blocking mode.
1620 * @param hswpmi SWPMI handle
1621 * @retval None
1623 static void SWPMI_EndTransmit_IT(SWPMI_HandleTypeDef *hswpmi)
1625 /* Clear the SWPMI Transmit buffer empty Flag */
1626 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_TXBEF);
1627 /* Disable the all SWPMI Transmit Interrupts */
1628 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_TIE | SWPMI_IT_TXUNRIE | SWPMI_IT_TXBEIE);
1630 /* Check if a receive Process is ongoing or not */
1631 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
1633 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
1635 else
1637 hswpmi->State = HAL_SWPMI_STATE_READY;
1640 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1641 hswpmi->TxCpltCallback(hswpmi);
1642 #else
1643 HAL_SWPMI_TxCpltCallback(hswpmi);
1644 #endif
1648 * @brief Receive an amount of data in interrupt mode.
1649 * @note Function called under interruption only, once interruptions have been enabled by HAL_SWPMI_Receive_IT()
1650 * @param hswpmi SWPMI handle
1651 * @retval None
1653 static void SWPMI_Receive_IT(SWPMI_HandleTypeDef *hswpmi)
1655 HAL_SWPMI_StateTypeDef tmp_state = hswpmi->State;
1657 if((tmp_state == HAL_SWPMI_STATE_BUSY_RX) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX_RX))
1659 *hswpmi->pRxBuffPtr = (uint32_t)(hswpmi->Instance->RDR);
1660 hswpmi->pRxBuffPtr++;
1662 --hswpmi->RxXferCount;
1663 if(hswpmi->RxXferCount == 0U)
1665 /* Wait for RXBFF flag to update state */
1666 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1667 hswpmi->RxCpltCallback(hswpmi);
1668 #else
1669 HAL_SWPMI_RxCpltCallback(hswpmi);
1670 #endif
1673 else
1675 /* nothing to do */
1680 * @brief Wraps up reception in non-blocking mode.
1681 * @param hswpmi SWPMI handle
1682 * @retval None
1684 static void SWPMI_EndReceive_IT(SWPMI_HandleTypeDef *hswpmi)
1686 /* Clear the SWPMI Receive buffer full Flag */
1687 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXBFF);
1688 /* Disable the all SWPMI Receive Interrupts */
1689 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
1691 /* Check if a transmit Process is ongoing or not */
1692 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
1694 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
1696 else
1698 hswpmi->State = HAL_SWPMI_STATE_READY;
1703 * @brief Wraps up transmission and reception in non-blocking mode.
1704 * @param hswpmi SWPMI handle
1705 * @retval None
1707 static void SWPMI_EndTransmitReceive_IT(SWPMI_HandleTypeDef *hswpmi)
1709 /* Clear the SWPMI Transmission Complete Flag */
1710 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_TCF);
1711 /* Disable the SWPMI Transmission Complete Interrupt */
1712 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_TCIE);
1714 /* Check if a receive Process is ongoing or not */
1715 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
1717 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
1719 else if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX)
1721 hswpmi->State = HAL_SWPMI_STATE_READY;
1723 else
1725 /* nothing to do */
1730 * @brief DMA SWPMI transmit process complete callback.
1731 * @param hdma DMA handle
1732 * @retval None
1734 static void SWPMI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
1736 SWPMI_HandleTypeDef* hswpmi = ( SWPMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1737 uint32_t tickstart;
1739 /* DMA Normal mode*/
1740 if(((((DMA_Stream_TypeDef *)hdma->Instance)->CR) & DMA_SxCR_CIRC) == 0U)
1742 hswpmi->TxXferCount = 0U;
1744 /* Disable the DMA transfer for transmit request by setting the TXDMA bit
1745 in the SWPMI CR register */
1746 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_TXDMA);
1748 /* Init tickstart for timeout managment*/
1749 tickstart = HAL_GetTick();
1751 /* Wait the TXBEF */
1752 if(SWPMI_WaitOnFlagSetUntilTimeout(hswpmi, SWPMI_FLAG_TXBEF, tickstart, SWPMI_TIMEOUT_VALUE) != HAL_OK)
1754 /* Timeout occurred */
1755 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_TXBEF_TIMEOUT;
1757 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1758 hswpmi->ErrorCallback(hswpmi);
1759 #else
1760 HAL_SWPMI_ErrorCallback(hswpmi);
1761 #endif
1763 else
1765 /* No Timeout */
1766 /* Check if a receive process is ongoing or not */
1767 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
1769 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
1771 else
1773 hswpmi->State = HAL_SWPMI_STATE_READY;
1776 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1777 hswpmi->TxCpltCallback(hswpmi);
1778 #else
1779 HAL_SWPMI_TxCpltCallback(hswpmi);
1780 #endif
1783 /* DMA Circular mode */
1784 else
1786 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1787 hswpmi->TxCpltCallback(hswpmi);
1788 #else
1789 HAL_SWPMI_TxCpltCallback(hswpmi);
1790 #endif
1795 * @brief DMA SWPMI transmit process half complete callback.
1796 * @param hdma DMA handle
1797 * @retval None
1799 static void SWPMI_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
1801 SWPMI_HandleTypeDef* hswpmi = (SWPMI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
1803 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1804 hswpmi->TxHalfCpltCallback(hswpmi);
1805 #else
1806 HAL_SWPMI_TxHalfCpltCallback(hswpmi);
1807 #endif
1812 * @brief DMA SWPMI receive process complete callback.
1813 * @param hdma DMA handle
1814 * @retval None
1816 static void SWPMI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1818 SWPMI_HandleTypeDef* hswpmi = ( SWPMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1820 /* DMA Normal mode*/
1821 if(((((DMA_Stream_TypeDef *)hdma->Instance)->CR) & DMA_SxCR_CIRC) == 0U)
1823 hswpmi->RxXferCount = 0U;
1825 /* Disable the DMA transfer for the receiver request by setting the RXDMA bit
1826 in the SWPMI CR register */
1827 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_RXDMA);
1829 /* Check if a transmit Process is ongoing or not */
1830 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
1832 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
1834 else
1836 hswpmi->State = HAL_SWPMI_STATE_READY;
1839 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1840 hswpmi->RxCpltCallback(hswpmi);
1841 #else
1842 HAL_SWPMI_RxCpltCallback(hswpmi);
1843 #endif
1847 * @brief DMA SWPMI receive process half complete callback.
1848 * @param hdma DMA handle
1849 * @retval None
1851 static void SWPMI_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
1853 SWPMI_HandleTypeDef* hswpmi = (SWPMI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
1855 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1856 hswpmi->RxHalfCpltCallback(hswpmi);
1857 #else
1858 HAL_SWPMI_RxHalfCpltCallback(hswpmi);
1859 #endif
1863 * @brief DMA SWPMI communication error callback.
1864 * @param hdma DMA handle
1865 * @retval None
1867 static void SWPMI_DMAError(DMA_HandleTypeDef *hdma)
1869 SWPMI_HandleTypeDef* hswpmi = ( SWPMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1871 /* Update handle */
1872 hswpmi->RxXferCount = 0U;
1873 hswpmi->TxXferCount = 0U;
1874 hswpmi->State= HAL_SWPMI_STATE_READY;
1875 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_DMA;
1877 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1878 hswpmi->ErrorCallback(hswpmi);
1879 #else
1880 HAL_SWPMI_ErrorCallback(hswpmi);
1881 #endif
1885 * @brief DMA SWPMI communication abort callback.
1886 * @param hdma DMA handle
1887 * @retval None
1889 static void SWPMI_DMAAbortOnError(DMA_HandleTypeDef *hdma)
1891 SWPMI_HandleTypeDef* hswpmi = ( SWPMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1893 /* Update handle */
1894 hswpmi->RxXferCount = 0U;
1895 hswpmi->TxXferCount = 0U;
1896 hswpmi->State= HAL_SWPMI_STATE_READY;
1898 #if (USE_HAL_SWPMI_REGISTER_CALLBACKS == 1)
1899 hswpmi->ErrorCallback(hswpmi);
1900 #else
1901 HAL_SWPMI_ErrorCallback(hswpmi);
1902 #endif
1906 * @brief Handle SWPMI Communication Timeout.
1907 * @param hswpmi SWPMI handle
1908 * @param Flag: specifies the SWPMI flag to check.
1909 * @param Tickstart Tick start value
1910 * @param Timeout timeout duration.
1911 * @retval HAL status
1913 static HAL_StatusTypeDef SWPMI_WaitOnFlagSetUntilTimeout(SWPMI_HandleTypeDef *hswpmi, uint32_t Flag, uint32_t Tickstart, uint32_t Timeout)
1915 HAL_StatusTypeDef status = HAL_OK;
1917 /* Wait until flag is set */
1918 while(!(HAL_IS_BIT_SET(hswpmi->Instance->ISR, Flag)))
1920 /* Check for the Timeout */
1921 if ((((HAL_GetTick() - Tickstart) > Timeout) && (Timeout != HAL_MAX_DELAY)) || (Timeout == 0U))
1923 /* Set the SWPMI state ready to be able to start again the process */
1924 hswpmi->State = HAL_SWPMI_STATE_READY;
1926 status = HAL_TIMEOUT;
1927 break;
1931 return status;
1935 * @}
1938 #endif /* HAL_SWPMI_MODULE_ENABLED */
1941 * @}
1946 * @}
1949 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/