TUKS MCU Introductory course / TUKS-COURSE-2-LED
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmot 1:d0dfbce63a89 1 /**
elmot 1:d0dfbce63a89 2 ******************************************************************************
elmot 1:d0dfbce63a89 3 * @file stm32l4xx_hal_swpmi.c
elmot 1:d0dfbce63a89 4 * @author MCD Application Team
elmot 1:d0dfbce63a89 5 * @version V1.5.1
elmot 1:d0dfbce63a89 6 * @date 31-May-2016
elmot 1:d0dfbce63a89 7 * @brief SWPMI HAL module driver.
elmot 1:d0dfbce63a89 8 * This file provides firmware functions to manage the following
elmot 1:d0dfbce63a89 9 * functionalities of the Single Wire Protocol Master Interface (SWPMI).
elmot 1:d0dfbce63a89 10 * + Initialization and Configuration
elmot 1:d0dfbce63a89 11 * + Data transfers functions
elmot 1:d0dfbce63a89 12 * + DMA transfers management
elmot 1:d0dfbce63a89 13 * + Interrupts and flags management
elmot 1:d0dfbce63a89 14 @verbatim
elmot 1:d0dfbce63a89 15 ===============================================================================
elmot 1:d0dfbce63a89 16 ##### How to use this driver #####
elmot 1:d0dfbce63a89 17 ===============================================================================
elmot 1:d0dfbce63a89 18 [..]
elmot 1:d0dfbce63a89 19 The SWPMI HAL driver can be used as follows:
elmot 1:d0dfbce63a89 20
elmot 1:d0dfbce63a89 21 (#) Declare a SWPMI_HandleTypeDef handle structure (eg. SWPMI_HandleTypeDef hswpmi).
elmot 1:d0dfbce63a89 22
elmot 1:d0dfbce63a89 23 (#) Initialize the SWPMI low level resources by implementing the HAL_SWPMI_MspInit() API:
elmot 1:d0dfbce63a89 24 (##) Enable the SWPMIx interface clock with __HAL_RCC_SWPMIx_CLK_ENABLE().
elmot 1:d0dfbce63a89 25 (##) SWPMI IO configuration:
elmot 1:d0dfbce63a89 26 (+++) Enable the clock for the SWPMI GPIO.
elmot 1:d0dfbce63a89 27 (+++) Configure these SWPMI pins as alternate function pull-up.
elmot 1:d0dfbce63a89 28 (##) NVIC configuration if you need to use interrupt process (HAL_SWPMI_Transmit_IT()
elmot 1:d0dfbce63a89 29 and HAL_SWPMI_Receive_IT() APIs):
elmot 1:d0dfbce63a89 30 (+++) Configure the SWPMIx interrupt priority with HAL_NVIC_SetPriority().
elmot 1:d0dfbce63a89 31 (+++) Enable the NVIC SWPMI IRQ handle with HAL_NVIC_EnableIRQ().
elmot 1:d0dfbce63a89 32
elmot 1:d0dfbce63a89 33 (##) DMA Configuration if you need to use DMA process (HAL_SWPMI_Transmit_DMA()
elmot 1:d0dfbce63a89 34 and HAL_SWPMI_Receive_DMA() APIs):
elmot 1:d0dfbce63a89 35 (+++) Declare a DMA handle structure for the Tx/Rx channels.
elmot 1:d0dfbce63a89 36 (+++) Enable the DMAx interface clock.
elmot 1:d0dfbce63a89 37 (+++) Configure the declared DMA handle structure with the required
elmot 1:d0dfbce63a89 38 Tx/Rx parameters.
elmot 1:d0dfbce63a89 39 (+++) Configure the DMA Tx/Rx channels and requests.
elmot 1:d0dfbce63a89 40 (+++) Associate the initialized DMA handle to the SWPMI DMA Tx/Rx handle.
elmot 1:d0dfbce63a89 41 (+++) Configure the priority and enable the NVIC for the transfer complete
elmot 1:d0dfbce63a89 42 interrupt on the DMA Tx/Rx channels.
elmot 1:d0dfbce63a89 43
elmot 1:d0dfbce63a89 44 (#) Program the Bite Rate, Tx Buffering mode, Rx Buffering mode in the Init structure.
elmot 1:d0dfbce63a89 45
elmot 1:d0dfbce63a89 46 (#) Enable the SWPMI peripheral by calling the HAL_SWPMI_Init() function.
elmot 1:d0dfbce63a89 47
elmot 1:d0dfbce63a89 48 @endverbatim
elmot 1:d0dfbce63a89 49 ******************************************************************************
elmot 1:d0dfbce63a89 50 * @attention
elmot 1:d0dfbce63a89 51 *
elmot 1:d0dfbce63a89 52 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
elmot 1:d0dfbce63a89 53 *
elmot 1:d0dfbce63a89 54 * Redistribution and use in source and binary forms, with or without modification,
elmot 1:d0dfbce63a89 55 * are permitted provided that the following conditions are met:
elmot 1:d0dfbce63a89 56 * 1. Redistributions of source code must retain the above copyright notice,
elmot 1:d0dfbce63a89 57 * this list of conditions and the following disclaimer.
elmot 1:d0dfbce63a89 58 * 2. Redistributions in binary form must reproduce the above copyright notice,
elmot 1:d0dfbce63a89 59 * this list of conditions and the following disclaimer in the documentation
elmot 1:d0dfbce63a89 60 * and/or other materials provided with the distribution.
elmot 1:d0dfbce63a89 61 * 3. Neither the name of STMicroelectronics nor the names of its contributors
elmot 1:d0dfbce63a89 62 * may be used to endorse or promote products derived from this software
elmot 1:d0dfbce63a89 63 * without specific prior written permission.
elmot 1:d0dfbce63a89 64 *
elmot 1:d0dfbce63a89 65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elmot 1:d0dfbce63a89 66 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elmot 1:d0dfbce63a89 67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
elmot 1:d0dfbce63a89 68 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
elmot 1:d0dfbce63a89 69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
elmot 1:d0dfbce63a89 70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
elmot 1:d0dfbce63a89 71 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
elmot 1:d0dfbce63a89 72 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
elmot 1:d0dfbce63a89 73 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
elmot 1:d0dfbce63a89 74 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
elmot 1:d0dfbce63a89 75 *
elmot 1:d0dfbce63a89 76 ******************************************************************************
elmot 1:d0dfbce63a89 77 */
elmot 1:d0dfbce63a89 78
elmot 1:d0dfbce63a89 79 /* Includes ------------------------------------------------------------------*/
elmot 1:d0dfbce63a89 80 #include "stm32l4xx_hal.h"
elmot 1:d0dfbce63a89 81
elmot 1:d0dfbce63a89 82 /** @addtogroup STM32L4xx_HAL_Driver
elmot 1:d0dfbce63a89 83 * @{
elmot 1:d0dfbce63a89 84 */
elmot 1:d0dfbce63a89 85
elmot 1:d0dfbce63a89 86 /** @defgroup SWPMI SWPMI
elmot 1:d0dfbce63a89 87 * @brief HAL SWPMI module driver
elmot 1:d0dfbce63a89 88 * @{
elmot 1:d0dfbce63a89 89 */
elmot 1:d0dfbce63a89 90 #ifdef HAL_SWPMI_MODULE_ENABLED
elmot 1:d0dfbce63a89 91
elmot 1:d0dfbce63a89 92 /* Private typedef -----------------------------------------------------------*/
elmot 1:d0dfbce63a89 93 /* Private define ------------------------------------------------------------*/
elmot 1:d0dfbce63a89 94 /* Private constants ---------------------------------------------------------*/
elmot 1:d0dfbce63a89 95 /** @addtogroup SWPMI_Private_Constants SWPMI Private Constants
elmot 1:d0dfbce63a89 96 * @{
elmot 1:d0dfbce63a89 97 */
elmot 1:d0dfbce63a89 98 #define SWPMI_TIMEOUT_VALUE ((uint32_t) 22000)
elmot 1:d0dfbce63a89 99
elmot 1:d0dfbce63a89 100 /**
elmot 1:d0dfbce63a89 101 * @}
elmot 1:d0dfbce63a89 102 */
elmot 1:d0dfbce63a89 103
elmot 1:d0dfbce63a89 104 /* Private macros ------------------------------------------------------------*/
elmot 1:d0dfbce63a89 105 /* Private variables ---------------------------------------------------------*/
elmot 1:d0dfbce63a89 106 /* Private function prototypes -----------------------------------------------*/
elmot 1:d0dfbce63a89 107 static void SWPMI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 108 static void SWPMI_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 109 static void SWPMI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 110 static void SWPMI_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 111 static void SWPMI_DMAError(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 112 static HAL_StatusTypeDef SWPMI_Transmit_IT(SWPMI_HandleTypeDef *hswpmi);
elmot 1:d0dfbce63a89 113 static HAL_StatusTypeDef SWPMI_EndTransmit_IT(SWPMI_HandleTypeDef *hswpmi);
elmot 1:d0dfbce63a89 114 static HAL_StatusTypeDef SWPMI_Receive_IT(SWPMI_HandleTypeDef *hswpmi);
elmot 1:d0dfbce63a89 115 static HAL_StatusTypeDef SWPMI_EndReceive_IT(SWPMI_HandleTypeDef *hswpmi);
elmot 1:d0dfbce63a89 116 static HAL_StatusTypeDef SWPMI_EndTransmitReceive_IT(SWPMI_HandleTypeDef *hswpmi);
elmot 1:d0dfbce63a89 117 static HAL_StatusTypeDef SWPMI_WaitOnFlagSetUntilTimeout(SWPMI_HandleTypeDef *hswpmi, uint32_t Flag, uint32_t Tickstart, uint32_t Timeout);
elmot 1:d0dfbce63a89 118
elmot 1:d0dfbce63a89 119 /* Exported functions --------------------------------------------------------*/
elmot 1:d0dfbce63a89 120
elmot 1:d0dfbce63a89 121 /** @defgroup SWPMI_Exported_Functions SWPMI Exported Functions
elmot 1:d0dfbce63a89 122 * @{
elmot 1:d0dfbce63a89 123 */
elmot 1:d0dfbce63a89 124
elmot 1:d0dfbce63a89 125 /** @defgroup SWPMI_Exported_Group1 Initialization/de-initialization methods
elmot 1:d0dfbce63a89 126 * @brief Initialization and Configuration functions
elmot 1:d0dfbce63a89 127 *
elmot 1:d0dfbce63a89 128 @verbatim
elmot 1:d0dfbce63a89 129 ===============================================================================
elmot 1:d0dfbce63a89 130 ##### Initialization and Configuration functions #####
elmot 1:d0dfbce63a89 131 ===============================================================================
elmot 1:d0dfbce63a89 132 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 133 (+) Initialize and configure the SWPMI peripheral.
elmot 1:d0dfbce63a89 134 (+) De-initialize the SWPMI peripheral.
elmot 1:d0dfbce63a89 135
elmot 1:d0dfbce63a89 136 @endverbatim
elmot 1:d0dfbce63a89 137 * @{
elmot 1:d0dfbce63a89 138 */
elmot 1:d0dfbce63a89 139
elmot 1:d0dfbce63a89 140 /**
elmot 1:d0dfbce63a89 141 * @brief Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitTypeDef.
elmot 1:d0dfbce63a89 142 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 143 * @retval HAL status
elmot 1:d0dfbce63a89 144 */
elmot 1:d0dfbce63a89 145 HAL_StatusTypeDef HAL_SWPMI_Init(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 146 {
elmot 1:d0dfbce63a89 147 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 148 __IO uint32_t wait_loop_index = 0;
elmot 1:d0dfbce63a89 149
elmot 1:d0dfbce63a89 150 /* Check the SWPMI handle allocation */
elmot 1:d0dfbce63a89 151 if(hswpmi == NULL)
elmot 1:d0dfbce63a89 152 {
elmot 1:d0dfbce63a89 153 status = HAL_ERROR;
elmot 1:d0dfbce63a89 154 }
elmot 1:d0dfbce63a89 155 else
elmot 1:d0dfbce63a89 156 {
elmot 1:d0dfbce63a89 157 /* Check the parameters */
elmot 1:d0dfbce63a89 158 assert_param(IS_SWPMI_VOLTAGE_CLASS(hswpmi->Init.VoltageClass));
elmot 1:d0dfbce63a89 159 assert_param(IS_SWPMI_BITRATE_VALUE(hswpmi->Init.BitRate));
elmot 1:d0dfbce63a89 160 assert_param(IS_SWPMI_TX_BUFFERING_MODE(hswpmi->Init.TxBufferingMode));
elmot 1:d0dfbce63a89 161 assert_param(IS_SWPMI_RX_BUFFERING_MODE(hswpmi->Init.RxBufferingMode));
elmot 1:d0dfbce63a89 162
elmot 1:d0dfbce63a89 163 if(hswpmi->State == HAL_SWPMI_STATE_RESET)
elmot 1:d0dfbce63a89 164 {
elmot 1:d0dfbce63a89 165 /* Allocate lock resource and initialize it */
elmot 1:d0dfbce63a89 166 hswpmi->Lock = HAL_UNLOCKED;
elmot 1:d0dfbce63a89 167 }
elmot 1:d0dfbce63a89 168
elmot 1:d0dfbce63a89 169 hswpmi->State = HAL_SWPMI_STATE_BUSY;
elmot 1:d0dfbce63a89 170
elmot 1:d0dfbce63a89 171 /* Disable SWPMI interface */
elmot 1:d0dfbce63a89 172 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 173
elmot 1:d0dfbce63a89 174 /* Clear all SWPMI interface flags */
elmot 1:d0dfbce63a89 175 WRITE_REG(hswpmi->Instance->ICR, 0x019F);
elmot 1:d0dfbce63a89 176
elmot 1:d0dfbce63a89 177 /* Apply Voltage class selection */
elmot 1:d0dfbce63a89 178 MODIFY_REG(hswpmi->Instance->OR, SWPMI_OR_CLASS, hswpmi->Init.VoltageClass);
elmot 1:d0dfbce63a89 179
elmot 1:d0dfbce63a89 180 /* Init the low level hardware : GPIO, CLOCK, CORTEX */
elmot 1:d0dfbce63a89 181 HAL_SWPMI_MspInit(hswpmi);
elmot 1:d0dfbce63a89 182
elmot 1:d0dfbce63a89 183 /* If Voltage class B, apply 300 µs delay */
elmot 1:d0dfbce63a89 184 if(hswpmi->Init.VoltageClass == SWPMI_VOLTAGE_CLASS_B)
elmot 1:d0dfbce63a89 185 {
elmot 1:d0dfbce63a89 186 /* Insure 300 µs wait to insure SWPMI_IO output not higher than 1.8V */
elmot 1:d0dfbce63a89 187 /* Wait loop initialization and execution */
elmot 1:d0dfbce63a89 188 /* Note: Variable divided by 4 to compensate partially CPU processing cycles. */
elmot 1:d0dfbce63a89 189 wait_loop_index = (300 * (SystemCoreClock / (1000000 * 4))) + 150;
elmot 1:d0dfbce63a89 190 while(wait_loop_index != 0)
elmot 1:d0dfbce63a89 191 {
elmot 1:d0dfbce63a89 192 wait_loop_index--;
elmot 1:d0dfbce63a89 193 }
elmot 1:d0dfbce63a89 194 }
elmot 1:d0dfbce63a89 195
elmot 1:d0dfbce63a89 196 /* Configure the BRR register (Bitrate) */
elmot 1:d0dfbce63a89 197 WRITE_REG(hswpmi->Instance->BRR, hswpmi->Init.BitRate);
elmot 1:d0dfbce63a89 198
elmot 1:d0dfbce63a89 199 /* Apply SWPMI CR configuration */
elmot 1:d0dfbce63a89 200 MODIFY_REG(hswpmi->Instance->CR, \
elmot 1:d0dfbce63a89 201 SWPMI_CR_RXDMA | SWPMI_CR_TXDMA | SWPMI_CR_RXMODE | SWPMI_CR_TXMODE, \
elmot 1:d0dfbce63a89 202 hswpmi->Init.TxBufferingMode | hswpmi->Init.RxBufferingMode);
elmot 1:d0dfbce63a89 203
elmot 1:d0dfbce63a89 204 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
elmot 1:d0dfbce63a89 205 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 206
elmot 1:d0dfbce63a89 207 /* Enable SWPMI peripheral if not */
elmot 1:d0dfbce63a89 208 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 209 }
elmot 1:d0dfbce63a89 210
elmot 1:d0dfbce63a89 211 return status;
elmot 1:d0dfbce63a89 212 }
elmot 1:d0dfbce63a89 213
elmot 1:d0dfbce63a89 214 /**
elmot 1:d0dfbce63a89 215 * @brief De-initialize the SWPMI peripheral.
elmot 1:d0dfbce63a89 216 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 217 * @retval HAL status
elmot 1:d0dfbce63a89 218 */
elmot 1:d0dfbce63a89 219 HAL_StatusTypeDef HAL_SWPMI_DeInit(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 220 {
elmot 1:d0dfbce63a89 221 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 222
elmot 1:d0dfbce63a89 223 /* Check the SWPMI handle allocation */
elmot 1:d0dfbce63a89 224 if(hswpmi == NULL)
elmot 1:d0dfbce63a89 225 {
elmot 1:d0dfbce63a89 226 status = HAL_ERROR;
elmot 1:d0dfbce63a89 227 }
elmot 1:d0dfbce63a89 228 else
elmot 1:d0dfbce63a89 229 {
elmot 1:d0dfbce63a89 230 /* Check the parameters */
elmot 1:d0dfbce63a89 231 assert_param(IS_SWPMI_INSTANCE(hswpmi->Instance));
elmot 1:d0dfbce63a89 232
elmot 1:d0dfbce63a89 233 hswpmi->State = HAL_SWPMI_STATE_BUSY;
elmot 1:d0dfbce63a89 234
elmot 1:d0dfbce63a89 235 /* Disable SWPMI interface */
elmot 1:d0dfbce63a89 236 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 237
elmot 1:d0dfbce63a89 238 /* DeInit the low level hardware */
elmot 1:d0dfbce63a89 239 HAL_SWPMI_MspDeInit(hswpmi);
elmot 1:d0dfbce63a89 240
elmot 1:d0dfbce63a89 241 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
elmot 1:d0dfbce63a89 242
elmot 1:d0dfbce63a89 243 hswpmi->State = HAL_SWPMI_STATE_RESET;
elmot 1:d0dfbce63a89 244
elmot 1:d0dfbce63a89 245 /* Release Lock */
elmot 1:d0dfbce63a89 246 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 247 }
elmot 1:d0dfbce63a89 248
elmot 1:d0dfbce63a89 249 return status;
elmot 1:d0dfbce63a89 250 }
elmot 1:d0dfbce63a89 251
elmot 1:d0dfbce63a89 252 /**
elmot 1:d0dfbce63a89 253 * @brief Initialize the SWPMI MSP.
elmot 1:d0dfbce63a89 254 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 255 * @retval None
elmot 1:d0dfbce63a89 256 */
elmot 1:d0dfbce63a89 257 __weak void HAL_SWPMI_MspInit(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 258 {
elmot 1:d0dfbce63a89 259 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 260 UNUSED(hswpmi);
elmot 1:d0dfbce63a89 261
elmot 1:d0dfbce63a89 262 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 263 the HAL_SWPMI_MspInit can be implemented in the user file
elmot 1:d0dfbce63a89 264 */
elmot 1:d0dfbce63a89 265 }
elmot 1:d0dfbce63a89 266
elmot 1:d0dfbce63a89 267 /**
elmot 1:d0dfbce63a89 268 * @brief DeInitialize the SWPMI MSP.
elmot 1:d0dfbce63a89 269 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 270 * @retval None
elmot 1:d0dfbce63a89 271 */
elmot 1:d0dfbce63a89 272 __weak void HAL_SWPMI_MspDeInit(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 273 {
elmot 1:d0dfbce63a89 274 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 275 UNUSED(hswpmi);
elmot 1:d0dfbce63a89 276
elmot 1:d0dfbce63a89 277 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 278 the HAL_SWPMI_MspDeInit can be implemented in the user file
elmot 1:d0dfbce63a89 279 */
elmot 1:d0dfbce63a89 280 }
elmot 1:d0dfbce63a89 281
elmot 1:d0dfbce63a89 282 /**
elmot 1:d0dfbce63a89 283 * @}
elmot 1:d0dfbce63a89 284 */
elmot 1:d0dfbce63a89 285
elmot 1:d0dfbce63a89 286 /** @defgroup SWPMI_Exported_Group2 IO operation methods
elmot 1:d0dfbce63a89 287 * @brief SWPMI Transmit/Receive functions
elmot 1:d0dfbce63a89 288 *
elmot 1:d0dfbce63a89 289 @verbatim
elmot 1:d0dfbce63a89 290 ===============================================================================
elmot 1:d0dfbce63a89 291 ##### IO operation methods #####
elmot 1:d0dfbce63a89 292 ===============================================================================
elmot 1:d0dfbce63a89 293 [..]
elmot 1:d0dfbce63a89 294 This subsection provides a set of functions allowing to manage the SWPMI
elmot 1:d0dfbce63a89 295 data transfers.
elmot 1:d0dfbce63a89 296
elmot 1:d0dfbce63a89 297 (#) There are two modes of transfer:
elmot 1:d0dfbce63a89 298 (++) Blocking mode: The communication is performed in polling mode.
elmot 1:d0dfbce63a89 299 The HAL status of all data processing is returned by the same function
elmot 1:d0dfbce63a89 300 after finishing transfer.
elmot 1:d0dfbce63a89 301 (++) Non-Blocking mode: The communication is performed using Interrupts
elmot 1:d0dfbce63a89 302 or DMA. The end of the data processing will be indicated through the
elmot 1:d0dfbce63a89 303 dedicated SWPMI Interrupt handler (HAL_SWPMI_IRQHandler()) when using Interrupt mode or
elmot 1:d0dfbce63a89 304 the selected DMA channel interrupt handler when using DMA mode.
elmot 1:d0dfbce63a89 305 The HAL_SWPMI_TxCpltCallback(), HAL_SWPMI_RxCpltCallback() user callbacks
elmot 1:d0dfbce63a89 306 will be executed respectively at the end of the transmit or receive process.
elmot 1:d0dfbce63a89 307 The HAL_SWPMI_ErrorCallback() user callback will be executed when a communication error is detected.
elmot 1:d0dfbce63a89 308
elmot 1:d0dfbce63a89 309 (#) Blocking mode API's are:
elmot 1:d0dfbce63a89 310 (++) HAL_SWPMI_Transmit()
elmot 1:d0dfbce63a89 311 (++) HAL_SWPMI_Receive()
elmot 1:d0dfbce63a89 312
elmot 1:d0dfbce63a89 313 (#) Non-Blocking mode API's with Interrupt are:
elmot 1:d0dfbce63a89 314 (++) HAL_SWPMI_Transmit_IT()
elmot 1:d0dfbce63a89 315 (++) HAL_SWPMI_Receive_IT()
elmot 1:d0dfbce63a89 316 (++) HAL_SWPMI_IRQHandler()
elmot 1:d0dfbce63a89 317
elmot 1:d0dfbce63a89 318 (#) Non-Blocking mode API's with DMA are:
elmot 1:d0dfbce63a89 319 (++) HAL_SWPMI_Transmit_DMA()
elmot 1:d0dfbce63a89 320 (++) HAL_SWPMI_Receive_DMA()
elmot 1:d0dfbce63a89 321 (++) HAL_SWPMI_DMAPause()
elmot 1:d0dfbce63a89 322 (++) HAL_SWPMI_DMAResume()
elmot 1:d0dfbce63a89 323 (++) HAL_SWPMI_DMAStop()
elmot 1:d0dfbce63a89 324
elmot 1:d0dfbce63a89 325 (#) A set of Transfer Complete Callbacks are provided in Non-Blocking mode:
elmot 1:d0dfbce63a89 326 (++) HAL_SWPMI_TxHalfCpltCallback()
elmot 1:d0dfbce63a89 327 (++) HAL_SWPMI_TxCpltCallback()
elmot 1:d0dfbce63a89 328 (++) HAL_SWPMI_RxHalfCpltCallback()
elmot 1:d0dfbce63a89 329 (++) HAL_SWPMI_RxCpltCallback()
elmot 1:d0dfbce63a89 330 (++) HAL_SWPMI_ErrorCallback()
elmot 1:d0dfbce63a89 331
elmot 1:d0dfbce63a89 332 (#) The capability to launch the above IO operations in loopback mode for
elmot 1:d0dfbce63a89 333 user application verification:
elmot 1:d0dfbce63a89 334 (++) HAL_SWPMI_EnableLoopback()
elmot 1:d0dfbce63a89 335 (++) HAL_SWPMI_DisableLoopback()
elmot 1:d0dfbce63a89 336
elmot 1:d0dfbce63a89 337 @endverbatim
elmot 1:d0dfbce63a89 338 * @{
elmot 1:d0dfbce63a89 339 */
elmot 1:d0dfbce63a89 340
elmot 1:d0dfbce63a89 341 /**
elmot 1:d0dfbce63a89 342 * @brief Transmit an amount of data in blocking mode.
elmot 1:d0dfbce63a89 343 * @param hswpmi: pointer to a SWPMI_HandleTypeDef structure that contains
elmot 1:d0dfbce63a89 344 * the configuration information for SWPMI module.
elmot 1:d0dfbce63a89 345 * @param pData: Pointer to data buffer
elmot 1:d0dfbce63a89 346 * @param Size: Amount of data to be sent
elmot 1:d0dfbce63a89 347 * @param Timeout: Timeout duration
elmot 1:d0dfbce63a89 348 * @retval HAL status
elmot 1:d0dfbce63a89 349 */
elmot 1:d0dfbce63a89 350 HAL_StatusTypeDef HAL_SWPMI_Transmit(SWPMI_HandleTypeDef *hswpmi, uint32_t* pData, uint16_t Size, uint32_t Timeout)
elmot 1:d0dfbce63a89 351 {
elmot 1:d0dfbce63a89 352 uint32_t tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 353 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 354
elmot 1:d0dfbce63a89 355 if((pData == NULL ) || (Size == 0))
elmot 1:d0dfbce63a89 356 {
elmot 1:d0dfbce63a89 357 status = HAL_ERROR;
elmot 1:d0dfbce63a89 358 }
elmot 1:d0dfbce63a89 359 else
elmot 1:d0dfbce63a89 360 {
elmot 1:d0dfbce63a89 361 /* Process Locked */
elmot 1:d0dfbce63a89 362 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 363
elmot 1:d0dfbce63a89 364 if((hswpmi->State == HAL_SWPMI_STATE_READY) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_RX))
elmot 1:d0dfbce63a89 365 {
elmot 1:d0dfbce63a89 366 /* Check if a non-blocking receive process is ongoing or not */
elmot 1:d0dfbce63a89 367 if(hswpmi->State == HAL_SWPMI_STATE_READY)
elmot 1:d0dfbce63a89 368 {
elmot 1:d0dfbce63a89 369 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
elmot 1:d0dfbce63a89 370
elmot 1:d0dfbce63a89 371 /* Disable any transmitter interrupts */
elmot 1:d0dfbce63a89 372 __HAL_SWPMI_DISABLE_IT(hswpmi, SWPMI_IT_TCIE | SWPMI_IT_TIE | SWPMI_IT_TXUNRIE | SWPMI_IT_TXBEIE);
elmot 1:d0dfbce63a89 373
elmot 1:d0dfbce63a89 374 /* Disable any transmitter flags */
elmot 1:d0dfbce63a89 375 __HAL_SWPMI_CLEAR_FLAG(hswpmi, SWPMI_FLAG_TXBEF | SWPMI_FLAG_TXUNRF | SWPMI_FLAG_TCF);
elmot 1:d0dfbce63a89 376
elmot 1:d0dfbce63a89 377 /* Enable SWPMI peripheral if not */
elmot 1:d0dfbce63a89 378 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 379 }
elmot 1:d0dfbce63a89 380 else
elmot 1:d0dfbce63a89 381 {
elmot 1:d0dfbce63a89 382 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
elmot 1:d0dfbce63a89 383 }
elmot 1:d0dfbce63a89 384
elmot 1:d0dfbce63a89 385 do
elmot 1:d0dfbce63a89 386 {
elmot 1:d0dfbce63a89 387 /* Wait the TXE to write data */
elmot 1:d0dfbce63a89 388 if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_TXE))
elmot 1:d0dfbce63a89 389 {
elmot 1:d0dfbce63a89 390 hswpmi->Instance->TDR = (*pData++);
elmot 1:d0dfbce63a89 391 Size--;
elmot 1:d0dfbce63a89 392 }
elmot 1:d0dfbce63a89 393 else
elmot 1:d0dfbce63a89 394 {
elmot 1:d0dfbce63a89 395 /* Check for the Timeout */
elmot 1:d0dfbce63a89 396 if(Timeout != HAL_MAX_DELAY)
elmot 1:d0dfbce63a89 397 {
elmot 1:d0dfbce63a89 398 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
elmot 1:d0dfbce63a89 399 {
elmot 1:d0dfbce63a89 400 status = HAL_TIMEOUT;
elmot 1:d0dfbce63a89 401 break;
elmot 1:d0dfbce63a89 402 }
elmot 1:d0dfbce63a89 403 }
elmot 1:d0dfbce63a89 404 }
elmot 1:d0dfbce63a89 405 } while(Size != 0);
elmot 1:d0dfbce63a89 406
elmot 1:d0dfbce63a89 407 /* Wait on TXBEF flag to be able to start a second transfer */
elmot 1:d0dfbce63a89 408 if(SWPMI_WaitOnFlagSetUntilTimeout(hswpmi, SWPMI_FLAG_TXBEF, tickstart, Timeout) != HAL_OK)
elmot 1:d0dfbce63a89 409 {
elmot 1:d0dfbce63a89 410 status = HAL_TIMEOUT;
elmot 1:d0dfbce63a89 411 }
elmot 1:d0dfbce63a89 412
elmot 1:d0dfbce63a89 413 if(status == HAL_OK)
elmot 1:d0dfbce63a89 414 {
elmot 1:d0dfbce63a89 415 /* Check if a non-blocking receive Process is ongoing or not */
elmot 1:d0dfbce63a89 416 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
elmot 1:d0dfbce63a89 417 {
elmot 1:d0dfbce63a89 418 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
elmot 1:d0dfbce63a89 419 }
elmot 1:d0dfbce63a89 420 else
elmot 1:d0dfbce63a89 421 {
elmot 1:d0dfbce63a89 422 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 423 }
elmot 1:d0dfbce63a89 424 }
elmot 1:d0dfbce63a89 425 }
elmot 1:d0dfbce63a89 426 else
elmot 1:d0dfbce63a89 427 {
elmot 1:d0dfbce63a89 428 status = HAL_BUSY;
elmot 1:d0dfbce63a89 429 }
elmot 1:d0dfbce63a89 430 }
elmot 1:d0dfbce63a89 431
elmot 1:d0dfbce63a89 432 if((status != HAL_OK) && (status != HAL_BUSY))
elmot 1:d0dfbce63a89 433 {
elmot 1:d0dfbce63a89 434 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 435 }
elmot 1:d0dfbce63a89 436 /* Process Unlocked */
elmot 1:d0dfbce63a89 437 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 438
elmot 1:d0dfbce63a89 439 return status;
elmot 1:d0dfbce63a89 440 }
elmot 1:d0dfbce63a89 441
elmot 1:d0dfbce63a89 442 /**
elmot 1:d0dfbce63a89 443 * @brief Receive an amount of data in blocking mode.
elmot 1:d0dfbce63a89 444 * @param hswpmi: pointer to a SWPMI_HandleTypeDef structure that contains
elmot 1:d0dfbce63a89 445 * the configuration information for SWPMI module.
elmot 1:d0dfbce63a89 446 * @param pData: Pointer to data buffer
elmot 1:d0dfbce63a89 447 * @param Size: Amount of data to be received
elmot 1:d0dfbce63a89 448 * @param Timeout: Timeout duration
elmot 1:d0dfbce63a89 449 * @retval HAL status
elmot 1:d0dfbce63a89 450 */
elmot 1:d0dfbce63a89 451 HAL_StatusTypeDef HAL_SWPMI_Receive(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size, uint32_t Timeout)
elmot 1:d0dfbce63a89 452 {
elmot 1:d0dfbce63a89 453 uint32_t tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 454 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 455
elmot 1:d0dfbce63a89 456 if((pData == NULL ) || (Size == 0))
elmot 1:d0dfbce63a89 457 {
elmot 1:d0dfbce63a89 458 status = HAL_ERROR;
elmot 1:d0dfbce63a89 459 }
elmot 1:d0dfbce63a89 460 else
elmot 1:d0dfbce63a89 461 {
elmot 1:d0dfbce63a89 462 /* Process Locked */
elmot 1:d0dfbce63a89 463 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 464
elmot 1:d0dfbce63a89 465 if((hswpmi->State == HAL_SWPMI_STATE_READY) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_TX))
elmot 1:d0dfbce63a89 466 {
elmot 1:d0dfbce63a89 467 /* Check if a non-blocking transmit process is ongoing or not */
elmot 1:d0dfbce63a89 468 if(hswpmi->State == HAL_SWPMI_STATE_READY)
elmot 1:d0dfbce63a89 469 {
elmot 1:d0dfbce63a89 470 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
elmot 1:d0dfbce63a89 471
elmot 1:d0dfbce63a89 472 /* Disable any receiver interrupts */
elmot 1:d0dfbce63a89 473 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_SRIE | SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
elmot 1:d0dfbce63a89 474
elmot 1:d0dfbce63a89 475 /* Enable SWPMI peripheral if not */
elmot 1:d0dfbce63a89 476 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 477 }
elmot 1:d0dfbce63a89 478 else
elmot 1:d0dfbce63a89 479 {
elmot 1:d0dfbce63a89 480 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
elmot 1:d0dfbce63a89 481 }
elmot 1:d0dfbce63a89 482
elmot 1:d0dfbce63a89 483 do
elmot 1:d0dfbce63a89 484 {
elmot 1:d0dfbce63a89 485 /* Wait the RXNE to read data */
elmot 1:d0dfbce63a89 486 if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_RXNE))
elmot 1:d0dfbce63a89 487 {
elmot 1:d0dfbce63a89 488 (*pData++) = hswpmi->Instance->RDR;
elmot 1:d0dfbce63a89 489 Size--;
elmot 1:d0dfbce63a89 490 }
elmot 1:d0dfbce63a89 491 else
elmot 1:d0dfbce63a89 492 {
elmot 1:d0dfbce63a89 493 /* Check for the Timeout */
elmot 1:d0dfbce63a89 494 if(Timeout != HAL_MAX_DELAY)
elmot 1:d0dfbce63a89 495 {
elmot 1:d0dfbce63a89 496 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
elmot 1:d0dfbce63a89 497 {
elmot 1:d0dfbce63a89 498 status = HAL_TIMEOUT;
elmot 1:d0dfbce63a89 499 break;
elmot 1:d0dfbce63a89 500 }
elmot 1:d0dfbce63a89 501 }
elmot 1:d0dfbce63a89 502 }
elmot 1:d0dfbce63a89 503 } while(Size != 0);
elmot 1:d0dfbce63a89 504
elmot 1:d0dfbce63a89 505 if(status == HAL_OK)
elmot 1:d0dfbce63a89 506 {
elmot 1:d0dfbce63a89 507 if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_RXBFF))
elmot 1:d0dfbce63a89 508 {
elmot 1:d0dfbce63a89 509 /* Clear RXBFF at end of reception */
elmot 1:d0dfbce63a89 510 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXBFF);
elmot 1:d0dfbce63a89 511 }
elmot 1:d0dfbce63a89 512
elmot 1:d0dfbce63a89 513 /* Check if a non-blocking transmit Process is ongoing or not */
elmot 1:d0dfbce63a89 514 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
elmot 1:d0dfbce63a89 515 {
elmot 1:d0dfbce63a89 516 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
elmot 1:d0dfbce63a89 517 }
elmot 1:d0dfbce63a89 518 else
elmot 1:d0dfbce63a89 519 {
elmot 1:d0dfbce63a89 520 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 521 }
elmot 1:d0dfbce63a89 522 }
elmot 1:d0dfbce63a89 523 }
elmot 1:d0dfbce63a89 524 else
elmot 1:d0dfbce63a89 525 {
elmot 1:d0dfbce63a89 526 status = HAL_BUSY;
elmot 1:d0dfbce63a89 527 }
elmot 1:d0dfbce63a89 528 }
elmot 1:d0dfbce63a89 529
elmot 1:d0dfbce63a89 530 if((status != HAL_OK) && (status != HAL_BUSY))
elmot 1:d0dfbce63a89 531 {
elmot 1:d0dfbce63a89 532 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 533 }
elmot 1:d0dfbce63a89 534 /* Process Unlocked */
elmot 1:d0dfbce63a89 535 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 536
elmot 1:d0dfbce63a89 537 return status;
elmot 1:d0dfbce63a89 538 }
elmot 1:d0dfbce63a89 539
elmot 1:d0dfbce63a89 540 /**
elmot 1:d0dfbce63a89 541 * @brief Transmit an amount of data in non-blocking mode with interrupt.
elmot 1:d0dfbce63a89 542 * @param hswpmi: pointer to a SWPMI_HandleTypeDef structure that contains
elmot 1:d0dfbce63a89 543 * the configuration information for SWPMI module.
elmot 1:d0dfbce63a89 544 * @param pData: Pointer to data buffer
elmot 1:d0dfbce63a89 545 * @param Size: Amount of data to be sent
elmot 1:d0dfbce63a89 546 * @retval HAL status
elmot 1:d0dfbce63a89 547 */
elmot 1:d0dfbce63a89 548 HAL_StatusTypeDef HAL_SWPMI_Transmit_IT(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
elmot 1:d0dfbce63a89 549 {
elmot 1:d0dfbce63a89 550 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 551
elmot 1:d0dfbce63a89 552 if((pData == NULL ) || (Size == 0))
elmot 1:d0dfbce63a89 553 {
elmot 1:d0dfbce63a89 554 status = HAL_ERROR;
elmot 1:d0dfbce63a89 555 }
elmot 1:d0dfbce63a89 556 else
elmot 1:d0dfbce63a89 557 {
elmot 1:d0dfbce63a89 558 /* Process Locked */
elmot 1:d0dfbce63a89 559 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 560
elmot 1:d0dfbce63a89 561 if((hswpmi->State == HAL_SWPMI_STATE_READY) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_RX))
elmot 1:d0dfbce63a89 562 {
elmot 1:d0dfbce63a89 563 /* Update handle */
elmot 1:d0dfbce63a89 564 hswpmi->pTxBuffPtr = pData;
elmot 1:d0dfbce63a89 565 hswpmi->TxXferSize = Size;
elmot 1:d0dfbce63a89 566 hswpmi->TxXferCount = Size;
elmot 1:d0dfbce63a89 567 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
elmot 1:d0dfbce63a89 568
elmot 1:d0dfbce63a89 569 /* Check if a receive process is ongoing or not */
elmot 1:d0dfbce63a89 570 if(hswpmi->State == HAL_SWPMI_STATE_READY)
elmot 1:d0dfbce63a89 571 {
elmot 1:d0dfbce63a89 572 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
elmot 1:d0dfbce63a89 573
elmot 1:d0dfbce63a89 574 /* Enable SWPMI peripheral if not */
elmot 1:d0dfbce63a89 575 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 576 }
elmot 1:d0dfbce63a89 577 else
elmot 1:d0dfbce63a89 578 {
elmot 1:d0dfbce63a89 579 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
elmot 1:d0dfbce63a89 580 }
elmot 1:d0dfbce63a89 581
elmot 1:d0dfbce63a89 582 /* Enable the SWPMI transmit underrun error */
elmot 1:d0dfbce63a89 583 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TXUNRIE);
elmot 1:d0dfbce63a89 584
elmot 1:d0dfbce63a89 585 /* Process Unlocked */
elmot 1:d0dfbce63a89 586 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 587
elmot 1:d0dfbce63a89 588 /* Enable the SWPMI interrupts: */
elmot 1:d0dfbce63a89 589 /* - Transmit data register empty */
elmot 1:d0dfbce63a89 590 /* - Transmit buffer empty */
elmot 1:d0dfbce63a89 591 /* - Transmit/Reception completion */
elmot 1:d0dfbce63a89 592 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TIE | SWPMI_IT_TXBEIE | SWPMI_IT_TCIE);
elmot 1:d0dfbce63a89 593 }
elmot 1:d0dfbce63a89 594 else
elmot 1:d0dfbce63a89 595 {
elmot 1:d0dfbce63a89 596 status = HAL_BUSY;
elmot 1:d0dfbce63a89 597
elmot 1:d0dfbce63a89 598 /* Process Unlocked */
elmot 1:d0dfbce63a89 599 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 600 }
elmot 1:d0dfbce63a89 601 }
elmot 1:d0dfbce63a89 602
elmot 1:d0dfbce63a89 603 return status;
elmot 1:d0dfbce63a89 604 }
elmot 1:d0dfbce63a89 605
elmot 1:d0dfbce63a89 606 /**
elmot 1:d0dfbce63a89 607 * @brief Receive an amount of data in non-blocking mode with interrupt.
elmot 1:d0dfbce63a89 608 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 609 * @param pData: pointer to data buffer
elmot 1:d0dfbce63a89 610 * @param Size: amount of data to be received
elmot 1:d0dfbce63a89 611 * @retval HAL status
elmot 1:d0dfbce63a89 612 */
elmot 1:d0dfbce63a89 613 HAL_StatusTypeDef HAL_SWPMI_Receive_IT(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
elmot 1:d0dfbce63a89 614 {
elmot 1:d0dfbce63a89 615 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 616
elmot 1:d0dfbce63a89 617 if((pData == NULL ) || (Size == 0))
elmot 1:d0dfbce63a89 618 {
elmot 1:d0dfbce63a89 619 status = HAL_ERROR;
elmot 1:d0dfbce63a89 620 }
elmot 1:d0dfbce63a89 621 else
elmot 1:d0dfbce63a89 622 {
elmot 1:d0dfbce63a89 623 /* Process Locked */
elmot 1:d0dfbce63a89 624 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 625
elmot 1:d0dfbce63a89 626 if((hswpmi->State == HAL_SWPMI_STATE_READY) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_TX))
elmot 1:d0dfbce63a89 627 {
elmot 1:d0dfbce63a89 628 /* Update handle */
elmot 1:d0dfbce63a89 629 hswpmi->pRxBuffPtr = pData;
elmot 1:d0dfbce63a89 630 hswpmi->RxXferSize = Size;
elmot 1:d0dfbce63a89 631 hswpmi->RxXferCount = Size;
elmot 1:d0dfbce63a89 632 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
elmot 1:d0dfbce63a89 633
elmot 1:d0dfbce63a89 634 /* Check if a transmit process is ongoing or not */
elmot 1:d0dfbce63a89 635 if(hswpmi->State == HAL_SWPMI_STATE_READY)
elmot 1:d0dfbce63a89 636 {
elmot 1:d0dfbce63a89 637 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
elmot 1:d0dfbce63a89 638
elmot 1:d0dfbce63a89 639 /* Enable SWPMI peripheral if not */
elmot 1:d0dfbce63a89 640 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 641 }
elmot 1:d0dfbce63a89 642 else
elmot 1:d0dfbce63a89 643 {
elmot 1:d0dfbce63a89 644 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
elmot 1:d0dfbce63a89 645 }
elmot 1:d0dfbce63a89 646
elmot 1:d0dfbce63a89 647 /* Process Unlocked */
elmot 1:d0dfbce63a89 648 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 649
elmot 1:d0dfbce63a89 650 /* Enable the SWPMI slave resume */
elmot 1:d0dfbce63a89 651 /* Enable the SWPMI Data Register not empty Interrupt, receive CRC Error, receive overrun and RxBuf Interrupt */
elmot 1:d0dfbce63a89 652 /* Enable the SWPMI Transmit/Reception completion */
elmot 1:d0dfbce63a89 653 __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
elmot 1:d0dfbce63a89 654 }
elmot 1:d0dfbce63a89 655 else
elmot 1:d0dfbce63a89 656 {
elmot 1:d0dfbce63a89 657 status = HAL_BUSY;
elmot 1:d0dfbce63a89 658
elmot 1:d0dfbce63a89 659 /* Process Unlocked */
elmot 1:d0dfbce63a89 660 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 661 }
elmot 1:d0dfbce63a89 662 }
elmot 1:d0dfbce63a89 663
elmot 1:d0dfbce63a89 664 return status;
elmot 1:d0dfbce63a89 665 }
elmot 1:d0dfbce63a89 666
elmot 1:d0dfbce63a89 667 /**
elmot 1:d0dfbce63a89 668 * @brief Transmit an amount of data in non-blocking mode with DMA interrupt.
elmot 1:d0dfbce63a89 669 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 670 * @param pData: pointer to data buffer
elmot 1:d0dfbce63a89 671 * @param Size: amount of data to be sent
elmot 1:d0dfbce63a89 672 * @retval HAL status
elmot 1:d0dfbce63a89 673 */
elmot 1:d0dfbce63a89 674 HAL_StatusTypeDef HAL_SWPMI_Transmit_DMA(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
elmot 1:d0dfbce63a89 675 {
elmot 1:d0dfbce63a89 676 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 677
elmot 1:d0dfbce63a89 678 if((pData == NULL ) || (Size == 0))
elmot 1:d0dfbce63a89 679 {
elmot 1:d0dfbce63a89 680 status = HAL_ERROR;
elmot 1:d0dfbce63a89 681 }
elmot 1:d0dfbce63a89 682 else
elmot 1:d0dfbce63a89 683 {
elmot 1:d0dfbce63a89 684 /* Process Locked */
elmot 1:d0dfbce63a89 685 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 686
elmot 1:d0dfbce63a89 687 if((hswpmi->State == HAL_SWPMI_STATE_READY) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_RX))
elmot 1:d0dfbce63a89 688 {
elmot 1:d0dfbce63a89 689 /* Update handle */
elmot 1:d0dfbce63a89 690 hswpmi->pTxBuffPtr = pData;
elmot 1:d0dfbce63a89 691 hswpmi->TxXferSize = Size;
elmot 1:d0dfbce63a89 692 hswpmi->TxXferCount = Size;
elmot 1:d0dfbce63a89 693 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
elmot 1:d0dfbce63a89 694
elmot 1:d0dfbce63a89 695 /* Check if a receive process is ongoing or not */
elmot 1:d0dfbce63a89 696 if(hswpmi->State == HAL_SWPMI_STATE_READY)
elmot 1:d0dfbce63a89 697 {
elmot 1:d0dfbce63a89 698 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
elmot 1:d0dfbce63a89 699
elmot 1:d0dfbce63a89 700 /* Enable SWPMI peripheral if not */
elmot 1:d0dfbce63a89 701 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 702 }
elmot 1:d0dfbce63a89 703 else
elmot 1:d0dfbce63a89 704 {
elmot 1:d0dfbce63a89 705 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
elmot 1:d0dfbce63a89 706 }
elmot 1:d0dfbce63a89 707
elmot 1:d0dfbce63a89 708 /* Set the SWPMI DMA transfer complete callback */
elmot 1:d0dfbce63a89 709 hswpmi->hdmatx->XferCpltCallback = SWPMI_DMATransmitCplt;
elmot 1:d0dfbce63a89 710
elmot 1:d0dfbce63a89 711 /* Set the SWPMI DMA Half transfer complete callback */
elmot 1:d0dfbce63a89 712 hswpmi->hdmatx->XferHalfCpltCallback = SWPMI_DMATxHalfCplt;
elmot 1:d0dfbce63a89 713
elmot 1:d0dfbce63a89 714 /* Set the DMA error callback */
elmot 1:d0dfbce63a89 715 hswpmi->hdmatx->XferErrorCallback = SWPMI_DMAError;
elmot 1:d0dfbce63a89 716
elmot 1:d0dfbce63a89 717 /* Enable the SWPMI transmit DMA Stream */
elmot 1:d0dfbce63a89 718 HAL_DMA_Start_IT(hswpmi->hdmatx, (uint32_t)hswpmi->pTxBuffPtr, (uint32_t)&hswpmi->Instance->TDR, Size);
elmot 1:d0dfbce63a89 719
elmot 1:d0dfbce63a89 720 /* Process Unlocked */
elmot 1:d0dfbce63a89 721 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 722
elmot 1:d0dfbce63a89 723 /* Enable the DMA transfer for transmit request by setting the TXDMA bit
elmot 1:d0dfbce63a89 724 in the SWPMI CR register */
elmot 1:d0dfbce63a89 725 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_TXDMA);
elmot 1:d0dfbce63a89 726 }
elmot 1:d0dfbce63a89 727 else
elmot 1:d0dfbce63a89 728 {
elmot 1:d0dfbce63a89 729 status = HAL_BUSY;
elmot 1:d0dfbce63a89 730
elmot 1:d0dfbce63a89 731 /* Process Unlocked */
elmot 1:d0dfbce63a89 732 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 733 }
elmot 1:d0dfbce63a89 734 }
elmot 1:d0dfbce63a89 735
elmot 1:d0dfbce63a89 736 return status;
elmot 1:d0dfbce63a89 737 }
elmot 1:d0dfbce63a89 738
elmot 1:d0dfbce63a89 739 /**
elmot 1:d0dfbce63a89 740 * @brief Receive an amount of data in non-blocking mode with DMA interrupt.
elmot 1:d0dfbce63a89 741 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 742 * @param pData: pointer to data buffer
elmot 1:d0dfbce63a89 743 * @param Size: amount of data to be received
elmot 1:d0dfbce63a89 744 * @retval HAL status
elmot 1:d0dfbce63a89 745 */
elmot 1:d0dfbce63a89 746 HAL_StatusTypeDef HAL_SWPMI_Receive_DMA(SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
elmot 1:d0dfbce63a89 747 {
elmot 1:d0dfbce63a89 748 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 749
elmot 1:d0dfbce63a89 750 if((pData == NULL ) || (Size == 0))
elmot 1:d0dfbce63a89 751 {
elmot 1:d0dfbce63a89 752 status = HAL_ERROR;
elmot 1:d0dfbce63a89 753 }
elmot 1:d0dfbce63a89 754 else
elmot 1:d0dfbce63a89 755 {
elmot 1:d0dfbce63a89 756 /* Process Locked */
elmot 1:d0dfbce63a89 757 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 758
elmot 1:d0dfbce63a89 759 if((hswpmi->State == HAL_SWPMI_STATE_READY) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_TX))
elmot 1:d0dfbce63a89 760 {
elmot 1:d0dfbce63a89 761 /* Update handle */
elmot 1:d0dfbce63a89 762 hswpmi->pRxBuffPtr = pData;
elmot 1:d0dfbce63a89 763 hswpmi->RxXferSize = Size;
elmot 1:d0dfbce63a89 764 hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
elmot 1:d0dfbce63a89 765
elmot 1:d0dfbce63a89 766 /* Check if a transmit process is ongoing or not */
elmot 1:d0dfbce63a89 767 if(hswpmi->State == HAL_SWPMI_STATE_READY)
elmot 1:d0dfbce63a89 768 {
elmot 1:d0dfbce63a89 769 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
elmot 1:d0dfbce63a89 770
elmot 1:d0dfbce63a89 771 /* Enable SWPMI peripheral if not */
elmot 1:d0dfbce63a89 772 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 773 }
elmot 1:d0dfbce63a89 774 else
elmot 1:d0dfbce63a89 775 {
elmot 1:d0dfbce63a89 776 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
elmot 1:d0dfbce63a89 777 }
elmot 1:d0dfbce63a89 778
elmot 1:d0dfbce63a89 779 /* Set the SWPMI DMA transfer complete callback */
elmot 1:d0dfbce63a89 780 hswpmi->hdmarx->XferCpltCallback = SWPMI_DMAReceiveCplt;
elmot 1:d0dfbce63a89 781
elmot 1:d0dfbce63a89 782 /* Set the SWPMI DMA Half transfer complete callback */
elmot 1:d0dfbce63a89 783 hswpmi->hdmarx->XferHalfCpltCallback = SWPMI_DMARxHalfCplt;
elmot 1:d0dfbce63a89 784
elmot 1:d0dfbce63a89 785 /* Set the DMA error callback */
elmot 1:d0dfbce63a89 786 hswpmi->hdmarx->XferErrorCallback = SWPMI_DMAError;
elmot 1:d0dfbce63a89 787
elmot 1:d0dfbce63a89 788 /* Enable the DMA request */
elmot 1:d0dfbce63a89 789 HAL_DMA_Start_IT(hswpmi->hdmarx, (uint32_t)&hswpmi->Instance->RDR, (uint32_t)hswpmi->pRxBuffPtr, Size);
elmot 1:d0dfbce63a89 790
elmot 1:d0dfbce63a89 791 /* Process Unlocked */
elmot 1:d0dfbce63a89 792 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 793
elmot 1:d0dfbce63a89 794 /* Enable the DMA transfer for the receiver request by setting the RXDMA bit
elmot 1:d0dfbce63a89 795 in the SWPMI CR register */
elmot 1:d0dfbce63a89 796 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_RXDMA);
elmot 1:d0dfbce63a89 797 }
elmot 1:d0dfbce63a89 798 else
elmot 1:d0dfbce63a89 799 {
elmot 1:d0dfbce63a89 800 status = HAL_BUSY;
elmot 1:d0dfbce63a89 801
elmot 1:d0dfbce63a89 802 /* Process Unlocked */
elmot 1:d0dfbce63a89 803 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 804 }
elmot 1:d0dfbce63a89 805 }
elmot 1:d0dfbce63a89 806
elmot 1:d0dfbce63a89 807 return status;
elmot 1:d0dfbce63a89 808 }
elmot 1:d0dfbce63a89 809
elmot 1:d0dfbce63a89 810 /**
elmot 1:d0dfbce63a89 811 * @brief Stop all DMA transfers.
elmot 1:d0dfbce63a89 812 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 813 * @retval HAL_OK
elmot 1:d0dfbce63a89 814 */
elmot 1:d0dfbce63a89 815 HAL_StatusTypeDef HAL_SWPMI_DMAStop(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 816 {
elmot 1:d0dfbce63a89 817 /* Process Locked */
elmot 1:d0dfbce63a89 818 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 819
elmot 1:d0dfbce63a89 820 /* Disable the SWPMI Tx/Rx DMA requests */
elmot 1:d0dfbce63a89 821 CLEAR_BIT(hswpmi->Instance->CR, (SWPMI_CR_TXDMA | SWPMI_CR_RXDMA));
elmot 1:d0dfbce63a89 822
elmot 1:d0dfbce63a89 823 /* Abort the SWPMI DMA tx channel */
elmot 1:d0dfbce63a89 824 if(hswpmi->hdmatx != NULL)
elmot 1:d0dfbce63a89 825 {
elmot 1:d0dfbce63a89 826 HAL_DMA_Abort(hswpmi->hdmatx);
elmot 1:d0dfbce63a89 827 }
elmot 1:d0dfbce63a89 828 /* Abort the SWPMI DMA rx channel */
elmot 1:d0dfbce63a89 829 if(hswpmi->hdmarx != NULL)
elmot 1:d0dfbce63a89 830 {
elmot 1:d0dfbce63a89 831 HAL_DMA_Abort(hswpmi->hdmarx);
elmot 1:d0dfbce63a89 832 }
elmot 1:d0dfbce63a89 833
elmot 1:d0dfbce63a89 834 /* Disable SWPMI interface */
elmot 1:d0dfbce63a89 835 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
elmot 1:d0dfbce63a89 836
elmot 1:d0dfbce63a89 837 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 838
elmot 1:d0dfbce63a89 839 /* Process Unlocked */
elmot 1:d0dfbce63a89 840 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 841
elmot 1:d0dfbce63a89 842 return HAL_OK;
elmot 1:d0dfbce63a89 843 }
elmot 1:d0dfbce63a89 844
elmot 1:d0dfbce63a89 845
elmot 1:d0dfbce63a89 846 /**
elmot 1:d0dfbce63a89 847 * @brief Enable the Loopback mode.
elmot 1:d0dfbce63a89 848 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 849 * @note Loopback mode is to be used only for test purposes
elmot 1:d0dfbce63a89 850 * @retval HAL_OK / HAL_BUSY
elmot 1:d0dfbce63a89 851 */
elmot 1:d0dfbce63a89 852 HAL_StatusTypeDef HAL_SWPMI_EnableLoopback(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 853 {
elmot 1:d0dfbce63a89 854 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 855
elmot 1:d0dfbce63a89 856 /* Process Locked */
elmot 1:d0dfbce63a89 857 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 858
elmot 1:d0dfbce63a89 859 /* Check SWPMI not enabled */
elmot 1:d0dfbce63a89 860 if(READ_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT) != RESET)
elmot 1:d0dfbce63a89 861 {
elmot 1:d0dfbce63a89 862 status = HAL_BUSY;
elmot 1:d0dfbce63a89 863 }
elmot 1:d0dfbce63a89 864 else
elmot 1:d0dfbce63a89 865 {
elmot 1:d0dfbce63a89 866 /* Set Loopback */
elmot 1:d0dfbce63a89 867 SET_BIT(hswpmi->Instance->CR, SWPMI_CR_LPBK);
elmot 1:d0dfbce63a89 868 }
elmot 1:d0dfbce63a89 869
elmot 1:d0dfbce63a89 870 /* Process Unlocked */
elmot 1:d0dfbce63a89 871 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 872
elmot 1:d0dfbce63a89 873 return status;
elmot 1:d0dfbce63a89 874 }
elmot 1:d0dfbce63a89 875
elmot 1:d0dfbce63a89 876 /**
elmot 1:d0dfbce63a89 877 * @brief Disable the Loopback mode.
elmot 1:d0dfbce63a89 878 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 879 * @note Loopback mode is to be used only for test purposes
elmot 1:d0dfbce63a89 880 * @retval HAL_OK / HAL_BUSY
elmot 1:d0dfbce63a89 881 */
elmot 1:d0dfbce63a89 882 HAL_StatusTypeDef HAL_SWPMI_DisableLoopback(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 883 {
elmot 1:d0dfbce63a89 884 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 885
elmot 1:d0dfbce63a89 886 /* Process Locked */
elmot 1:d0dfbce63a89 887 __HAL_LOCK(hswpmi);
elmot 1:d0dfbce63a89 888
elmot 1:d0dfbce63a89 889 /* Check SWPMI not enabled */
elmot 1:d0dfbce63a89 890 if(READ_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT) != RESET)
elmot 1:d0dfbce63a89 891 {
elmot 1:d0dfbce63a89 892 status = HAL_BUSY;
elmot 1:d0dfbce63a89 893 }
elmot 1:d0dfbce63a89 894 else
elmot 1:d0dfbce63a89 895 {
elmot 1:d0dfbce63a89 896 /* Reset Loopback */
elmot 1:d0dfbce63a89 897 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_LPBK);
elmot 1:d0dfbce63a89 898 }
elmot 1:d0dfbce63a89 899
elmot 1:d0dfbce63a89 900 /* Process Unlocked */
elmot 1:d0dfbce63a89 901 __HAL_UNLOCK(hswpmi);
elmot 1:d0dfbce63a89 902
elmot 1:d0dfbce63a89 903 return status;
elmot 1:d0dfbce63a89 904 }
elmot 1:d0dfbce63a89 905
elmot 1:d0dfbce63a89 906 /**
elmot 1:d0dfbce63a89 907 * @}
elmot 1:d0dfbce63a89 908 */
elmot 1:d0dfbce63a89 909
elmot 1:d0dfbce63a89 910 /** @defgroup SWPMI_Exported_Group3 SWPMI IRQ handler and callbacks
elmot 1:d0dfbce63a89 911 * @brief SWPMI IRQ handler.
elmot 1:d0dfbce63a89 912 *
elmot 1:d0dfbce63a89 913 @verbatim
elmot 1:d0dfbce63a89 914 ==============================================================================
elmot 1:d0dfbce63a89 915 ##### SWPMI IRQ handler and callbacks #####
elmot 1:d0dfbce63a89 916 ==============================================================================
elmot 1:d0dfbce63a89 917 [..] This section provides SWPMI IRQ handler and callback functions called within
elmot 1:d0dfbce63a89 918 the IRQ handler.
elmot 1:d0dfbce63a89 919
elmot 1:d0dfbce63a89 920 @endverbatim
elmot 1:d0dfbce63a89 921 * @{
elmot 1:d0dfbce63a89 922 */
elmot 1:d0dfbce63a89 923
elmot 1:d0dfbce63a89 924 /**
elmot 1:d0dfbce63a89 925 * @brief Handle SWPMI interrupt request.
elmot 1:d0dfbce63a89 926 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 927 * @retval None
elmot 1:d0dfbce63a89 928 */
elmot 1:d0dfbce63a89 929 void HAL_SWPMI_IRQHandler(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 930 {
elmot 1:d0dfbce63a89 931 uint32_t regisr = READ_REG(hswpmi->Instance->ISR);
elmot 1:d0dfbce63a89 932 uint32_t regier = READ_REG(hswpmi->Instance->IER);
elmot 1:d0dfbce63a89 933
elmot 1:d0dfbce63a89 934 /* SWPMI CRC error interrupt occurred --------------------------------------*/
elmot 1:d0dfbce63a89 935 if(((regisr & SWPMI_FLAG_RXBERF) != RESET) && ((regier & SWPMI_IT_RXBERIE) != RESET))
elmot 1:d0dfbce63a89 936 {
elmot 1:d0dfbce63a89 937 /* Disable Receive CRC interrupt */
elmot 1:d0dfbce63a89 938 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_RXBERIE | SWPMI_IT_RXBFIE);
elmot 1:d0dfbce63a89 939 /* Clear Receive CRC and Receive buffer full flag */
elmot 1:d0dfbce63a89 940 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXBERF | SWPMI_FLAG_RXBFF);
elmot 1:d0dfbce63a89 941
elmot 1:d0dfbce63a89 942 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_CRC;
elmot 1:d0dfbce63a89 943 }
elmot 1:d0dfbce63a89 944
elmot 1:d0dfbce63a89 945 /* SWPMI Over-Run interrupt occurred -----------------------------------------*/
elmot 1:d0dfbce63a89 946 if(((regisr & SWPMI_FLAG_RXOVRF) != RESET) && ((regier & SWPMI_IT_RXOVRIE) != RESET))
elmot 1:d0dfbce63a89 947 {
elmot 1:d0dfbce63a89 948 /* Disable Receive overrun interrupt */
elmot 1:d0dfbce63a89 949 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_RXOVRIE);
elmot 1:d0dfbce63a89 950 /* Clear Receive overrun flag */
elmot 1:d0dfbce63a89 951 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXOVRF);
elmot 1:d0dfbce63a89 952
elmot 1:d0dfbce63a89 953 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_OVR;
elmot 1:d0dfbce63a89 954 }
elmot 1:d0dfbce63a89 955
elmot 1:d0dfbce63a89 956 /* SWPMI Under-Run interrupt occurred -----------------------------------------*/
elmot 1:d0dfbce63a89 957 if(((regisr & SWPMI_FLAG_TXUNRF) != RESET) && ((regier & SWPMI_IT_TXUNRIE) != RESET))
elmot 1:d0dfbce63a89 958 {
elmot 1:d0dfbce63a89 959 /* Disable Transmit under run interrupt */
elmot 1:d0dfbce63a89 960 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_TXUNRIE);
elmot 1:d0dfbce63a89 961 /* Clear Transmit under run flag */
elmot 1:d0dfbce63a89 962 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_TXUNRF);
elmot 1:d0dfbce63a89 963
elmot 1:d0dfbce63a89 964 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_UDR;
elmot 1:d0dfbce63a89 965 }
elmot 1:d0dfbce63a89 966
elmot 1:d0dfbce63a89 967 /* Call SWPMI Error Call back function if need be --------------------------*/
elmot 1:d0dfbce63a89 968 if(hswpmi->ErrorCode != HAL_SWPMI_ERROR_NONE)
elmot 1:d0dfbce63a89 969 {
elmot 1:d0dfbce63a89 970 /* Set the SWPMI state ready to be able to start again the process */
elmot 1:d0dfbce63a89 971 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 972
elmot 1:d0dfbce63a89 973 HAL_SWPMI_ErrorCallback(hswpmi);
elmot 1:d0dfbce63a89 974 }
elmot 1:d0dfbce63a89 975
elmot 1:d0dfbce63a89 976 /* SWPMI in mode Receiver ---------------------------------------------------*/
elmot 1:d0dfbce63a89 977 if(((regisr & SWPMI_FLAG_RXNE) != RESET) && ((regier & SWPMI_IT_RIE) != RESET))
elmot 1:d0dfbce63a89 978 {
elmot 1:d0dfbce63a89 979 SWPMI_Receive_IT(hswpmi);
elmot 1:d0dfbce63a89 980 }
elmot 1:d0dfbce63a89 981
elmot 1:d0dfbce63a89 982 /* SWPMI in mode Transmitter ------------------------------------------------*/
elmot 1:d0dfbce63a89 983 if(((regisr & SWPMI_FLAG_TXE) != RESET) && ((regier & SWPMI_IT_TIE) != RESET))
elmot 1:d0dfbce63a89 984 {
elmot 1:d0dfbce63a89 985 SWPMI_Transmit_IT(hswpmi);
elmot 1:d0dfbce63a89 986 }
elmot 1:d0dfbce63a89 987
elmot 1:d0dfbce63a89 988 /* SWPMI in mode Transmitter (Transmit buffer empty) ------------------------*/
elmot 1:d0dfbce63a89 989 if(((regisr & SWPMI_FLAG_TXBEF) != RESET) && ((regier & SWPMI_IT_TXBEIE) != RESET))
elmot 1:d0dfbce63a89 990 {
elmot 1:d0dfbce63a89 991 SWPMI_EndTransmit_IT(hswpmi);
elmot 1:d0dfbce63a89 992 }
elmot 1:d0dfbce63a89 993
elmot 1:d0dfbce63a89 994 /* SWPMI in mode Receiver (Receive buffer full) -----------------------------*/
elmot 1:d0dfbce63a89 995 if(((regisr & SWPMI_FLAG_RXBFF) != RESET) && ((regier & SWPMI_IT_RXBFIE) != RESET))
elmot 1:d0dfbce63a89 996 {
elmot 1:d0dfbce63a89 997 SWPMI_EndReceive_IT(hswpmi);
elmot 1:d0dfbce63a89 998 }
elmot 1:d0dfbce63a89 999
elmot 1:d0dfbce63a89 1000 /* Both Transmission and reception complete ---------------------------------*/
elmot 1:d0dfbce63a89 1001 if(((regisr & SWPMI_FLAG_TCF) != RESET) && ((regier & SWPMI_IT_TCIE) != RESET))
elmot 1:d0dfbce63a89 1002 {
elmot 1:d0dfbce63a89 1003 SWPMI_EndTransmitReceive_IT(hswpmi);
elmot 1:d0dfbce63a89 1004 }
elmot 1:d0dfbce63a89 1005 }
elmot 1:d0dfbce63a89 1006
elmot 1:d0dfbce63a89 1007 /**
elmot 1:d0dfbce63a89 1008 * @brief Tx Transfer completed callback.
elmot 1:d0dfbce63a89 1009 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1010 * @retval None
elmot 1:d0dfbce63a89 1011 */
elmot 1:d0dfbce63a89 1012 __weak void HAL_SWPMI_TxCpltCallback(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1013 {
elmot 1:d0dfbce63a89 1014 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1015 UNUSED(hswpmi);
elmot 1:d0dfbce63a89 1016
elmot 1:d0dfbce63a89 1017 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1018 the HAL_SWPMI_TxCpltCallback is to be implemented in the user file
elmot 1:d0dfbce63a89 1019 */
elmot 1:d0dfbce63a89 1020 }
elmot 1:d0dfbce63a89 1021
elmot 1:d0dfbce63a89 1022 /**
elmot 1:d0dfbce63a89 1023 * @brief Tx Half Transfer completed callback.
elmot 1:d0dfbce63a89 1024 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1025 * @retval None
elmot 1:d0dfbce63a89 1026 */
elmot 1:d0dfbce63a89 1027 __weak void HAL_SWPMI_TxHalfCpltCallback(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1028 {
elmot 1:d0dfbce63a89 1029 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1030 UNUSED(hswpmi);
elmot 1:d0dfbce63a89 1031
elmot 1:d0dfbce63a89 1032 /* NOTE: This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1033 the HAL_SWPMI_TxHalfCpltCallback is to be implemented in the user file
elmot 1:d0dfbce63a89 1034 */
elmot 1:d0dfbce63a89 1035 }
elmot 1:d0dfbce63a89 1036
elmot 1:d0dfbce63a89 1037 /**
elmot 1:d0dfbce63a89 1038 * @brief Rx Transfer completed callback.
elmot 1:d0dfbce63a89 1039 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1040 * @retval None
elmot 1:d0dfbce63a89 1041 */
elmot 1:d0dfbce63a89 1042 __weak void HAL_SWPMI_RxCpltCallback(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1043 {
elmot 1:d0dfbce63a89 1044 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1045 UNUSED(hswpmi);
elmot 1:d0dfbce63a89 1046
elmot 1:d0dfbce63a89 1047 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1048 the HAL_SWPMI_RxCpltCallback is to be implemented in the user file
elmot 1:d0dfbce63a89 1049 */
elmot 1:d0dfbce63a89 1050 }
elmot 1:d0dfbce63a89 1051
elmot 1:d0dfbce63a89 1052 /**
elmot 1:d0dfbce63a89 1053 * @brief Rx Half Transfer completed callback.
elmot 1:d0dfbce63a89 1054 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1055 * @retval None
elmot 1:d0dfbce63a89 1056 */
elmot 1:d0dfbce63a89 1057 __weak void HAL_SWPMI_RxHalfCpltCallback(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1058 {
elmot 1:d0dfbce63a89 1059 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1060 UNUSED(hswpmi);
elmot 1:d0dfbce63a89 1061
elmot 1:d0dfbce63a89 1062 /* NOTE: This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1063 the HAL_SWPMI_RxHalfCpltCallback is to be implemented in the user file
elmot 1:d0dfbce63a89 1064 */
elmot 1:d0dfbce63a89 1065 }
elmot 1:d0dfbce63a89 1066
elmot 1:d0dfbce63a89 1067 /**
elmot 1:d0dfbce63a89 1068 * @brief SWPMI error callback.
elmot 1:d0dfbce63a89 1069 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1070 * @retval None
elmot 1:d0dfbce63a89 1071 */
elmot 1:d0dfbce63a89 1072 __weak void HAL_SWPMI_ErrorCallback(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1073 {
elmot 1:d0dfbce63a89 1074 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1075 UNUSED(hswpmi);
elmot 1:d0dfbce63a89 1076
elmot 1:d0dfbce63a89 1077 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1078 the HAL_SWPMI_ErrorCallback is to be implemented in the user file
elmot 1:d0dfbce63a89 1079 */
elmot 1:d0dfbce63a89 1080 }
elmot 1:d0dfbce63a89 1081
elmot 1:d0dfbce63a89 1082 /**
elmot 1:d0dfbce63a89 1083 * @}
elmot 1:d0dfbce63a89 1084 */
elmot 1:d0dfbce63a89 1085
elmot 1:d0dfbce63a89 1086 /** @defgroup SWPMI_Exported_Group4 Peripheral Control methods
elmot 1:d0dfbce63a89 1087 * @brief SWPMI control functions
elmot 1:d0dfbce63a89 1088 *
elmot 1:d0dfbce63a89 1089 @verbatim
elmot 1:d0dfbce63a89 1090 ===============================================================================
elmot 1:d0dfbce63a89 1091 ##### Peripheral Control methods #####
elmot 1:d0dfbce63a89 1092 ===============================================================================
elmot 1:d0dfbce63a89 1093 [..]
elmot 1:d0dfbce63a89 1094 This subsection provides a set of functions allowing to control the SWPMI.
elmot 1:d0dfbce63a89 1095 (+) HAL_SWPMI_GetState() API is helpful to check in run-time the state of the SWPMI peripheral
elmot 1:d0dfbce63a89 1096 (+) HAL_SWPMI_GetError() API is helpful to check in run-time the error state of the SWPMI peripheral
elmot 1:d0dfbce63a89 1097 @endverbatim
elmot 1:d0dfbce63a89 1098 * @{
elmot 1:d0dfbce63a89 1099 */
elmot 1:d0dfbce63a89 1100
elmot 1:d0dfbce63a89 1101 /**
elmot 1:d0dfbce63a89 1102 * @brief Return the SWPMI handle state.
elmot 1:d0dfbce63a89 1103 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1104 * @retval HAL state
elmot 1:d0dfbce63a89 1105 */
elmot 1:d0dfbce63a89 1106 HAL_SWPMI_StateTypeDef HAL_SWPMI_GetState(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1107 {
elmot 1:d0dfbce63a89 1108 /* Return SWPMI handle state */
elmot 1:d0dfbce63a89 1109 return hswpmi->State;
elmot 1:d0dfbce63a89 1110 }
elmot 1:d0dfbce63a89 1111
elmot 1:d0dfbce63a89 1112 /**
elmot 1:d0dfbce63a89 1113 * @brief Return the SWPMI error code.
elmot 1:d0dfbce63a89 1114 * @param hswpmi : pointer to a SWPMI_HandleTypeDef structure that contains
elmot 1:d0dfbce63a89 1115 * the configuration information for the specified SWPMI.
elmot 1:d0dfbce63a89 1116 * @retval SWPMI Error Code
elmot 1:d0dfbce63a89 1117 */
elmot 1:d0dfbce63a89 1118 uint32_t HAL_SWPMI_GetError(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1119 {
elmot 1:d0dfbce63a89 1120 return hswpmi->ErrorCode;
elmot 1:d0dfbce63a89 1121 }
elmot 1:d0dfbce63a89 1122
elmot 1:d0dfbce63a89 1123 /**
elmot 1:d0dfbce63a89 1124 * @}
elmot 1:d0dfbce63a89 1125 */
elmot 1:d0dfbce63a89 1126
elmot 1:d0dfbce63a89 1127 /**
elmot 1:d0dfbce63a89 1128 * @}
elmot 1:d0dfbce63a89 1129 */
elmot 1:d0dfbce63a89 1130
elmot 1:d0dfbce63a89 1131 /* Private functions ---------------------------------------------------------*/
elmot 1:d0dfbce63a89 1132
elmot 1:d0dfbce63a89 1133 /** @defgroup SWPMI_Private_Functions SWPMI Private Functions
elmot 1:d0dfbce63a89 1134 * @{
elmot 1:d0dfbce63a89 1135 */
elmot 1:d0dfbce63a89 1136
elmot 1:d0dfbce63a89 1137 /**
elmot 1:d0dfbce63a89 1138 * @brief Transmit an amount of data in interrupt mode.
elmot 1:d0dfbce63a89 1139 * @note Function called under interruption only, once interruptions have been enabled by HAL_SWPMI_Transmit_IT()
elmot 1:d0dfbce63a89 1140 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1141 * @retval HAL status
elmot 1:d0dfbce63a89 1142 */
elmot 1:d0dfbce63a89 1143 static HAL_StatusTypeDef SWPMI_Transmit_IT(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1144 {
elmot 1:d0dfbce63a89 1145 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1146
elmot 1:d0dfbce63a89 1147 if ((hswpmi->State == HAL_SWPMI_STATE_BUSY_TX) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX))
elmot 1:d0dfbce63a89 1148 {
elmot 1:d0dfbce63a89 1149 if(hswpmi->TxXferCount == 0)
elmot 1:d0dfbce63a89 1150 {
elmot 1:d0dfbce63a89 1151 /* Disable the SWPMI TXE and Underrun Interrupts */
elmot 1:d0dfbce63a89 1152 CLEAR_BIT(hswpmi->Instance->IER, (SWPMI_IT_TIE | SWPMI_IT_TXUNRIE));
elmot 1:d0dfbce63a89 1153 }
elmot 1:d0dfbce63a89 1154 else
elmot 1:d0dfbce63a89 1155 {
elmot 1:d0dfbce63a89 1156 hswpmi->Instance->TDR = (uint32_t)(*hswpmi->pTxBuffPtr++);
elmot 1:d0dfbce63a89 1157 hswpmi->TxXferCount--;
elmot 1:d0dfbce63a89 1158 }
elmot 1:d0dfbce63a89 1159 }
elmot 1:d0dfbce63a89 1160 else
elmot 1:d0dfbce63a89 1161 {
elmot 1:d0dfbce63a89 1162 status = HAL_BUSY;
elmot 1:d0dfbce63a89 1163 }
elmot 1:d0dfbce63a89 1164
elmot 1:d0dfbce63a89 1165 return status;
elmot 1:d0dfbce63a89 1166 }
elmot 1:d0dfbce63a89 1167
elmot 1:d0dfbce63a89 1168 /**
elmot 1:d0dfbce63a89 1169 * @brief Wraps up transmission in non-blocking mode.
elmot 1:d0dfbce63a89 1170 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1171 * @retval HAL status
elmot 1:d0dfbce63a89 1172 * @retval HAL status
elmot 1:d0dfbce63a89 1173 */
elmot 1:d0dfbce63a89 1174 static HAL_StatusTypeDef SWPMI_EndTransmit_IT(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1175 {
elmot 1:d0dfbce63a89 1176 /* Clear the SWPMI Transmit buffer empty Flag */
elmot 1:d0dfbce63a89 1177 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_TXBEF);
elmot 1:d0dfbce63a89 1178 /* Disable the all SWPMI Transmit Interrupts */
elmot 1:d0dfbce63a89 1179 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_TIE | SWPMI_IT_TXUNRIE | SWPMI_IT_TXBEIE);
elmot 1:d0dfbce63a89 1180
elmot 1:d0dfbce63a89 1181 /* Check if a receive Process is ongoing or not */
elmot 1:d0dfbce63a89 1182 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
elmot 1:d0dfbce63a89 1183 {
elmot 1:d0dfbce63a89 1184 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
elmot 1:d0dfbce63a89 1185 }
elmot 1:d0dfbce63a89 1186 else
elmot 1:d0dfbce63a89 1187 {
elmot 1:d0dfbce63a89 1188 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 1189 }
elmot 1:d0dfbce63a89 1190
elmot 1:d0dfbce63a89 1191 HAL_SWPMI_TxCpltCallback(hswpmi);
elmot 1:d0dfbce63a89 1192
elmot 1:d0dfbce63a89 1193 return HAL_OK;
elmot 1:d0dfbce63a89 1194 }
elmot 1:d0dfbce63a89 1195
elmot 1:d0dfbce63a89 1196 /**
elmot 1:d0dfbce63a89 1197 * @brief Receive an amount of data in interrupt mode.
elmot 1:d0dfbce63a89 1198 * @note Function called under interruption only, once interruptions have been enabled by HAL_SWPMI_Receive_IT()
elmot 1:d0dfbce63a89 1199 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1200 * @retval HAL status
elmot 1:d0dfbce63a89 1201 */
elmot 1:d0dfbce63a89 1202 static HAL_StatusTypeDef SWPMI_Receive_IT(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1203 {
elmot 1:d0dfbce63a89 1204 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1205
elmot 1:d0dfbce63a89 1206 if((hswpmi->State == HAL_SWPMI_STATE_BUSY_RX) || (hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX))
elmot 1:d0dfbce63a89 1207 {
elmot 1:d0dfbce63a89 1208 *hswpmi->pRxBuffPtr++ = (uint32_t)(hswpmi->Instance->RDR);
elmot 1:d0dfbce63a89 1209
elmot 1:d0dfbce63a89 1210 if(--hswpmi->RxXferCount == 0)
elmot 1:d0dfbce63a89 1211 {
elmot 1:d0dfbce63a89 1212 /* Wait for RXBFF flag to update state */
elmot 1:d0dfbce63a89 1213 HAL_SWPMI_RxCpltCallback(hswpmi);
elmot 1:d0dfbce63a89 1214 }
elmot 1:d0dfbce63a89 1215 }
elmot 1:d0dfbce63a89 1216 else
elmot 1:d0dfbce63a89 1217 {
elmot 1:d0dfbce63a89 1218 status = HAL_BUSY;
elmot 1:d0dfbce63a89 1219 }
elmot 1:d0dfbce63a89 1220
elmot 1:d0dfbce63a89 1221 return status;
elmot 1:d0dfbce63a89 1222 }
elmot 1:d0dfbce63a89 1223
elmot 1:d0dfbce63a89 1224 /**
elmot 1:d0dfbce63a89 1225 * @brief Wraps up reception in non-blocking mode.
elmot 1:d0dfbce63a89 1226 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1227 * @retval HAL status
elmot 1:d0dfbce63a89 1228 * @retval HAL status
elmot 1:d0dfbce63a89 1229 */
elmot 1:d0dfbce63a89 1230 static HAL_StatusTypeDef SWPMI_EndReceive_IT(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1231 {
elmot 1:d0dfbce63a89 1232 /* Clear the SWPMI Receive buffer full Flag */
elmot 1:d0dfbce63a89 1233 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXBFF);
elmot 1:d0dfbce63a89 1234 /* Disable the all SWPMI Receive Interrupts */
elmot 1:d0dfbce63a89 1235 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
elmot 1:d0dfbce63a89 1236
elmot 1:d0dfbce63a89 1237 /* Check if a transmit Process is ongoing or not */
elmot 1:d0dfbce63a89 1238 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
elmot 1:d0dfbce63a89 1239 {
elmot 1:d0dfbce63a89 1240 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
elmot 1:d0dfbce63a89 1241 }
elmot 1:d0dfbce63a89 1242 else
elmot 1:d0dfbce63a89 1243 {
elmot 1:d0dfbce63a89 1244 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 1245 }
elmot 1:d0dfbce63a89 1246
elmot 1:d0dfbce63a89 1247 return HAL_OK;
elmot 1:d0dfbce63a89 1248 }
elmot 1:d0dfbce63a89 1249
elmot 1:d0dfbce63a89 1250 /**
elmot 1:d0dfbce63a89 1251 * @brief Wraps up transmission and reception in non-blocking mode.
elmot 1:d0dfbce63a89 1252 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1253 * @retval HAL status
elmot 1:d0dfbce63a89 1254 * @retval HAL status
elmot 1:d0dfbce63a89 1255 */
elmot 1:d0dfbce63a89 1256 static HAL_StatusTypeDef SWPMI_EndTransmitReceive_IT(SWPMI_HandleTypeDef *hswpmi)
elmot 1:d0dfbce63a89 1257 {
elmot 1:d0dfbce63a89 1258 /* Clear the SWPMI Transmission Complete Flag */
elmot 1:d0dfbce63a89 1259 WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_TCF);
elmot 1:d0dfbce63a89 1260 /* Disable the SWPMI Transmission Complete Interrupt */
elmot 1:d0dfbce63a89 1261 CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_TCIE);
elmot 1:d0dfbce63a89 1262
elmot 1:d0dfbce63a89 1263 /* Check if a receive Process is ongoing or not */
elmot 1:d0dfbce63a89 1264 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
elmot 1:d0dfbce63a89 1265 {
elmot 1:d0dfbce63a89 1266 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
elmot 1:d0dfbce63a89 1267 }
elmot 1:d0dfbce63a89 1268 else if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX)
elmot 1:d0dfbce63a89 1269 {
elmot 1:d0dfbce63a89 1270 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 1271 }
elmot 1:d0dfbce63a89 1272
elmot 1:d0dfbce63a89 1273 return HAL_OK;
elmot 1:d0dfbce63a89 1274 }
elmot 1:d0dfbce63a89 1275
elmot 1:d0dfbce63a89 1276 /**
elmot 1:d0dfbce63a89 1277 * @brief DMA SWPMI transmit process complete callback.
elmot 1:d0dfbce63a89 1278 * @param hdma: DMA handle
elmot 1:d0dfbce63a89 1279 * @retval None
elmot 1:d0dfbce63a89 1280 */
elmot 1:d0dfbce63a89 1281 static void SWPMI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 1282 {
elmot 1:d0dfbce63a89 1283 SWPMI_HandleTypeDef* hswpmi = ( SWPMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
elmot 1:d0dfbce63a89 1284 uint32_t tickstart = 0;
elmot 1:d0dfbce63a89 1285
elmot 1:d0dfbce63a89 1286 /* DMA Normal mode*/
elmot 1:d0dfbce63a89 1287 if((hdma->Instance->CCR & DMA_CCR_CIRC) != SET)
elmot 1:d0dfbce63a89 1288 {
elmot 1:d0dfbce63a89 1289 hswpmi->TxXferCount = 0;
elmot 1:d0dfbce63a89 1290
elmot 1:d0dfbce63a89 1291 /* Disable the DMA transfer for transmit request by setting the TXDMA bit
elmot 1:d0dfbce63a89 1292 in the SWPMI CR register */
elmot 1:d0dfbce63a89 1293 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_TXDMA);
elmot 1:d0dfbce63a89 1294
elmot 1:d0dfbce63a89 1295 /* Init tickstart for timeout managment*/
elmot 1:d0dfbce63a89 1296 tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 1297
elmot 1:d0dfbce63a89 1298 /* Wait the TXBEF */
elmot 1:d0dfbce63a89 1299 if(SWPMI_WaitOnFlagSetUntilTimeout(hswpmi, SWPMI_FLAG_TXBEF, tickstart, SWPMI_TIMEOUT_VALUE) != HAL_OK)
elmot 1:d0dfbce63a89 1300 {
elmot 1:d0dfbce63a89 1301 /* Timeout occurred */
elmot 1:d0dfbce63a89 1302 HAL_SWPMI_ErrorCallback(hswpmi);
elmot 1:d0dfbce63a89 1303 }
elmot 1:d0dfbce63a89 1304 else
elmot 1:d0dfbce63a89 1305 {
elmot 1:d0dfbce63a89 1306 /* No Timeout */
elmot 1:d0dfbce63a89 1307 /* Check if a receive process is ongoing or not */
elmot 1:d0dfbce63a89 1308 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
elmot 1:d0dfbce63a89 1309 {
elmot 1:d0dfbce63a89 1310 hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
elmot 1:d0dfbce63a89 1311 }
elmot 1:d0dfbce63a89 1312 else
elmot 1:d0dfbce63a89 1313 {
elmot 1:d0dfbce63a89 1314 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 1315 }
elmot 1:d0dfbce63a89 1316
elmot 1:d0dfbce63a89 1317 HAL_SWPMI_TxCpltCallback(hswpmi);
elmot 1:d0dfbce63a89 1318 }
elmot 1:d0dfbce63a89 1319 }
elmot 1:d0dfbce63a89 1320 /* DMA Circular mode */
elmot 1:d0dfbce63a89 1321 else
elmot 1:d0dfbce63a89 1322 {
elmot 1:d0dfbce63a89 1323 HAL_SWPMI_TxCpltCallback(hswpmi);
elmot 1:d0dfbce63a89 1324 }
elmot 1:d0dfbce63a89 1325 }
elmot 1:d0dfbce63a89 1326
elmot 1:d0dfbce63a89 1327 /**
elmot 1:d0dfbce63a89 1328 * @brief DMA SWPMI transmit process half complete callback.
elmot 1:d0dfbce63a89 1329 * @param hdma : DMA handle
elmot 1:d0dfbce63a89 1330 * @retval None
elmot 1:d0dfbce63a89 1331 */
elmot 1:d0dfbce63a89 1332 static void SWPMI_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 1333 {
elmot 1:d0dfbce63a89 1334 SWPMI_HandleTypeDef* hswpmi = (SWPMI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
elmot 1:d0dfbce63a89 1335
elmot 1:d0dfbce63a89 1336 HAL_SWPMI_TxHalfCpltCallback(hswpmi);
elmot 1:d0dfbce63a89 1337 }
elmot 1:d0dfbce63a89 1338
elmot 1:d0dfbce63a89 1339
elmot 1:d0dfbce63a89 1340 /**
elmot 1:d0dfbce63a89 1341 * @brief DMA SWPMI receive process complete callback.
elmot 1:d0dfbce63a89 1342 * @param hdma: DMA handle
elmot 1:d0dfbce63a89 1343 * @retval None
elmot 1:d0dfbce63a89 1344 */
elmot 1:d0dfbce63a89 1345 static void SWPMI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 1346 {
elmot 1:d0dfbce63a89 1347 SWPMI_HandleTypeDef* hswpmi = ( SWPMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
elmot 1:d0dfbce63a89 1348
elmot 1:d0dfbce63a89 1349 /* DMA Normal mode*/
elmot 1:d0dfbce63a89 1350 if((hdma->Instance->CCR & DMA_CCR_CIRC) == RESET)
elmot 1:d0dfbce63a89 1351 {
elmot 1:d0dfbce63a89 1352 hswpmi->RxXferCount = 0;
elmot 1:d0dfbce63a89 1353
elmot 1:d0dfbce63a89 1354 /* Disable the DMA transfer for the receiver request by setting the RXDMA bit
elmot 1:d0dfbce63a89 1355 in the SWPMI CR register */
elmot 1:d0dfbce63a89 1356 CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_RXDMA);
elmot 1:d0dfbce63a89 1357
elmot 1:d0dfbce63a89 1358 /* Check if a transmit Process is ongoing or not */
elmot 1:d0dfbce63a89 1359 if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
elmot 1:d0dfbce63a89 1360 {
elmot 1:d0dfbce63a89 1361 hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
elmot 1:d0dfbce63a89 1362 }
elmot 1:d0dfbce63a89 1363 else
elmot 1:d0dfbce63a89 1364 {
elmot 1:d0dfbce63a89 1365 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 1366 }
elmot 1:d0dfbce63a89 1367 }
elmot 1:d0dfbce63a89 1368 HAL_SWPMI_RxCpltCallback(hswpmi);
elmot 1:d0dfbce63a89 1369 }
elmot 1:d0dfbce63a89 1370
elmot 1:d0dfbce63a89 1371 /**
elmot 1:d0dfbce63a89 1372 * @brief DMA SWPMI receive process half complete callback.
elmot 1:d0dfbce63a89 1373 * @param hdma : DMA handle
elmot 1:d0dfbce63a89 1374 * @retval None
elmot 1:d0dfbce63a89 1375 */
elmot 1:d0dfbce63a89 1376 static void SWPMI_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 1377 {
elmot 1:d0dfbce63a89 1378 SWPMI_HandleTypeDef* hswpmi = (SWPMI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
elmot 1:d0dfbce63a89 1379
elmot 1:d0dfbce63a89 1380 HAL_SWPMI_RxHalfCpltCallback(hswpmi);
elmot 1:d0dfbce63a89 1381 }
elmot 1:d0dfbce63a89 1382
elmot 1:d0dfbce63a89 1383 /**
elmot 1:d0dfbce63a89 1384 * @brief DMA SWPMI communication error callback.
elmot 1:d0dfbce63a89 1385 * @param hdma: DMA handle
elmot 1:d0dfbce63a89 1386 * @retval None
elmot 1:d0dfbce63a89 1387 */
elmot 1:d0dfbce63a89 1388 static void SWPMI_DMAError(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 1389 {
elmot 1:d0dfbce63a89 1390 SWPMI_HandleTypeDef* hswpmi = ( SWPMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
elmot 1:d0dfbce63a89 1391
elmot 1:d0dfbce63a89 1392 /* Update handle */
elmot 1:d0dfbce63a89 1393 hswpmi->RxXferCount = 0;
elmot 1:d0dfbce63a89 1394 hswpmi->TxXferCount = 0;
elmot 1:d0dfbce63a89 1395 hswpmi->State= HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 1396 hswpmi->ErrorCode |= HAL_SWPMI_ERROR_DMA;
elmot 1:d0dfbce63a89 1397
elmot 1:d0dfbce63a89 1398 HAL_SWPMI_ErrorCallback(hswpmi);
elmot 1:d0dfbce63a89 1399 }
elmot 1:d0dfbce63a89 1400
elmot 1:d0dfbce63a89 1401 /**
elmot 1:d0dfbce63a89 1402 * @brief Handle SWPMI Communication Timeout.
elmot 1:d0dfbce63a89 1403 * @param hswpmi: SWPMI handle
elmot 1:d0dfbce63a89 1404 * @param Flag: specifies the SWPMI flag to check.
elmot 1:d0dfbce63a89 1405 * @param Tickstart Tick start value
elmot 1:d0dfbce63a89 1406 * @param Timeout timeout duration.
elmot 1:d0dfbce63a89 1407 * @retval HAL status
elmot 1:d0dfbce63a89 1408 */
elmot 1:d0dfbce63a89 1409 static HAL_StatusTypeDef SWPMI_WaitOnFlagSetUntilTimeout(SWPMI_HandleTypeDef *hswpmi, uint32_t Flag, uint32_t Tickstart, uint32_t Timeout)
elmot 1:d0dfbce63a89 1410 {
elmot 1:d0dfbce63a89 1411 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1412
elmot 1:d0dfbce63a89 1413 /* Wait until flag is set */
elmot 1:d0dfbce63a89 1414 while(!(HAL_IS_BIT_SET(hswpmi->Instance->ISR, Flag)))
elmot 1:d0dfbce63a89 1415 {
elmot 1:d0dfbce63a89 1416 /* Check for the Timeout */
elmot 1:d0dfbce63a89 1417 if(Timeout != HAL_MAX_DELAY)
elmot 1:d0dfbce63a89 1418 {
elmot 1:d0dfbce63a89 1419 if((Timeout == 0) || ((HAL_GetTick()-Tickstart) > Timeout))
elmot 1:d0dfbce63a89 1420 {
elmot 1:d0dfbce63a89 1421 hswpmi->State = HAL_SWPMI_STATE_READY;
elmot 1:d0dfbce63a89 1422
elmot 1:d0dfbce63a89 1423 status = HAL_TIMEOUT;
elmot 1:d0dfbce63a89 1424 break;
elmot 1:d0dfbce63a89 1425 }
elmot 1:d0dfbce63a89 1426 }
elmot 1:d0dfbce63a89 1427 }
elmot 1:d0dfbce63a89 1428
elmot 1:d0dfbce63a89 1429 return status;
elmot 1:d0dfbce63a89 1430 }
elmot 1:d0dfbce63a89 1431
elmot 1:d0dfbce63a89 1432 /**
elmot 1:d0dfbce63a89 1433 * @}
elmot 1:d0dfbce63a89 1434 */
elmot 1:d0dfbce63a89 1435
elmot 1:d0dfbce63a89 1436 #endif /* HAL_SWPMI_MODULE_ENABLED */
elmot 1:d0dfbce63a89 1437 /**
elmot 1:d0dfbce63a89 1438 * @}
elmot 1:d0dfbce63a89 1439 */
elmot 1:d0dfbce63a89 1440
elmot 1:d0dfbce63a89 1441 /**
elmot 1:d0dfbce63a89 1442 * @}
elmot 1:d0dfbce63a89 1443 */
elmot 1:d0dfbce63a89 1444
elmot 1:d0dfbce63a89 1445 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/