stm32f10x_usart.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_usart.c
  4. * @author MCD Application Team
  5. * @version V3.3.0
  6. * @date 04/16/2010
  7. * @brief This file provides all the USART firmware functions.
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x_usart.h"
  22. #include "stm32f10x_rcc.h"
  23. /** @addtogroup STM32F10x_StdPeriph_Driver
  24. * @{
  25. */
  26. /** @defgroup USART
  27. * @brief USART driver modules
  28. * @{
  29. */
  30. /** @defgroup USART_Private_TypesDefinitions
  31. * @{
  32. */
  33. /**
  34. * @}
  35. */
  36. /** @defgroup USART_Private_Defines
  37. * @{
  38. */
  39. #define CR1_UE_Set ((uint16_t)0x2000) /*!< USART Enable Mask */
  40. #define CR1_UE_Reset ((uint16_t)0xDFFF) /*!< USART Disable Mask */
  41. #define CR1_WAKE_Mask ((uint16_t)0xF7FF) /*!< USART WakeUp Method Mask */
  42. #define CR1_RWU_Set ((uint16_t)0x0002) /*!< USART mute mode Enable Mask */
  43. #define CR1_RWU_Reset ((uint16_t)0xFFFD) /*!< USART mute mode Enable Mask */
  44. #define CR1_SBK_Set ((uint16_t)0x0001) /*!< USART Break Character send Mask */
  45. #define CR1_CLEAR_Mask ((uint16_t)0xE9F3) /*!< USART CR1 Mask */
  46. #define CR2_Address_Mask ((uint16_t)0xFFF0) /*!< USART address Mask */
  47. #define CR2_LINEN_Set ((uint16_t)0x4000) /*!< USART LIN Enable Mask */
  48. #define CR2_LINEN_Reset ((uint16_t)0xBFFF) /*!< USART LIN Disable Mask */
  49. #define CR2_LBDL_Mask ((uint16_t)0xFFDF) /*!< USART LIN Break detection Mask */
  50. #define CR2_STOP_CLEAR_Mask ((uint16_t)0xCFFF) /*!< USART CR2 STOP Bits Mask */
  51. #define CR2_CLOCK_CLEAR_Mask ((uint16_t)0xF0FF) /*!< USART CR2 Clock Mask */
  52. #define CR3_SCEN_Set ((uint16_t)0x0020) /*!< USART SC Enable Mask */
  53. #define CR3_SCEN_Reset ((uint16_t)0xFFDF) /*!< USART SC Disable Mask */
  54. #define CR3_NACK_Set ((uint16_t)0x0010) /*!< USART SC NACK Enable Mask */
  55. #define CR3_NACK_Reset ((uint16_t)0xFFEF) /*!< USART SC NACK Disable Mask */
  56. #define CR3_HDSEL_Set ((uint16_t)0x0008) /*!< USART Half-Duplex Enable Mask */
  57. #define CR3_HDSEL_Reset ((uint16_t)0xFFF7) /*!< USART Half-Duplex Disable Mask */
  58. #define CR3_IRLP_Mask ((uint16_t)0xFFFB) /*!< USART IrDA LowPower mode Mask */
  59. #define CR3_CLEAR_Mask ((uint16_t)0xFCFF) /*!< USART CR3 Mask */
  60. #define CR3_IREN_Set ((uint16_t)0x0002) /*!< USART IrDA Enable Mask */
  61. #define CR3_IREN_Reset ((uint16_t)0xFFFD) /*!< USART IrDA Disable Mask */
  62. #define GTPR_LSB_Mask ((uint16_t)0x00FF) /*!< Guard Time Register LSB Mask */
  63. #define GTPR_MSB_Mask ((uint16_t)0xFF00) /*!< Guard Time Register MSB Mask */
  64. #define IT_Mask ((uint16_t)0x001F) /*!< USART Interrupt Mask */
  65. /* USART OverSampling-8 Mask */
  66. #define CR1_OVER8_Set ((u16)0x8000) /* USART OVER8 mode Enable Mask */
  67. #define CR1_OVER8_Reset ((u16)0x7FFF) /* USART OVER8 mode Disable Mask */
  68. /* USART One Bit Sampling Mask */
  69. #define CR3_ONEBITE_Set ((u16)0x0800) /* USART ONEBITE mode Enable Mask */
  70. #define CR3_ONEBITE_Reset ((u16)0xF7FF) /* USART ONEBITE mode Disable Mask */
  71. /**
  72. * @}
  73. */
  74. /** @defgroup USART_Private_Macros
  75. * @{
  76. */
  77. /**
  78. * @}
  79. */
  80. /** @defgroup USART_Private_Variables
  81. * @{
  82. */
  83. /**
  84. * @}
  85. */
  86. /** @defgroup USART_Private_FunctionPrototypes
  87. * @{
  88. */
  89. /**
  90. * @}
  91. */
  92. /** @defgroup USART_Private_Functions
  93. * @{
  94. */
  95. /**
  96. * @brief Deinitializes the USARTx peripheral registers to their default reset values.
  97. * @param USARTx: Select the USART or the UART peripheral.
  98. * This parameter can be one of the following values: USART1, USART2, USART3, UART4 or UART5.
  99. * @retval None
  100. */
  101. void USART_DeInit(USART_TypeDef* USARTx)
  102. {
  103. /* Check the parameters */
  104. assert_param(IS_USART_ALL_PERIPH(USARTx));
  105. if (USARTx == USART1)
  106. {
  107. RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
  108. RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
  109. }
  110. else if (USARTx == USART2)
  111. {
  112. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
  113. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
  114. }
  115. else if (USARTx == USART3)
  116. {
  117. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
  118. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
  119. }
  120. else if (USARTx == UART4)
  121. {
  122. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
  123. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
  124. }
  125. else
  126. {
  127. if (USARTx == UART5)
  128. {
  129. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
  130. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
  131. }
  132. }
  133. }
  134. /**
  135. * @brief Initializes the USARTx peripheral according to the specified
  136. * parameters in the USART_InitStruct .
  137. * @param USARTx: Select the USART or the UART peripheral.
  138. * This parameter can be one of the following values:
  139. * USART1, USART2, USART3, UART4 or UART5.
  140. * @param USART_InitStruct: pointer to a USART_InitTypeDef structure
  141. * that contains the configuration information for the specified USART peripheral.
  142. * @retval None
  143. */
  144. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
  145. {
  146. uint32_t tmpreg = 0x00, apbclock = 0x00;
  147. uint32_t integerdivider = 0x00;
  148. uint32_t fractionaldivider = 0x00;
  149. uint32_t usartxbase = 0;
  150. RCC_ClocksTypeDef RCC_ClocksStatus;
  151. /* Check the parameters */
  152. assert_param(IS_USART_ALL_PERIPH(USARTx));
  153. assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));
  154. assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
  155. assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
  156. assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
  157. assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
  158. assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
  159. /* The hardware flow control is available only for USART1, USART2 and USART3 */
  160. if (USART_InitStruct->USART_HardwareFlowControl != USART_HardwareFlowControl_None)
  161. {
  162. assert_param(IS_USART_123_PERIPH(USARTx));
  163. }
  164. usartxbase = (uint32_t)USARTx;
  165. /*---------------------------- USART CR2 Configuration -----------------------*/
  166. tmpreg = USARTx->CR2;
  167. /* Clear STOP[13:12] bits */
  168. tmpreg &= CR2_STOP_CLEAR_Mask;
  169. /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
  170. /* Set STOP[13:12] bits according to USART_StopBits value */
  171. tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
  172. /* Write to USART CR2 */
  173. USARTx->CR2 = (uint16_t)tmpreg;
  174. /*---------------------------- USART CR1 Configuration -----------------------*/
  175. tmpreg = USARTx->CR1;
  176. /* Clear M, PCE, PS, TE and RE bits */
  177. tmpreg &= CR1_CLEAR_Mask;
  178. /* Configure the USART Word Length, Parity and mode ----------------------- */
  179. /* Set the M bits according to USART_WordLength value */
  180. /* Set PCE and PS bits according to USART_Parity value */
  181. /* Set TE and RE bits according to USART_Mode value */
  182. tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
  183. USART_InitStruct->USART_Mode;
  184. /* Write to USART CR1 */
  185. USARTx->CR1 = (uint16_t)tmpreg;
  186. /*---------------------------- USART CR3 Configuration -----------------------*/
  187. tmpreg = USARTx->CR3;
  188. /* Clear CTSE and RTSE bits */
  189. tmpreg &= CR3_CLEAR_Mask;
  190. /* Configure the USART HFC -------------------------------------------------*/
  191. /* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
  192. tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
  193. /* Write to USART CR3 */
  194. USARTx->CR3 = (uint16_t)tmpreg;
  195. /*---------------------------- USART BRR Configuration -----------------------*/
  196. /* Configure the USART Baud Rate -------------------------------------------*/
  197. RCC_GetClocksFreq(&RCC_ClocksStatus);
  198. if (usartxbase == USART1_BASE)
  199. {
  200. apbclock = RCC_ClocksStatus.PCLK2_Frequency;
  201. }
  202. else
  203. {
  204. apbclock = RCC_ClocksStatus.PCLK1_Frequency;
  205. }
  206. /* Determine the integer part */
  207. if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
  208. {
  209. /* Integer part computing in case Oversampling mode is 8 Samples */
  210. integerdivider = ((25 * apbclock) / (2 * (USART_InitStruct->USART_BaudRate)));
  211. }
  212. else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
  213. {
  214. /* Integer part computing in case Oversampling mode is 16 Samples */
  215. integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->USART_BaudRate)));
  216. }
  217. tmpreg = (integerdivider / 100) << 4;
  218. /* Determine the fractional part */
  219. fractionaldivider = integerdivider - (100 * (tmpreg >> 4));
  220. /* Implement the fractional part in the register */
  221. if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
  222. {
  223. tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
  224. }
  225. else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
  226. {
  227. tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
  228. }
  229. /* Write to USART BRR */
  230. USARTx->BRR = (uint16_t)tmpreg;
  231. }
  232. /**
  233. * @brief Fills each USART_InitStruct member with its default value.
  234. * @param USART_InitStruct: pointer to a USART_InitTypeDef structure
  235. * which will be initialized.
  236. * @retval None
  237. */
  238. void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
  239. {
  240. /* USART_InitStruct members default value */
  241. USART_InitStruct->USART_BaudRate = 9600;
  242. USART_InitStruct->USART_WordLength = USART_WordLength_8b;
  243. USART_InitStruct->USART_StopBits = USART_StopBits_1;
  244. USART_InitStruct->USART_Parity = USART_Parity_No ;
  245. USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  246. USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  247. }
  248. /**
  249. * @brief Initializes the USARTx peripheral Clock according to the
  250. * specified parameters in the USART_ClockInitStruct .
  251. * @param USARTx: where x can be 1, 2, 3 to select the USART peripheral.
  252. * @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
  253. * structure that contains the configuration information for the specified
  254. * USART peripheral.
  255. * @note The Smart Card mode is not available for UART4 and UART5.
  256. * @retval None
  257. */
  258. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
  259. {
  260. uint32_t tmpreg = 0x00;
  261. /* Check the parameters */
  262. assert_param(IS_USART_123_PERIPH(USARTx));
  263. assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
  264. assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
  265. assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
  266. assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
  267. /*---------------------------- USART CR2 Configuration -----------------------*/
  268. tmpreg = USARTx->CR2;
  269. /* Clear CLKEN, CPOL, CPHA and LBCL bits */
  270. tmpreg &= CR2_CLOCK_CLEAR_Mask;
  271. /* Configure the USART Clock, CPOL, CPHA and LastBit ------------*/
  272. /* Set CLKEN bit according to USART_Clock value */
  273. /* Set CPOL bit according to USART_CPOL value */
  274. /* Set CPHA bit according to USART_CPHA value */
  275. /* Set LBCL bit according to USART_LastBit value */
  276. tmpreg |= (uint32_t)USART_ClockInitStruct->USART_Clock | USART_ClockInitStruct->USART_CPOL |
  277. USART_ClockInitStruct->USART_CPHA | USART_ClockInitStruct->USART_LastBit;
  278. /* Write to USART CR2 */
  279. USARTx->CR2 = (uint16_t)tmpreg;
  280. }
  281. /**
  282. * @brief Fills each USART_ClockInitStruct member with its default value.
  283. * @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
  284. * structure which will be initialized.
  285. * @retval None
  286. */
  287. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct)
  288. {
  289. /* USART_ClockInitStruct members default value */
  290. USART_ClockInitStruct->USART_Clock = USART_Clock_Disable;
  291. USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
  292. USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
  293. USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
  294. }
  295. /**
  296. * @brief Enables or disables the specified USART peripheral.
  297. * @param USARTx: Select the USART or the UART peripheral.
  298. * This parameter can be one of the following values:
  299. * USART1, USART2, USART3, UART4 or UART5.
  300. * @param NewState: new state of the USARTx peripheral.
  301. * This parameter can be: ENABLE or DISABLE.
  302. * @retval None
  303. */
  304. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
  305. {
  306. /* Check the parameters */
  307. assert_param(IS_USART_ALL_PERIPH(USARTx));
  308. assert_param(IS_FUNCTIONAL_STATE(NewState));
  309. if (NewState != DISABLE)
  310. {
  311. /* Enable the selected USART by setting the UE bit in the CR1 register */
  312. USARTx->CR1 |= CR1_UE_Set;
  313. }
  314. else
  315. {
  316. /* Disable the selected USART by clearing the UE bit in the CR1 register */
  317. USARTx->CR1 &= CR1_UE_Reset;
  318. }
  319. }
  320. /**
  321. * @brief Enables or disables the specified USART interrupts.
  322. * @param USARTx: Select the USART or the UART peripheral.
  323. * This parameter can be one of the following values:
  324. * USART1, USART2, USART3, UART4 or UART5.
  325. * @param USART_IT: specifies the USART interrupt sources to be enabled or disabled.
  326. * This parameter can be one of the following values:
  327. * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  328. * @arg USART_IT_LBD: LIN Break detection interrupt
  329. * @arg USART_IT_TXE: Tansmit Data Register empty interrupt
  330. * @arg USART_IT_TC: Transmission complete interrupt
  331. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  332. * @arg USART_IT_IDLE: Idle line detection interrupt
  333. * @arg USART_IT_PE: Parity Error interrupt
  334. * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  335. * @param NewState: new state of the specified USARTx interrupts.
  336. * This parameter can be: ENABLE or DISABLE.
  337. * @retval None
  338. */
  339. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState)
  340. {
  341. uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00;
  342. uint32_t usartxbase = 0x00;
  343. /* Check the parameters */
  344. assert_param(IS_USART_ALL_PERIPH(USARTx));
  345. assert_param(IS_USART_CONFIG_IT(USART_IT));
  346. assert_param(IS_FUNCTIONAL_STATE(NewState));
  347. /* The CTS interrupt is not available for UART4 and UART5 */
  348. if (USART_IT == USART_IT_CTS)
  349. {
  350. assert_param(IS_USART_123_PERIPH(USARTx));
  351. }
  352. usartxbase = (uint32_t)USARTx;
  353. /* Get the USART register index */
  354. usartreg = (((uint8_t)USART_IT) >> 0x05);
  355. /* Get the interrupt position */
  356. itpos = USART_IT & IT_Mask;
  357. itmask = (((uint32_t)0x01) << itpos);
  358. if (usartreg == 0x01) /* The IT is in CR1 register */
  359. {
  360. usartxbase += 0x0C;
  361. }
  362. else if (usartreg == 0x02) /* The IT is in CR2 register */
  363. {
  364. usartxbase += 0x10;
  365. }
  366. else /* The IT is in CR3 register */
  367. {
  368. usartxbase += 0x14;
  369. }
  370. if (NewState != DISABLE)
  371. {
  372. *(__IO uint32_t*)usartxbase |= itmask;
  373. }
  374. else
  375. {
  376. *(__IO uint32_t*)usartxbase &= ~itmask;
  377. }
  378. }
  379. /**
  380. * @brief Enables or disables the USART’s DMA interface.
  381. * @param USARTx: Select the USART or the UART peripheral.
  382. * This parameter can be one of the following values:
  383. * USART1, USART2, USART3 or UART4.
  384. * @param USART_DMAReq: specifies the DMA request.
  385. * This parameter can be any combination of the following values:
  386. * @arg USART_DMAReq_Tx: USART DMA transmit request
  387. * @arg USART_DMAReq_Rx: USART DMA receive request
  388. * @param NewState: new state of the DMA Request sources.
  389. * This parameter can be: ENABLE or DISABLE.
  390. * @note The DMA mode is not available for UART5.
  391. * @retval None
  392. */
  393. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
  394. {
  395. /* Check the parameters */
  396. assert_param(IS_USART_1234_PERIPH(USARTx));
  397. assert_param(IS_USART_DMAREQ(USART_DMAReq));
  398. assert_param(IS_FUNCTIONAL_STATE(NewState));
  399. if (NewState != DISABLE)
  400. {
  401. /* Enable the DMA transfer for selected requests by setting the DMAT and/or
  402. DMAR bits in the USART CR3 register */
  403. USARTx->CR3 |= USART_DMAReq;
  404. }
  405. else
  406. {
  407. /* Disable the DMA transfer for selected requests by clearing the DMAT and/or
  408. DMAR bits in the USART CR3 register */
  409. USARTx->CR3 &= (uint16_t)~USART_DMAReq;
  410. }
  411. }
  412. /**
  413. * @brief Sets the address of the USART node.
  414. * @param USARTx: Select the USART or the UART peripheral.
  415. * This parameter can be one of the following values:
  416. * USART1, USART2, USART3, UART4 or UART5.
  417. * @param USART_Address: Indicates the address of the USART node.
  418. * @retval None
  419. */
  420. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address)
  421. {
  422. /* Check the parameters */
  423. assert_param(IS_USART_ALL_PERIPH(USARTx));
  424. assert_param(IS_USART_ADDRESS(USART_Address));
  425. /* Clear the USART address */
  426. USARTx->CR2 &= CR2_Address_Mask;
  427. /* Set the USART address node */
  428. USARTx->CR2 |= USART_Address;
  429. }
  430. /**
  431. * @brief Selects the USART WakeUp method.
  432. * @param USARTx: Select the USART or the UART peripheral.
  433. * This parameter can be one of the following values:
  434. * USART1, USART2, USART3, UART4 or UART5.
  435. * @param USART_WakeUp: specifies the USART wakeup method.
  436. * This parameter can be one of the following values:
  437. * @arg USART_WakeUp_IdleLine: WakeUp by an idle line detection
  438. * @arg USART_WakeUp_AddressMark: WakeUp by an address mark
  439. * @retval None
  440. */
  441. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp)
  442. {
  443. /* Check the parameters */
  444. assert_param(IS_USART_ALL_PERIPH(USARTx));
  445. assert_param(IS_USART_WAKEUP(USART_WakeUp));
  446. USARTx->CR1 &= CR1_WAKE_Mask;
  447. USARTx->CR1 |= USART_WakeUp;
  448. }
  449. /**
  450. * @brief Determines if the USART is in mute mode or not.
  451. * @param USARTx: Select the USART or the UART peripheral.
  452. * This parameter can be one of the following values:
  453. * USART1, USART2, USART3, UART4 or UART5.
  454. * @param NewState: new state of the USART mute mode.
  455. * This parameter can be: ENABLE or DISABLE.
  456. * @retval None
  457. */
  458. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  459. {
  460. /* Check the parameters */
  461. assert_param(IS_USART_ALL_PERIPH(USARTx));
  462. assert_param(IS_FUNCTIONAL_STATE(NewState));
  463. if (NewState != DISABLE)
  464. {
  465. /* Enable the USART mute mode by setting the RWU bit in the CR1 register */
  466. USARTx->CR1 |= CR1_RWU_Set;
  467. }
  468. else
  469. {
  470. /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
  471. USARTx->CR1 &= CR1_RWU_Reset;
  472. }
  473. }
  474. /**
  475. * @brief Sets the USART LIN Break detection length.
  476. * @param USARTx: Select the USART or the UART peripheral.
  477. * This parameter can be one of the following values:
  478. * USART1, USART2, USART3, UART4 or UART5.
  479. * @param USART_LINBreakDetectLength: specifies the LIN break detection length.
  480. * This parameter can be one of the following values:
  481. * @arg USART_LINBreakDetectLength_10b: 10-bit break detection
  482. * @arg USART_LINBreakDetectLength_11b: 11-bit break detection
  483. * @retval None
  484. */
  485. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength)
  486. {
  487. /* Check the parameters */
  488. assert_param(IS_USART_ALL_PERIPH(USARTx));
  489. assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
  490. USARTx->CR2 &= CR2_LBDL_Mask;
  491. USARTx->CR2 |= USART_LINBreakDetectLength;
  492. }
  493. /**
  494. * @brief Enables or disables the USART’s LIN mode.
  495. * @param USARTx: Select the USART or the UART peripheral.
  496. * This parameter can be one of the following values:
  497. * USART1, USART2, USART3, UART4 or UART5.
  498. * @param NewState: new state of the USART LIN mode.
  499. * This parameter can be: ENABLE or DISABLE.
  500. * @retval None
  501. */
  502. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  503. {
  504. /* Check the parameters */
  505. assert_param(IS_USART_ALL_PERIPH(USARTx));
  506. assert_param(IS_FUNCTIONAL_STATE(NewState));
  507. if (NewState != DISABLE)
  508. {
  509. /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
  510. USARTx->CR2 |= CR2_LINEN_Set;
  511. }
  512. else
  513. {
  514. /* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
  515. USARTx->CR2 &= CR2_LINEN_Reset;
  516. }
  517. }
  518. /**
  519. * @brief Transmits single data through the USARTx peripheral.
  520. * @param USARTx: Select the USART or the UART peripheral.
  521. * This parameter can be one of the following values:
  522. * USART1, USART2, USART3, UART4 or UART5.
  523. * @param Data: the data to transmit.
  524. * @retval None
  525. */
  526. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
  527. {
  528. /* Check the parameters */
  529. assert_param(IS_USART_ALL_PERIPH(USARTx));
  530. assert_param(IS_USART_DATA(Data));
  531. /* Transmit Data */
  532. USARTx->DR = (Data & (uint16_t)0x01FF);
  533. }
  534. /**
  535. * @brief Returns the most recent received data by the USARTx peripheral.
  536. * @param USARTx: Select the USART or the UART peripheral.
  537. * This parameter can be one of the following values:
  538. * USART1, USART2, USART3, UART4 or UART5.
  539. * @retval The received data.
  540. */
  541. uint16_t USART_ReceiveData(USART_TypeDef* USARTx)
  542. {
  543. /* Check the parameters */
  544. assert_param(IS_USART_ALL_PERIPH(USARTx));
  545. /* Receive Data */
  546. return (uint16_t)(USARTx->DR & (uint16_t)0x01FF);
  547. }
  548. /**
  549. * @brief Transmits break characters.
  550. * @param USARTx: Select the USART or the UART peripheral.
  551. * This parameter can be one of the following values:
  552. * USART1, USART2, USART3, UART4 or UART5.
  553. * @retval None
  554. */
  555. void USART_SendBreak(USART_TypeDef* USARTx)
  556. {
  557. /* Check the parameters */
  558. assert_param(IS_USART_ALL_PERIPH(USARTx));
  559. /* Send break characters */
  560. USARTx->CR1 |= CR1_SBK_Set;
  561. }
  562. /**
  563. * @brief Sets the specified USART guard time.
  564. * @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
  565. * @param USART_GuardTime: specifies the guard time.
  566. * @note The guard time bits are not available for UART4 and UART5.
  567. * @retval None
  568. */
  569. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime)
  570. {
  571. /* Check the parameters */
  572. assert_param(IS_USART_123_PERIPH(USARTx));
  573. /* Clear the USART Guard time */
  574. USARTx->GTPR &= GTPR_LSB_Mask;
  575. /* Set the USART guard time */
  576. USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
  577. }
  578. /**
  579. * @brief Sets the system clock prescaler.
  580. * @param USARTx: Select the USART or the UART peripheral.
  581. * This parameter can be one of the following values:
  582. * USART1, USART2, USART3, UART4 or UART5.
  583. * @param USART_Prescaler: specifies the prescaler clock.
  584. * @note The function is used for IrDA mode with UART4 and UART5.
  585. * @retval None
  586. */
  587. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler)
  588. {
  589. /* Check the parameters */
  590. assert_param(IS_USART_ALL_PERIPH(USARTx));
  591. /* Clear the USART prescaler */
  592. USARTx->GTPR &= GTPR_MSB_Mask;
  593. /* Set the USART prescaler */
  594. USARTx->GTPR |= USART_Prescaler;
  595. }
  596. /**
  597. * @brief Enables or disables the USART’s Smart Card mode.
  598. * @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
  599. * @param NewState: new state of the Smart Card mode.
  600. * This parameter can be: ENABLE or DISABLE.
  601. * @note The Smart Card mode is not available for UART4 and UART5.
  602. * @retval None
  603. */
  604. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  605. {
  606. /* Check the parameters */
  607. assert_param(IS_USART_123_PERIPH(USARTx));
  608. assert_param(IS_FUNCTIONAL_STATE(NewState));
  609. if (NewState != DISABLE)
  610. {
  611. /* Enable the SC mode by setting the SCEN bit in the CR3 register */
  612. USARTx->CR3 |= CR3_SCEN_Set;
  613. }
  614. else
  615. {
  616. /* Disable the SC mode by clearing the SCEN bit in the CR3 register */
  617. USARTx->CR3 &= CR3_SCEN_Reset;
  618. }
  619. }
  620. /**
  621. * @brief Enables or disables NACK transmission.
  622. * @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
  623. * @param NewState: new state of the NACK transmission.
  624. * This parameter can be: ENABLE or DISABLE.
  625. * @note The Smart Card mode is not available for UART4 and UART5.
  626. * @retval None
  627. */
  628. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  629. {
  630. /* Check the parameters */
  631. assert_param(IS_USART_123_PERIPH(USARTx));
  632. assert_param(IS_FUNCTIONAL_STATE(NewState));
  633. if (NewState != DISABLE)
  634. {
  635. /* Enable the NACK transmission by setting the NACK bit in the CR3 register */
  636. USARTx->CR3 |= CR3_NACK_Set;
  637. }
  638. else
  639. {
  640. /* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
  641. USARTx->CR3 &= CR3_NACK_Reset;
  642. }
  643. }
  644. /**
  645. * @brief Enables or disables the USART’s Half Duplex communication.
  646. * @param USARTx: Select the USART or the UART peripheral.
  647. * This parameter can be one of the following values:
  648. * USART1, USART2, USART3, UART4 or UART5.
  649. * @param NewState: new state of the USART Communication.
  650. * This parameter can be: ENABLE or DISABLE.
  651. * @retval None
  652. */
  653. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  654. {
  655. /* Check the parameters */
  656. assert_param(IS_USART_ALL_PERIPH(USARTx));
  657. assert_param(IS_FUNCTIONAL_STATE(NewState));
  658. if (NewState != DISABLE)
  659. {
  660. /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
  661. USARTx->CR3 |= CR3_HDSEL_Set;
  662. }
  663. else
  664. {
  665. /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
  666. USARTx->CR3 &= CR3_HDSEL_Reset;
  667. }
  668. }
  669. /**
  670. * @brief Enables or disables the USART's 8x oversampling mode.
  671. * @param USARTx: Select the USART or the UART peripheral.
  672. * This parameter can be one of the following values:
  673. * USART1, USART2, USART3, UART4 or UART5.
  674. * @param NewState: new state of the USART one bit sampling methode.
  675. * This parameter can be: ENABLE or DISABLE.
  676. * @note
  677. * This function has to be called before calling USART_Init()
  678. * function in order to have correct baudrate Divider value.
  679. * @retval None
  680. */
  681. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
  682. {
  683. /* Check the parameters */
  684. assert_param(IS_USART_ALL_PERIPH(USARTx));
  685. assert_param(IS_FUNCTIONAL_STATE(NewState));
  686. if (NewState != DISABLE)
  687. {
  688. /* Enable the 8x Oversampling mode by setting the OVER8 bit in the CR1 register */
  689. USARTx->CR1 |= CR1_OVER8_Set;
  690. }
  691. else
  692. {
  693. /* Disable the 8x Oversampling mode by clearing the OVER8 bit in the CR1 register */
  694. USARTx->CR1 &= CR1_OVER8_Reset;
  695. }
  696. }
  697. /**
  698. * @brief Enables or disables the USART's one bit sampling methode.
  699. * @param USARTx: Select the USART or the UART peripheral.
  700. * This parameter can be one of the following values:
  701. * USART1, USART2, USART3, UART4 or UART5.
  702. * @param NewState: new state of the USART one bit sampling methode.
  703. * This parameter can be: ENABLE or DISABLE.
  704. * @retval None
  705. */
  706. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  707. {
  708. /* Check the parameters */
  709. assert_param(IS_USART_ALL_PERIPH(USARTx));
  710. assert_param(IS_FUNCTIONAL_STATE(NewState));
  711. if (NewState != DISABLE)
  712. {
  713. /* Enable the one bit method by setting the ONEBITE bit in the CR3 register */
  714. USARTx->CR3 |= CR3_ONEBITE_Set;
  715. }
  716. else
  717. {
  718. /* Disable tthe one bit method by clearing the ONEBITE bit in the CR3 register */
  719. USARTx->CR3 &= CR3_ONEBITE_Reset;
  720. }
  721. }
  722. /**
  723. * @brief Configures the USART’s IrDA interface.
  724. * @param USARTx: Select the USART or the UART peripheral.
  725. * This parameter can be one of the following values:
  726. * USART1, USART2, USART3, UART4 or UART5.
  727. * @param USART_IrDAMode: specifies the IrDA mode.
  728. * This parameter can be one of the following values:
  729. * @arg USART_IrDAMode_LowPower
  730. * @arg USART_IrDAMode_Normal
  731. * @retval None
  732. */
  733. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode)
  734. {
  735. /* Check the parameters */
  736. assert_param(IS_USART_ALL_PERIPH(USARTx));
  737. assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
  738. USARTx->CR3 &= CR3_IRLP_Mask;
  739. USARTx->CR3 |= USART_IrDAMode;
  740. }
  741. /**
  742. * @brief Enables or disables the USART’s IrDA interface.
  743. * @param USARTx: Select the USART or the UART peripheral.
  744. * This parameter can be one of the following values:
  745. * USART1, USART2, USART3, UART4 or UART5.
  746. * @param NewState: new state of the IrDA mode.
  747. * This parameter can be: ENABLE or DISABLE.
  748. * @retval None
  749. */
  750. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
  751. {
  752. /* Check the parameters */
  753. assert_param(IS_USART_ALL_PERIPH(USARTx));
  754. assert_param(IS_FUNCTIONAL_STATE(NewState));
  755. if (NewState != DISABLE)
  756. {
  757. /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
  758. USARTx->CR3 |= CR3_IREN_Set;
  759. }
  760. else
  761. {
  762. /* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
  763. USARTx->CR3 &= CR3_IREN_Reset;
  764. }
  765. }
  766. /**
  767. * @brief Checks whether the specified USART flag is set or not.
  768. * @param USARTx: Select the USART or the UART peripheral.
  769. * This parameter can be one of the following values:
  770. * USART1, USART2, USART3, UART4 or UART5.
  771. * @param USART_FLAG: specifies the flag to check.
  772. * This parameter can be one of the following values:
  773. * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
  774. * @arg USART_FLAG_LBD: LIN Break detection flag
  775. * @arg USART_FLAG_TXE: Transmit data register empty flag
  776. * @arg USART_FLAG_TC: Transmission Complete flag
  777. * @arg USART_FLAG_RXNE: Receive data register not empty flag
  778. * @arg USART_FLAG_IDLE: Idle Line detection flag
  779. * @arg USART_FLAG_ORE: OverRun Error flag
  780. * @arg USART_FLAG_NE: Noise Error flag
  781. * @arg USART_FLAG_FE: Framing Error flag
  782. * @arg USART_FLAG_PE: Parity Error flag
  783. * @retval The new state of USART_FLAG (SET or RESET).
  784. */
  785. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG)
  786. {
  787. FlagStatus bitstatus = RESET;
  788. /* Check the parameters */
  789. assert_param(IS_USART_ALL_PERIPH(USARTx));
  790. assert_param(IS_USART_FLAG(USART_FLAG));
  791. /* The CTS flag is not available for UART4 and UART5 */
  792. if (USART_FLAG == USART_FLAG_CTS)
  793. {
  794. assert_param(IS_USART_123_PERIPH(USARTx));
  795. }
  796. if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
  797. {
  798. bitstatus = SET;
  799. }
  800. else
  801. {
  802. bitstatus = RESET;
  803. }
  804. return bitstatus;
  805. }
  806. /**
  807. * @brief Clears the USARTx's pending flags.
  808. * @param USARTx: Select the USART or the UART peripheral.
  809. * This parameter can be one of the following values:
  810. * USART1, USART2, USART3, UART4 or UART5.
  811. * @param USART_FLAG: specifies the flag to clear.
  812. * This parameter can be any combination of the following values:
  813. * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
  814. * @arg USART_FLAG_LBD: LIN Break detection flag.
  815. * @arg USART_FLAG_TC: Transmission Complete flag.
  816. * @arg USART_FLAG_RXNE: Receive data register not empty flag.
  817. *
  818. * @note
  819. * - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
  820. * error) and IDLE (Idle line detected) flags are cleared by software
  821. * sequence: a read operation to USART_SR register (USART_GetFlagStatus())
  822. * followed by a read operation to USART_DR register (USART_ReceiveData()).
  823. * - RXNE flag can be also cleared by a read to the USART_DR register
  824. * (USART_ReceiveData()).
  825. * - TC flag can be also cleared by software sequence: a read operation to
  826. * USART_SR register (USART_GetFlagStatus()) followed by a write operation
  827. * to USART_DR register (USART_SendData()).
  828. * - TXE flag is cleared only by a write to the USART_DR register
  829. * (USART_SendData()).
  830. * @retval None
  831. */
  832. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG)
  833. {
  834. /* Check the parameters */
  835. assert_param(IS_USART_ALL_PERIPH(USARTx));
  836. assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
  837. /* The CTS flag is not available for UART4 and UART5 */
  838. if ((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)
  839. {
  840. assert_param(IS_USART_123_PERIPH(USARTx));
  841. }
  842. USARTx->SR = (uint16_t)~USART_FLAG;
  843. }
  844. /**
  845. * @brief Checks whether the specified USART interrupt has occurred or not.
  846. * @param USARTx: Select the USART or the UART peripheral.
  847. * This parameter can be one of the following values:
  848. * USART1, USART2, USART3, UART4 or UART5.
  849. * @param USART_IT: specifies the USART interrupt source to check.
  850. * This parameter can be one of the following values:
  851. * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  852. * @arg USART_IT_LBD: LIN Break detection interrupt
  853. * @arg USART_IT_TXE: Tansmit Data Register empty interrupt
  854. * @arg USART_IT_TC: Transmission complete interrupt
  855. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  856. * @arg USART_IT_IDLE: Idle line detection interrupt
  857. * @arg USART_IT_ORE: OverRun Error interrupt
  858. * @arg USART_IT_NE: Noise Error interrupt
  859. * @arg USART_IT_FE: Framing Error interrupt
  860. * @arg USART_IT_PE: Parity Error interrupt
  861. * @retval The new state of USART_IT (SET or RESET).
  862. */
  863. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
  864. {
  865. uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
  866. ITStatus bitstatus = RESET;
  867. /* Check the parameters */
  868. assert_param(IS_USART_ALL_PERIPH(USARTx));
  869. assert_param(IS_USART_GET_IT(USART_IT));
  870. /* The CTS interrupt is not available for UART4 and UART5 */
  871. if (USART_IT == USART_IT_CTS)
  872. {
  873. assert_param(IS_USART_123_PERIPH(USARTx));
  874. }
  875. /* Get the USART register index */
  876. usartreg = (((uint8_t)USART_IT) >> 0x05);
  877. /* Get the interrupt position */
  878. itmask = USART_IT & IT_Mask;
  879. itmask = (uint32_t)0x01 << itmask;
  880. if (usartreg == 0x01) /* The IT is in CR1 register */
  881. {
  882. itmask &= USARTx->CR1;
  883. }
  884. else if (usartreg == 0x02) /* The IT is in CR2 register */
  885. {
  886. itmask &= USARTx->CR2;
  887. }
  888. else /* The IT is in CR3 register */
  889. {
  890. itmask &= USARTx->CR3;
  891. }
  892. bitpos = USART_IT >> 0x08;
  893. bitpos = (uint32_t)0x01 << bitpos;
  894. bitpos &= USARTx->SR;
  895. if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
  896. {
  897. bitstatus = SET;
  898. }
  899. else
  900. {
  901. bitstatus = RESET;
  902. }
  903. return bitstatus;
  904. }
  905. /**
  906. * @brief Clears the USARTx’s interrupt pending bits.
  907. * @param USARTx: Select the USART or the UART peripheral.
  908. * This parameter can be one of the following values:
  909. * USART1, USART2, USART3, UART4 or UART5.
  910. * @param USART_IT: specifies the interrupt pending bit to clear.
  911. * This parameter can be one of the following values:
  912. * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  913. * @arg USART_IT_LBD: LIN Break detection interrupt
  914. * @arg USART_IT_TC: Transmission complete interrupt.
  915. * @arg USART_IT_RXNE: Receive Data register not empty interrupt.
  916. *
  917. * @note
  918. * - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
  919. * error) and IDLE (Idle line detected) pending bits are cleared by
  920. * software sequence: a read operation to USART_SR register
  921. * (USART_GetITStatus()) followed by a read operation to USART_DR register
  922. * (USART_ReceiveData()).
  923. * - RXNE pending bit can be also cleared by a read to the USART_DR register
  924. * (USART_ReceiveData()).
  925. * - TC pending bit can be also cleared by software sequence: a read
  926. * operation to USART_SR register (USART_GetITStatus()) followed by a write
  927. * operation to USART_DR register (USART_SendData()).
  928. * - TXE pending bit is cleared only by a write to the USART_DR register
  929. * (USART_SendData()).
  930. * @retval None
  931. */
  932. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT)
  933. {
  934. uint16_t bitpos = 0x00, itmask = 0x00;
  935. /* Check the parameters */
  936. assert_param(IS_USART_ALL_PERIPH(USARTx));
  937. assert_param(IS_USART_CLEAR_IT(USART_IT));
  938. /* The CTS interrupt is not available for UART4 and UART5 */
  939. if (USART_IT == USART_IT_CTS)
  940. {
  941. assert_param(IS_USART_123_PERIPH(USARTx));
  942. }
  943. bitpos = USART_IT >> 0x08;
  944. itmask = ((uint16_t)0x01 << (uint16_t)bitpos);
  945. USARTx->SR = (uint16_t)~itmask;
  946. }
  947. /**
  948. * @}
  949. */
  950. /**
  951. * @}
  952. */
  953. /**
  954. * @}
  955. */
  956. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/