py32f002b_hal_uart.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_hal_uart.c
  4. * @author MCU Application Team
  5. * @brief UART HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State and Errors functions
  12. @verbatim
  13. ==============================================================================
  14. ##### How to use this driver #####
  15. ==============================================================================
  16. [..]
  17. The UART HAL driver can be used as follows:
  18. (#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart).
  19. (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
  20. (##) Enable the USARTx interface clock.
  21. (##) UART pins configuration:
  22. (+++) Enable the clock for the UART GPIOs.
  23. (+++) Configure these UART pins (TX as alternate function pull-up, RX as alternate function Input).
  24. (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT()
  25. and HAL_UART_Receive_IT() APIs):
  26. (+++) Configure the USARTx interrupt priority.
  27. (+++) Enable the NVIC USART IRQ handle.
  28. (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware
  29. flow control and Mode(Receiver/Transmitter) in the huart Init structure.
  30. (#) For the UART asynchronous mode, initialize the UART registers by calling
  31. the HAL_UART_Init() API.
  32. (#) For the UART Half duplex mode, initialize the UART registers by calling
  33. the HAL_HalfDuplex_Init() API.
  34. (#) For the LIN mode, initialize the UART registers by calling the HAL_LIN_Init() API.
  35. (#) For the Multi-Processor mode, initialize the UART registers by calling
  36. the HAL_MultiProcessor_Init() API.
  37. [..]
  38. (@) The specific UART interrupts (Transmission complete interrupt,
  39. RXNE interrupt and Error Interrupts) will be managed using the macros
  40. __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit
  41. and receive process.
  42. [..]
  43. (@) These APIs (HAL_UART_Init() and HAL_HalfDuplex_Init()) configure also the
  44. low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized
  45. HAL_UART_MspInit() API.
  46. ##### Callback registration #####
  47. ==================================
  48. [..]
  49. The compilation define USE_HAL_UART_REGISTER_CALLBACKS when set to 1
  50. allows the user to configure dynamically the driver callbacks.
  51. [..]
  52. Use Function @ref HAL_UART_RegisterCallback() to register a user callback.
  53. Function @ref HAL_UART_RegisterCallback() allows to register following callbacks:
  54. (+) TxHalfCpltCallback : Tx Half Complete Callback.
  55. (+) TxCpltCallback : Tx Complete Callback.
  56. (+) RxHalfCpltCallback : Rx Half Complete Callback.
  57. (+) RxCpltCallback : Rx Complete Callback.
  58. (+) ErrorCallback : Error Callback.
  59. (+) AbortCpltCallback : Abort Complete Callback.
  60. (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback.
  61. (+) AbortReceiveCpltCallback : Abort Receive Complete Callback.
  62. (+) MspInitCallback : UART MspInit.
  63. (+) MspDeInitCallback : UART MspDeInit.
  64. This function takes as parameters the HAL peripheral handle, the Callback ID
  65. and a pointer to the user callback function.
  66. [..]
  67. Use function @ref HAL_UART_UnRegisterCallback() to reset a callback to the default
  68. weak (surcharged) function.
  69. @ref HAL_UART_UnRegisterCallback() takes as parameters the HAL peripheral handle,
  70. and the Callback ID.
  71. This function allows to reset following callbacks:
  72. (+) TxHalfCpltCallback : Tx Half Complete Callback.
  73. (+) TxCpltCallback : Tx Complete Callback.
  74. (+) RxHalfCpltCallback : Rx Half Complete Callback.
  75. (+) RxCpltCallback : Rx Complete Callback.
  76. (+) ErrorCallback : Error Callback.
  77. (+) AbortCpltCallback : Abort Complete Callback.
  78. (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback.
  79. (+) AbortReceiveCpltCallback : Abort Receive Complete Callback.
  80. (+) MspInitCallback : UART MspInit.
  81. (+) MspDeInitCallback : UART MspDeInit.
  82. [..]
  83. By default, after the @ref HAL_UART_Init() and when the state is HAL_UART_STATE_RESET
  84. all callbacks are set to the corresponding weak (surcharged) functions:
  85. examples @ref HAL_UART_TxCpltCallback(), @ref HAL_UART_RxHalfCpltCallback().
  86. Exception done for MspInit and MspDeInit functions that are respectively
  87. reset to the legacy weak (surcharged) functions in the @ref HAL_UART_Init()
  88. and @ref HAL_UART_DeInit() only when these callbacks are null (not registered beforehand).
  89. If not, MspInit or MspDeInit are not null, the @ref HAL_UART_Init() and @ref HAL_UART_DeInit()
  90. keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
  91. [..]
  92. Callbacks can be registered/unregistered in HAL_UART_STATE_READY state only.
  93. Exception done MspInit/MspDeInit that can be registered/unregistered
  94. in HAL_UART_STATE_READY or HAL_UART_STATE_RESET state, thus registered (user)
  95. MspInit/DeInit callbacks can be used during the Init/DeInit.
  96. In that case first register the MspInit/MspDeInit user callbacks
  97. using @ref HAL_UART_RegisterCallback() before calling @ref HAL_UART_DeInit()
  98. or @ref HAL_UART_Init() function.
  99. [..]
  100. When The compilation define USE_HAL_UART_REGISTER_CALLBACKS is set to 0 or
  101. not defined, the callback registration feature is not available
  102. and weak (surcharged) callbacks are used.
  103. [..]
  104. Three operation modes are available within this driver :
  105. *** Polling mode IO operation ***
  106. =================================
  107. [..]
  108. (+) Send an amount of data in blocking mode using HAL_UART_Transmit()
  109. (+) Receive an amount of data in blocking mode using HAL_UART_Receive()
  110. *** Interrupt mode IO operation ***
  111. ===================================
  112. [..]
  113. (+) Send an amount of data in non blocking mode using HAL_UART_Transmit_IT()
  114. (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can
  115. add his own code by customization of function pointer HAL_UART_TxCpltCallback
  116. (+) Receive an amount of data in non blocking mode using HAL_UART_Receive_IT()
  117. (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can
  118. add his own code by customization of function pointer HAL_UART_RxCpltCallback
  119. (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can
  120. add his own code by customization of function pointer HAL_UART_ErrorCallback
  121. *** UART HAL driver macros list ***
  122. =============================================
  123. [..]
  124. Below the list of most used macros in UART HAL driver.
  125. (+) __HAL_UART_ENABLE: Enable the UART peripheral
  126. (+) __HAL_UART_DISABLE: Disable the UART peripheral
  127. (+) __HAL_UART_GET_FLAG : Check whether the specified UART flag is set or not
  128. (+) __HAL_UART_CLEAR_FLAG : Clear the specified UART pending flag
  129. (+) __HAL_UART_ENABLE_IT: Enable the specified UART interrupt
  130. (+) __HAL_UART_DISABLE_IT: Disable the specified UART interrupt
  131. (+) __HAL_UART_GET_IT_SOURCE: Check whether the specified UART interrupt has occurred or not
  132. [..]
  133. (@) You can refer to the UART HAL driver header file for more useful macros
  134. @endverbatim
  135. [..]
  136. (@) Additionnal remark: If the parity is enabled, then the MSB bit of the data written
  137. in the data register is transmitted but is changed by the parity bit.
  138. Depending on the frame length defined by the M bit (8-bits or 9-bits),
  139. the possible UART frame formats are as listed in the following table:
  140. +-------------------------------------------------------------+
  141. | M bit | PCE bit | UART frame |
  142. |---------------------|---------------------------------------|
  143. | 0 | 0 | | SB | 8 bit data | STB | |
  144. |---------|-----------|---------------------------------------|
  145. | 0 | 1 | | SB | 7 bit data | PB | STB | |
  146. |---------|-----------|---------------------------------------|
  147. | 1 | 0 | | SB | 9 bit data | STB | |
  148. |---------|-----------|---------------------------------------|
  149. | 1 | 1 | | SB | 8 bit data | PB | STB | |
  150. +-------------------------------------------------------------+
  151. ******************************************************************************
  152. * @attention
  153. *
  154. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  155. * All rights reserved.</center></h2>
  156. *
  157. * This software component is licensed by Puya under BSD 3-Clause license,
  158. * the "License"; You may not use this file except in compliance with the
  159. * License. You may obtain a copy of the License at:
  160. * opensource.org/licenses/BSD-3-Clause
  161. *
  162. ******************************************************************************
  163. * @attention
  164. *
  165. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  166. * All rights reserved.</center></h2>
  167. *
  168. * This software component is licensed by ST under BSD 3-Clause license,
  169. * the "License"; You may not use this file except in compliance with the
  170. * License. You may obtain a copy of the License at:
  171. * opensource.org/licenses/BSD-3-Clause
  172. *
  173. ******************************************************************************
  174. */
  175. /* Includes ------------------------------------------------------------------*/
  176. #include "py32f0xx_hal.h"
  177. /** @addtogroup PY32F002B_HAL_Driver
  178. * @{
  179. */
  180. /** @defgroup UART UART
  181. * @brief HAL UART module driver
  182. * @{
  183. */
  184. #ifdef HAL_UART_MODULE_ENABLED
  185. /* Private typedef -----------------------------------------------------------*/
  186. /* Private define ------------------------------------------------------------*/
  187. /** @addtogroup UART_Private_Constants
  188. * @{
  189. */
  190. /**
  191. * @}
  192. */
  193. /* Private macro -------------------------------------------------------------*/
  194. /* Private variables ---------------------------------------------------------*/
  195. /* Private function prototypes -----------------------------------------------*/
  196. /** @addtogroup UART_Private_Functions UART Private Functions
  197. * @{
  198. */
  199. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  200. void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart);
  201. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  202. static void UART_EndRxTransfer(UART_HandleTypeDef *huart);
  203. static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart);
  204. static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart);
  205. static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart);
  206. static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
  207. static void UART_SetConfig(UART_HandleTypeDef *huart);
  208. static void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
  209. /**
  210. * @}
  211. */
  212. /* Exported functions ---------------------------------------------------------*/
  213. /** @defgroup UART_Exported_Functions UART Exported Functions
  214. * @{
  215. */
  216. /** @defgroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
  217. * @brief Initialization and Configuration functions
  218. *
  219. @verbatim
  220. ===============================================================================
  221. ##### Initialization and Configuration functions #####
  222. ===============================================================================
  223. [..]
  224. This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
  225. in asynchronous mode.
  226. (+) For the asynchronous mode only these parameters can be configured:
  227. (++) Baud Rate
  228. (++) Word Length
  229. (++) Stop Bit
  230. (++) Parity: If the parity is enabled, then the MSB bit of the data written
  231. in the data register is transmitted but is changed by the parity bit.
  232. Depending on the frame length defined by the M bit (8-bits or 9-bits),
  233. please refer to Reference manual for possible UART frame formats.
  234. (++) Hardware flow control
  235. (++) Receiver/transmitter modes
  236. (++) Over Sampling Method
  237. [..]
  238. The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init() and HAL_MultiProcessor_Init() APIs
  239. follow respectively the UART asynchronous, UART Half duplex, LIN and Multi-Processor configuration
  240. procedures (details for the procedures are available in reference manuals
  241. @endverbatim
  242. * @{
  243. */
  244. /**
  245. * @brief Initializes the UART mode according to the specified parameters in
  246. * the UART_InitTypeDef and create the associated handle.
  247. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  248. * the configuration information for the specified UART module.
  249. * @retval HAL status
  250. */
  251. HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
  252. {
  253. /* Check the UART handle allocation */
  254. if (huart == NULL)
  255. {
  256. return HAL_ERROR;
  257. }
  258. /* Check the parameters */
  259. if (huart->Init.HwFlowCtl != UART_HWCONTROL_NONE)
  260. {
  261. /* The hardware flow control is available only for USART1 */
  262. assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance));
  263. assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl));
  264. }
  265. else
  266. {
  267. assert_param(IS_UART_INSTANCE(huart->Instance));
  268. }
  269. assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
  270. #if defined(USART_CR3_OVER8)
  271. assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
  272. #endif /* USART_CR3_OVER8 */
  273. if (huart->gState == HAL_UART_STATE_RESET)
  274. {
  275. /* Allocate lock resource and initialize it */
  276. huart->Lock = HAL_UNLOCKED;
  277. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  278. UART_InitCallbacksToDefault(huart);
  279. if (huart->MspInitCallback == NULL)
  280. {
  281. huart->MspInitCallback = HAL_UART_MspInit;
  282. }
  283. /* Init the low level hardware */
  284. huart->MspInitCallback(huart);
  285. #else
  286. /* Init the low level hardware : GPIO, CLOCK */
  287. HAL_UART_MspInit(huart);
  288. #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
  289. }
  290. huart->gState = HAL_UART_STATE_BUSY;
  291. /* Disable the peripheral */
  292. __HAL_UART_DISABLE(huart);
  293. /* Set the UART Communication parameters */
  294. UART_SetConfig(huart);
  295. if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
  296. {
  297. UART_AdvFeatureConfig(huart);
  298. }
  299. /* In asynchronous mode, the following bits must be kept cleared:
  300. - CLKEN bit in the USART_CR2 register,
  301. - HDSEL bit in the USART_CR3 register.*/
  302. CLEAR_BIT(huart->Instance->CR2, USART_CR2_CLKEN);
  303. CLEAR_BIT(huart->Instance->CR3, USART_CR3_HDSEL);
  304. /* Enable the peripheral */
  305. __HAL_UART_ENABLE(huart);
  306. /* Initialize the UART state */
  307. huart->ErrorCode = HAL_UART_ERROR_NONE;
  308. huart->gState = HAL_UART_STATE_READY;
  309. huart->RxState = HAL_UART_STATE_READY;
  310. return HAL_OK;
  311. }
  312. /**
  313. * @brief Initializes the half-duplex mode according to the specified
  314. * parameters in the UART_InitTypeDef and create the associated handle.
  315. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  316. * the configuration information for the specified UART module.
  317. * @retval HAL status
  318. */
  319. HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart)
  320. {
  321. /* Check the UART handle allocation */
  322. if (huart == NULL)
  323. {
  324. return HAL_ERROR;
  325. }
  326. /* Check the parameters */
  327. assert_param(IS_UART_HALFDUPLEX_INSTANCE(huart->Instance));
  328. assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
  329. #if defined(USART_CR3_OVER8)
  330. assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
  331. #endif /* USART_CR3_OVER8 */
  332. if (huart->gState == HAL_UART_STATE_RESET)
  333. {
  334. /* Allocate lock resource and initialize it */
  335. huart->Lock = HAL_UNLOCKED;
  336. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  337. UART_InitCallbacksToDefault(huart);
  338. if (huart->MspInitCallback == NULL)
  339. {
  340. huart->MspInitCallback = HAL_UART_MspInit;
  341. }
  342. /* Init the low level hardware */
  343. huart->MspInitCallback(huart);
  344. #else
  345. /* Init the low level hardware : GPIO, CLOCK */
  346. HAL_UART_MspInit(huart);
  347. #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
  348. }
  349. huart->gState = HAL_UART_STATE_BUSY;
  350. /* Disable the peripheral */
  351. __HAL_UART_DISABLE(huart);
  352. /* Set the UART Communication parameters */
  353. UART_SetConfig(huart);
  354. /* In half-duplex mode, the following bits must be kept cleared:
  355. - CLKEN bit in the USART_CR2 register.*/
  356. CLEAR_BIT(huart->Instance->CR2, USART_CR2_CLKEN);
  357. /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
  358. SET_BIT(huart->Instance->CR3, USART_CR3_HDSEL);
  359. /* Enable the peripheral */
  360. __HAL_UART_ENABLE(huart);
  361. /* Initialize the UART state*/
  362. huart->ErrorCode = HAL_UART_ERROR_NONE;
  363. huart->gState = HAL_UART_STATE_READY;
  364. huart->RxState = HAL_UART_STATE_READY;
  365. return HAL_OK;
  366. }
  367. /**
  368. * @brief Initializes the Multi-Processor mode according to the specified
  369. * parameters in the UART_InitTypeDef and create the associated handle.
  370. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  371. * the configuration information for the specified UART module.
  372. * @param Address USART address
  373. * @param WakeUpMethod specifies the USART wake-up method.
  374. * This parameter can be one of the following values:
  375. * @arg UART_WAKEUPMETHOD_IDLELINE: Wake-up by an idle line detection
  376. * @arg UART_WAKEUPMETHOD_ADDRESSMARK: Wake-up by an address mark
  377. * @retval HAL status
  378. */
  379. HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
  380. {
  381. /* Check the UART handle allocation */
  382. if (huart == NULL)
  383. {
  384. return HAL_ERROR;
  385. }
  386. /* Check the parameters */
  387. assert_param(IS_UART_INSTANCE(huart->Instance));
  388. /* Check the Address & wake up method parameters */
  389. assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod));
  390. assert_param(IS_UART_ADDRESS(Address));
  391. assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
  392. #if defined(USART_CR3_OVER8)
  393. assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
  394. #endif /* USART_CR3_OVER8 */
  395. if (huart->gState == HAL_UART_STATE_RESET)
  396. {
  397. /* Allocate lock resource and initialize it */
  398. huart->Lock = HAL_UNLOCKED;
  399. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  400. UART_InitCallbacksToDefault(huart);
  401. if (huart->MspInitCallback == NULL)
  402. {
  403. huart->MspInitCallback = HAL_UART_MspInit;
  404. }
  405. /* Init the low level hardware */
  406. huart->MspInitCallback(huart);
  407. #else
  408. /* Init the low level hardware : GPIO, CLOCK */
  409. HAL_UART_MspInit(huart);
  410. #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
  411. }
  412. huart->gState = HAL_UART_STATE_BUSY;
  413. /* Disable the peripheral */
  414. __HAL_UART_DISABLE(huart);
  415. /* Set the UART Communication parameters */
  416. UART_SetConfig(huart);
  417. /* In Multi-Processor mode, the following bits must be kept cleared:
  418. - LINEN and CLKEN bits in the USART_CR2 register,
  419. - SCEN, HDSEL and IREN bits in the USART_CR3 register */
  420. CLEAR_BIT(huart->Instance->CR2, USART_CR2_CLKEN);
  421. CLEAR_BIT(huart->Instance->CR3, USART_CR3_HDSEL);
  422. /* Set the USART address node */
  423. CLEAR_BIT(huart->Instance->CR2, USART_CR2_ADD);
  424. SET_BIT(huart->Instance->CR2, Address);
  425. /* Set the wake up method by setting the WAKE bit in the CR1 register */
  426. CLEAR_BIT(huart->Instance->CR1, USART_CR1_WAKE);
  427. SET_BIT(huart->Instance->CR1, WakeUpMethod);
  428. /* Enable the peripheral */
  429. __HAL_UART_ENABLE(huart);
  430. /* Initialize the UART state */
  431. huart->ErrorCode = HAL_UART_ERROR_NONE;
  432. huart->gState = HAL_UART_STATE_READY;
  433. huart->RxState = HAL_UART_STATE_READY;
  434. return HAL_OK;
  435. }
  436. /**
  437. * @brief DeInitializes the UART peripheral.
  438. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  439. * the configuration information for the specified UART module.
  440. * @retval HAL status
  441. */
  442. HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
  443. {
  444. /* Check the UART handle allocation */
  445. if (huart == NULL)
  446. {
  447. return HAL_ERROR;
  448. }
  449. /* Check the parameters */
  450. assert_param(IS_UART_INSTANCE(huart->Instance));
  451. huart->gState = HAL_UART_STATE_BUSY;
  452. /* Disable the Peripheral */
  453. __HAL_UART_DISABLE(huart);
  454. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  455. if (huart->MspDeInitCallback == NULL)
  456. {
  457. huart->MspDeInitCallback = HAL_UART_MspDeInit;
  458. }
  459. /* DeInit the low level hardware */
  460. huart->MspDeInitCallback(huart);
  461. #else
  462. /* DeInit the low level hardware */
  463. HAL_UART_MspDeInit(huart);
  464. #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
  465. huart->ErrorCode = HAL_UART_ERROR_NONE;
  466. huart->gState = HAL_UART_STATE_RESET;
  467. huart->RxState = HAL_UART_STATE_RESET;
  468. /* Process Unlock */
  469. __HAL_UNLOCK(huart);
  470. return HAL_OK;
  471. }
  472. /**
  473. * @brief UART MSP Init.
  474. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  475. * the configuration information for the specified UART module.
  476. * @retval None
  477. */
  478. __weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
  479. {
  480. /* Prevent unused argument(s) compilation warning */
  481. UNUSED(huart);
  482. /* NOTE: This function should not be modified, when the callback is needed,
  483. the HAL_UART_MspInit could be implemented in the user file
  484. */
  485. }
  486. /**
  487. * @brief UART MSP DeInit.
  488. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  489. * the configuration information for the specified UART module.
  490. * @retval None
  491. */
  492. __weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
  493. {
  494. /* Prevent unused argument(s) compilation warning */
  495. UNUSED(huart);
  496. /* NOTE: This function should not be modified, when the callback is needed,
  497. the HAL_UART_MspDeInit could be implemented in the user file
  498. */
  499. }
  500. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  501. /**
  502. * @brief Register a User UART Callback
  503. * To be used instead of the weak predefined callback
  504. * @param huart uart handle
  505. * @param CallbackID ID of the callback to be registered
  506. * This parameter can be one of the following values:
  507. * @arg @ref HAL_UART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID
  508. * @arg @ref HAL_UART_TX_COMPLETE_CB_ID Tx Complete Callback ID
  509. * @arg @ref HAL_UART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID
  510. * @arg @ref HAL_UART_RX_COMPLETE_CB_ID Rx Complete Callback ID
  511. * @arg @ref HAL_UART_ERROR_CB_ID Error Callback ID
  512. * @arg @ref HAL_UART_ABORT_COMPLETE_CB_ID Abort Complete Callback ID
  513. * @arg @ref HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID
  514. * @arg @ref HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID
  515. * @arg @ref HAL_UART_MSPINIT_CB_ID MspInit Callback ID
  516. * @arg @ref HAL_UART_MSPDEINIT_CB_ID MspDeInit Callback ID
  517. * @param pCallback pointer to the Callback function
  518. * @retval HAL status
  519. */
  520. HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback)
  521. {
  522. HAL_StatusTypeDef status = HAL_OK;
  523. if (pCallback == NULL)
  524. {
  525. /* Update the error code */
  526. huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
  527. return HAL_ERROR;
  528. }
  529. /* Process locked */
  530. __HAL_LOCK(huart);
  531. if (huart->gState == HAL_UART_STATE_READY)
  532. {
  533. switch (CallbackID)
  534. {
  535. case HAL_UART_TX_HALFCOMPLETE_CB_ID :
  536. huart->TxHalfCpltCallback = pCallback;
  537. break;
  538. case HAL_UART_TX_COMPLETE_CB_ID :
  539. huart->TxCpltCallback = pCallback;
  540. break;
  541. case HAL_UART_RX_HALFCOMPLETE_CB_ID :
  542. huart->RxHalfCpltCallback = pCallback;
  543. break;
  544. case HAL_UART_RX_COMPLETE_CB_ID :
  545. huart->RxCpltCallback = pCallback;
  546. break;
  547. case HAL_UART_ERROR_CB_ID :
  548. huart->ErrorCallback = pCallback;
  549. break;
  550. case HAL_UART_ABORT_COMPLETE_CB_ID :
  551. huart->AbortCpltCallback = pCallback;
  552. break;
  553. case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
  554. huart->AbortTransmitCpltCallback = pCallback;
  555. break;
  556. case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
  557. huart->AbortReceiveCpltCallback = pCallback;
  558. break;
  559. case HAL_UART_MSPINIT_CB_ID :
  560. huart->MspInitCallback = pCallback;
  561. break;
  562. case HAL_UART_MSPDEINIT_CB_ID :
  563. huart->MspDeInitCallback = pCallback;
  564. break;
  565. default :
  566. /* Update the error code */
  567. huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
  568. /* Return error status */
  569. status = HAL_ERROR;
  570. break;
  571. }
  572. }
  573. else if (huart->gState == HAL_UART_STATE_RESET)
  574. {
  575. switch (CallbackID)
  576. {
  577. case HAL_UART_MSPINIT_CB_ID :
  578. huart->MspInitCallback = pCallback;
  579. break;
  580. case HAL_UART_MSPDEINIT_CB_ID :
  581. huart->MspDeInitCallback = pCallback;
  582. break;
  583. default :
  584. /* Update the error code */
  585. huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
  586. /* Return error status */
  587. status = HAL_ERROR;
  588. break;
  589. }
  590. }
  591. else
  592. {
  593. /* Update the error code */
  594. huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
  595. /* Return error status */
  596. status = HAL_ERROR;
  597. }
  598. /* Release Lock */
  599. __HAL_UNLOCK(huart);
  600. return status;
  601. }
  602. /**
  603. * @brief Unregister an UART Callback
  604. * UART callaback is redirected to the weak predefined callback
  605. * @param huart uart handle
  606. * @param CallbackID ID of the callback to be unregistered
  607. * This parameter can be one of the following values:
  608. * @arg @ref HAL_UART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID
  609. * @arg @ref HAL_UART_TX_COMPLETE_CB_ID Tx Complete Callback ID
  610. * @arg @ref HAL_UART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID
  611. * @arg @ref HAL_UART_RX_COMPLETE_CB_ID Rx Complete Callback ID
  612. * @arg @ref HAL_UART_ERROR_CB_ID Error Callback ID
  613. * @arg @ref HAL_UART_ABORT_COMPLETE_CB_ID Abort Complete Callback ID
  614. * @arg @ref HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID
  615. * @arg @ref HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID
  616. * @arg @ref HAL_UART_MSPINIT_CB_ID MspInit Callback ID
  617. * @arg @ref HAL_UART_MSPDEINIT_CB_ID MspDeInit Callback ID
  618. * @retval HAL status
  619. */
  620. HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID)
  621. {
  622. HAL_StatusTypeDef status = HAL_OK;
  623. /* Process locked */
  624. __HAL_LOCK(huart);
  625. if (HAL_UART_STATE_READY == huart->gState)
  626. {
  627. switch (CallbackID)
  628. {
  629. case HAL_UART_TX_HALFCOMPLETE_CB_ID :
  630. huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */
  631. break;
  632. case HAL_UART_TX_COMPLETE_CB_ID :
  633. huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */
  634. break;
  635. case HAL_UART_RX_HALFCOMPLETE_CB_ID :
  636. huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
  637. break;
  638. case HAL_UART_RX_COMPLETE_CB_ID :
  639. huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */
  640. break;
  641. case HAL_UART_ERROR_CB_ID :
  642. huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */
  643. break;
  644. case HAL_UART_ABORT_COMPLETE_CB_ID :
  645. huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
  646. break;
  647. case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
  648. huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
  649. break;
  650. case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
  651. huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
  652. break;
  653. case HAL_UART_MSPINIT_CB_ID :
  654. huart->MspInitCallback = HAL_UART_MspInit; /* Legacy weak MspInitCallback */
  655. break;
  656. case HAL_UART_MSPDEINIT_CB_ID :
  657. huart->MspDeInitCallback = HAL_UART_MspDeInit; /* Legacy weak MspDeInitCallback */
  658. break;
  659. default :
  660. /* Update the error code */
  661. huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
  662. /* Return error status */
  663. status = HAL_ERROR;
  664. break;
  665. }
  666. }
  667. else if (HAL_UART_STATE_RESET == huart->gState)
  668. {
  669. switch (CallbackID)
  670. {
  671. case HAL_UART_MSPINIT_CB_ID :
  672. huart->MspInitCallback = HAL_UART_MspInit;
  673. break;
  674. case HAL_UART_MSPDEINIT_CB_ID :
  675. huart->MspDeInitCallback = HAL_UART_MspDeInit;
  676. break;
  677. default :
  678. /* Update the error code */
  679. huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
  680. /* Return error status */
  681. status = HAL_ERROR;
  682. break;
  683. }
  684. }
  685. else
  686. {
  687. /* Update the error code */
  688. huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
  689. /* Return error status */
  690. status = HAL_ERROR;
  691. }
  692. /* Release Lock */
  693. __HAL_UNLOCK(huart);
  694. return status;
  695. }
  696. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  697. /**
  698. * @}
  699. */
  700. /** @defgroup UART_Exported_Functions_Group2 IO operation functions
  701. * @brief UART Transmit and Receive functions
  702. *
  703. @verbatim
  704. ===============================================================================
  705. ##### IO operation functions #####
  706. ===============================================================================
  707. This subsection provides a set of functions allowing to manage the UART asynchronous
  708. and Half duplex data transfers.
  709. (#) There are two modes of transfer:
  710. (+) Blocking mode: The communication is performed in polling mode.
  711. The HAL status of all data processing is returned by the same function
  712. after finishing transfer.
  713. (+) Non-Blocking mode: The communication is performed using Interrupts
  714. , these API's return the HAL status.
  715. The end of the data processing will be indicated through the
  716. dedicated UART IRQ when using Interrupt mode.
  717. The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks
  718. will be executed respectively at the end of the transmit or receive process
  719. The HAL_UART_ErrorCallback()user callback will be executed when a communication error is detected.
  720. (#) Blocking mode API's are :
  721. (+) HAL_UART_Transmit()
  722. (+) HAL_UART_Receive()
  723. (#) Non-Blocking mode API's with Interrupt are :
  724. (+) HAL_UART_Transmit_IT()
  725. (+) HAL_UART_Receive_IT()
  726. (+) HAL_UART_IRQHandler()
  727. (#) A set of Transfer Complete Callbacks are provided in Non_Blocking mode:
  728. (+) HAL_UART_TxHalfCpltCallback()
  729. (+) HAL_UART_TxCpltCallback()
  730. (+) HAL_UART_RxHalfCpltCallback()
  731. (+) HAL_UART_RxCpltCallback()
  732. (+) HAL_UART_ErrorCallback()
  733. (#) Non-Blocking mode transfers could be aborted using Abort API's :
  734. (+) HAL_UART_Abort()
  735. (+) HAL_UART_AbortTransmit()
  736. (+) HAL_UART_AbortReceive()
  737. (+) HAL_UART_Abort_IT()
  738. (+) HAL_UART_AbortTransmit_IT()
  739. (+) HAL_UART_AbortReceive_IT()
  740. (#) For Abort services based on interrupts (HAL_UART_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
  741. (+) HAL_UART_AbortCpltCallback()
  742. (+) HAL_UART_AbortTransmitCpltCallback()
  743. (+) HAL_UART_AbortReceiveCpltCallback()
  744. (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
  745. Errors are handled as follows :
  746. (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
  747. to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
  748. Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
  749. and HAL_UART_ErrorCallback() user callback is executed. Transfer is kept ongoing on UART side.
  750. If user wants to abort it, Abort services should be called by user.
  751. (+) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
  752. This concerns Overrun Error In Interrupt mode reception.
  753. Error code is set to allow user to identify error type, and HAL_UART_ErrorCallback() user callback is executed.
  754. -@- In the Half duplex communication, it is forbidden to run the transmit
  755. and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful.
  756. @endverbatim
  757. * @{
  758. */
  759. /**
  760. * @brief Sends an amount of data in blocking mode.
  761. * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M=1),
  762. * the sent data is handled as a set of u16. In this case, Size must indicate the number
  763. * of u16 provided through pData.
  764. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  765. * the configuration information for the specified UART module.
  766. * @param pData Pointer to data buffer (u8 or u16 data elements).
  767. * @param Size Amount of data elements (u8 or u16) to be sent
  768. * @param Timeout Timeout duration
  769. * @retval HAL status
  770. */
  771. HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
  772. {
  773. uint8_t *pdata8bits;
  774. uint16_t *pdata16bits;
  775. uint32_t tickstart = 0U;
  776. /* Check that a Tx process is not already ongoing */
  777. if (huart->gState == HAL_UART_STATE_READY)
  778. {
  779. if ((pData == NULL) || (Size == 0U))
  780. {
  781. return HAL_ERROR;
  782. }
  783. /* In case of 9bits/No Parity transfer, pData buffer provided as input parameter
  784. should be aligned on a u16 frontier, as data to be filled into DR will be
  785. handled through a u16 cast. */
  786. if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
  787. {
  788. if ((((uint32_t)pData) & 1U) != 0U)
  789. {
  790. return HAL_ERROR;
  791. }
  792. }
  793. /* Process Locked */
  794. __HAL_LOCK(huart);
  795. huart->ErrorCode = HAL_UART_ERROR_NONE;
  796. huart->gState = HAL_UART_STATE_BUSY_TX;
  797. /* Init tickstart for timeout managment */
  798. tickstart = HAL_GetTick();
  799. huart->TxXferSize = Size;
  800. huart->TxXferCount = Size;
  801. /* In case of 9bits/No Parity transfer, pData needs to be handled as a uint16_t pointer */
  802. if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
  803. {
  804. pdata8bits = NULL;
  805. pdata16bits = (uint16_t *) pData;
  806. }
  807. else
  808. {
  809. pdata8bits = pData;
  810. pdata16bits = NULL;
  811. }
  812. while (huart->TxXferCount > 0U)
  813. {
  814. if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
  815. {
  816. return HAL_TIMEOUT;
  817. }
  818. if (pdata8bits == NULL)
  819. {
  820. huart->Instance->DR = (uint16_t)(*pdata16bits & 0x01FFU);
  821. pdata16bits++;
  822. }
  823. else
  824. {
  825. huart->Instance->DR = (uint8_t)(*pdata8bits & 0xFFU);
  826. pdata8bits++;
  827. }
  828. huart->TxXferCount--;
  829. }
  830. if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
  831. {
  832. return HAL_TIMEOUT;
  833. }
  834. /* At end of Tx process, restore huart->gState to Ready */
  835. huart->gState = HAL_UART_STATE_READY;
  836. /* Process Unlocked */
  837. __HAL_UNLOCK(huart);
  838. return HAL_OK;
  839. }
  840. else
  841. {
  842. return HAL_BUSY;
  843. }
  844. }
  845. /**
  846. * @brief Receives an amount of data in blocking mode.
  847. * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M=1),
  848. * the received data is handled as a set of u16. In this case, Size must indicate the number
  849. * of u16 available through pData.
  850. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  851. * the configuration information for the specified UART module.
  852. * @param pData Pointer to data buffer (u8 or u16 data elements).
  853. * @param Size Amount of data elements (u8 or u16) to be received.
  854. * @param Timeout Timeout duration
  855. * @retval HAL status
  856. */
  857. HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
  858. {
  859. uint8_t *pdata8bits;
  860. uint16_t *pdata16bits;
  861. uint32_t tickstart = 0U;
  862. /* Check that a Rx process is not already ongoing */
  863. if (huart->RxState == HAL_UART_STATE_READY)
  864. {
  865. if ((pData == NULL) || (Size == 0U))
  866. {
  867. return HAL_ERROR;
  868. }
  869. /* In case of 9bits/No Parity transfer, pData buffer provided as input parameter
  870. should be aligned on a u16 frontier, as data to be received from RDR will be
  871. handled through a u16 cast. */
  872. if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
  873. {
  874. if ((((uint32_t)pData) & 1U) != 0U)
  875. {
  876. return HAL_ERROR;
  877. }
  878. }
  879. /* Process Locked */
  880. __HAL_LOCK(huart);
  881. huart->ErrorCode = HAL_UART_ERROR_NONE;
  882. huart->RxState = HAL_UART_STATE_BUSY_RX;
  883. /* Init tickstart for timeout managment */
  884. tickstart = HAL_GetTick();
  885. huart->RxXferSize = Size;
  886. huart->RxXferCount = Size;
  887. /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */
  888. if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
  889. {
  890. pdata8bits = NULL;
  891. pdata16bits = (uint16_t *) pData;
  892. }
  893. else
  894. {
  895. pdata8bits = pData;
  896. pdata16bits = NULL;
  897. }
  898. /* as long as data have to be received */
  899. while (huart->RxXferCount > 0U)
  900. {
  901. if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
  902. {
  903. return HAL_TIMEOUT;
  904. }
  905. if (pdata8bits == NULL)
  906. {
  907. *pdata16bits = (uint16_t)(huart->Instance->DR & 0x1FF);
  908. pdata16bits++;
  909. }
  910. else
  911. {
  912. *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0xFF);
  913. pdata8bits++;
  914. }
  915. huart->RxXferCount--;
  916. }
  917. /* At end of Rx process, restore huart->RxState to Ready */
  918. huart->RxState = HAL_UART_STATE_READY;
  919. /* Process Unlocked */
  920. __HAL_UNLOCK(huart);
  921. return HAL_OK;
  922. }
  923. else
  924. {
  925. return HAL_BUSY;
  926. }
  927. }
  928. /**
  929. * @brief Sends an amount of data in non blocking mode.
  930. * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M=1),
  931. * the sent data is handled as a set of u16. In this case, Size must indicate the number
  932. * of u16 provided through pData.
  933. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  934. * the configuration information for the specified UART module.
  935. * @param pData Pointer to data buffer (u8 or u16 data elements).
  936. * @param Size Amount of data elements (u8 or u16) to be sent
  937. * @retval HAL status
  938. */
  939. HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
  940. {
  941. /* Check that a Tx process is not already ongoing */
  942. if (huart->gState == HAL_UART_STATE_READY)
  943. {
  944. if ((pData == NULL) || (Size == 0U))
  945. {
  946. return HAL_ERROR;
  947. }
  948. /* Process Locked */
  949. __HAL_LOCK(huart);
  950. huart->pTxBuffPtr = pData;
  951. huart->TxXferSize = Size;
  952. huart->TxXferCount = Size;
  953. huart->ErrorCode = HAL_UART_ERROR_NONE;
  954. huart->gState = HAL_UART_STATE_BUSY_TX;
  955. /* Process Unlocked */
  956. __HAL_UNLOCK(huart);
  957. /* Enable the UART Transmit data register empty Interrupt */
  958. __HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
  959. return HAL_OK;
  960. }
  961. else
  962. {
  963. return HAL_BUSY;
  964. }
  965. }
  966. /**
  967. * @brief Receives an amount of data in non blocking mode.
  968. * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M=1),
  969. * the received data is handled as a set of u16. In this case, Size must indicate the number
  970. * of u16 available through pData.
  971. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  972. * the configuration information for the specified UART module.
  973. * @param pData Pointer to data buffer (u8 or u16 data elements).
  974. * @param Size Amount of data elements (u8 or u16) to be received.
  975. * @retval HAL status
  976. */
  977. HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
  978. {
  979. /* Check that a Rx process is not already ongoing */
  980. if (huart->RxState == HAL_UART_STATE_READY)
  981. {
  982. if ((pData == NULL) || (Size == 0U))
  983. {
  984. return HAL_ERROR;
  985. }
  986. /* Process Locked */
  987. __HAL_LOCK(huart);
  988. huart->pRxBuffPtr = pData;
  989. huart->RxXferSize = Size;
  990. huart->RxXferCount = Size;
  991. huart->ErrorCode = HAL_UART_ERROR_NONE;
  992. huart->RxState = HAL_UART_STATE_BUSY_RX;
  993. /* Process Unlocked */
  994. __HAL_UNLOCK(huart);
  995. /* Enable the UART Parity Error Interrupt */
  996. __HAL_UART_ENABLE_IT(huart, UART_IT_PE);
  997. /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
  998. __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
  999. /* Enable the UART Data Register not empty Interrupt */
  1000. __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
  1001. return HAL_OK;
  1002. }
  1003. else
  1004. {
  1005. return HAL_BUSY;
  1006. }
  1007. }
  1008. /**
  1009. * @brief Abort ongoing transfers (blocking mode).
  1010. * @param huart UART handle.
  1011. * @note This procedure could be used for aborting any ongoing transfer started in Interrupt mode.
  1012. * This procedure performs following operations :
  1013. * - Disable UART Interrupts (Tx and Rx)
  1014. * - Set handle State to READY
  1015. * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
  1016. * @retval HAL status
  1017. */
  1018. HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart)
  1019. {
  1020. /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
  1021. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
  1022. CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
  1023. /* Reset Tx and Rx transfer counters */
  1024. huart->TxXferCount = 0x00U;
  1025. huart->RxXferCount = 0x00U;
  1026. /* Reset ErrorCode */
  1027. huart->ErrorCode = HAL_UART_ERROR_NONE;
  1028. /* Restore huart->RxState and huart->gState to Ready */
  1029. huart->RxState = HAL_UART_STATE_READY;
  1030. huart->gState = HAL_UART_STATE_READY;
  1031. return HAL_OK;
  1032. }
  1033. /**
  1034. * @brief Abort ongoing Transmit transfer (blocking mode).
  1035. * @param huart UART handle.
  1036. * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt mode.
  1037. * This procedure performs following operations :
  1038. * - Disable UART Interrupts (Tx)
  1039. * - Set handle State to READY
  1040. * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
  1041. * @retval HAL status
  1042. */
  1043. HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart)
  1044. {
  1045. /* Disable TXEIE and TCIE interrupts */
  1046. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
  1047. /* Reset Tx transfer counter */
  1048. huart->TxXferCount = 0x00U;
  1049. /* Restore huart->gState to Ready */
  1050. huart->gState = HAL_UART_STATE_READY;
  1051. return HAL_OK;
  1052. }
  1053. /**
  1054. * @brief Abort ongoing Receive transfer (blocking mode).
  1055. * @param huart UART handle.
  1056. * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt mode.
  1057. * This procedure performs following operations :
  1058. * - Disable UART Interrupts (Rx)
  1059. * - Set handle State to READY
  1060. * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
  1061. * @retval HAL status
  1062. */
  1063. HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
  1064. {
  1065. /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
  1066. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
  1067. CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
  1068. /* Reset Rx transfer counter */
  1069. huart->RxXferCount = 0x00U;
  1070. /* Restore huart->RxState to Ready */
  1071. huart->RxState = HAL_UART_STATE_READY;
  1072. return HAL_OK;
  1073. }
  1074. /**
  1075. * @brief Abort ongoing transfers (Interrupt mode).
  1076. * @param huart UART handle.
  1077. * @note This procedure could be used for aborting any ongoing transfer started in Interrupt mode.
  1078. * This procedure performs following operations :
  1079. * - Disable UART Interrupts (Tx and Rx)
  1080. * - Set handle State to READY
  1081. * - At abort completion, call user abort complete callback
  1082. * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
  1083. * considered as completed only when user abort complete callback is executed (not when exiting function).
  1084. * @retval HAL status
  1085. */
  1086. HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart)
  1087. {
  1088. uint32_t AbortCplt = 0x01U;
  1089. /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
  1090. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
  1091. CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
  1092. /* call user Abort Complete callback */
  1093. if (AbortCplt == 0x01U)
  1094. {
  1095. /* Reset Tx and Rx transfer counters */
  1096. huart->TxXferCount = 0x00U;
  1097. huart->RxXferCount = 0x00U;
  1098. /* Reset ErrorCode */
  1099. huart->ErrorCode = HAL_UART_ERROR_NONE;
  1100. /* Restore huart->gState and huart->RxState to Ready */
  1101. huart->gState = HAL_UART_STATE_READY;
  1102. huart->RxState = HAL_UART_STATE_READY;
  1103. /* call directly user Abort complete callback */
  1104. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1105. /* Call registered Abort complete callback */
  1106. huart->AbortCpltCallback(huart);
  1107. #else
  1108. /* Call legacy weak Abort complete callback */
  1109. HAL_UART_AbortCpltCallback(huart);
  1110. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1111. }
  1112. return HAL_OK;
  1113. }
  1114. /**
  1115. * @brief Abort ongoing Transmit transfer (Interrupt mode).
  1116. * @param huart UART handle.
  1117. * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt mode.
  1118. * This procedure performs following operations :
  1119. * - Disable UART Interrupts (Tx)
  1120. * - Set handle State to READY
  1121. * - At abort completion, call user abort complete callback
  1122. * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
  1123. * considered as completed only when user abort complete callback is executed (not when exiting function).
  1124. * @retval HAL status
  1125. */
  1126. HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart)
  1127. {
  1128. /* Disable TXEIE and TCIE interrupts */
  1129. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
  1130. /* Reset Tx transfer counter */
  1131. huart->TxXferCount = 0x00U;
  1132. /* Restore huart->gState to Ready */
  1133. huart->gState = HAL_UART_STATE_READY;
  1134. /* call directly user Abort complete callback */
  1135. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1136. /* Call registered Abort Transmit Complete Callback */
  1137. huart->AbortTransmitCpltCallback(huart);
  1138. #else
  1139. /* Call legacy weak Abort Transmit Complete Callback */
  1140. HAL_UART_AbortTransmitCpltCallback(huart);
  1141. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1142. return HAL_OK;
  1143. }
  1144. /**
  1145. * @brief Abort ongoing Receive transfer (Interrupt mode).
  1146. * @param huart UART handle.
  1147. * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt mode.
  1148. * This procedure performs following operations :
  1149. * - Disable UART Interrupts (Rx)
  1150. * - Set handle State to READY
  1151. * - At abort completion, call user abort complete callback
  1152. * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
  1153. * considered as completed only when user abort complete callback is executed (not when exiting function).
  1154. * @retval HAL status
  1155. */
  1156. HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart)
  1157. {
  1158. /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
  1159. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
  1160. CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
  1161. /* Reset Rx transfer counter */
  1162. huart->RxXferCount = 0x00U;
  1163. /* Restore huart->RxState to Ready */
  1164. huart->RxState = HAL_UART_STATE_READY;
  1165. /* call directly user Abort complete callback */
  1166. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1167. /* Call registered Abort Receive Complete Callback */
  1168. huart->AbortReceiveCpltCallback(huart);
  1169. #else
  1170. /* Call legacy weak Abort Receive Complete Callback */
  1171. HAL_UART_AbortReceiveCpltCallback(huart);
  1172. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1173. return HAL_OK;
  1174. }
  1175. /**
  1176. * @brief This function handles UART interrupt request.
  1177. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1178. * the configuration information for the specified UART module.
  1179. * @retval None
  1180. */
  1181. void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
  1182. {
  1183. uint32_t isrflags = READ_REG(huart->Instance->SR);
  1184. uint32_t cr1its = READ_REG(huart->Instance->CR1);
  1185. uint32_t cr3its = READ_REG(huart->Instance->CR3);
  1186. uint32_t errorflags = 0x00U;
  1187. /* If no error occurs */
  1188. errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
  1189. if (errorflags == RESET)
  1190. {
  1191. /* UART in mode Receiver -------------------------------------------------*/
  1192. if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
  1193. {
  1194. UART_Receive_IT(huart);
  1195. return;
  1196. }
  1197. }
  1198. /* If some errors occur */
  1199. if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
  1200. {
  1201. /* UART parity error interrupt occurred ----------------------------------*/
  1202. if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
  1203. {
  1204. huart->ErrorCode |= HAL_UART_ERROR_PE;
  1205. }
  1206. /* UART noise error interrupt occurred -----------------------------------*/
  1207. if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
  1208. {
  1209. huart->ErrorCode |= HAL_UART_ERROR_NE;
  1210. }
  1211. /* UART frame error interrupt occurred -----------------------------------*/
  1212. if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
  1213. {
  1214. huart->ErrorCode |= HAL_UART_ERROR_FE;
  1215. }
  1216. /* UART Over-Run interrupt occurred --------------------------------------*/
  1217. if (((isrflags & USART_SR_ORE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
  1218. {
  1219. huart->ErrorCode |= HAL_UART_ERROR_ORE;
  1220. }
  1221. /* Call UART Error Call back function if need be --------------------------*/
  1222. if (huart->ErrorCode != HAL_UART_ERROR_NONE)
  1223. {
  1224. /* UART in mode Receiver -----------------------------------------------*/
  1225. if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
  1226. {
  1227. UART_Receive_IT(huart);
  1228. }
  1229. /* If Overrun error occurs,
  1230. consider error as blocking */
  1231. if ((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET)
  1232. {
  1233. /* Blocking error : transfer is aborted
  1234. Set the UART state ready to be able to start again the process,
  1235. Disable Rx Interrupts, if ongoing */
  1236. UART_EndRxTransfer(huart);
  1237. /* Call user error callback */
  1238. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1239. /*Call registered error callback*/
  1240. huart->ErrorCallback(huart);
  1241. #else
  1242. /*Call legacy weak error callback*/
  1243. HAL_UART_ErrorCallback(huart);
  1244. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1245. }
  1246. else
  1247. {
  1248. /* Non Blocking error : transfer could go on.
  1249. Error is notified to user through user error callback */
  1250. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1251. /*Call registered error callback*/
  1252. huart->ErrorCallback(huart);
  1253. #else
  1254. /*Call legacy weak error callback*/
  1255. HAL_UART_ErrorCallback(huart);
  1256. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1257. huart->ErrorCode = HAL_UART_ERROR_NONE;
  1258. }
  1259. }
  1260. return;
  1261. } /* End if some error occurs */
  1262. /* Idle frame detect */
  1263. if (((isrflags & USART_SR_IDLE) != RESET) && ((cr1its & USART_CR1_IDLEIE) != RESET))
  1264. {
  1265. __HAL_UART_CLEAR_IDLEFLAG(huart);
  1266. HAL_UART_IdleFrameDetectCpltCallback(huart);
  1267. }
  1268. /* UART in mode Transmitter ------------------------------------------------*/
  1269. if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
  1270. {
  1271. UART_Transmit_IT(huart);
  1272. return;
  1273. }
  1274. /* UART in mode Transmitter end --------------------------------------------*/
  1275. if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
  1276. {
  1277. UART_EndTransmit_IT(huart);
  1278. return;
  1279. }
  1280. }
  1281. /**
  1282. * @brief Tx Transfer completed callbacks.
  1283. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1284. * the configuration information for the specified UART module.
  1285. * @retval None
  1286. */
  1287. __weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
  1288. {
  1289. /* Prevent unused argument(s) compilation warning */
  1290. UNUSED(huart);
  1291. /* NOTE: This function should not be modified, when the callback is needed,
  1292. the HAL_UART_TxCpltCallback could be implemented in the user file
  1293. */
  1294. }
  1295. /**
  1296. * @brief Tx Half Transfer completed callbacks.
  1297. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1298. * the configuration information for the specified UART module.
  1299. * @retval None
  1300. */
  1301. __weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
  1302. {
  1303. /* Prevent unused argument(s) compilation warning */
  1304. UNUSED(huart);
  1305. /* NOTE: This function should not be modified, when the callback is needed,
  1306. the HAL_UART_TxHalfCpltCallback could be implemented in the user file
  1307. */
  1308. }
  1309. /**
  1310. * @brief Rx Transfer completed callbacks.
  1311. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1312. * the configuration information for the specified UART module.
  1313. * @retval None
  1314. */
  1315. __weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  1316. {
  1317. /* Prevent unused argument(s) compilation warning */
  1318. UNUSED(huart);
  1319. /* NOTE: This function should not be modified, when the callback is needed,
  1320. the HAL_UART_RxCpltCallback could be implemented in the user file
  1321. */
  1322. }
  1323. /**
  1324. * @brief Rx Half Transfer completed callbacks.
  1325. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1326. * the configuration information for the specified UART module.
  1327. * @retval None
  1328. */
  1329. __weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
  1330. {
  1331. /* Prevent unused argument(s) compilation warning */
  1332. UNUSED(huart);
  1333. /* NOTE: This function should not be modified, when the callback is needed,
  1334. the HAL_UART_RxHalfCpltCallback could be implemented in the user file
  1335. */
  1336. }
  1337. /**
  1338. * @brief UART error callbacks.
  1339. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1340. * the configuration information for the specified UART module.
  1341. * @retval None
  1342. */
  1343. __weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
  1344. {
  1345. /* Prevent unused argument(s) compilation warning */
  1346. UNUSED(huart);
  1347. /* NOTE: This function should not be modified, when the callback is needed,
  1348. the HAL_UART_ErrorCallback could be implemented in the user file
  1349. */
  1350. }
  1351. /**
  1352. * @brief UART Abort Complete callback.
  1353. * @param huart UART handle.
  1354. * @retval None
  1355. */
  1356. __weak void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart)
  1357. {
  1358. /* Prevent unused argument(s) compilation warning */
  1359. UNUSED(huart);
  1360. /* NOTE : This function should not be modified, when the callback is needed,
  1361. the HAL_UART_AbortCpltCallback can be implemented in the user file.
  1362. */
  1363. }
  1364. /**
  1365. * @brief UART Abort Complete callback.
  1366. * @param huart UART handle.
  1367. * @retval None
  1368. */
  1369. __weak void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart)
  1370. {
  1371. /* Prevent unused argument(s) compilation warning */
  1372. UNUSED(huart);
  1373. /* NOTE : This function should not be modified, when the callback is needed,
  1374. the HAL_UART_AbortTransmitCpltCallback can be implemented in the user file.
  1375. */
  1376. }
  1377. /**
  1378. * @brief UART Abort Receive Complete callback.
  1379. * @param huart UART handle.
  1380. * @retval None
  1381. */
  1382. __weak void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart)
  1383. {
  1384. /* Prevent unused argument(s) compilation warning */
  1385. UNUSED(huart);
  1386. /* NOTE : This function should not be modified, when the callback is needed,
  1387. the HAL_UART_AbortReceiveCpltCallback can be implemented in the user file.
  1388. */
  1389. }
  1390. /**
  1391. * @brief UART Idle Frame Detect Complete callback.
  1392. * @param huart UART handle.
  1393. * @retval None
  1394. */
  1395. __weak void HAL_UART_IdleFrameDetectCpltCallback(UART_HandleTypeDef *huart)
  1396. {
  1397. /* Prevent unused argument(s) compilation warning */
  1398. UNUSED(huart);
  1399. /* NOTE : This function should not be modified, when the callback is needed,
  1400. the HAL_UART_IdleFrameDetectCpltCallback can be implemented in the user file.
  1401. */
  1402. }
  1403. /**
  1404. * @}
  1405. */
  1406. /** @defgroup UART_Exported_Functions_Group3 Peripheral Control functions
  1407. * @brief UART control functions
  1408. *
  1409. @verbatim
  1410. ==============================================================================
  1411. ##### Peripheral Control functions #####
  1412. ==============================================================================
  1413. [..]
  1414. This subsection provides a set of functions allowing to control the UART:
  1415. (+) HAL_MultiProcessor_EnterMuteMode() API can be helpful to enter the UART in mute mode.
  1416. (+) HAL_MultiProcessor_ExitMuteMode() API can be helpful to exit the UART mute mode by software.
  1417. (+) HAL_HalfDuplex_EnableTransmitter() API to enable the UART transmitter and disables the UART receiver in Half Duplex mode
  1418. (+) HAL_HalfDuplex_EnableReceiver() API to enable the UART receiver and disables the UART transmitter in Half Duplex mode
  1419. @endverbatim
  1420. * @{
  1421. */
  1422. /**
  1423. * @brief Enters the UART in mute mode.
  1424. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1425. * the configuration information for the specified UART module.
  1426. * @retval HAL status
  1427. */
  1428. HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart)
  1429. {
  1430. /* Check the parameters */
  1431. assert_param(IS_UART_INSTANCE(huart->Instance));
  1432. /* Process Locked */
  1433. __HAL_LOCK(huart);
  1434. huart->gState = HAL_UART_STATE_BUSY;
  1435. /* Enable the USART mute mode by setting the RWU bit in the CR1 register */
  1436. SET_BIT(huart->Instance->CR1, USART_CR1_RWU);
  1437. huart->gState = HAL_UART_STATE_READY;
  1438. /* Process Unlocked */
  1439. __HAL_UNLOCK(huart);
  1440. return HAL_OK;
  1441. }
  1442. /**
  1443. * @brief Exits the UART mute mode: wake up software.
  1444. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1445. * the configuration information for the specified UART module.
  1446. * @retval HAL status
  1447. */
  1448. HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart)
  1449. {
  1450. /* Check the parameters */
  1451. assert_param(IS_UART_INSTANCE(huart->Instance));
  1452. /* Process Locked */
  1453. __HAL_LOCK(huart);
  1454. huart->gState = HAL_UART_STATE_BUSY;
  1455. /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
  1456. CLEAR_BIT(huart->Instance->CR1, USART_CR1_RWU);
  1457. huart->gState = HAL_UART_STATE_READY;
  1458. /* Process Unlocked */
  1459. __HAL_UNLOCK(huart);
  1460. return HAL_OK;
  1461. }
  1462. /**
  1463. * @brief Enables the UART transmitter and disables the UART receiver.
  1464. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1465. * the configuration information for the specified UART module.
  1466. * @retval HAL status
  1467. */
  1468. HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart)
  1469. {
  1470. uint32_t tmpreg = 0x00U;
  1471. /* Process Locked */
  1472. __HAL_LOCK(huart);
  1473. huart->gState = HAL_UART_STATE_BUSY;
  1474. /*-------------------------- USART CR1 Configuration -----------------------*/
  1475. tmpreg = huart->Instance->CR1;
  1476. /* Clear TE and RE bits */
  1477. tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
  1478. /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */
  1479. tmpreg |= (uint32_t)USART_CR1_TE;
  1480. /* Write to USART CR1 */
  1481. WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg);
  1482. huart->gState = HAL_UART_STATE_READY;
  1483. /* Process Unlocked */
  1484. __HAL_UNLOCK(huart);
  1485. return HAL_OK;
  1486. }
  1487. /**
  1488. * @brief Enables the UART receiver and disables the UART transmitter.
  1489. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1490. * the configuration information for the specified UART module.
  1491. * @retval HAL status
  1492. */
  1493. HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart)
  1494. {
  1495. uint32_t tmpreg = 0x00U;
  1496. /* Process Locked */
  1497. __HAL_LOCK(huart);
  1498. huart->gState = HAL_UART_STATE_BUSY;
  1499. /*-------------------------- USART CR1 Configuration -----------------------*/
  1500. tmpreg = huart->Instance->CR1;
  1501. /* Clear TE and RE bits */
  1502. tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
  1503. /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */
  1504. tmpreg |= (uint32_t)USART_CR1_RE;
  1505. /* Write to USART CR1 */
  1506. WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg);
  1507. huart->gState = HAL_UART_STATE_READY;
  1508. /* Process Unlocked */
  1509. __HAL_UNLOCK(huart);
  1510. return HAL_OK;
  1511. }
  1512. /**
  1513. * @}
  1514. */
  1515. /** @defgroup UART_Exported_Functions_Group4 Peripheral State and Errors functions
  1516. * @brief UART State and Errors functions
  1517. *
  1518. @verbatim
  1519. ==============================================================================
  1520. ##### Peripheral State and Errors functions #####
  1521. ==============================================================================
  1522. [..]
  1523. This subsection provides a set of functions allowing to return the State of
  1524. UART communication process, return Peripheral Errors occurred during communication
  1525. process
  1526. (+) HAL_UART_GetState() API can be helpful to check in run-time the state of the UART peripheral.
  1527. (+) HAL_UART_GetError() check in run-time errors that could be occurred during communication.
  1528. @endverbatim
  1529. * @{
  1530. */
  1531. /**
  1532. * @brief Returns the UART state.
  1533. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1534. * the configuration information for the specified UART module.
  1535. * @retval HAL state
  1536. */
  1537. HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart)
  1538. {
  1539. uint32_t temp1 = 0x00U, temp2 = 0x00U;
  1540. temp1 = huart->gState;
  1541. temp2 = huart->RxState;
  1542. return (HAL_UART_StateTypeDef)(temp1 | temp2);
  1543. }
  1544. /**
  1545. * @brief Return the UART error code
  1546. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1547. * the configuration information for the specified UART.
  1548. * @retval UART Error Code
  1549. */
  1550. uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart)
  1551. {
  1552. return huart->ErrorCode;
  1553. }
  1554. /**
  1555. * @}
  1556. */
  1557. /**
  1558. * @}
  1559. */
  1560. /** @defgroup UART_Private_Functions UART Private Functions
  1561. * @{
  1562. */
  1563. /**
  1564. * @brief Initialize the callbacks to their default values.
  1565. * @param huart UART handle.
  1566. * @retval none
  1567. */
  1568. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1569. void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart)
  1570. {
  1571. /* Init the UART Callback settings */
  1572. huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */
  1573. huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */
  1574. huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
  1575. huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */
  1576. huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */
  1577. huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
  1578. huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
  1579. huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
  1580. }
  1581. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1582. /**
  1583. * @brief This function handles UART Communication Timeout.
  1584. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1585. * the configuration information for the specified UART module.
  1586. * @param Flag specifies the UART flag to check.
  1587. * @param Status The new Flag status (SET or RESET).
  1588. * @param Tickstart Tick start value
  1589. * @param Timeout Timeout duration
  1590. * @retval HAL status
  1591. */
  1592. static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
  1593. {
  1594. /* Wait until flag is set */
  1595. while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)
  1596. {
  1597. /* Check for the Timeout */
  1598. if (Timeout != HAL_MAX_DELAY)
  1599. {
  1600. if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout))
  1601. {
  1602. /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
  1603. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
  1604. CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
  1605. huart->gState = HAL_UART_STATE_READY;
  1606. huart->RxState = HAL_UART_STATE_READY;
  1607. /* Process Unlocked */
  1608. __HAL_UNLOCK(huart);
  1609. return HAL_TIMEOUT;
  1610. }
  1611. }
  1612. }
  1613. return HAL_OK;
  1614. }
  1615. /**
  1616. * @brief End ongoing Rx transfer on UART peripheral (following error detection or Reception completion).
  1617. * @param huart UART handle.
  1618. * @retval None
  1619. */
  1620. static void UART_EndRxTransfer(UART_HandleTypeDef *huart)
  1621. {
  1622. /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
  1623. CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
  1624. CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
  1625. /* At end of Rx process, restore huart->RxState to Ready */
  1626. huart->RxState = HAL_UART_STATE_READY;
  1627. }
  1628. /**
  1629. * @brief Sends an amount of data in non blocking mode.
  1630. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1631. * the configuration information for the specified UART module.
  1632. * @retval HAL status
  1633. */
  1634. static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart)
  1635. {
  1636. uint16_t *tmp16bit;
  1637. uint8_t *tmp8bit;
  1638. /* Check that a Tx process is ongoing */
  1639. if (huart->gState == HAL_UART_STATE_BUSY_TX)
  1640. {
  1641. if ((huart->Init.WordLength == UART_WORDLENGTH_9B)&&(huart->Init.Parity == UART_PARITY_NONE))
  1642. {
  1643. tmp16bit=(uint16_t *) huart->pTxBuffPtr;
  1644. huart->Instance->DR = (uint16_t)(*tmp16bit & (uint16_t)0x01FF);
  1645. huart->pTxBuffPtr += 2U;
  1646. }
  1647. else
  1648. {
  1649. tmp8bit=(uint8_t *) huart->pTxBuffPtr;
  1650. huart->Instance->DR = (uint8_t)(*tmp8bit & (uint8_t)0x00FF);
  1651. huart->pTxBuffPtr++;
  1652. }
  1653. if (--huart->TxXferCount == 0U)
  1654. {
  1655. /* Disable the UART Transmit Complete Interrupt */
  1656. __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
  1657. /* Enable the UART Transmit Complete Interrupt */
  1658. __HAL_UART_ENABLE_IT(huart, UART_IT_TC);
  1659. }
  1660. return HAL_OK;
  1661. }
  1662. else
  1663. {
  1664. return HAL_BUSY;
  1665. }
  1666. }
  1667. /**
  1668. * @brief Wraps up transmission in non blocking mode.
  1669. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1670. * the configuration information for the specified UART module.
  1671. * @retval HAL status
  1672. */
  1673. static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart)
  1674. {
  1675. /* Disable the UART Transmit Complete Interrupt */
  1676. __HAL_UART_DISABLE_IT(huart, UART_IT_TC);
  1677. /* Tx process is ended, restore huart->gState to Ready */
  1678. huart->gState = HAL_UART_STATE_READY;
  1679. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1680. /*Call registered Tx complete callback*/
  1681. huart->TxCpltCallback(huart);
  1682. #else
  1683. /*Call legacy weak Tx complete callback*/
  1684. HAL_UART_TxCpltCallback(huart);
  1685. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1686. return HAL_OK;
  1687. }
  1688. /**
  1689. * @brief Receives an amount of data in non blocking mode
  1690. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1691. * the configuration information for the specified UART module.
  1692. * @retval HAL status
  1693. */
  1694. static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
  1695. {
  1696. uint16_t *tmp16bit;
  1697. /* Check that a Rx process is ongoing */
  1698. if (huart->RxState == HAL_UART_STATE_BUSY_RX)
  1699. {
  1700. /* Set the Rx ISR function pointer according to the data word length */
  1701. if((huart->Init.WordLength == UART_WORDLENGTH_9B)&& (huart->Init.Parity == UART_PARITY_NONE))
  1702. {
  1703. tmp16bit = (uint16_t *) huart->pRxBuffPtr;
  1704. *tmp16bit = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
  1705. huart->pRxBuffPtr += 2U;
  1706. }
  1707. else
  1708. {
  1709. *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
  1710. }
  1711. if (--huart->RxXferCount == 0U)
  1712. {
  1713. /* Disable the UART Data Register not empty Interrupt */
  1714. __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
  1715. /* Disable the UART Parity Error Interrupt */
  1716. __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
  1717. /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
  1718. __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
  1719. /* Rx process is completed, restore huart->RxState to Ready */
  1720. huart->RxState = HAL_UART_STATE_READY;
  1721. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1722. /*Call registered Rx complete callback*/
  1723. huart->RxCpltCallback(huart);
  1724. #else
  1725. /*Call legacy weak Rx complete callback*/
  1726. HAL_UART_RxCpltCallback(huart);
  1727. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1728. return HAL_OK;
  1729. }
  1730. return HAL_OK;
  1731. }
  1732. else
  1733. {
  1734. return HAL_BUSY;
  1735. }
  1736. }
  1737. /**
  1738. * @brief Configures the UART peripheral.
  1739. * @param huart Pointer to a UART_HandleTypeDef structure that contains
  1740. * the configuration information for the specified UART module.
  1741. * @retval None
  1742. */
  1743. static void UART_SetConfig(UART_HandleTypeDef *huart)
  1744. {
  1745. uint32_t tmpreg;
  1746. uint32_t pclk;
  1747. /* Check the parameters */
  1748. assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
  1749. assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
  1750. assert_param(IS_UART_PARITY(huart->Init.Parity));
  1751. assert_param(IS_UART_MODE(huart->Init.Mode));
  1752. /*-------------------------- USART CR2 Configuration -----------------------*/
  1753. /* Configure the UART Stop Bits: Set STOP[13:12] bits
  1754. according to huart->Init.StopBits value */
  1755. MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits);
  1756. /*-------------------------- USART CR1 Configuration -----------------------*/
  1757. /* Configure the UART Word Length, Parity and mode:
  1758. Set the M bits according to huart->Init.WordLength value
  1759. Set PCE and PS bits according to huart->Init.Parity value
  1760. Set TE and RE bits according to huart->Init.Mode value
  1761. Set OVER8 bit according to huart->Init.OverSampling value */
  1762. #if defined(USART_CR3_OVER8)
  1763. tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode;
  1764. MODIFY_REG(huart->Instance->CR1,
  1765. (uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE),
  1766. tmpreg);
  1767. tmpreg = (uint32_t) huart->Init.OverSampling;
  1768. MODIFY_REG(huart->Instance->CR3,
  1769. (uint32_t)(USART_CR3_OVER8),
  1770. tmpreg);
  1771. #else
  1772. tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode;
  1773. MODIFY_REG(huart->Instance->CR1,
  1774. (uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE),
  1775. tmpreg);
  1776. #endif /* USART_CR3_OVER8 */
  1777. /*-------------------------- USART CR3 Configuration -----------------------*/
  1778. /* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */
  1779. MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE), huart->Init.HwFlowCtl);
  1780. #if defined(USART_CR3_OVER8)
  1781. /* Check the Over Sampling */
  1782. if(huart->Init.OverSampling == UART_OVERSAMPLING_8)
  1783. {
  1784. /*-------------------------- USART BRR Configuration ---------------------*/
  1785. pclk = HAL_RCC_GetPCLK1Freq();
  1786. huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate);
  1787. }
  1788. else
  1789. {
  1790. /*-------------------------- USART BRR Configuration ---------------------*/
  1791. pclk = HAL_RCC_GetPCLK1Freq();
  1792. huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
  1793. }
  1794. #else
  1795. /*-------------------------- USART BRR Configuration ---------------------*/
  1796. pclk = HAL_RCC_GetPCLK1Freq();
  1797. huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
  1798. #endif /* USART_CR3_OVER8 */
  1799. }
  1800. /**
  1801. * @brief Configure the UART peripheral advanced features.
  1802. * @param huart UART handle.
  1803. * @retval None
  1804. */
  1805. void UART_AdvFeatureConfig(UART_HandleTypeDef *huart)
  1806. {
  1807. /* Check whether the set of advanced features to configure is properly set */
  1808. assert_param(IS_UART_ADVFEATURE_INIT(huart->AdvancedInit.AdvFeatureInit));
  1809. /* if required, configure auto Baud rate detection scheme */
  1810. if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_AUTOBAUDRATE_INIT))
  1811. {
  1812. assert_param(IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(huart->Instance));
  1813. assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATE(huart->AdvancedInit.AutoBaudRateEnable));
  1814. MODIFY_REG(huart->Instance->CR3, USART_CR3_ABREN, huart->AdvancedInit.AutoBaudRateEnable);
  1815. /* set auto Baudrate detection parameters if detection is enabled */
  1816. if (huart->AdvancedInit.AutoBaudRateEnable == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE)
  1817. {
  1818. assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(huart->AdvancedInit.AutoBaudRateMode));
  1819. MODIFY_REG(huart->Instance->CR3, USART_CR3_ABRMODE, huart->AdvancedInit.AutoBaudRateMode);
  1820. }
  1821. }
  1822. }
  1823. /**
  1824. * @}
  1825. */
  1826. #endif /* HAL_UART_MODULE_ENABLED */
  1827. /**
  1828. * @}
  1829. */
  1830. /**
  1831. * @}
  1832. */
  1833. /************************ (C) COPYRIGHT Puya *****END OF FILE****/