stm32f4xx_hal_irda.c 72 KB

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