stm32f0xx_hal_irda.c 109 KB

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