Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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