inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1 /**
NYX 0:85b3fd62ea1a 2 ******************************************************************************
NYX 0:85b3fd62ea1a 3 * @file stm32f4xx_hal_irda.c
NYX 0:85b3fd62ea1a 4 * @author MCD Application Team
NYX 0:85b3fd62ea1a 5 * @version V1.7.1
NYX 0:85b3fd62ea1a 6 * @date 14-April-2017
NYX 0:85b3fd62ea1a 7 * @brief IRDA HAL module driver.
NYX 0:85b3fd62ea1a 8 * This file provides firmware functions to manage the following
NYX 0:85b3fd62ea1a 9 * functionalities of the IrDA SIR ENDEC block (IrDA):
NYX 0:85b3fd62ea1a 10 * + Initialization and de-initialization methods
NYX 0:85b3fd62ea1a 11 * + IO operation methods
NYX 0:85b3fd62ea1a 12 * + Peripheral Control methods
NYX 0:85b3fd62ea1a 13 *
NYX 0:85b3fd62ea1a 14 @verbatim
NYX 0:85b3fd62ea1a 15 ==============================================================================
NYX 0:85b3fd62ea1a 16 ##### How to use this driver #####
NYX 0:85b3fd62ea1a 17 ==============================================================================
NYX 0:85b3fd62ea1a 18 [..]
NYX 0:85b3fd62ea1a 19 The IRDA HAL driver can be used as follows:
NYX 0:85b3fd62ea1a 20
NYX 0:85b3fd62ea1a 21 (#) Declare a IRDA_HandleTypeDef handle structure.
NYX 0:85b3fd62ea1a 22 (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API:
NYX 0:85b3fd62ea1a 23 (##) Enable the USARTx interface clock.
NYX 0:85b3fd62ea1a 24 (##) IRDA pins configuration:
NYX 0:85b3fd62ea1a 25 (+++) Enable the clock for the IRDA GPIOs.
NYX 0:85b3fd62ea1a 26 (+++) Configure these IRDA pins as alternate function pull-up.
NYX 0:85b3fd62ea1a 27 (##) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
NYX 0:85b3fd62ea1a 28 and HAL_IRDA_Receive_IT() APIs):
NYX 0:85b3fd62ea1a 29 (+++) Configure the USARTx interrupt priority.
NYX 0:85b3fd62ea1a 30 (+++) Enable the NVIC USART IRQ handle.
NYX 0:85b3fd62ea1a 31 (##) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
NYX 0:85b3fd62ea1a 32 and HAL_IRDA_Receive_DMA() APIs):
NYX 0:85b3fd62ea1a 33 (+++) Declare a DMA handle structure for the Tx/Rx stream.
NYX 0:85b3fd62ea1a 34 (+++) Enable the DMAx interface clock.
NYX 0:85b3fd62ea1a 35 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
NYX 0:85b3fd62ea1a 36 (+++) Configure the DMA Tx/Rx Stream.
NYX 0:85b3fd62ea1a 37 (+++) Associate the initialized DMA handle to the IRDA DMA Tx/Rx handle.
NYX 0:85b3fd62ea1a 38 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.
NYX 0:85b3fd62ea1a 39
NYX 0:85b3fd62ea1a 40 (#) Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler
NYX 0:85b3fd62ea1a 41 and Mode(Receiver/Transmitter) in the hirda Init structure.
NYX 0:85b3fd62ea1a 42
NYX 0:85b3fd62ea1a 43 (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API:
NYX 0:85b3fd62ea1a 44 (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
NYX 0:85b3fd62ea1a 45 by calling the customized HAL_IRDA_MspInit() API.
NYX 0:85b3fd62ea1a 46 -@@- The specific IRDA interrupts (Transmission complete interrupt,
NYX 0:85b3fd62ea1a 47 RXNE interrupt and Error Interrupts) will be managed using the macros
NYX 0:85b3fd62ea1a 48 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
NYX 0:85b3fd62ea1a 49
NYX 0:85b3fd62ea1a 50 (#) Three operation modes are available within this driver :
NYX 0:85b3fd62ea1a 51
NYX 0:85b3fd62ea1a 52 *** Polling mode IO operation ***
NYX 0:85b3fd62ea1a 53 =================================
NYX 0:85b3fd62ea1a 54 [..]
NYX 0:85b3fd62ea1a 55 (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit()
NYX 0:85b3fd62ea1a 56 (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive()
NYX 0:85b3fd62ea1a 57
NYX 0:85b3fd62ea1a 58 *** Interrupt mode IO operation ***
NYX 0:85b3fd62ea1a 59 ===================================
NYX 0:85b3fd62ea1a 60 [..]
NYX 0:85b3fd62ea1a 61 (+) Send an amount of data in non blocking mode using HAL_IRDA_Transmit_IT()
NYX 0:85b3fd62ea1a 62 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
NYX 0:85b3fd62ea1a 63 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
NYX 0:85b3fd62ea1a 64 (+) Receive an amount of data in non blocking mode using HAL_IRDA_Receive_IT()
NYX 0:85b3fd62ea1a 65 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
NYX 0:85b3fd62ea1a 66 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
NYX 0:85b3fd62ea1a 67 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
NYX 0:85b3fd62ea1a 68 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
NYX 0:85b3fd62ea1a 69
NYX 0:85b3fd62ea1a 70 *** DMA mode IO operation ***
NYX 0:85b3fd62ea1a 71 =============================
NYX 0:85b3fd62ea1a 72 [..]
NYX 0:85b3fd62ea1a 73 (+) Send an amount of data in non blocking mode (DMA) using HAL_IRDA_Transmit_DMA()
NYX 0:85b3fd62ea1a 74 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
NYX 0:85b3fd62ea1a 75 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
NYX 0:85b3fd62ea1a 76 (+) Receive an amount of data in non blocking mode (DMA) using HAL_IRDA_Receive_DMA()
NYX 0:85b3fd62ea1a 77 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
NYX 0:85b3fd62ea1a 78 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
NYX 0:85b3fd62ea1a 79 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
NYX 0:85b3fd62ea1a 80 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
NYX 0:85b3fd62ea1a 81
NYX 0:85b3fd62ea1a 82 *** IRDA HAL driver macros list ***
NYX 0:85b3fd62ea1a 83 ===================================
NYX 0:85b3fd62ea1a 84 [..]
NYX 0:85b3fd62ea1a 85 Below the list of most used macros in IRDA HAL driver.
NYX 0:85b3fd62ea1a 86
NYX 0:85b3fd62ea1a 87 (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral
NYX 0:85b3fd62ea1a 88 (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral
NYX 0:85b3fd62ea1a 89 (+) __HAL_IRDA_GET_FLAG : Checks whether the specified IRDA flag is set or not
NYX 0:85b3fd62ea1a 90 (+) __HAL_IRDA_CLEAR_FLAG : Clears the specified IRDA pending flag
NYX 0:85b3fd62ea1a 91 (+) __HAL_IRDA_ENABLE_IT: Enables the specified IRDA interrupt
NYX 0:85b3fd62ea1a 92 (+) __HAL_IRDA_DISABLE_IT: Disables the specified IRDA interrupt
NYX 0:85b3fd62ea1a 93
NYX 0:85b3fd62ea1a 94 [..]
NYX 0:85b3fd62ea1a 95 (@) You can refer to the IRDA HAL driver header file for more useful macros
NYX 0:85b3fd62ea1a 96
NYX 0:85b3fd62ea1a 97 @endverbatim
NYX 0:85b3fd62ea1a 98 ******************************************************************************
NYX 0:85b3fd62ea1a 99 * @attention
NYX 0:85b3fd62ea1a 100 *
NYX 0:85b3fd62ea1a 101 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
NYX 0:85b3fd62ea1a 102 *
NYX 0:85b3fd62ea1a 103 * Redistribution and use in source and binary forms, with or without modification,
NYX 0:85b3fd62ea1a 104 * are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 105 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 106 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 107 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 108 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 109 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 110 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 111 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 112 * without specific prior written permission.
NYX 0:85b3fd62ea1a 113 *
NYX 0:85b3fd62ea1a 114 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 115 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 116 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 117 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 118 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 119 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 120 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 121 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 122 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 123 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 124 *
NYX 0:85b3fd62ea1a 125 ******************************************************************************
NYX 0:85b3fd62ea1a 126 */
NYX 0:85b3fd62ea1a 127
NYX 0:85b3fd62ea1a 128 /* Includes ------------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 129 #include "stm32f4xx_hal.h"
NYX 0:85b3fd62ea1a 130
NYX 0:85b3fd62ea1a 131 /** @addtogroup STM32F4xx_HAL_Driver
NYX 0:85b3fd62ea1a 132 * @{
NYX 0:85b3fd62ea1a 133 */
NYX 0:85b3fd62ea1a 134
NYX 0:85b3fd62ea1a 135 /** @defgroup IRDA IRDA
NYX 0:85b3fd62ea1a 136 * @brief HAL IRDA module driver
NYX 0:85b3fd62ea1a 137 * @{
NYX 0:85b3fd62ea1a 138 */
NYX 0:85b3fd62ea1a 139
NYX 0:85b3fd62ea1a 140 #ifdef HAL_IRDA_MODULE_ENABLED
NYX 0:85b3fd62ea1a 141
NYX 0:85b3fd62ea1a 142 /* Private typedef -----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 143 /* Private define ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 144 /** @addtogroup IRDA_Private_Constants
NYX 0:85b3fd62ea1a 145 * @{
NYX 0:85b3fd62ea1a 146 */
NYX 0:85b3fd62ea1a 147 /**
NYX 0:85b3fd62ea1a 148 * @}
NYX 0:85b3fd62ea1a 149 */
NYX 0:85b3fd62ea1a 150 /* Private macro -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 151 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 152 /* Private function prototypes -----------------------------------------------*/
NYX 0:85b3fd62ea1a 153 /** @addtogroup IRDA_Private_Functions
NYX 0:85b3fd62ea1a 154 * @{
NYX 0:85b3fd62ea1a 155 */
NYX 0:85b3fd62ea1a 156 static void IRDA_SetConfig (IRDA_HandleTypeDef *hirda);
NYX 0:85b3fd62ea1a 157 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
NYX 0:85b3fd62ea1a 158 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
NYX 0:85b3fd62ea1a 159 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
NYX 0:85b3fd62ea1a 160 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 161 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 162 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 163 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 164 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 165 static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 166 static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 167 static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 168 static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 169 static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 170 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart,uint32_t Timeout);
NYX 0:85b3fd62ea1a 171 static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda);
NYX 0:85b3fd62ea1a 172 static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda);
NYX 0:85b3fd62ea1a 173 /**
NYX 0:85b3fd62ea1a 174 * @}
NYX 0:85b3fd62ea1a 175 */
NYX 0:85b3fd62ea1a 176 /* Exported functions --------------------------------------------------------*/
NYX 0:85b3fd62ea1a 177 /** @defgroup IRDA_Exported_Functions IrDA Exported Functions
NYX 0:85b3fd62ea1a 178 * @{
NYX 0:85b3fd62ea1a 179 */
NYX 0:85b3fd62ea1a 180
NYX 0:85b3fd62ea1a 181 /** @defgroup IRDA_Exported_Functions_Group1 IrDA Initialization and de-initialization functions
NYX 0:85b3fd62ea1a 182 * @brief Initialization and Configuration functions
NYX 0:85b3fd62ea1a 183 *
NYX 0:85b3fd62ea1a 184 @verbatim
NYX 0:85b3fd62ea1a 185
NYX 0:85b3fd62ea1a 186 ===============================================================================
NYX 0:85b3fd62ea1a 187 ##### Initialization and Configuration functions #####
NYX 0:85b3fd62ea1a 188 ===============================================================================
NYX 0:85b3fd62ea1a 189 [..]
NYX 0:85b3fd62ea1a 190 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
NYX 0:85b3fd62ea1a 191 in IrDA mode.
NYX 0:85b3fd62ea1a 192 (+) For the asynchronous mode only these parameters can be configured:
NYX 0:85b3fd62ea1a 193 (++) BaudRate
NYX 0:85b3fd62ea1a 194 (++) WordLength
NYX 0:85b3fd62ea1a 195 (++) Parity: If the parity is enabled, then the MSB bit of the data written
NYX 0:85b3fd62ea1a 196 in the data register is transmitted but is changed by the parity bit.
NYX 0:85b3fd62ea1a 197 Depending on the frame length defined by the M bit (8-bits or 9-bits),
NYX 0:85b3fd62ea1a 198 please refer to Reference manual for possible IRDA frame formats.
NYX 0:85b3fd62ea1a 199 (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
NYX 0:85b3fd62ea1a 200 not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
NYX 0:85b3fd62ea1a 201 specification specifies a minimum of 10 ms delay between transmission and
NYX 0:85b3fd62ea1a 202 reception (IrDA is a half duplex protocol).
NYX 0:85b3fd62ea1a 203 (++) Mode: Receiver/transmitter modes
NYX 0:85b3fd62ea1a 204 (++) IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode.
NYX 0:85b3fd62ea1a 205 [..]
NYX 0:85b3fd62ea1a 206 The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures
NYX 0:85b3fd62ea1a 207 are available in reference manual).
NYX 0:85b3fd62ea1a 208
NYX 0:85b3fd62ea1a 209 @endverbatim
NYX 0:85b3fd62ea1a 210 * @{
NYX 0:85b3fd62ea1a 211 */
NYX 0:85b3fd62ea1a 212
NYX 0:85b3fd62ea1a 213 /**
NYX 0:85b3fd62ea1a 214 * @brief Initializes the IRDA mode according to the specified
NYX 0:85b3fd62ea1a 215 * parameters in the IRDA_InitTypeDef and create the associated handle.
NYX 0:85b3fd62ea1a 216 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 217 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 218 * @retval HAL status
NYX 0:85b3fd62ea1a 219 */
NYX 0:85b3fd62ea1a 220 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 221 {
NYX 0:85b3fd62ea1a 222 /* Check the IRDA handle allocation */
NYX 0:85b3fd62ea1a 223 if(hirda == NULL)
NYX 0:85b3fd62ea1a 224 {
NYX 0:85b3fd62ea1a 225 return HAL_ERROR;
NYX 0:85b3fd62ea1a 226 }
NYX 0:85b3fd62ea1a 227
NYX 0:85b3fd62ea1a 228 /* Check the IRDA instance parameters */
NYX 0:85b3fd62ea1a 229 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
NYX 0:85b3fd62ea1a 230 /* Check the IRDA mode parameter in the IRDA handle */
NYX 0:85b3fd62ea1a 231 assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
NYX 0:85b3fd62ea1a 232
NYX 0:85b3fd62ea1a 233 if(hirda->gState == HAL_IRDA_STATE_RESET)
NYX 0:85b3fd62ea1a 234 {
NYX 0:85b3fd62ea1a 235 /* Allocate lock resource and initialize it */
NYX 0:85b3fd62ea1a 236 hirda->Lock = HAL_UNLOCKED;
NYX 0:85b3fd62ea1a 237 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
NYX 0:85b3fd62ea1a 238 HAL_IRDA_MspInit(hirda);
NYX 0:85b3fd62ea1a 239 }
NYX 0:85b3fd62ea1a 240
NYX 0:85b3fd62ea1a 241 hirda->gState = HAL_IRDA_STATE_BUSY;
NYX 0:85b3fd62ea1a 242
NYX 0:85b3fd62ea1a 243 /* Disable the IRDA peripheral */
NYX 0:85b3fd62ea1a 244 __HAL_IRDA_DISABLE(hirda);
NYX 0:85b3fd62ea1a 245
NYX 0:85b3fd62ea1a 246 /* Set the IRDA communication parameters */
NYX 0:85b3fd62ea1a 247 IRDA_SetConfig(hirda);
NYX 0:85b3fd62ea1a 248
NYX 0:85b3fd62ea1a 249 /* In IrDA mode, the following bits must be kept cleared:
NYX 0:85b3fd62ea1a 250 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
NYX 0:85b3fd62ea1a 251 - SCEN and HDSEL bits in the USART_CR3 register.*/
NYX 0:85b3fd62ea1a 252 CLEAR_BIT(hirda->Instance->CR2, USART_CR2_LINEN | USART_CR2_STOP | USART_CR2_CLKEN);
NYX 0:85b3fd62ea1a 253 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_SCEN | USART_CR3_HDSEL);
NYX 0:85b3fd62ea1a 254
NYX 0:85b3fd62ea1a 255 /* Enable the IRDA peripheral */
NYX 0:85b3fd62ea1a 256 __HAL_IRDA_ENABLE(hirda);
NYX 0:85b3fd62ea1a 257
NYX 0:85b3fd62ea1a 258 /* Set the prescaler */
NYX 0:85b3fd62ea1a 259 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
NYX 0:85b3fd62ea1a 260
NYX 0:85b3fd62ea1a 261 /* Configure the IrDA mode */
NYX 0:85b3fd62ea1a 262 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.IrDAMode);
NYX 0:85b3fd62ea1a 263
NYX 0:85b3fd62ea1a 264 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
NYX 0:85b3fd62ea1a 265 SET_BIT(hirda->Instance->CR3, USART_CR3_IREN);
NYX 0:85b3fd62ea1a 266
NYX 0:85b3fd62ea1a 267 /* Initialize the IRDA state*/
NYX 0:85b3fd62ea1a 268 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 269 hirda->gState= HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 270 hirda->RxState= HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 271
NYX 0:85b3fd62ea1a 272 return HAL_OK;
NYX 0:85b3fd62ea1a 273 }
NYX 0:85b3fd62ea1a 274
NYX 0:85b3fd62ea1a 275 /**
NYX 0:85b3fd62ea1a 276 * @brief DeInitializes the IRDA peripheral
NYX 0:85b3fd62ea1a 277 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 278 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 279 * @retval HAL status
NYX 0:85b3fd62ea1a 280 */
NYX 0:85b3fd62ea1a 281 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 282 {
NYX 0:85b3fd62ea1a 283 /* Check the IRDA handle allocation */
NYX 0:85b3fd62ea1a 284 if(hirda == NULL)
NYX 0:85b3fd62ea1a 285 {
NYX 0:85b3fd62ea1a 286 return HAL_ERROR;
NYX 0:85b3fd62ea1a 287 }
NYX 0:85b3fd62ea1a 288
NYX 0:85b3fd62ea1a 289 /* Check the parameters */
NYX 0:85b3fd62ea1a 290 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
NYX 0:85b3fd62ea1a 291
NYX 0:85b3fd62ea1a 292 hirda->gState = HAL_IRDA_STATE_BUSY;
NYX 0:85b3fd62ea1a 293
NYX 0:85b3fd62ea1a 294 /* Disable the Peripheral */
NYX 0:85b3fd62ea1a 295 __HAL_IRDA_DISABLE(hirda);
NYX 0:85b3fd62ea1a 296
NYX 0:85b3fd62ea1a 297 /* DeInit the low level hardware */
NYX 0:85b3fd62ea1a 298 HAL_IRDA_MspDeInit(hirda);
NYX 0:85b3fd62ea1a 299
NYX 0:85b3fd62ea1a 300 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 301
NYX 0:85b3fd62ea1a 302 hirda->gState = HAL_IRDA_STATE_RESET;
NYX 0:85b3fd62ea1a 303 hirda->RxState = HAL_IRDA_STATE_RESET;
NYX 0:85b3fd62ea1a 304
NYX 0:85b3fd62ea1a 305 /* Release Lock */
NYX 0:85b3fd62ea1a 306 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 307
NYX 0:85b3fd62ea1a 308 return HAL_OK;
NYX 0:85b3fd62ea1a 309 }
NYX 0:85b3fd62ea1a 310
NYX 0:85b3fd62ea1a 311 /**
NYX 0:85b3fd62ea1a 312 * @brief IRDA MSP Init.
NYX 0:85b3fd62ea1a 313 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 314 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 315 * @retval None
NYX 0:85b3fd62ea1a 316 */
NYX 0:85b3fd62ea1a 317 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 318 {
NYX 0:85b3fd62ea1a 319 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 320 UNUSED(hirda);
NYX 0:85b3fd62ea1a 321 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 322 the HAL_IRDA_MspInit could be implemented in the user file
NYX 0:85b3fd62ea1a 323 */
NYX 0:85b3fd62ea1a 324 }
NYX 0:85b3fd62ea1a 325
NYX 0:85b3fd62ea1a 326 /**
NYX 0:85b3fd62ea1a 327 * @brief IRDA MSP DeInit.
NYX 0:85b3fd62ea1a 328 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 329 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 330 * @retval None
NYX 0:85b3fd62ea1a 331 */
NYX 0:85b3fd62ea1a 332 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 333 {
NYX 0:85b3fd62ea1a 334 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 335 UNUSED(hirda);
NYX 0:85b3fd62ea1a 336 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 337 the HAL_IRDA_MspDeInit could be implemented in the user file
NYX 0:85b3fd62ea1a 338 */
NYX 0:85b3fd62ea1a 339 }
NYX 0:85b3fd62ea1a 340
NYX 0:85b3fd62ea1a 341 /**
NYX 0:85b3fd62ea1a 342 * @}
NYX 0:85b3fd62ea1a 343 */
NYX 0:85b3fd62ea1a 344
NYX 0:85b3fd62ea1a 345 /** @defgroup IRDA_Exported_Functions_Group2 IO operation functions
NYX 0:85b3fd62ea1a 346 * @brief IRDA Transmit/Receive functions
NYX 0:85b3fd62ea1a 347 *
NYX 0:85b3fd62ea1a 348 @verbatim
NYX 0:85b3fd62ea1a 349 ===============================================================================
NYX 0:85b3fd62ea1a 350 ##### IO operation functions #####
NYX 0:85b3fd62ea1a 351 ===============================================================================
NYX 0:85b3fd62ea1a 352 This subsection provides a set of functions allowing to manage the IRDA data transfers.
NYX 0:85b3fd62ea1a 353 [..]
NYX 0:85b3fd62ea1a 354 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
NYX 0:85b3fd62ea1a 355 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
NYX 0:85b3fd62ea1a 356 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
NYX 0:85b3fd62ea1a 357 While receiving data, transmission should be avoided as the data to be transmitted
NYX 0:85b3fd62ea1a 358 could be corrupted.
NYX 0:85b3fd62ea1a 359
NYX 0:85b3fd62ea1a 360 (#) There are two modes of transfer:
NYX 0:85b3fd62ea1a 361 (++) Blocking mode: The communication is performed in polling mode.
NYX 0:85b3fd62ea1a 362 The HAL status of all data processing is returned by the same function
NYX 0:85b3fd62ea1a 363 after finishing transfer.
NYX 0:85b3fd62ea1a 364 (++) No-Blocking mode: The communication is performed using Interrupts
NYX 0:85b3fd62ea1a 365 or DMA, These APIs return the HAL status.
NYX 0:85b3fd62ea1a 366 The end of the data processing will be indicated through the
NYX 0:85b3fd62ea1a 367 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
NYX 0:85b3fd62ea1a 368 using DMA mode.
NYX 0:85b3fd62ea1a 369 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
NYX 0:85b3fd62ea1a 370 will be executed respectively at the end of the transmit or Receive process
NYX 0:85b3fd62ea1a 371 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
NYX 0:85b3fd62ea1a 372
NYX 0:85b3fd62ea1a 373 (#) Blocking mode API's are :
NYX 0:85b3fd62ea1a 374 (++) HAL_IRDA_Transmit()
NYX 0:85b3fd62ea1a 375 (++) HAL_IRDA_Receive()
NYX 0:85b3fd62ea1a 376
NYX 0:85b3fd62ea1a 377 (#) Non Blocking mode APIs with Interrupt are :
NYX 0:85b3fd62ea1a 378 (++) HAL_IRDA_Transmit_IT()
NYX 0:85b3fd62ea1a 379 (++) HAL_IRDA_Receive_IT()
NYX 0:85b3fd62ea1a 380 (++) HAL_IRDA_IRQHandler()
NYX 0:85b3fd62ea1a 381
NYX 0:85b3fd62ea1a 382 (#) Non Blocking mode functions with DMA are :
NYX 0:85b3fd62ea1a 383 (++) HAL_IRDA_Transmit_DMA()
NYX 0:85b3fd62ea1a 384 (++) HAL_IRDA_Receive_DMA()
NYX 0:85b3fd62ea1a 385
NYX 0:85b3fd62ea1a 386 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
NYX 0:85b3fd62ea1a 387 (++) HAL_IRDA_TxCpltCallback()
NYX 0:85b3fd62ea1a 388 (++) HAL_IRDA_RxCpltCallback()
NYX 0:85b3fd62ea1a 389 (++) HAL_IRDA_ErrorCallback()
NYX 0:85b3fd62ea1a 390
NYX 0:85b3fd62ea1a 391 @endverbatim
NYX 0:85b3fd62ea1a 392 * @{
NYX 0:85b3fd62ea1a 393 */
NYX 0:85b3fd62ea1a 394
NYX 0:85b3fd62ea1a 395 /**
NYX 0:85b3fd62ea1a 396 * @brief Sends an amount of data in blocking mode.
NYX 0:85b3fd62ea1a 397 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 398 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 399 * @param pData: Pointer to data buffer
NYX 0:85b3fd62ea1a 400 * @param Size: Amount of data to be sent
NYX 0:85b3fd62ea1a 401 * @param Timeout: Specify timeout value
NYX 0:85b3fd62ea1a 402 * @retval HAL status
NYX 0:85b3fd62ea1a 403 */
NYX 0:85b3fd62ea1a 404 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
NYX 0:85b3fd62ea1a 405 {
NYX 0:85b3fd62ea1a 406 uint16_t* tmp;
NYX 0:85b3fd62ea1a 407 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 408
NYX 0:85b3fd62ea1a 409 /* Check that a Tx process is not already ongoing */
NYX 0:85b3fd62ea1a 410 if(hirda->gState == HAL_IRDA_STATE_READY)
NYX 0:85b3fd62ea1a 411 {
NYX 0:85b3fd62ea1a 412 if((pData == NULL) || (Size == 0))
NYX 0:85b3fd62ea1a 413 {
NYX 0:85b3fd62ea1a 414 return HAL_ERROR;
NYX 0:85b3fd62ea1a 415 }
NYX 0:85b3fd62ea1a 416
NYX 0:85b3fd62ea1a 417 /* Process Locked */
NYX 0:85b3fd62ea1a 418 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 419
NYX 0:85b3fd62ea1a 420 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 421 hirda->gState = HAL_IRDA_STATE_BUSY_TX;
NYX 0:85b3fd62ea1a 422
NYX 0:85b3fd62ea1a 423 /* Init tickstart for timeout managment*/
NYX 0:85b3fd62ea1a 424 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 425
NYX 0:85b3fd62ea1a 426 hirda->TxXferSize = Size;
NYX 0:85b3fd62ea1a 427 hirda->TxXferCount = Size;
NYX 0:85b3fd62ea1a 428 while(hirda->TxXferCount > 0U)
NYX 0:85b3fd62ea1a 429 {
NYX 0:85b3fd62ea1a 430 hirda->TxXferCount--;
NYX 0:85b3fd62ea1a 431 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
NYX 0:85b3fd62ea1a 432 {
NYX 0:85b3fd62ea1a 433 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 434 {
NYX 0:85b3fd62ea1a 435 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 436 }
NYX 0:85b3fd62ea1a 437 tmp = (uint16_t*) pData;
NYX 0:85b3fd62ea1a 438 hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
NYX 0:85b3fd62ea1a 439 if(hirda->Init.Parity == IRDA_PARITY_NONE)
NYX 0:85b3fd62ea1a 440 {
NYX 0:85b3fd62ea1a 441 pData +=2;
NYX 0:85b3fd62ea1a 442 }
NYX 0:85b3fd62ea1a 443 else
NYX 0:85b3fd62ea1a 444 {
NYX 0:85b3fd62ea1a 445 pData +=1;
NYX 0:85b3fd62ea1a 446 }
NYX 0:85b3fd62ea1a 447 }
NYX 0:85b3fd62ea1a 448 else
NYX 0:85b3fd62ea1a 449 {
NYX 0:85b3fd62ea1a 450 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 451 {
NYX 0:85b3fd62ea1a 452 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 453 }
NYX 0:85b3fd62ea1a 454 hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
NYX 0:85b3fd62ea1a 455 }
NYX 0:85b3fd62ea1a 456 }
NYX 0:85b3fd62ea1a 457
NYX 0:85b3fd62ea1a 458 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 459 {
NYX 0:85b3fd62ea1a 460 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 461 }
NYX 0:85b3fd62ea1a 462
NYX 0:85b3fd62ea1a 463 /* At end of Tx process, restore hirda->gState to Ready */
NYX 0:85b3fd62ea1a 464 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 465
NYX 0:85b3fd62ea1a 466 /* Process Unlocked */
NYX 0:85b3fd62ea1a 467 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 468
NYX 0:85b3fd62ea1a 469 return HAL_OK;
NYX 0:85b3fd62ea1a 470 }
NYX 0:85b3fd62ea1a 471 else
NYX 0:85b3fd62ea1a 472 {
NYX 0:85b3fd62ea1a 473 return HAL_BUSY;
NYX 0:85b3fd62ea1a 474 }
NYX 0:85b3fd62ea1a 475 }
NYX 0:85b3fd62ea1a 476
NYX 0:85b3fd62ea1a 477 /**
NYX 0:85b3fd62ea1a 478 * @brief Receive an amount of data in blocking mode.
NYX 0:85b3fd62ea1a 479 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 480 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 481 * @param pData: Pointer to data buffer
NYX 0:85b3fd62ea1a 482 * @param Size: Amount of data to be received
NYX 0:85b3fd62ea1a 483 * @param Timeout: Specify timeout value
NYX 0:85b3fd62ea1a 484 * @retval HAL status
NYX 0:85b3fd62ea1a 485 */
NYX 0:85b3fd62ea1a 486 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
NYX 0:85b3fd62ea1a 487 {
NYX 0:85b3fd62ea1a 488 uint16_t* tmp;
NYX 0:85b3fd62ea1a 489 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 490
NYX 0:85b3fd62ea1a 491 /* Check that a Rx process is not already ongoing */
NYX 0:85b3fd62ea1a 492 if(hirda->RxState == HAL_IRDA_STATE_READY)
NYX 0:85b3fd62ea1a 493 {
NYX 0:85b3fd62ea1a 494 if((pData == NULL) || (Size == 0))
NYX 0:85b3fd62ea1a 495 {
NYX 0:85b3fd62ea1a 496 return HAL_ERROR;
NYX 0:85b3fd62ea1a 497 }
NYX 0:85b3fd62ea1a 498
NYX 0:85b3fd62ea1a 499 /* Process Locked */
NYX 0:85b3fd62ea1a 500 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 501
NYX 0:85b3fd62ea1a 502 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 503 hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
NYX 0:85b3fd62ea1a 504
NYX 0:85b3fd62ea1a 505 /* Init tickstart for timeout managment*/
NYX 0:85b3fd62ea1a 506 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 507
NYX 0:85b3fd62ea1a 508 hirda->RxXferSize = Size;
NYX 0:85b3fd62ea1a 509 hirda->RxXferCount = Size;
NYX 0:85b3fd62ea1a 510 /* Check the remain data to be received */
NYX 0:85b3fd62ea1a 511 while(hirda->RxXferCount > 0U)
NYX 0:85b3fd62ea1a 512 {
NYX 0:85b3fd62ea1a 513 hirda->RxXferCount--;
NYX 0:85b3fd62ea1a 514 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
NYX 0:85b3fd62ea1a 515 {
NYX 0:85b3fd62ea1a 516 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 517 {
NYX 0:85b3fd62ea1a 518 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 519 }
NYX 0:85b3fd62ea1a 520 tmp = (uint16_t*) pData ;
NYX 0:85b3fd62ea1a 521 if(hirda->Init.Parity == IRDA_PARITY_NONE)
NYX 0:85b3fd62ea1a 522 {
NYX 0:85b3fd62ea1a 523 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
NYX 0:85b3fd62ea1a 524 pData +=2;
NYX 0:85b3fd62ea1a 525 }
NYX 0:85b3fd62ea1a 526 else
NYX 0:85b3fd62ea1a 527 {
NYX 0:85b3fd62ea1a 528 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
NYX 0:85b3fd62ea1a 529 pData +=1;
NYX 0:85b3fd62ea1a 530 }
NYX 0:85b3fd62ea1a 531 }
NYX 0:85b3fd62ea1a 532 else
NYX 0:85b3fd62ea1a 533 {
NYX 0:85b3fd62ea1a 534 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 535 {
NYX 0:85b3fd62ea1a 536 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 537 }
NYX 0:85b3fd62ea1a 538 if(hirda->Init.Parity == IRDA_PARITY_NONE)
NYX 0:85b3fd62ea1a 539 {
NYX 0:85b3fd62ea1a 540 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
NYX 0:85b3fd62ea1a 541 }
NYX 0:85b3fd62ea1a 542 else
NYX 0:85b3fd62ea1a 543 {
NYX 0:85b3fd62ea1a 544 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
NYX 0:85b3fd62ea1a 545 }
NYX 0:85b3fd62ea1a 546 }
NYX 0:85b3fd62ea1a 547 }
NYX 0:85b3fd62ea1a 548
NYX 0:85b3fd62ea1a 549 /* At end of Rx process, restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 550 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 551
NYX 0:85b3fd62ea1a 552 /* Process Unlocked */
NYX 0:85b3fd62ea1a 553 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 554
NYX 0:85b3fd62ea1a 555 return HAL_OK;
NYX 0:85b3fd62ea1a 556 }
NYX 0:85b3fd62ea1a 557 else
NYX 0:85b3fd62ea1a 558 {
NYX 0:85b3fd62ea1a 559 return HAL_BUSY;
NYX 0:85b3fd62ea1a 560 }
NYX 0:85b3fd62ea1a 561 }
NYX 0:85b3fd62ea1a 562
NYX 0:85b3fd62ea1a 563 /**
NYX 0:85b3fd62ea1a 564 * @brief Send an amount of data in non blocking mode.
NYX 0:85b3fd62ea1a 565 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 566 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 567 * @param pData: Pointer to data buffer
NYX 0:85b3fd62ea1a 568 * @param Size: Amount of data to be sent
NYX 0:85b3fd62ea1a 569 * @retval HAL status
NYX 0:85b3fd62ea1a 570 */
NYX 0:85b3fd62ea1a 571 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
NYX 0:85b3fd62ea1a 572 {
NYX 0:85b3fd62ea1a 573 /* Check that a Tx process is not already ongoing */
NYX 0:85b3fd62ea1a 574 if(hirda->gState == HAL_IRDA_STATE_READY)
NYX 0:85b3fd62ea1a 575 {
NYX 0:85b3fd62ea1a 576 if((pData == NULL) || (Size == 0))
NYX 0:85b3fd62ea1a 577 {
NYX 0:85b3fd62ea1a 578 return HAL_ERROR;
NYX 0:85b3fd62ea1a 579 }
NYX 0:85b3fd62ea1a 580 /* Process Locked */
NYX 0:85b3fd62ea1a 581 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 582
NYX 0:85b3fd62ea1a 583 hirda->pTxBuffPtr = pData;
NYX 0:85b3fd62ea1a 584 hirda->TxXferSize = Size;
NYX 0:85b3fd62ea1a 585 hirda->TxXferCount = Size;
NYX 0:85b3fd62ea1a 586 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 587 hirda->gState = HAL_IRDA_STATE_BUSY_TX;
NYX 0:85b3fd62ea1a 588
NYX 0:85b3fd62ea1a 589 /* Process Unlocked */
NYX 0:85b3fd62ea1a 590 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 591
NYX 0:85b3fd62ea1a 592 /* Enable the IRDA Transmit Data Register Empty Interrupt */
NYX 0:85b3fd62ea1a 593 SET_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
NYX 0:85b3fd62ea1a 594
NYX 0:85b3fd62ea1a 595 return HAL_OK;
NYX 0:85b3fd62ea1a 596 }
NYX 0:85b3fd62ea1a 597 else
NYX 0:85b3fd62ea1a 598 {
NYX 0:85b3fd62ea1a 599 return HAL_BUSY;
NYX 0:85b3fd62ea1a 600 }
NYX 0:85b3fd62ea1a 601 }
NYX 0:85b3fd62ea1a 602
NYX 0:85b3fd62ea1a 603 /**
NYX 0:85b3fd62ea1a 604 * @brief Receives an amount of data in non blocking mode.
NYX 0:85b3fd62ea1a 605 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 606 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 607 * @param pData: Pointer to data buffer
NYX 0:85b3fd62ea1a 608 * @param Size: Amount of data to be received
NYX 0:85b3fd62ea1a 609 * @retval HAL status
NYX 0:85b3fd62ea1a 610 */
NYX 0:85b3fd62ea1a 611 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
NYX 0:85b3fd62ea1a 612 {
NYX 0:85b3fd62ea1a 613 /* Check that a Rx process is not already ongoing */
NYX 0:85b3fd62ea1a 614 if(hirda->RxState == HAL_IRDA_STATE_READY)
NYX 0:85b3fd62ea1a 615 {
NYX 0:85b3fd62ea1a 616 if((pData == NULL) || (Size == 0))
NYX 0:85b3fd62ea1a 617 {
NYX 0:85b3fd62ea1a 618 return HAL_ERROR;
NYX 0:85b3fd62ea1a 619 }
NYX 0:85b3fd62ea1a 620
NYX 0:85b3fd62ea1a 621 /* Process Locked */
NYX 0:85b3fd62ea1a 622 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 623
NYX 0:85b3fd62ea1a 624 hirda->pRxBuffPtr = pData;
NYX 0:85b3fd62ea1a 625 hirda->RxXferSize = Size;
NYX 0:85b3fd62ea1a 626 hirda->RxXferCount = Size;
NYX 0:85b3fd62ea1a 627 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 628 hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
NYX 0:85b3fd62ea1a 629
NYX 0:85b3fd62ea1a 630 /* Process Unlocked */
NYX 0:85b3fd62ea1a 631 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 632
NYX 0:85b3fd62ea1a 633 /* Enable the IRDA Parity Error and Data Register not empty Interrupts */
NYX 0:85b3fd62ea1a 634 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE| USART_CR1_RXNEIE);
NYX 0:85b3fd62ea1a 635
NYX 0:85b3fd62ea1a 636 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
NYX 0:85b3fd62ea1a 637 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 638
NYX 0:85b3fd62ea1a 639 return HAL_OK;
NYX 0:85b3fd62ea1a 640 }
NYX 0:85b3fd62ea1a 641 else
NYX 0:85b3fd62ea1a 642 {
NYX 0:85b3fd62ea1a 643 return HAL_BUSY;
NYX 0:85b3fd62ea1a 644 }
NYX 0:85b3fd62ea1a 645 }
NYX 0:85b3fd62ea1a 646
NYX 0:85b3fd62ea1a 647 /**
NYX 0:85b3fd62ea1a 648 * @brief Sends an amount of data in non blocking mode.
NYX 0:85b3fd62ea1a 649 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 650 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 651 * @param pData: Pointer to data buffer
NYX 0:85b3fd62ea1a 652 * @param Size: Amount of data to be sent
NYX 0:85b3fd62ea1a 653 * @retval HAL status
NYX 0:85b3fd62ea1a 654 */
NYX 0:85b3fd62ea1a 655 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
NYX 0:85b3fd62ea1a 656 {
NYX 0:85b3fd62ea1a 657 uint32_t *tmp;
NYX 0:85b3fd62ea1a 658
NYX 0:85b3fd62ea1a 659 /* Check that a Tx process is not already ongoing */
NYX 0:85b3fd62ea1a 660 if(hirda->gState == HAL_IRDA_STATE_READY)
NYX 0:85b3fd62ea1a 661 {
NYX 0:85b3fd62ea1a 662 if((pData == NULL) || (Size == 0))
NYX 0:85b3fd62ea1a 663 {
NYX 0:85b3fd62ea1a 664 return HAL_ERROR;
NYX 0:85b3fd62ea1a 665 }
NYX 0:85b3fd62ea1a 666
NYX 0:85b3fd62ea1a 667 /* Process Locked */
NYX 0:85b3fd62ea1a 668 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 669
NYX 0:85b3fd62ea1a 670 hirda->pTxBuffPtr = pData;
NYX 0:85b3fd62ea1a 671 hirda->TxXferSize = Size;
NYX 0:85b3fd62ea1a 672 hirda->TxXferCount = Size;
NYX 0:85b3fd62ea1a 673 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 674 hirda->gState = HAL_IRDA_STATE_BUSY_TX;
NYX 0:85b3fd62ea1a 675
NYX 0:85b3fd62ea1a 676 /* Set the IRDA DMA transfer complete callback */
NYX 0:85b3fd62ea1a 677 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
NYX 0:85b3fd62ea1a 678
NYX 0:85b3fd62ea1a 679 /* Set the IRDA DMA half transfer complete callback */
NYX 0:85b3fd62ea1a 680 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
NYX 0:85b3fd62ea1a 681
NYX 0:85b3fd62ea1a 682 /* Set the DMA error callback */
NYX 0:85b3fd62ea1a 683 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
NYX 0:85b3fd62ea1a 684
NYX 0:85b3fd62ea1a 685 /* Set the DMA abort callback */
NYX 0:85b3fd62ea1a 686 hirda->hdmatx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 687
NYX 0:85b3fd62ea1a 688 /* Enable the IRDA transmit DMA Stream */
NYX 0:85b3fd62ea1a 689 tmp = (uint32_t*)&pData;
NYX 0:85b3fd62ea1a 690 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->DR, Size);
NYX 0:85b3fd62ea1a 691
NYX 0:85b3fd62ea1a 692 /* Clear the TC flag in the SR register by writing 0 to it */
NYX 0:85b3fd62ea1a 693 __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_FLAG_TC);
NYX 0:85b3fd62ea1a 694
NYX 0:85b3fd62ea1a 695 /* Process Unlocked */
NYX 0:85b3fd62ea1a 696 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 697
NYX 0:85b3fd62ea1a 698 /* Enable the DMA transfer for transmit request by setting the DMAT bit
NYX 0:85b3fd62ea1a 699 in the USART CR3 register */
NYX 0:85b3fd62ea1a 700 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 701
NYX 0:85b3fd62ea1a 702 return HAL_OK;
NYX 0:85b3fd62ea1a 703 }
NYX 0:85b3fd62ea1a 704 else
NYX 0:85b3fd62ea1a 705 {
NYX 0:85b3fd62ea1a 706 return HAL_BUSY;
NYX 0:85b3fd62ea1a 707 }
NYX 0:85b3fd62ea1a 708 }
NYX 0:85b3fd62ea1a 709
NYX 0:85b3fd62ea1a 710 /**
NYX 0:85b3fd62ea1a 711 * @brief Receives an amount of data in non blocking mode.
NYX 0:85b3fd62ea1a 712 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 713 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 714 * @param pData: Pointer to data buffer
NYX 0:85b3fd62ea1a 715 * @param Size: Amount of data to be received
NYX 0:85b3fd62ea1a 716 * @note When the IRDA parity is enabled (PCE = 1) the data received contain the parity bit.
NYX 0:85b3fd62ea1a 717 * @retval HAL status
NYX 0:85b3fd62ea1a 718 */
NYX 0:85b3fd62ea1a 719 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
NYX 0:85b3fd62ea1a 720 {
NYX 0:85b3fd62ea1a 721 uint32_t *tmp;
NYX 0:85b3fd62ea1a 722
NYX 0:85b3fd62ea1a 723 /* Check that a Rx process is not already ongoing */
NYX 0:85b3fd62ea1a 724 if(hirda->RxState == HAL_IRDA_STATE_READY)
NYX 0:85b3fd62ea1a 725 {
NYX 0:85b3fd62ea1a 726 if((pData == NULL) || (Size == 0))
NYX 0:85b3fd62ea1a 727 {
NYX 0:85b3fd62ea1a 728 return HAL_ERROR;
NYX 0:85b3fd62ea1a 729 }
NYX 0:85b3fd62ea1a 730
NYX 0:85b3fd62ea1a 731 /* Process Locked */
NYX 0:85b3fd62ea1a 732 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 733
NYX 0:85b3fd62ea1a 734 hirda->pRxBuffPtr = pData;
NYX 0:85b3fd62ea1a 735 hirda->RxXferSize = Size;
NYX 0:85b3fd62ea1a 736 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 737 hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
NYX 0:85b3fd62ea1a 738
NYX 0:85b3fd62ea1a 739 /* Set the IRDA DMA transfer complete callback */
NYX 0:85b3fd62ea1a 740 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
NYX 0:85b3fd62ea1a 741
NYX 0:85b3fd62ea1a 742 /* Set the IRDA DMA half transfer complete callback */
NYX 0:85b3fd62ea1a 743 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
NYX 0:85b3fd62ea1a 744
NYX 0:85b3fd62ea1a 745 /* Set the DMA error callback */
NYX 0:85b3fd62ea1a 746 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
NYX 0:85b3fd62ea1a 747
NYX 0:85b3fd62ea1a 748 /* Set the DMA abort callback */
NYX 0:85b3fd62ea1a 749 hirda->hdmarx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 750
NYX 0:85b3fd62ea1a 751 /* Enable the DMA Stream */
NYX 0:85b3fd62ea1a 752 tmp = (uint32_t*)&pData;
NYX 0:85b3fd62ea1a 753 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t*)tmp, Size);
NYX 0:85b3fd62ea1a 754
NYX 0:85b3fd62ea1a 755 /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
NYX 0:85b3fd62ea1a 756 __HAL_IRDA_CLEAR_OREFLAG(hirda);
NYX 0:85b3fd62ea1a 757
NYX 0:85b3fd62ea1a 758 /* Process Unlocked */
NYX 0:85b3fd62ea1a 759 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 760
NYX 0:85b3fd62ea1a 761 /* Enable the IRDA Parity Error Interrupt */
NYX 0:85b3fd62ea1a 762 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
NYX 0:85b3fd62ea1a 763
NYX 0:85b3fd62ea1a 764 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
NYX 0:85b3fd62ea1a 765 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 766
NYX 0:85b3fd62ea1a 767 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
NYX 0:85b3fd62ea1a 768 in the USART CR3 register */
NYX 0:85b3fd62ea1a 769 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 770
NYX 0:85b3fd62ea1a 771 return HAL_OK;
NYX 0:85b3fd62ea1a 772 }
NYX 0:85b3fd62ea1a 773 else
NYX 0:85b3fd62ea1a 774 {
NYX 0:85b3fd62ea1a 775 return HAL_BUSY;
NYX 0:85b3fd62ea1a 776 }
NYX 0:85b3fd62ea1a 777 }
NYX 0:85b3fd62ea1a 778
NYX 0:85b3fd62ea1a 779 /**
NYX 0:85b3fd62ea1a 780 * @brief Pauses the DMA Transfer.
NYX 0:85b3fd62ea1a 781 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 782 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 783 * @retval HAL status
NYX 0:85b3fd62ea1a 784 */
NYX 0:85b3fd62ea1a 785 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 786 {
NYX 0:85b3fd62ea1a 787 uint32_t dmarequest = 0x00U;
NYX 0:85b3fd62ea1a 788
NYX 0:85b3fd62ea1a 789 /* Process Locked */
NYX 0:85b3fd62ea1a 790 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 791
NYX 0:85b3fd62ea1a 792 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 793 if((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
NYX 0:85b3fd62ea1a 794 {
NYX 0:85b3fd62ea1a 795 /* Disable the IRDA DMA Tx request */
NYX 0:85b3fd62ea1a 796 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 797 }
NYX 0:85b3fd62ea1a 798
NYX 0:85b3fd62ea1a 799 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 800 if((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
NYX 0:85b3fd62ea1a 801 {
NYX 0:85b3fd62ea1a 802 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 803 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
NYX 0:85b3fd62ea1a 804 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 805
NYX 0:85b3fd62ea1a 806 /* Disable the IRDA DMA Rx request */
NYX 0:85b3fd62ea1a 807 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 808 }
NYX 0:85b3fd62ea1a 809
NYX 0:85b3fd62ea1a 810 /* Process Unlocked */
NYX 0:85b3fd62ea1a 811 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 812
NYX 0:85b3fd62ea1a 813 return HAL_OK;
NYX 0:85b3fd62ea1a 814 }
NYX 0:85b3fd62ea1a 815
NYX 0:85b3fd62ea1a 816 /**
NYX 0:85b3fd62ea1a 817 * @brief Resumes the DMA Transfer.
NYX 0:85b3fd62ea1a 818 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 819 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 820 * @retval HAL status
NYX 0:85b3fd62ea1a 821 */
NYX 0:85b3fd62ea1a 822 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 823 {
NYX 0:85b3fd62ea1a 824 /* Process Locked */
NYX 0:85b3fd62ea1a 825 __HAL_LOCK(hirda);
NYX 0:85b3fd62ea1a 826
NYX 0:85b3fd62ea1a 827 if(hirda->gState == HAL_IRDA_STATE_BUSY_TX)
NYX 0:85b3fd62ea1a 828 {
NYX 0:85b3fd62ea1a 829 /* Enable the IRDA DMA Tx request */
NYX 0:85b3fd62ea1a 830 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 831 }
NYX 0:85b3fd62ea1a 832 if(hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
NYX 0:85b3fd62ea1a 833 {
NYX 0:85b3fd62ea1a 834 /* Clear the Overrun flag before resuming the Rx transfer */
NYX 0:85b3fd62ea1a 835 __HAL_IRDA_CLEAR_OREFLAG(hirda);
NYX 0:85b3fd62ea1a 836
NYX 0:85b3fd62ea1a 837 /* Reenable PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 838 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
NYX 0:85b3fd62ea1a 839 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 840
NYX 0:85b3fd62ea1a 841 /* Enable the IRDA DMA Rx request */
NYX 0:85b3fd62ea1a 842 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 843 }
NYX 0:85b3fd62ea1a 844
NYX 0:85b3fd62ea1a 845 /* Process Unlocked */
NYX 0:85b3fd62ea1a 846 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 847
NYX 0:85b3fd62ea1a 848 return HAL_OK;
NYX 0:85b3fd62ea1a 849 }
NYX 0:85b3fd62ea1a 850
NYX 0:85b3fd62ea1a 851 /**
NYX 0:85b3fd62ea1a 852 * @brief Stops the DMA Transfer.
NYX 0:85b3fd62ea1a 853 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 854 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 855 * @retval HAL status
NYX 0:85b3fd62ea1a 856 */
NYX 0:85b3fd62ea1a 857 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 858 {
NYX 0:85b3fd62ea1a 859 uint32_t dmarequest = 0x00U;
NYX 0:85b3fd62ea1a 860 /* The Lock is not implemented on this API to allow the user application
NYX 0:85b3fd62ea1a 861 to call the HAL IRDA API under callbacks HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback():
NYX 0:85b3fd62ea1a 862 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
NYX 0:85b3fd62ea1a 863 and the correspond call back is executed HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback()
NYX 0:85b3fd62ea1a 864 */
NYX 0:85b3fd62ea1a 865
NYX 0:85b3fd62ea1a 866 /* Stop IRDA DMA Tx request if ongoing */
NYX 0:85b3fd62ea1a 867 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 868 if((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
NYX 0:85b3fd62ea1a 869 {
NYX 0:85b3fd62ea1a 870 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 871
NYX 0:85b3fd62ea1a 872 /* Abort the IRDA DMA Tx channel */
NYX 0:85b3fd62ea1a 873 if(hirda->hdmatx != NULL)
NYX 0:85b3fd62ea1a 874 {
NYX 0:85b3fd62ea1a 875 HAL_DMA_Abort(hirda->hdmatx);
NYX 0:85b3fd62ea1a 876 }
NYX 0:85b3fd62ea1a 877 IRDA_EndTxTransfer(hirda);
NYX 0:85b3fd62ea1a 878 }
NYX 0:85b3fd62ea1a 879
NYX 0:85b3fd62ea1a 880 /* Stop IRDA DMA Rx request if ongoing */
NYX 0:85b3fd62ea1a 881 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 882 if((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
NYX 0:85b3fd62ea1a 883 {
NYX 0:85b3fd62ea1a 884 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 885
NYX 0:85b3fd62ea1a 886 /* Abort the IRDA DMA Rx channel */
NYX 0:85b3fd62ea1a 887 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 888 {
NYX 0:85b3fd62ea1a 889 HAL_DMA_Abort(hirda->hdmarx);
NYX 0:85b3fd62ea1a 890 }
NYX 0:85b3fd62ea1a 891 IRDA_EndRxTransfer(hirda);
NYX 0:85b3fd62ea1a 892 }
NYX 0:85b3fd62ea1a 893 return HAL_OK;
NYX 0:85b3fd62ea1a 894 }
NYX 0:85b3fd62ea1a 895
NYX 0:85b3fd62ea1a 896 /**
NYX 0:85b3fd62ea1a 897 * @brief Abort ongoing transfers (blocking mode).
NYX 0:85b3fd62ea1a 898 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 899 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
NYX 0:85b3fd62ea1a 900 * This procedure performs following operations :
NYX 0:85b3fd62ea1a 901 * - Disable PPP Interrupts
NYX 0:85b3fd62ea1a 902 * - Disable the DMA transfer in the peripheral register (if enabled)
NYX 0:85b3fd62ea1a 903 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
NYX 0:85b3fd62ea1a 904 * - Set handle State to READY
NYX 0:85b3fd62ea1a 905 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
NYX 0:85b3fd62ea1a 906 * @retval HAL status
NYX 0:85b3fd62ea1a 907 */
NYX 0:85b3fd62ea1a 908 HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 909 {
NYX 0:85b3fd62ea1a 910 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 911 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
NYX 0:85b3fd62ea1a 912 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 913
NYX 0:85b3fd62ea1a 914 /* Disable the IRDA DMA Tx request if enabled */
NYX 0:85b3fd62ea1a 915 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
NYX 0:85b3fd62ea1a 916 {
NYX 0:85b3fd62ea1a 917 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 918
NYX 0:85b3fd62ea1a 919 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
NYX 0:85b3fd62ea1a 920 if(hirda->hdmatx != NULL)
NYX 0:85b3fd62ea1a 921 {
NYX 0:85b3fd62ea1a 922 /* Set the IRDA DMA Abort callback to Null.
NYX 0:85b3fd62ea1a 923 No call back execution at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 924 hirda->hdmatx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 925
NYX 0:85b3fd62ea1a 926 HAL_DMA_Abort(hirda->hdmatx);
NYX 0:85b3fd62ea1a 927 }
NYX 0:85b3fd62ea1a 928 }
NYX 0:85b3fd62ea1a 929
NYX 0:85b3fd62ea1a 930 /* Disable the IRDA DMA Rx request if enabled */
NYX 0:85b3fd62ea1a 931 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
NYX 0:85b3fd62ea1a 932 {
NYX 0:85b3fd62ea1a 933 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 934
NYX 0:85b3fd62ea1a 935 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
NYX 0:85b3fd62ea1a 936 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 937 {
NYX 0:85b3fd62ea1a 938 /* Set the IRDA DMA Abort callback to Null.
NYX 0:85b3fd62ea1a 939 No call back execution at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 940 hirda->hdmarx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 941
NYX 0:85b3fd62ea1a 942 HAL_DMA_Abort(hirda->hdmarx);
NYX 0:85b3fd62ea1a 943 }
NYX 0:85b3fd62ea1a 944 }
NYX 0:85b3fd62ea1a 945
NYX 0:85b3fd62ea1a 946 /* Reset Tx and Rx transfer counters */
NYX 0:85b3fd62ea1a 947 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 948 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 949
NYX 0:85b3fd62ea1a 950 /* Reset ErrorCode */
NYX 0:85b3fd62ea1a 951 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 952
NYX 0:85b3fd62ea1a 953 /* Restore hirda->RxState and hirda->gState to Ready */
NYX 0:85b3fd62ea1a 954 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 955 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 956
NYX 0:85b3fd62ea1a 957 return HAL_OK;
NYX 0:85b3fd62ea1a 958 }
NYX 0:85b3fd62ea1a 959
NYX 0:85b3fd62ea1a 960 /**
NYX 0:85b3fd62ea1a 961 * @brief Abort ongoing Transmit transfer (blocking mode).
NYX 0:85b3fd62ea1a 962 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 963 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
NYX 0:85b3fd62ea1a 964 * This procedure performs following operations :
NYX 0:85b3fd62ea1a 965 * - Disable PPP Interrupts
NYX 0:85b3fd62ea1a 966 * - Disable the DMA transfer in the peripheral register (if enabled)
NYX 0:85b3fd62ea1a 967 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
NYX 0:85b3fd62ea1a 968 * - Set handle State to READY
NYX 0:85b3fd62ea1a 969 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
NYX 0:85b3fd62ea1a 970 * @retval HAL status
NYX 0:85b3fd62ea1a 971 */
NYX 0:85b3fd62ea1a 972 HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 973 {
NYX 0:85b3fd62ea1a 974 /* Disable TXEIE and TCIE interrupts */
NYX 0:85b3fd62ea1a 975 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
NYX 0:85b3fd62ea1a 976
NYX 0:85b3fd62ea1a 977 /* Disable the IRDA DMA Tx request if enabled */
NYX 0:85b3fd62ea1a 978 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
NYX 0:85b3fd62ea1a 979 {
NYX 0:85b3fd62ea1a 980 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 981
NYX 0:85b3fd62ea1a 982 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
NYX 0:85b3fd62ea1a 983 if(hirda->hdmatx != NULL)
NYX 0:85b3fd62ea1a 984 {
NYX 0:85b3fd62ea1a 985 /* Set the IRDA DMA Abort callback to Null.
NYX 0:85b3fd62ea1a 986 No call back execution at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 987 hirda->hdmatx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 988
NYX 0:85b3fd62ea1a 989 HAL_DMA_Abort(hirda->hdmatx);
NYX 0:85b3fd62ea1a 990 }
NYX 0:85b3fd62ea1a 991 }
NYX 0:85b3fd62ea1a 992
NYX 0:85b3fd62ea1a 993 /* Reset Tx transfer counter */
NYX 0:85b3fd62ea1a 994 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 995
NYX 0:85b3fd62ea1a 996 /* Restore hirda->gState to Ready */
NYX 0:85b3fd62ea1a 997 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 998
NYX 0:85b3fd62ea1a 999 return HAL_OK;
NYX 0:85b3fd62ea1a 1000 }
NYX 0:85b3fd62ea1a 1001
NYX 0:85b3fd62ea1a 1002 /**
NYX 0:85b3fd62ea1a 1003 * @brief Abort ongoing Receive transfer (blocking mode).
NYX 0:85b3fd62ea1a 1004 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 1005 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
NYX 0:85b3fd62ea1a 1006 * This procedure performs following operations :
NYX 0:85b3fd62ea1a 1007 * - Disable PPP Interrupts
NYX 0:85b3fd62ea1a 1008 * - Disable the DMA transfer in the peripheral register (if enabled)
NYX 0:85b3fd62ea1a 1009 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
NYX 0:85b3fd62ea1a 1010 * - Set handle State to READY
NYX 0:85b3fd62ea1a 1011 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
NYX 0:85b3fd62ea1a 1012 * @retval HAL status
NYX 0:85b3fd62ea1a 1013 */
NYX 0:85b3fd62ea1a 1014 HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1015 {
NYX 0:85b3fd62ea1a 1016 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 1017 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
NYX 0:85b3fd62ea1a 1018 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 1019
NYX 0:85b3fd62ea1a 1020 /* Disable the IRDA DMA Rx request if enabled */
NYX 0:85b3fd62ea1a 1021 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
NYX 0:85b3fd62ea1a 1022 {
NYX 0:85b3fd62ea1a 1023 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 1024
NYX 0:85b3fd62ea1a 1025 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
NYX 0:85b3fd62ea1a 1026 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 1027 {
NYX 0:85b3fd62ea1a 1028 /* Set the IRDA DMA Abort callback to Null.
NYX 0:85b3fd62ea1a 1029 No call back execution at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 1030 hirda->hdmarx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 1031
NYX 0:85b3fd62ea1a 1032 HAL_DMA_Abort(hirda->hdmarx);
NYX 0:85b3fd62ea1a 1033 }
NYX 0:85b3fd62ea1a 1034 }
NYX 0:85b3fd62ea1a 1035
NYX 0:85b3fd62ea1a 1036 /* Reset Rx transfer counter */
NYX 0:85b3fd62ea1a 1037 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1038
NYX 0:85b3fd62ea1a 1039 /* Restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1040 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1041
NYX 0:85b3fd62ea1a 1042 return HAL_OK;
NYX 0:85b3fd62ea1a 1043 }
NYX 0:85b3fd62ea1a 1044
NYX 0:85b3fd62ea1a 1045 /**
NYX 0:85b3fd62ea1a 1046 * @brief Abort ongoing transfers (Interrupt mode).
NYX 0:85b3fd62ea1a 1047 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 1048 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
NYX 0:85b3fd62ea1a 1049 * This procedure performs following operations :
NYX 0:85b3fd62ea1a 1050 * - Disable PPP Interrupts
NYX 0:85b3fd62ea1a 1051 * - Disable the DMA transfer in the peripheral register (if enabled)
NYX 0:85b3fd62ea1a 1052 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
NYX 0:85b3fd62ea1a 1053 * - Set handle State to READY
NYX 0:85b3fd62ea1a 1054 * - At abort completion, call user abort complete callback
NYX 0:85b3fd62ea1a 1055 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
NYX 0:85b3fd62ea1a 1056 * considered as completed only when user abort complete callback is executed (not when exiting function).
NYX 0:85b3fd62ea1a 1057 * @retval HAL status
NYX 0:85b3fd62ea1a 1058 */
NYX 0:85b3fd62ea1a 1059 HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1060 {
NYX 0:85b3fd62ea1a 1061 uint32_t AbortCplt = 1U;
NYX 0:85b3fd62ea1a 1062
NYX 0:85b3fd62ea1a 1063 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 1064 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
NYX 0:85b3fd62ea1a 1065 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 1066
NYX 0:85b3fd62ea1a 1067 /* If DMA Tx and/or DMA Rx Handles are associated to IRDA Handle, DMA Abort complete callbacks should be initialised
NYX 0:85b3fd62ea1a 1068 before any call to DMA Abort functions */
NYX 0:85b3fd62ea1a 1069 /* DMA Tx Handle is valid */
NYX 0:85b3fd62ea1a 1070 if(hirda->hdmatx != NULL)
NYX 0:85b3fd62ea1a 1071 {
NYX 0:85b3fd62ea1a 1072 /* Set DMA Abort Complete callback if IRDA DMA Tx request if enabled.
NYX 0:85b3fd62ea1a 1073 Otherwise, set it to NULL */
NYX 0:85b3fd62ea1a 1074 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
NYX 0:85b3fd62ea1a 1075 {
NYX 0:85b3fd62ea1a 1076 hirda->hdmatx->XferAbortCallback = IRDA_DMATxAbortCallback;
NYX 0:85b3fd62ea1a 1077 }
NYX 0:85b3fd62ea1a 1078 else
NYX 0:85b3fd62ea1a 1079 {
NYX 0:85b3fd62ea1a 1080 hirda->hdmatx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 1081 }
NYX 0:85b3fd62ea1a 1082 }
NYX 0:85b3fd62ea1a 1083 /* DMA Rx Handle is valid */
NYX 0:85b3fd62ea1a 1084 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 1085 {
NYX 0:85b3fd62ea1a 1086 /* Set DMA Abort Complete callback if IRDA DMA Rx request if enabled.
NYX 0:85b3fd62ea1a 1087 Otherwise, set it to NULL */
NYX 0:85b3fd62ea1a 1088 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
NYX 0:85b3fd62ea1a 1089 {
NYX 0:85b3fd62ea1a 1090 hirda->hdmarx->XferAbortCallback = IRDA_DMARxAbortCallback;
NYX 0:85b3fd62ea1a 1091 }
NYX 0:85b3fd62ea1a 1092 else
NYX 0:85b3fd62ea1a 1093 {
NYX 0:85b3fd62ea1a 1094 hirda->hdmarx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 1095 }
NYX 0:85b3fd62ea1a 1096 }
NYX 0:85b3fd62ea1a 1097
NYX 0:85b3fd62ea1a 1098 /* Disable the IRDA DMA Tx request if enabled */
NYX 0:85b3fd62ea1a 1099 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
NYX 0:85b3fd62ea1a 1100 {
NYX 0:85b3fd62ea1a 1101 /* Disable DMA Tx at IRDA level */
NYX 0:85b3fd62ea1a 1102 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 1103
NYX 0:85b3fd62ea1a 1104 /* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
NYX 0:85b3fd62ea1a 1105 if(hirda->hdmatx != NULL)
NYX 0:85b3fd62ea1a 1106 {
NYX 0:85b3fd62ea1a 1107 /* IRDA Tx DMA Abort callback has already been initialised :
NYX 0:85b3fd62ea1a 1108 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 1109
NYX 0:85b3fd62ea1a 1110 /* Abort DMA TX */
NYX 0:85b3fd62ea1a 1111 if(HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
NYX 0:85b3fd62ea1a 1112 {
NYX 0:85b3fd62ea1a 1113 hirda->hdmatx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 1114 }
NYX 0:85b3fd62ea1a 1115 else
NYX 0:85b3fd62ea1a 1116 {
NYX 0:85b3fd62ea1a 1117 AbortCplt = 0x00U;
NYX 0:85b3fd62ea1a 1118 }
NYX 0:85b3fd62ea1a 1119 }
NYX 0:85b3fd62ea1a 1120 }
NYX 0:85b3fd62ea1a 1121
NYX 0:85b3fd62ea1a 1122 /* Disable the IRDA DMA Rx request if enabled */
NYX 0:85b3fd62ea1a 1123 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
NYX 0:85b3fd62ea1a 1124 {
NYX 0:85b3fd62ea1a 1125 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 1126
NYX 0:85b3fd62ea1a 1127 /* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
NYX 0:85b3fd62ea1a 1128 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 1129 {
NYX 0:85b3fd62ea1a 1130 /* IRDA Rx DMA Abort callback has already been initialised :
NYX 0:85b3fd62ea1a 1131 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 1132
NYX 0:85b3fd62ea1a 1133 /* Abort DMA RX */
NYX 0:85b3fd62ea1a 1134 if(HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
NYX 0:85b3fd62ea1a 1135 {
NYX 0:85b3fd62ea1a 1136 hirda->hdmarx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 1137 AbortCplt = 0x01U;
NYX 0:85b3fd62ea1a 1138 }
NYX 0:85b3fd62ea1a 1139 else
NYX 0:85b3fd62ea1a 1140 {
NYX 0:85b3fd62ea1a 1141 AbortCplt = 0x00U;
NYX 0:85b3fd62ea1a 1142 }
NYX 0:85b3fd62ea1a 1143 }
NYX 0:85b3fd62ea1a 1144 }
NYX 0:85b3fd62ea1a 1145
NYX 0:85b3fd62ea1a 1146 /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
NYX 0:85b3fd62ea1a 1147 if(AbortCplt == 0x01U)
NYX 0:85b3fd62ea1a 1148 {
NYX 0:85b3fd62ea1a 1149 /* Reset Tx and Rx transfer counters */
NYX 0:85b3fd62ea1a 1150 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1151 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1152
NYX 0:85b3fd62ea1a 1153 /* Reset ErrorCode */
NYX 0:85b3fd62ea1a 1154 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 1155
NYX 0:85b3fd62ea1a 1156 /* Restore hirda->gState and hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1157 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1158 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1159
NYX 0:85b3fd62ea1a 1160 /* As no DMA to be aborted, call directly user Abort complete callback */
NYX 0:85b3fd62ea1a 1161 HAL_IRDA_AbortCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1162 }
NYX 0:85b3fd62ea1a 1163
NYX 0:85b3fd62ea1a 1164 return HAL_OK;
NYX 0:85b3fd62ea1a 1165 }
NYX 0:85b3fd62ea1a 1166
NYX 0:85b3fd62ea1a 1167 /**
NYX 0:85b3fd62ea1a 1168 * @brief Abort ongoing Transmit transfer (Interrupt mode).
NYX 0:85b3fd62ea1a 1169 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 1170 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
NYX 0:85b3fd62ea1a 1171 * This procedure performs following operations :
NYX 0:85b3fd62ea1a 1172 * - Disable PPP Interrupts
NYX 0:85b3fd62ea1a 1173 * - Disable the DMA transfer in the peripheral register (if enabled)
NYX 0:85b3fd62ea1a 1174 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
NYX 0:85b3fd62ea1a 1175 * - Set handle State to READY
NYX 0:85b3fd62ea1a 1176 * - At abort completion, call user abort complete callback
NYX 0:85b3fd62ea1a 1177 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
NYX 0:85b3fd62ea1a 1178 * considered as completed only when user abort complete callback is executed (not when exiting function).
NYX 0:85b3fd62ea1a 1179 * @retval HAL status
NYX 0:85b3fd62ea1a 1180 */
NYX 0:85b3fd62ea1a 1181 HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1182 {
NYX 0:85b3fd62ea1a 1183 /* Disable TXEIE and TCIE interrupts */
NYX 0:85b3fd62ea1a 1184 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
NYX 0:85b3fd62ea1a 1185
NYX 0:85b3fd62ea1a 1186 /* Disable the IRDA DMA Tx request if enabled */
NYX 0:85b3fd62ea1a 1187 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
NYX 0:85b3fd62ea1a 1188 {
NYX 0:85b3fd62ea1a 1189 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 1190
NYX 0:85b3fd62ea1a 1191 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
NYX 0:85b3fd62ea1a 1192 if(hirda->hdmatx != NULL)
NYX 0:85b3fd62ea1a 1193 {
NYX 0:85b3fd62ea1a 1194 /* Set the IRDA DMA Abort callback :
NYX 0:85b3fd62ea1a 1195 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 1196 hirda->hdmatx->XferAbortCallback = IRDA_DMATxOnlyAbortCallback;
NYX 0:85b3fd62ea1a 1197
NYX 0:85b3fd62ea1a 1198 /* Abort DMA TX */
NYX 0:85b3fd62ea1a 1199 if(HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
NYX 0:85b3fd62ea1a 1200 {
NYX 0:85b3fd62ea1a 1201 /* Call Directly hirda->hdmatx->XferAbortCallback function in case of error */
NYX 0:85b3fd62ea1a 1202 hirda->hdmatx->XferAbortCallback(hirda->hdmatx);
NYX 0:85b3fd62ea1a 1203 }
NYX 0:85b3fd62ea1a 1204 }
NYX 0:85b3fd62ea1a 1205 else
NYX 0:85b3fd62ea1a 1206 {
NYX 0:85b3fd62ea1a 1207 /* Reset Tx transfer counter */
NYX 0:85b3fd62ea1a 1208 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1209
NYX 0:85b3fd62ea1a 1210 /* Restore hirda->gState to Ready */
NYX 0:85b3fd62ea1a 1211 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1212
NYX 0:85b3fd62ea1a 1213 /* As no DMA to be aborted, call directly user Abort complete callback */
NYX 0:85b3fd62ea1a 1214 HAL_IRDA_AbortTransmitCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1215 }
NYX 0:85b3fd62ea1a 1216 }
NYX 0:85b3fd62ea1a 1217 else
NYX 0:85b3fd62ea1a 1218 {
NYX 0:85b3fd62ea1a 1219 /* Reset Tx transfer counter */
NYX 0:85b3fd62ea1a 1220 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1221
NYX 0:85b3fd62ea1a 1222 /* Restore hirda->gState to Ready */
NYX 0:85b3fd62ea1a 1223 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1224
NYX 0:85b3fd62ea1a 1225 /* As no DMA to be aborted, call directly user Abort complete callback */
NYX 0:85b3fd62ea1a 1226 HAL_IRDA_AbortTransmitCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1227 }
NYX 0:85b3fd62ea1a 1228
NYX 0:85b3fd62ea1a 1229 return HAL_OK;
NYX 0:85b3fd62ea1a 1230 }
NYX 0:85b3fd62ea1a 1231
NYX 0:85b3fd62ea1a 1232 /**
NYX 0:85b3fd62ea1a 1233 * @brief Abort ongoing Receive transfer (Interrupt mode).
NYX 0:85b3fd62ea1a 1234 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 1235 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
NYX 0:85b3fd62ea1a 1236 * This procedure performs following operations :
NYX 0:85b3fd62ea1a 1237 * - Disable PPP Interrupts
NYX 0:85b3fd62ea1a 1238 * - Disable the DMA transfer in the peripheral register (if enabled)
NYX 0:85b3fd62ea1a 1239 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
NYX 0:85b3fd62ea1a 1240 * - Set handle State to READY
NYX 0:85b3fd62ea1a 1241 * - At abort completion, call user abort complete callback
NYX 0:85b3fd62ea1a 1242 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
NYX 0:85b3fd62ea1a 1243 * considered as completed only when user abort complete callback is executed (not when exiting function).
NYX 0:85b3fd62ea1a 1244 * @retval HAL status
NYX 0:85b3fd62ea1a 1245 */
NYX 0:85b3fd62ea1a 1246 HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1247 {
NYX 0:85b3fd62ea1a 1248 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 1249 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
NYX 0:85b3fd62ea1a 1250 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 1251
NYX 0:85b3fd62ea1a 1252 /* Disable the IRDA DMA Rx request if enabled */
NYX 0:85b3fd62ea1a 1253 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
NYX 0:85b3fd62ea1a 1254 {
NYX 0:85b3fd62ea1a 1255 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 1256
NYX 0:85b3fd62ea1a 1257 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
NYX 0:85b3fd62ea1a 1258 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 1259 {
NYX 0:85b3fd62ea1a 1260 /* Set the IRDA DMA Abort callback :
NYX 0:85b3fd62ea1a 1261 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 1262 hirda->hdmarx->XferAbortCallback = IRDA_DMARxOnlyAbortCallback;
NYX 0:85b3fd62ea1a 1263
NYX 0:85b3fd62ea1a 1264 /* Abort DMA RX */
NYX 0:85b3fd62ea1a 1265 if(HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
NYX 0:85b3fd62ea1a 1266 {
NYX 0:85b3fd62ea1a 1267 /* Call Directly hirda->hdmarx->XferAbortCallback function in case of error */
NYX 0:85b3fd62ea1a 1268 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
NYX 0:85b3fd62ea1a 1269 }
NYX 0:85b3fd62ea1a 1270 }
NYX 0:85b3fd62ea1a 1271 else
NYX 0:85b3fd62ea1a 1272 {
NYX 0:85b3fd62ea1a 1273 /* Reset Rx transfer counter */
NYX 0:85b3fd62ea1a 1274 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1275
NYX 0:85b3fd62ea1a 1276 /* Restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1277 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1278
NYX 0:85b3fd62ea1a 1279 /* As no DMA to be aborted, call directly user Abort complete callback */
NYX 0:85b3fd62ea1a 1280 HAL_IRDA_AbortReceiveCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1281 }
NYX 0:85b3fd62ea1a 1282 }
NYX 0:85b3fd62ea1a 1283 else
NYX 0:85b3fd62ea1a 1284 {
NYX 0:85b3fd62ea1a 1285 /* Reset Rx transfer counter */
NYX 0:85b3fd62ea1a 1286 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1287
NYX 0:85b3fd62ea1a 1288 /* Restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1289 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1290
NYX 0:85b3fd62ea1a 1291 /* As no DMA to be aborted, call directly user Abort complete callback */
NYX 0:85b3fd62ea1a 1292 HAL_IRDA_AbortReceiveCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1293 }
NYX 0:85b3fd62ea1a 1294
NYX 0:85b3fd62ea1a 1295 return HAL_OK;
NYX 0:85b3fd62ea1a 1296 }
NYX 0:85b3fd62ea1a 1297
NYX 0:85b3fd62ea1a 1298 /**
NYX 0:85b3fd62ea1a 1299 * @brief This function handles IRDA interrupt request.
NYX 0:85b3fd62ea1a 1300 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1301 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1302 * @retval None
NYX 0:85b3fd62ea1a 1303 */
NYX 0:85b3fd62ea1a 1304 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1305 {
NYX 0:85b3fd62ea1a 1306 uint32_t isrflags = READ_REG(hirda->Instance->SR);
NYX 0:85b3fd62ea1a 1307 uint32_t cr1its = READ_REG(hirda->Instance->CR1);
NYX 0:85b3fd62ea1a 1308 uint32_t cr3its = READ_REG(hirda->Instance->CR3);
NYX 0:85b3fd62ea1a 1309 uint32_t errorflags = 0x00U;
NYX 0:85b3fd62ea1a 1310 uint32_t dmarequest = 0x00U;
NYX 0:85b3fd62ea1a 1311
NYX 0:85b3fd62ea1a 1312 /* If no error occurs */
NYX 0:85b3fd62ea1a 1313 errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
NYX 0:85b3fd62ea1a 1314 if(errorflags == RESET)
NYX 0:85b3fd62ea1a 1315 {
NYX 0:85b3fd62ea1a 1316 /* IRDA in mode Receiver -----------------------------------------------*/
NYX 0:85b3fd62ea1a 1317 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
NYX 0:85b3fd62ea1a 1318 {
NYX 0:85b3fd62ea1a 1319 IRDA_Receive_IT(hirda);
NYX 0:85b3fd62ea1a 1320 return;
NYX 0:85b3fd62ea1a 1321 }
NYX 0:85b3fd62ea1a 1322 }
NYX 0:85b3fd62ea1a 1323
NYX 0:85b3fd62ea1a 1324 /* If some errors occur */
NYX 0:85b3fd62ea1a 1325 if((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
NYX 0:85b3fd62ea1a 1326 {
NYX 0:85b3fd62ea1a 1327 /* IRDA parity error interrupt occurred -------------------------------*/
NYX 0:85b3fd62ea1a 1328 if(((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
NYX 0:85b3fd62ea1a 1329 {
NYX 0:85b3fd62ea1a 1330 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
NYX 0:85b3fd62ea1a 1331 }
NYX 0:85b3fd62ea1a 1332
NYX 0:85b3fd62ea1a 1333 /* IRDA noise error interrupt occurred --------------------------------*/
NYX 0:85b3fd62ea1a 1334 if(((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
NYX 0:85b3fd62ea1a 1335 {
NYX 0:85b3fd62ea1a 1336 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
NYX 0:85b3fd62ea1a 1337 }
NYX 0:85b3fd62ea1a 1338
NYX 0:85b3fd62ea1a 1339 /* IRDA frame error interrupt occurred --------------------------------*/
NYX 0:85b3fd62ea1a 1340 if(((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
NYX 0:85b3fd62ea1a 1341 {
NYX 0:85b3fd62ea1a 1342 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
NYX 0:85b3fd62ea1a 1343 }
NYX 0:85b3fd62ea1a 1344
NYX 0:85b3fd62ea1a 1345 /* IRDA Over-Run interrupt occurred -----------------------------------*/
NYX 0:85b3fd62ea1a 1346 if(((isrflags & USART_SR_ORE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
NYX 0:85b3fd62ea1a 1347 {
NYX 0:85b3fd62ea1a 1348 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
NYX 0:85b3fd62ea1a 1349 }
NYX 0:85b3fd62ea1a 1350 /* Call IRDA Error Call back function if need be -----------------------*/
NYX 0:85b3fd62ea1a 1351 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
NYX 0:85b3fd62ea1a 1352 {
NYX 0:85b3fd62ea1a 1353 /* IRDA in mode Receiver ---------------------------------------------*/
NYX 0:85b3fd62ea1a 1354 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
NYX 0:85b3fd62ea1a 1355 {
NYX 0:85b3fd62ea1a 1356 IRDA_Receive_IT(hirda);
NYX 0:85b3fd62ea1a 1357 }
NYX 0:85b3fd62ea1a 1358
NYX 0:85b3fd62ea1a 1359 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 1360 /* If Overrun error occurs, or if any error occurs in DMA mode reception,
NYX 0:85b3fd62ea1a 1361 consider error as blocking */
NYX 0:85b3fd62ea1a 1362 if(((hirda->ErrorCode & HAL_IRDA_ERROR_ORE) != RESET) || dmarequest)
NYX 0:85b3fd62ea1a 1363 {
NYX 0:85b3fd62ea1a 1364 /* Blocking error : transfer is aborted
NYX 0:85b3fd62ea1a 1365 Set the IRDA state ready to be able to start again the process,
NYX 0:85b3fd62ea1a 1366 Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
NYX 0:85b3fd62ea1a 1367 IRDA_EndRxTransfer(hirda);
NYX 0:85b3fd62ea1a 1368
NYX 0:85b3fd62ea1a 1369 /* Disable the IRDA DMA Rx request if enabled */
NYX 0:85b3fd62ea1a 1370 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
NYX 0:85b3fd62ea1a 1371 {
NYX 0:85b3fd62ea1a 1372 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 1373
NYX 0:85b3fd62ea1a 1374 /* Abort the IRDA DMA Rx channel */
NYX 0:85b3fd62ea1a 1375 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 1376 {
NYX 0:85b3fd62ea1a 1377 /* Set the IRDA DMA Abort callback :
NYX 0:85b3fd62ea1a 1378 will lead to call HAL_IRDA_ErrorCallback() at end of DMA abort procedure */
NYX 0:85b3fd62ea1a 1379 hirda->hdmarx->XferAbortCallback = IRDA_DMAAbortOnError;
NYX 0:85b3fd62ea1a 1380
NYX 0:85b3fd62ea1a 1381 if(HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
NYX 0:85b3fd62ea1a 1382 {
NYX 0:85b3fd62ea1a 1383 /* Call Directly XferAbortCallback function in case of error */
NYX 0:85b3fd62ea1a 1384 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
NYX 0:85b3fd62ea1a 1385 }
NYX 0:85b3fd62ea1a 1386 }
NYX 0:85b3fd62ea1a 1387 else
NYX 0:85b3fd62ea1a 1388 {
NYX 0:85b3fd62ea1a 1389 /* Call user error callback */
NYX 0:85b3fd62ea1a 1390 HAL_IRDA_ErrorCallback(hirda);
NYX 0:85b3fd62ea1a 1391 }
NYX 0:85b3fd62ea1a 1392 }
NYX 0:85b3fd62ea1a 1393 else
NYX 0:85b3fd62ea1a 1394 {
NYX 0:85b3fd62ea1a 1395 /* Call user error callback */
NYX 0:85b3fd62ea1a 1396 HAL_IRDA_ErrorCallback(hirda);
NYX 0:85b3fd62ea1a 1397 }
NYX 0:85b3fd62ea1a 1398 }
NYX 0:85b3fd62ea1a 1399 else
NYX 0:85b3fd62ea1a 1400 {
NYX 0:85b3fd62ea1a 1401 /* Non Blocking error : transfer could go on.
NYX 0:85b3fd62ea1a 1402 Error is notified to user through user error callback */
NYX 0:85b3fd62ea1a 1403 HAL_IRDA_ErrorCallback(hirda);
NYX 0:85b3fd62ea1a 1404 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 1405 }
NYX 0:85b3fd62ea1a 1406 }
NYX 0:85b3fd62ea1a 1407 return;
NYX 0:85b3fd62ea1a 1408 } /* End if some error occurs */
NYX 0:85b3fd62ea1a 1409
NYX 0:85b3fd62ea1a 1410 /* IRDA in mode Transmitter ------------------------------------------------*/
NYX 0:85b3fd62ea1a 1411 if(((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
NYX 0:85b3fd62ea1a 1412 {
NYX 0:85b3fd62ea1a 1413 IRDA_Transmit_IT(hirda);
NYX 0:85b3fd62ea1a 1414 return;
NYX 0:85b3fd62ea1a 1415 }
NYX 0:85b3fd62ea1a 1416
NYX 0:85b3fd62ea1a 1417 /* IRDA in mode Transmitter end --------------------------------------------*/
NYX 0:85b3fd62ea1a 1418 if(((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
NYX 0:85b3fd62ea1a 1419 {
NYX 0:85b3fd62ea1a 1420 IRDA_EndTransmit_IT(hirda);
NYX 0:85b3fd62ea1a 1421 return;
NYX 0:85b3fd62ea1a 1422 }
NYX 0:85b3fd62ea1a 1423 }
NYX 0:85b3fd62ea1a 1424
NYX 0:85b3fd62ea1a 1425 /**
NYX 0:85b3fd62ea1a 1426 * @brief End ongoing Tx transfer on IRDA peripheral (following error detection or Transmit completion).
NYX 0:85b3fd62ea1a 1427 * @param hirda: IRDA handle.
NYX 0:85b3fd62ea1a 1428 * @retval None
NYX 0:85b3fd62ea1a 1429 */
NYX 0:85b3fd62ea1a 1430 static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1431 {
NYX 0:85b3fd62ea1a 1432 /* Disable TXEIE and TCIE interrupts */
NYX 0:85b3fd62ea1a 1433 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
NYX 0:85b3fd62ea1a 1434
NYX 0:85b3fd62ea1a 1435 /* At end of Tx process, restore hirda->gState to Ready */
NYX 0:85b3fd62ea1a 1436 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1437 }
NYX 0:85b3fd62ea1a 1438
NYX 0:85b3fd62ea1a 1439 /**
NYX 0:85b3fd62ea1a 1440 * @brief End ongoing Rx transfer on IRDA peripheral (following error detection or Reception completion).
NYX 0:85b3fd62ea1a 1441 * @param hirda: IRDA handle.
NYX 0:85b3fd62ea1a 1442 * @retval None
NYX 0:85b3fd62ea1a 1443 */
NYX 0:85b3fd62ea1a 1444 static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1445 {
NYX 0:85b3fd62ea1a 1446 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 1447 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
NYX 0:85b3fd62ea1a 1448 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 1449
NYX 0:85b3fd62ea1a 1450 /* At end of Rx process, restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1451 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1452 }
NYX 0:85b3fd62ea1a 1453
NYX 0:85b3fd62ea1a 1454 /**
NYX 0:85b3fd62ea1a 1455 * @brief DMA IRDA communication abort callback, when initiated by HAL services on Error
NYX 0:85b3fd62ea1a 1456 * (To be called at end of DMA Abort procedure following error occurrence).
NYX 0:85b3fd62ea1a 1457 * @param hdma DMA handle.
NYX 0:85b3fd62ea1a 1458 * @retval None
NYX 0:85b3fd62ea1a 1459 */
NYX 0:85b3fd62ea1a 1460 static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1461 {
NYX 0:85b3fd62ea1a 1462 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1463 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1464 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1465
NYX 0:85b3fd62ea1a 1466 HAL_IRDA_ErrorCallback(hirda);
NYX 0:85b3fd62ea1a 1467 }
NYX 0:85b3fd62ea1a 1468
NYX 0:85b3fd62ea1a 1469 /**
NYX 0:85b3fd62ea1a 1470 * @brief DMA IRDA Tx communication abort callback, when initiated by user
NYX 0:85b3fd62ea1a 1471 * (To be called at end of DMA Tx Abort procedure following user abort request).
NYX 0:85b3fd62ea1a 1472 * @note When this callback is executed, User Abort complete call back is called only if no
NYX 0:85b3fd62ea1a 1473 * Abort still ongoing for Rx DMA Handle.
NYX 0:85b3fd62ea1a 1474 * @param hdma DMA handle.
NYX 0:85b3fd62ea1a 1475 * @retval None
NYX 0:85b3fd62ea1a 1476 */
NYX 0:85b3fd62ea1a 1477 static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1478 {
NYX 0:85b3fd62ea1a 1479 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1480
NYX 0:85b3fd62ea1a 1481 hirda->hdmatx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 1482
NYX 0:85b3fd62ea1a 1483 /* Check if an Abort process is still ongoing */
NYX 0:85b3fd62ea1a 1484 if(hirda->hdmarx != NULL)
NYX 0:85b3fd62ea1a 1485 {
NYX 0:85b3fd62ea1a 1486 if(hirda->hdmarx->XferAbortCallback != NULL)
NYX 0:85b3fd62ea1a 1487 {
NYX 0:85b3fd62ea1a 1488 return;
NYX 0:85b3fd62ea1a 1489 }
NYX 0:85b3fd62ea1a 1490 }
NYX 0:85b3fd62ea1a 1491
NYX 0:85b3fd62ea1a 1492 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
NYX 0:85b3fd62ea1a 1493 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1494 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1495
NYX 0:85b3fd62ea1a 1496 /* Reset ErrorCode */
NYX 0:85b3fd62ea1a 1497 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 1498
NYX 0:85b3fd62ea1a 1499 /* Restore hirda->gState and hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1500 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1501 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1502
NYX 0:85b3fd62ea1a 1503 /* Call user Abort complete callback */
NYX 0:85b3fd62ea1a 1504 HAL_IRDA_AbortCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1505 }
NYX 0:85b3fd62ea1a 1506
NYX 0:85b3fd62ea1a 1507 /**
NYX 0:85b3fd62ea1a 1508 * @brief DMA IRDA Rx communication abort callback, when initiated by user
NYX 0:85b3fd62ea1a 1509 * (To be called at end of DMA Rx Abort procedure following user abort request).
NYX 0:85b3fd62ea1a 1510 * @note When this callback is executed, User Abort complete call back is called only if no
NYX 0:85b3fd62ea1a 1511 * Abort still ongoing for Tx DMA Handle.
NYX 0:85b3fd62ea1a 1512 * @param hdma DMA handle.
NYX 0:85b3fd62ea1a 1513 * @retval None
NYX 0:85b3fd62ea1a 1514 */
NYX 0:85b3fd62ea1a 1515 static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1516 {
NYX 0:85b3fd62ea1a 1517 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1518
NYX 0:85b3fd62ea1a 1519 hirda->hdmarx->XferAbortCallback = NULL;
NYX 0:85b3fd62ea1a 1520
NYX 0:85b3fd62ea1a 1521 /* Check if an Abort process is still ongoing */
NYX 0:85b3fd62ea1a 1522 if(hirda->hdmatx != NULL)
NYX 0:85b3fd62ea1a 1523 {
NYX 0:85b3fd62ea1a 1524 if(hirda->hdmatx->XferAbortCallback != NULL)
NYX 0:85b3fd62ea1a 1525 {
NYX 0:85b3fd62ea1a 1526 return;
NYX 0:85b3fd62ea1a 1527 }
NYX 0:85b3fd62ea1a 1528 }
NYX 0:85b3fd62ea1a 1529
NYX 0:85b3fd62ea1a 1530 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
NYX 0:85b3fd62ea1a 1531 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1532 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1533
NYX 0:85b3fd62ea1a 1534 /* Reset ErrorCode */
NYX 0:85b3fd62ea1a 1535 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
NYX 0:85b3fd62ea1a 1536
NYX 0:85b3fd62ea1a 1537 /* Restore hirda->gState and hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1538 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1539 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1540
NYX 0:85b3fd62ea1a 1541 /* Call user Abort complete callback */
NYX 0:85b3fd62ea1a 1542 HAL_IRDA_AbortCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1543 }
NYX 0:85b3fd62ea1a 1544
NYX 0:85b3fd62ea1a 1545 /**
NYX 0:85b3fd62ea1a 1546 * @brief DMA IRDA Tx communication abort callback, when initiated by user by a call to
NYX 0:85b3fd62ea1a 1547 * HAL_IRDA_AbortTransmit_IT API (Abort only Tx transfer)
NYX 0:85b3fd62ea1a 1548 * (This callback is executed at end of DMA Tx Abort procedure following user abort request,
NYX 0:85b3fd62ea1a 1549 * and leads to user Tx Abort Complete callback execution).
NYX 0:85b3fd62ea1a 1550 * @param hdma DMA handle.
NYX 0:85b3fd62ea1a 1551 * @retval None
NYX 0:85b3fd62ea1a 1552 */
NYX 0:85b3fd62ea1a 1553 static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1554 {
NYX 0:85b3fd62ea1a 1555 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1556
NYX 0:85b3fd62ea1a 1557 hirda->TxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1558
NYX 0:85b3fd62ea1a 1559 /* Restore hirda->gState to Ready */
NYX 0:85b3fd62ea1a 1560 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1561
NYX 0:85b3fd62ea1a 1562 /* Call user Abort complete callback */
NYX 0:85b3fd62ea1a 1563 HAL_IRDA_AbortTransmitCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1564 }
NYX 0:85b3fd62ea1a 1565
NYX 0:85b3fd62ea1a 1566 /**
NYX 0:85b3fd62ea1a 1567 * @brief DMA IRDA Rx communication abort callback, when initiated by user by a call to
NYX 0:85b3fd62ea1a 1568 * HAL_IRDA_AbortReceive_IT API (Abort only Rx transfer)
NYX 0:85b3fd62ea1a 1569 * (This callback is executed at end of DMA Rx Abort procedure following user abort request,
NYX 0:85b3fd62ea1a 1570 * and leads to user Rx Abort Complete callback execution).
NYX 0:85b3fd62ea1a 1571 * @param hdma DMA handle.
NYX 0:85b3fd62ea1a 1572 * @retval None
NYX 0:85b3fd62ea1a 1573 */
NYX 0:85b3fd62ea1a 1574 static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1575 {
NYX 0:85b3fd62ea1a 1576 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1577
NYX 0:85b3fd62ea1a 1578 hirda->RxXferCount = 0x00U;
NYX 0:85b3fd62ea1a 1579
NYX 0:85b3fd62ea1a 1580 /* Restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1581 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1582
NYX 0:85b3fd62ea1a 1583 /* Call user Abort complete callback */
NYX 0:85b3fd62ea1a 1584 HAL_IRDA_AbortReceiveCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1585 }
NYX 0:85b3fd62ea1a 1586
NYX 0:85b3fd62ea1a 1587 /**
NYX 0:85b3fd62ea1a 1588 * @brief Tx Transfer complete callbacks.
NYX 0:85b3fd62ea1a 1589 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1590 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1591 * @retval None
NYX 0:85b3fd62ea1a 1592 */
NYX 0:85b3fd62ea1a 1593 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1594 {
NYX 0:85b3fd62ea1a 1595 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1596 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1597 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1598 the HAL_IRDA_TxCpltCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 1599 */
NYX 0:85b3fd62ea1a 1600 }
NYX 0:85b3fd62ea1a 1601
NYX 0:85b3fd62ea1a 1602 /**
NYX 0:85b3fd62ea1a 1603 * @brief Tx Half Transfer completed callbacks.
NYX 0:85b3fd62ea1a 1604 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1605 * the configuration information for the specified USART module.
NYX 0:85b3fd62ea1a 1606 * @retval None
NYX 0:85b3fd62ea1a 1607 */
NYX 0:85b3fd62ea1a 1608 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1609 {
NYX 0:85b3fd62ea1a 1610 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1611 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1612 /* NOTE: This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1613 the HAL_IRDA_TxHalfCpltCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 1614 */
NYX 0:85b3fd62ea1a 1615 }
NYX 0:85b3fd62ea1a 1616
NYX 0:85b3fd62ea1a 1617 /**
NYX 0:85b3fd62ea1a 1618 * @brief Rx Transfer complete callbacks.
NYX 0:85b3fd62ea1a 1619 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1620 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1621 * @retval None
NYX 0:85b3fd62ea1a 1622 */
NYX 0:85b3fd62ea1a 1623 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1624 {
NYX 0:85b3fd62ea1a 1625 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1626 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1627 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1628 the HAL_IRDA_RxCpltCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 1629 */
NYX 0:85b3fd62ea1a 1630 }
NYX 0:85b3fd62ea1a 1631
NYX 0:85b3fd62ea1a 1632 /**
NYX 0:85b3fd62ea1a 1633 * @brief Rx Half Transfer complete callbacks.
NYX 0:85b3fd62ea1a 1634 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1635 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1636 * @retval None
NYX 0:85b3fd62ea1a 1637 */
NYX 0:85b3fd62ea1a 1638 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1639 {
NYX 0:85b3fd62ea1a 1640 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1641 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1642 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1643 the HAL_IRDA_RxHalfCpltCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 1644 */
NYX 0:85b3fd62ea1a 1645 }
NYX 0:85b3fd62ea1a 1646
NYX 0:85b3fd62ea1a 1647 /**
NYX 0:85b3fd62ea1a 1648 * @brief IRDA error callbacks.
NYX 0:85b3fd62ea1a 1649 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1650 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1651 * @retval None
NYX 0:85b3fd62ea1a 1652 */
NYX 0:85b3fd62ea1a 1653 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1654 {
NYX 0:85b3fd62ea1a 1655 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1656 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1657 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1658 the HAL_IRDA_ErrorCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 1659 */
NYX 0:85b3fd62ea1a 1660 }
NYX 0:85b3fd62ea1a 1661
NYX 0:85b3fd62ea1a 1662 /**
NYX 0:85b3fd62ea1a 1663 * @brief IRDA Abort Complete callback.
NYX 0:85b3fd62ea1a 1664 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 1665 * @retval None
NYX 0:85b3fd62ea1a 1666 */
NYX 0:85b3fd62ea1a 1667 __weak void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1668 {
NYX 0:85b3fd62ea1a 1669 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1670 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1671
NYX 0:85b3fd62ea1a 1672 /* NOTE : This function should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1673 the HAL_IRDA_AbortCpltCallback can be implemented in the user file.
NYX 0:85b3fd62ea1a 1674 */
NYX 0:85b3fd62ea1a 1675 }
NYX 0:85b3fd62ea1a 1676
NYX 0:85b3fd62ea1a 1677 /**
NYX 0:85b3fd62ea1a 1678 * @brief IRDA Abort Transmit Complete callback.
NYX 0:85b3fd62ea1a 1679 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 1680 * @retval None
NYX 0:85b3fd62ea1a 1681 */
NYX 0:85b3fd62ea1a 1682 __weak void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1683 {
NYX 0:85b3fd62ea1a 1684 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1685 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1686
NYX 0:85b3fd62ea1a 1687 /* NOTE : This function should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1688 the HAL_IRDA_AbortTransmitCpltCallback can be implemented in the user file.
NYX 0:85b3fd62ea1a 1689 */
NYX 0:85b3fd62ea1a 1690 }
NYX 0:85b3fd62ea1a 1691
NYX 0:85b3fd62ea1a 1692 /**
NYX 0:85b3fd62ea1a 1693 * @brief IRDA Abort ReceiveComplete callback.
NYX 0:85b3fd62ea1a 1694 * @param hirda IRDA handle.
NYX 0:85b3fd62ea1a 1695 * @retval None
NYX 0:85b3fd62ea1a 1696 */
NYX 0:85b3fd62ea1a 1697 __weak void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1698 {
NYX 0:85b3fd62ea1a 1699 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 1700 UNUSED(hirda);
NYX 0:85b3fd62ea1a 1701
NYX 0:85b3fd62ea1a 1702 /* NOTE : This function should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 1703 the HAL_IRDA_AbortReceiveCpltCallback can be implemented in the user file.
NYX 0:85b3fd62ea1a 1704 */
NYX 0:85b3fd62ea1a 1705 }
NYX 0:85b3fd62ea1a 1706
NYX 0:85b3fd62ea1a 1707 /**
NYX 0:85b3fd62ea1a 1708 * @}
NYX 0:85b3fd62ea1a 1709 */
NYX 0:85b3fd62ea1a 1710
NYX 0:85b3fd62ea1a 1711 /** @defgroup IRDA_Exported_Functions_Group3 Peripheral State and Errors functions
NYX 0:85b3fd62ea1a 1712 * @brief IRDA State and Errors functions
NYX 0:85b3fd62ea1a 1713 *
NYX 0:85b3fd62ea1a 1714 @verbatim
NYX 0:85b3fd62ea1a 1715 ==============================================================================
NYX 0:85b3fd62ea1a 1716 ##### Peripheral State and Errors functions #####
NYX 0:85b3fd62ea1a 1717 ==============================================================================
NYX 0:85b3fd62ea1a 1718 [..]
NYX 0:85b3fd62ea1a 1719 This subsection provides a set of functions allowing to return the State of IrDA
NYX 0:85b3fd62ea1a 1720 communication process and also return Peripheral Errors occurred during communication process
NYX 0:85b3fd62ea1a 1721 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IrDA peripheral.
NYX 0:85b3fd62ea1a 1722 (+) HAL_IRDA_GetError() check in run-time errors that could be occurred during communication.
NYX 0:85b3fd62ea1a 1723
NYX 0:85b3fd62ea1a 1724 @endverbatim
NYX 0:85b3fd62ea1a 1725 * @{
NYX 0:85b3fd62ea1a 1726 */
NYX 0:85b3fd62ea1a 1727
NYX 0:85b3fd62ea1a 1728 /**
NYX 0:85b3fd62ea1a 1729 * @brief Returns the IRDA state.
NYX 0:85b3fd62ea1a 1730 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1731 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1732 * @retval HAL state
NYX 0:85b3fd62ea1a 1733 */
NYX 0:85b3fd62ea1a 1734 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1735 {
NYX 0:85b3fd62ea1a 1736 uint32_t temp1 = 0x00U, temp2 = 0x00U;
NYX 0:85b3fd62ea1a 1737 temp1 = hirda->gState;
NYX 0:85b3fd62ea1a 1738 temp2 = hirda->RxState;
NYX 0:85b3fd62ea1a 1739
NYX 0:85b3fd62ea1a 1740 return (HAL_IRDA_StateTypeDef)(temp1 | temp2);
NYX 0:85b3fd62ea1a 1741 }
NYX 0:85b3fd62ea1a 1742
NYX 0:85b3fd62ea1a 1743 /**
NYX 0:85b3fd62ea1a 1744 * @brief Return the IARDA error code
NYX 0:85b3fd62ea1a 1745 * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1746 * the configuration information for the specified IRDA.
NYX 0:85b3fd62ea1a 1747 * @retval IRDA Error Code
NYX 0:85b3fd62ea1a 1748 */
NYX 0:85b3fd62ea1a 1749 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1750 {
NYX 0:85b3fd62ea1a 1751 return hirda->ErrorCode;
NYX 0:85b3fd62ea1a 1752 }
NYX 0:85b3fd62ea1a 1753
NYX 0:85b3fd62ea1a 1754 /**
NYX 0:85b3fd62ea1a 1755 * @}
NYX 0:85b3fd62ea1a 1756 */
NYX 0:85b3fd62ea1a 1757
NYX 0:85b3fd62ea1a 1758 /**
NYX 0:85b3fd62ea1a 1759 * @brief DMA IRDA transmit process complete callback.
NYX 0:85b3fd62ea1a 1760 * @param hdma : DMA handle
NYX 0:85b3fd62ea1a 1761 * @retval None
NYX 0:85b3fd62ea1a 1762 */
NYX 0:85b3fd62ea1a 1763 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1764 {
NYX 0:85b3fd62ea1a 1765 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1766 /* DMA Normal mode */
NYX 0:85b3fd62ea1a 1767 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
NYX 0:85b3fd62ea1a 1768 {
NYX 0:85b3fd62ea1a 1769 hirda->TxXferCount = 0U;
NYX 0:85b3fd62ea1a 1770
NYX 0:85b3fd62ea1a 1771 /* Disable the DMA transfer for transmit request by setting the DMAT bit
NYX 0:85b3fd62ea1a 1772 in the IRDA CR3 register */
NYX 0:85b3fd62ea1a 1773 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 1774
NYX 0:85b3fd62ea1a 1775 /* Enable the IRDA Transmit Complete Interrupt */
NYX 0:85b3fd62ea1a 1776 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
NYX 0:85b3fd62ea1a 1777 }
NYX 0:85b3fd62ea1a 1778 /* DMA Circular mode */
NYX 0:85b3fd62ea1a 1779 else
NYX 0:85b3fd62ea1a 1780 {
NYX 0:85b3fd62ea1a 1781 HAL_IRDA_TxCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1782 }
NYX 0:85b3fd62ea1a 1783 }
NYX 0:85b3fd62ea1a 1784
NYX 0:85b3fd62ea1a 1785 /**
NYX 0:85b3fd62ea1a 1786 * @brief DMA IRDA receive process half complete callback
NYX 0:85b3fd62ea1a 1787 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1788 * the configuration information for the specified DMA module.
NYX 0:85b3fd62ea1a 1789 * @retval None
NYX 0:85b3fd62ea1a 1790 */
NYX 0:85b3fd62ea1a 1791 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1792 {
NYX 0:85b3fd62ea1a 1793 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1794
NYX 0:85b3fd62ea1a 1795 HAL_IRDA_TxHalfCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1796 }
NYX 0:85b3fd62ea1a 1797
NYX 0:85b3fd62ea1a 1798 /**
NYX 0:85b3fd62ea1a 1799 * @brief DMA IRDA receive process complete callback.
NYX 0:85b3fd62ea1a 1800 * @param hdma: DMA handle
NYX 0:85b3fd62ea1a 1801 * @retval None
NYX 0:85b3fd62ea1a 1802 */
NYX 0:85b3fd62ea1a 1803 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1804 {
NYX 0:85b3fd62ea1a 1805 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1806 /* DMA Normal mode */
NYX 0:85b3fd62ea1a 1807 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
NYX 0:85b3fd62ea1a 1808 {
NYX 0:85b3fd62ea1a 1809 hirda->RxXferCount = 0U;
NYX 0:85b3fd62ea1a 1810
NYX 0:85b3fd62ea1a 1811 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
NYX 0:85b3fd62ea1a 1812 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
NYX 0:85b3fd62ea1a 1813 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 1814
NYX 0:85b3fd62ea1a 1815 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
NYX 0:85b3fd62ea1a 1816 in the IRDA CR3 register */
NYX 0:85b3fd62ea1a 1817 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 1818
NYX 0:85b3fd62ea1a 1819 /* At end of Rx process, restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 1820 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1821 }
NYX 0:85b3fd62ea1a 1822
NYX 0:85b3fd62ea1a 1823 HAL_IRDA_RxCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1824 }
NYX 0:85b3fd62ea1a 1825
NYX 0:85b3fd62ea1a 1826 /**
NYX 0:85b3fd62ea1a 1827 * @brief DMA IRDA receive process half complete callback
NYX 0:85b3fd62ea1a 1828 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1829 * the configuration information for the specified DMA module.
NYX 0:85b3fd62ea1a 1830 * @retval None
NYX 0:85b3fd62ea1a 1831 */
NYX 0:85b3fd62ea1a 1832 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1833 {
NYX 0:85b3fd62ea1a 1834 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1835 HAL_IRDA_RxHalfCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1836 }
NYX 0:85b3fd62ea1a 1837
NYX 0:85b3fd62ea1a 1838 /**
NYX 0:85b3fd62ea1a 1839 * @brief DMA IRDA communication error callback.
NYX 0:85b3fd62ea1a 1840 * @param hdma: DMA handle
NYX 0:85b3fd62ea1a 1841 * @retval None
NYX 0:85b3fd62ea1a 1842 */
NYX 0:85b3fd62ea1a 1843 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 1844 {
NYX 0:85b3fd62ea1a 1845 uint32_t dmarequest = 0x00U;
NYX 0:85b3fd62ea1a 1846 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 1847
NYX 0:85b3fd62ea1a 1848 /* Stop IRDA DMA Tx request if ongoing */
NYX 0:85b3fd62ea1a 1849 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
NYX 0:85b3fd62ea1a 1850 if((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
NYX 0:85b3fd62ea1a 1851 {
NYX 0:85b3fd62ea1a 1852 hirda->TxXferCount = 0U;
NYX 0:85b3fd62ea1a 1853 IRDA_EndTxTransfer(hirda);
NYX 0:85b3fd62ea1a 1854 }
NYX 0:85b3fd62ea1a 1855
NYX 0:85b3fd62ea1a 1856 /* Stop IRDA DMA Rx request if ongoing */
NYX 0:85b3fd62ea1a 1857 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
NYX 0:85b3fd62ea1a 1858 if((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
NYX 0:85b3fd62ea1a 1859 {
NYX 0:85b3fd62ea1a 1860 hirda->RxXferCount = 0U;
NYX 0:85b3fd62ea1a 1861 IRDA_EndRxTransfer(hirda);
NYX 0:85b3fd62ea1a 1862 }
NYX 0:85b3fd62ea1a 1863
NYX 0:85b3fd62ea1a 1864 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
NYX 0:85b3fd62ea1a 1865
NYX 0:85b3fd62ea1a 1866 HAL_IRDA_ErrorCallback(hirda);
NYX 0:85b3fd62ea1a 1867 }
NYX 0:85b3fd62ea1a 1868
NYX 0:85b3fd62ea1a 1869 /**
NYX 0:85b3fd62ea1a 1870 * @brief This function handles IRDA Communication Timeout.
NYX 0:85b3fd62ea1a 1871 * @param hirda pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1872 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1873 * @param Flag specifies the IRDA flag to check.
NYX 0:85b3fd62ea1a 1874 * @param Status The new Flag status (SET or RESET).
NYX 0:85b3fd62ea1a 1875 * @param Tickstart Tick start value
NYX 0:85b3fd62ea1a 1876 * @param Timeout Timeout duration
NYX 0:85b3fd62ea1a 1877 * @retval HAL status
NYX 0:85b3fd62ea1a 1878 */
NYX 0:85b3fd62ea1a 1879 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
NYX 0:85b3fd62ea1a 1880 {
NYX 0:85b3fd62ea1a 1881 /* Wait until flag is set */
NYX 0:85b3fd62ea1a 1882 while((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status)
NYX 0:85b3fd62ea1a 1883 {
NYX 0:85b3fd62ea1a 1884 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 1885 if(Timeout != HAL_MAX_DELAY)
NYX 0:85b3fd62ea1a 1886 {
NYX 0:85b3fd62ea1a 1887 if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))
NYX 0:85b3fd62ea1a 1888 {
NYX 0:85b3fd62ea1a 1889 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
NYX 0:85b3fd62ea1a 1890 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
NYX 0:85b3fd62ea1a 1891 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 1892
NYX 0:85b3fd62ea1a 1893 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1894 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1895
NYX 0:85b3fd62ea1a 1896 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1897 __HAL_UNLOCK(hirda);
NYX 0:85b3fd62ea1a 1898
NYX 0:85b3fd62ea1a 1899 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 1900 }
NYX 0:85b3fd62ea1a 1901 }
NYX 0:85b3fd62ea1a 1902 }
NYX 0:85b3fd62ea1a 1903 return HAL_OK;
NYX 0:85b3fd62ea1a 1904 }
NYX 0:85b3fd62ea1a 1905
NYX 0:85b3fd62ea1a 1906 /**
NYX 0:85b3fd62ea1a 1907 * @brief Send an amount of data in non blocking mode.
NYX 0:85b3fd62ea1a 1908 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1909 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1910 * @retval HAL status
NYX 0:85b3fd62ea1a 1911 */
NYX 0:85b3fd62ea1a 1912 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1913 {
NYX 0:85b3fd62ea1a 1914 uint16_t* tmp;
NYX 0:85b3fd62ea1a 1915
NYX 0:85b3fd62ea1a 1916 /* Check that a Tx process is ongoing */
NYX 0:85b3fd62ea1a 1917 if(hirda->gState == HAL_IRDA_STATE_BUSY_TX)
NYX 0:85b3fd62ea1a 1918 {
NYX 0:85b3fd62ea1a 1919 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
NYX 0:85b3fd62ea1a 1920 {
NYX 0:85b3fd62ea1a 1921 tmp = (uint16_t*) hirda->pTxBuffPtr;
NYX 0:85b3fd62ea1a 1922 hirda->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
NYX 0:85b3fd62ea1a 1923 if(hirda->Init.Parity == IRDA_PARITY_NONE)
NYX 0:85b3fd62ea1a 1924 {
NYX 0:85b3fd62ea1a 1925 hirda->pTxBuffPtr += 2U;
NYX 0:85b3fd62ea1a 1926 }
NYX 0:85b3fd62ea1a 1927 else
NYX 0:85b3fd62ea1a 1928 {
NYX 0:85b3fd62ea1a 1929 hirda->pTxBuffPtr += 1U;
NYX 0:85b3fd62ea1a 1930 }
NYX 0:85b3fd62ea1a 1931 }
NYX 0:85b3fd62ea1a 1932 else
NYX 0:85b3fd62ea1a 1933 {
NYX 0:85b3fd62ea1a 1934 hirda->Instance->DR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0x00FF);
NYX 0:85b3fd62ea1a 1935 }
NYX 0:85b3fd62ea1a 1936
NYX 0:85b3fd62ea1a 1937 if(--hirda->TxXferCount == 0U)
NYX 0:85b3fd62ea1a 1938 {
NYX 0:85b3fd62ea1a 1939 /* Disable the IRDA Transmit Data Register Empty Interrupt */
NYX 0:85b3fd62ea1a 1940 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
NYX 0:85b3fd62ea1a 1941
NYX 0:85b3fd62ea1a 1942 /* Enable the IRDA Transmit Complete Interrupt */
NYX 0:85b3fd62ea1a 1943 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
NYX 0:85b3fd62ea1a 1944 }
NYX 0:85b3fd62ea1a 1945
NYX 0:85b3fd62ea1a 1946 return HAL_OK;
NYX 0:85b3fd62ea1a 1947 }
NYX 0:85b3fd62ea1a 1948 else
NYX 0:85b3fd62ea1a 1949 {
NYX 0:85b3fd62ea1a 1950 return HAL_BUSY;
NYX 0:85b3fd62ea1a 1951 }
NYX 0:85b3fd62ea1a 1952 }
NYX 0:85b3fd62ea1a 1953
NYX 0:85b3fd62ea1a 1954 /**
NYX 0:85b3fd62ea1a 1955 * @brief Wraps up transmission in non blocking mode.
NYX 0:85b3fd62ea1a 1956 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1957 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1958 * @retval HAL status
NYX 0:85b3fd62ea1a 1959 */
NYX 0:85b3fd62ea1a 1960 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1961 {
NYX 0:85b3fd62ea1a 1962 /* Disable the IRDA Transmit Complete Interrupt */
NYX 0:85b3fd62ea1a 1963 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
NYX 0:85b3fd62ea1a 1964
NYX 0:85b3fd62ea1a 1965 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
NYX 0:85b3fd62ea1a 1966 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 1967
NYX 0:85b3fd62ea1a 1968 /* Tx process is ended, restore hirda->gState to Ready */
NYX 0:85b3fd62ea1a 1969 hirda->gState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 1970
NYX 0:85b3fd62ea1a 1971 HAL_IRDA_TxCpltCallback(hirda);
NYX 0:85b3fd62ea1a 1972
NYX 0:85b3fd62ea1a 1973 return HAL_OK;
NYX 0:85b3fd62ea1a 1974 }
NYX 0:85b3fd62ea1a 1975
NYX 0:85b3fd62ea1a 1976 /**
NYX 0:85b3fd62ea1a 1977 * @brief Receives an amount of data in non blocking mode.
NYX 0:85b3fd62ea1a 1978 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1979 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 1980 * @retval HAL status
NYX 0:85b3fd62ea1a 1981 */
NYX 0:85b3fd62ea1a 1982 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 1983 {
NYX 0:85b3fd62ea1a 1984 uint16_t* tmp;
NYX 0:85b3fd62ea1a 1985 uint16_t uhdata;
NYX 0:85b3fd62ea1a 1986
NYX 0:85b3fd62ea1a 1987 /* Check that a Rx process is ongoing */
NYX 0:85b3fd62ea1a 1988 if(hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
NYX 0:85b3fd62ea1a 1989 {
NYX 0:85b3fd62ea1a 1990 uhdata = (uint16_t) READ_REG(hirda->Instance->DR);
NYX 0:85b3fd62ea1a 1991 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
NYX 0:85b3fd62ea1a 1992 {
NYX 0:85b3fd62ea1a 1993 tmp = (uint16_t*) hirda->pRxBuffPtr;
NYX 0:85b3fd62ea1a 1994 if(hirda->Init.Parity == IRDA_PARITY_NONE)
NYX 0:85b3fd62ea1a 1995 {
NYX 0:85b3fd62ea1a 1996 *tmp = (uint16_t)(uhdata & (uint16_t)0x01FF);
NYX 0:85b3fd62ea1a 1997 hirda->pRxBuffPtr += 2U;
NYX 0:85b3fd62ea1a 1998 }
NYX 0:85b3fd62ea1a 1999 else
NYX 0:85b3fd62ea1a 2000 {
NYX 0:85b3fd62ea1a 2001 *tmp = (uint16_t)(uhdata & (uint16_t)0x00FF);
NYX 0:85b3fd62ea1a 2002 hirda->pRxBuffPtr += 1U;
NYX 0:85b3fd62ea1a 2003 }
NYX 0:85b3fd62ea1a 2004 }
NYX 0:85b3fd62ea1a 2005 else
NYX 0:85b3fd62ea1a 2006 {
NYX 0:85b3fd62ea1a 2007 if(hirda->Init.Parity == IRDA_PARITY_NONE)
NYX 0:85b3fd62ea1a 2008 {
NYX 0:85b3fd62ea1a 2009 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x00FF);
NYX 0:85b3fd62ea1a 2010 }
NYX 0:85b3fd62ea1a 2011 else
NYX 0:85b3fd62ea1a 2012 {
NYX 0:85b3fd62ea1a 2013 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x007F);
NYX 0:85b3fd62ea1a 2014 }
NYX 0:85b3fd62ea1a 2015 }
NYX 0:85b3fd62ea1a 2016
NYX 0:85b3fd62ea1a 2017 if(--hirda->RxXferCount == 0U)
NYX 0:85b3fd62ea1a 2018 {
NYX 0:85b3fd62ea1a 2019 /* Disable the IRDA Data Register not empty Interrupt */
NYX 0:85b3fd62ea1a 2020 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
NYX 0:85b3fd62ea1a 2021
NYX 0:85b3fd62ea1a 2022 /* Disable the IRDA Parity Error Interrupt */
NYX 0:85b3fd62ea1a 2023 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
NYX 0:85b3fd62ea1a 2024
NYX 0:85b3fd62ea1a 2025 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
NYX 0:85b3fd62ea1a 2026 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
NYX 0:85b3fd62ea1a 2027
NYX 0:85b3fd62ea1a 2028 /* Rx process is completed, restore hirda->RxState to Ready */
NYX 0:85b3fd62ea1a 2029 hirda->RxState = HAL_IRDA_STATE_READY;
NYX 0:85b3fd62ea1a 2030
NYX 0:85b3fd62ea1a 2031 HAL_IRDA_RxCpltCallback(hirda);
NYX 0:85b3fd62ea1a 2032
NYX 0:85b3fd62ea1a 2033 return HAL_OK;
NYX 0:85b3fd62ea1a 2034 }
NYX 0:85b3fd62ea1a 2035 return HAL_OK;
NYX 0:85b3fd62ea1a 2036 }
NYX 0:85b3fd62ea1a 2037 else
NYX 0:85b3fd62ea1a 2038 {
NYX 0:85b3fd62ea1a 2039 return HAL_BUSY;
NYX 0:85b3fd62ea1a 2040 }
NYX 0:85b3fd62ea1a 2041 }
NYX 0:85b3fd62ea1a 2042
NYX 0:85b3fd62ea1a 2043 /**
NYX 0:85b3fd62ea1a 2044 * @brief Configures the IRDA peripheral.
NYX 0:85b3fd62ea1a 2045 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2046 * the configuration information for the specified IRDA module.
NYX 0:85b3fd62ea1a 2047 * @retval None
NYX 0:85b3fd62ea1a 2048 */
NYX 0:85b3fd62ea1a 2049 static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
NYX 0:85b3fd62ea1a 2050 {
NYX 0:85b3fd62ea1a 2051 /* Check the parameters */
NYX 0:85b3fd62ea1a 2052 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
NYX 0:85b3fd62ea1a 2053 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
NYX 0:85b3fd62ea1a 2054 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
NYX 0:85b3fd62ea1a 2055 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
NYX 0:85b3fd62ea1a 2056 assert_param(IS_IRDA_MODE(hirda->Init.Mode));
NYX 0:85b3fd62ea1a 2057
NYX 0:85b3fd62ea1a 2058 /*-------------------------- IRDA CR2 Configuration ------------------------*/
NYX 0:85b3fd62ea1a 2059 /* Clear STOP[13:12] bits */
NYX 0:85b3fd62ea1a 2060 CLEAR_BIT(hirda->Instance->CR2, USART_CR2_STOP);
NYX 0:85b3fd62ea1a 2061
NYX 0:85b3fd62ea1a 2062 /*-------------------------- USART CR1 Configuration -----------------------*/
NYX 0:85b3fd62ea1a 2063 /* Clear M, PCE, PS, TE and RE bits */
NYX 0:85b3fd62ea1a 2064 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE);
NYX 0:85b3fd62ea1a 2065
NYX 0:85b3fd62ea1a 2066 /* Configure the USART Word Length, Parity and mode:
NYX 0:85b3fd62ea1a 2067 Set the M bits according to hirda->Init.WordLength value
NYX 0:85b3fd62ea1a 2068 Set PCE and PS bits according to hirda->Init.Parity value
NYX 0:85b3fd62ea1a 2069 Set TE and RE bits according to hirda->Init.Mode value */
NYX 0:85b3fd62ea1a 2070 /* Write to USART CR1 */
NYX 0:85b3fd62ea1a 2071 SET_BIT(hirda->Instance->CR1, (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode);
NYX 0:85b3fd62ea1a 2072
NYX 0:85b3fd62ea1a 2073 /*-------------------------- USART CR3 Configuration -----------------------*/
NYX 0:85b3fd62ea1a 2074 /* Clear CTSE and RTSE bits */
NYX 0:85b3fd62ea1a 2075 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_RTSE | USART_CR3_CTSE);
NYX 0:85b3fd62ea1a 2076
NYX 0:85b3fd62ea1a 2077 /*-------------------------- USART BRR Configuration -----------------------*/
NYX 0:85b3fd62ea1a 2078 #if defined(USART6)
NYX 0:85b3fd62ea1a 2079 if((hirda->Instance == USART1) || (hirda->Instance == USART6))
NYX 0:85b3fd62ea1a 2080 {
NYX 0:85b3fd62ea1a 2081 SET_BIT(hirda->Instance->BRR, IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate));
NYX 0:85b3fd62ea1a 2082 }
NYX 0:85b3fd62ea1a 2083 #else
NYX 0:85b3fd62ea1a 2084 if(hirda->Instance == USART1)
NYX 0:85b3fd62ea1a 2085 {
NYX 0:85b3fd62ea1a 2086 SET_BIT(hirda->Instance->BRR, IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate));
NYX 0:85b3fd62ea1a 2087 }
NYX 0:85b3fd62ea1a 2088 #endif /* USART6 */
NYX 0:85b3fd62ea1a 2089 else
NYX 0:85b3fd62ea1a 2090 {
NYX 0:85b3fd62ea1a 2091 SET_BIT(hirda->Instance->BRR, IRDA_BRR(HAL_RCC_GetPCLK1Freq(), hirda->Init.BaudRate));
NYX 0:85b3fd62ea1a 2092 }
NYX 0:85b3fd62ea1a 2093 }
NYX 0:85b3fd62ea1a 2094
NYX 0:85b3fd62ea1a 2095 /**
NYX 0:85b3fd62ea1a 2096 * @}
NYX 0:85b3fd62ea1a 2097 */
NYX 0:85b3fd62ea1a 2098
NYX 0:85b3fd62ea1a 2099 #endif /* HAL_IRDA_MODULE_ENABLED */
NYX 0:85b3fd62ea1a 2100 /**
NYX 0:85b3fd62ea1a 2101 * @}
NYX 0:85b3fd62ea1a 2102 */
NYX 0:85b3fd62ea1a 2103
NYX 0:85b3fd62ea1a 2104 /**
NYX 0:85b3fd62ea1a 2105 * @}
NYX 0:85b3fd62ea1a 2106 */
NYX 0:85b3fd62ea1a 2107
NYX 0:85b3fd62ea1a 2108 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/