stm32f4xx_hal_irda.c 70 KB

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