stm32f0xx_usart.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_usart.h
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 05-December-2014
  7. * @brief This file contains all the functions prototypes for the USART
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F0XX_USART_H
  30. #define __STM32F0XX_USART_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx.h"
  36. /** @addtogroup STM32F0xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup USART
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief USART Init Structure definition
  45. */
  46. typedef struct
  47. {
  48. uint32_t USART_BaudRate; /*!< This member configures the USART communication baud rate.
  49. The baud rate is computed using the following formula:
  50. - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate)))
  51. - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */
  52. uint32_t USART_WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  53. This parameter can be a value of @ref USART_Word_Length */
  54. uint32_t USART_StopBits; /*!< Specifies the number of stop bits transmitted.
  55. This parameter can be a value of @ref USART_Stop_Bits */
  56. uint32_t USART_Parity; /*!< Specifies the parity mode.
  57. This parameter can be a value of @ref USART_Parity
  58. @note When parity is enabled, the computed parity is inserted
  59. at the MSB position of the transmitted data (9th bit when
  60. the word length is set to 9 data bits; 8th bit when the
  61. word length is set to 8 data bits). */
  62. uint32_t USART_Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
  63. This parameter can be a value of @ref USART_Mode */
  64. uint32_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
  65. or disabled.
  66. This parameter can be a value of @ref USART_Hardware_Flow_Control*/
  67. } USART_InitTypeDef;
  68. /**
  69. * @brief USART Clock Init Structure definition
  70. */
  71. typedef struct
  72. {
  73. uint32_t USART_Clock; /*!< Specifies whether the USART clock is enabled or disabled.
  74. This parameter can be a value of @ref USART_Clock */
  75. uint32_t USART_CPOL; /*!< Specifies the steady state of the serial clock.
  76. This parameter can be a value of @ref USART_Clock_Polarity */
  77. uint32_t USART_CPHA; /*!< Specifies the clock transition on which the bit capture is made.
  78. This parameter can be a value of @ref USART_Clock_Phase */
  79. uint32_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  80. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  81. This parameter can be a value of @ref USART_Last_Bit */
  82. } USART_ClockInitTypeDef;
  83. /* Exported constants --------------------------------------------------------*/
  84. /** @defgroup USART_Exported_Constants
  85. * @{
  86. */
  87. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  88. ((PERIPH) == USART2) || \
  89. ((PERIPH) == USART3) || \
  90. ((PERIPH) == USART4) || \
  91. ((PERIPH) == USART5) || \
  92. ((PERIPH) == USART6) || \
  93. ((PERIPH) == USART7) || \
  94. ((PERIPH) == USART8))
  95. #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  96. ((PERIPH) == USART2) || \
  97. ((PERIPH) == USART3))
  98. /** @defgroup USART_Word_Length
  99. * @{
  100. */
  101. #define USART_WordLength_8b ((uint32_t)0x00000000)
  102. #define USART_WordLength_9b USART_CR1_M /* should be ((uint32_t)0x00001000) */
  103. #define USART_WordLength_7b ((uint32_t)0x10001000) /*!< only available for STM32F072 and STM32F030 devices */
  104. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
  105. ((LENGTH) == USART_WordLength_9b) || \
  106. ((LENGTH) == USART_WordLength_7b))
  107. /**
  108. * @}
  109. */
  110. /** @defgroup USART_Stop_Bits
  111. * @{
  112. */
  113. #define USART_StopBits_1 ((uint32_t)0x00000000)
  114. #define USART_StopBits_2 USART_CR2_STOP_1
  115. #define USART_StopBits_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1)
  116. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
  117. ((STOPBITS) == USART_StopBits_2) || \
  118. ((STOPBITS) == USART_StopBits_1_5))
  119. /**
  120. * @}
  121. */
  122. /** @defgroup USART_Parity
  123. * @{
  124. */
  125. #define USART_Parity_No ((uint32_t)0x00000000)
  126. #define USART_Parity_Even USART_CR1_PCE
  127. #define USART_Parity_Odd (USART_CR1_PCE | USART_CR1_PS)
  128. #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
  129. ((PARITY) == USART_Parity_Even) || \
  130. ((PARITY) == USART_Parity_Odd))
  131. /**
  132. * @}
  133. */
  134. /** @defgroup USART_Mode
  135. * @{
  136. */
  137. #define USART_Mode_Rx USART_CR1_RE
  138. #define USART_Mode_Tx USART_CR1_TE
  139. #define IS_USART_MODE(MODE) ((((MODE) & (uint32_t)0xFFFFFFF3) == 0x00) && \
  140. ((MODE) != (uint32_t)0x00))
  141. /**
  142. * @}
  143. */
  144. /** @defgroup USART_Hardware_Flow_Control
  145. * @{
  146. */
  147. #define USART_HardwareFlowControl_None ((uint32_t)0x00000000)
  148. #define USART_HardwareFlowControl_RTS USART_CR3_RTSE
  149. #define USART_HardwareFlowControl_CTS USART_CR3_CTSE
  150. #define USART_HardwareFlowControl_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE)
  151. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
  152. (((CONTROL) == USART_HardwareFlowControl_None) || \
  153. ((CONTROL) == USART_HardwareFlowControl_RTS) || \
  154. ((CONTROL) == USART_HardwareFlowControl_CTS) || \
  155. ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
  156. /**
  157. * @}
  158. */
  159. /** @defgroup USART_Clock
  160. * @{
  161. */
  162. #define USART_Clock_Disable ((uint32_t)0x00000000)
  163. #define USART_Clock_Enable USART_CR2_CLKEN
  164. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
  165. ((CLOCK) == USART_Clock_Enable))
  166. /**
  167. * @}
  168. */
  169. /** @defgroup USART_Clock_Polarity
  170. * @{
  171. */
  172. #define USART_CPOL_Low ((uint32_t)0x00000000)
  173. #define USART_CPOL_High USART_CR2_CPOL
  174. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
  175. /**
  176. * @}
  177. */
  178. /** @defgroup USART_Clock_Phase
  179. * @{
  180. */
  181. #define USART_CPHA_1Edge ((uint32_t)0x00000000)
  182. #define USART_CPHA_2Edge USART_CR2_CPHA
  183. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
  184. /**
  185. * @}
  186. */
  187. /** @defgroup USART_Last_Bit
  188. * @{
  189. */
  190. #define USART_LastBit_Disable ((uint32_t)0x00000000)
  191. #define USART_LastBit_Enable USART_CR2_LBCL
  192. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
  193. ((LASTBIT) == USART_LastBit_Enable))
  194. /**
  195. * @}
  196. */
  197. /** @defgroup USART_DMA_Requests
  198. * @{
  199. */
  200. #define USART_DMAReq_Tx USART_CR3_DMAT
  201. #define USART_DMAReq_Rx USART_CR3_DMAR
  202. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint32_t)0xFFFFFF3F) == 0x00) && \
  203. ((DMAREQ) != (uint32_t)0x00))
  204. /**
  205. * @}
  206. */
  207. /** @defgroup USART_DMA_Recception_Error
  208. * @{
  209. */
  210. #define USART_DMAOnError_Enable ((uint32_t)0x00000000)
  211. #define USART_DMAOnError_Disable USART_CR3_DDRE
  212. #define IS_USART_DMAONERROR(DMAERROR) (((DMAERROR) == USART_DMAOnError_Disable)|| \
  213. ((DMAERROR) == USART_DMAOnError_Enable))
  214. /**
  215. * @}
  216. */
  217. /** @defgroup USART_MuteMode_WakeUp_methods
  218. * @{
  219. */
  220. #define USART_WakeUp_IdleLine ((uint32_t)0x00000000)
  221. #define USART_WakeUp_AddressMark USART_CR1_WAKE
  222. #define IS_USART_MUTEMODE_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
  223. ((WAKEUP) == USART_WakeUp_AddressMark))
  224. /**
  225. * @}
  226. */
  227. /** @defgroup USART_Address_Detection
  228. * @{
  229. */
  230. #define USART_AddressLength_4b ((uint32_t)0x00000000)
  231. #define USART_AddressLength_7b USART_CR2_ADDM7
  232. #define IS_USART_ADDRESS_DETECTION(ADDRESS) (((ADDRESS) == USART_AddressLength_4b) || \
  233. ((ADDRESS) == USART_AddressLength_7b))
  234. /**
  235. * @}
  236. */
  237. /** @defgroup USART_StopMode_WakeUp_methods
  238. * @note These parameters are only available for STM32F051 and STM32F072 devices
  239. * @{
  240. */
  241. #define USART_WakeUpSource_AddressMatch ((uint32_t)0x00000000)
  242. #define USART_WakeUpSource_StartBit USART_CR3_WUS_1
  243. #define USART_WakeUpSource_RXNE (USART_CR3_WUS_0 | USART_CR3_WUS_1)
  244. #define IS_USART_STOPMODE_WAKEUPSOURCE(SOURCE) (((SOURCE) == USART_WakeUpSource_AddressMatch) || \
  245. ((SOURCE) == USART_WakeUpSource_StartBit) || \
  246. ((SOURCE) == USART_WakeUpSource_RXNE))
  247. /**
  248. * @}
  249. */
  250. /** @defgroup USART_LIN_Break_Detection_Length
  251. * @{
  252. */
  253. #define USART_LINBreakDetectLength_10b ((uint32_t)0x00000000)
  254. #define USART_LINBreakDetectLength_11b USART_CR2_LBDL
  255. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
  256. (((LENGTH) == USART_LINBreakDetectLength_10b) || \
  257. ((LENGTH) == USART_LINBreakDetectLength_11b))
  258. /**
  259. * @}
  260. */
  261. /** @defgroup USART_IrDA_Low_Power
  262. * @{
  263. */
  264. #define USART_IrDAMode_LowPower USART_CR3_IRLP
  265. #define USART_IrDAMode_Normal ((uint32_t)0x00000000)
  266. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \
  267. ((MODE) == USART_IrDAMode_Normal))
  268. /**
  269. * @}
  270. */
  271. /** @defgroup USART_DE_Polarity
  272. * @{
  273. */
  274. #define USART_DEPolarity_High ((uint32_t)0x00000000)
  275. #define USART_DEPolarity_Low USART_CR3_DEP
  276. #define IS_USART_DE_POLARITY(POLARITY) (((POLARITY) == USART_DEPolarity_Low) || \
  277. ((POLARITY) == USART_DEPolarity_High))
  278. /**
  279. * @}
  280. */
  281. /** @defgroup USART_Inversion_Pins
  282. * @{
  283. */
  284. #define USART_InvPin_Tx USART_CR2_TXINV
  285. #define USART_InvPin_Rx USART_CR2_RXINV
  286. #define IS_USART_INVERSTION_PIN(PIN) ((((PIN) & (uint32_t)0xFFFCFFFF) == 0x00) && \
  287. ((PIN) != (uint32_t)0x00))
  288. /**
  289. * @}
  290. */
  291. /** @defgroup USART_AutoBaudRate_Mode
  292. * @{
  293. */
  294. #define USART_AutoBaudRate_StartBit ((uint32_t)0x00000000)
  295. #define USART_AutoBaudRate_FallingEdge USART_CR2_ABRMODE_0
  296. #define IS_USART_AUTOBAUDRATE_MODE(MODE) (((MODE) == USART_AutoBaudRate_StartBit) || \
  297. ((MODE) == USART_AutoBaudRate_FallingEdge))
  298. /**
  299. * @}
  300. */
  301. /** @defgroup USART_OVR_DETECTION
  302. * @{
  303. */
  304. #define USART_OVRDetection_Enable ((uint32_t)0x00000000)
  305. #define USART_OVRDetection_Disable USART_CR3_OVRDIS
  306. #define IS_USART_OVRDETECTION(OVR) (((OVR) == USART_OVRDetection_Enable)|| \
  307. ((OVR) == USART_OVRDetection_Disable))
  308. /**
  309. * @}
  310. */
  311. /** @defgroup USART_Request
  312. * @{
  313. */
  314. #define USART_Request_ABRRQ USART_RQR_ABRRQ
  315. #define USART_Request_SBKRQ USART_RQR_SBKRQ
  316. #define USART_Request_MMRQ USART_RQR_MMRQ
  317. #define USART_Request_RXFRQ USART_RQR_RXFRQ
  318. #define USART_Request_TXFRQ USART_RQR_TXFRQ
  319. #define IS_USART_REQUEST(REQUEST) (((REQUEST) == USART_Request_TXFRQ) || \
  320. ((REQUEST) == USART_Request_RXFRQ) || \
  321. ((REQUEST) == USART_Request_MMRQ) || \
  322. ((REQUEST) == USART_Request_SBKRQ) || \
  323. ((REQUEST) == USART_Request_ABRRQ))
  324. /**
  325. * @}
  326. */
  327. /** @defgroup USART_Flags
  328. * @{
  329. */
  330. #define USART_FLAG_REACK USART_ISR_REACK
  331. #define USART_FLAG_TEACK USART_ISR_TEACK
  332. #define USART_FLAG_WU USART_ISR_WUF /*!< Not available for STM32F030 devices */
  333. #define USART_FLAG_RWU USART_ISR_RWU /*!< Not available for STM32F030 devices */
  334. #define USART_FLAG_SBK USART_ISR_SBKF
  335. #define USART_FLAG_CM USART_ISR_CMF
  336. #define USART_FLAG_BUSY USART_ISR_BUSY
  337. #define USART_FLAG_ABRF USART_ISR_ABRF
  338. #define USART_FLAG_ABRE USART_ISR_ABRE
  339. #define USART_FLAG_EOB USART_ISR_EOBF /*!< Not available for STM32F030 devices */
  340. #define USART_FLAG_RTO USART_ISR_RTOF
  341. #define USART_FLAG_nCTSS USART_ISR_CTS
  342. #define USART_FLAG_CTS USART_ISR_CTSIF
  343. #define USART_FLAG_LBD USART_ISR_LBD /*!< Not available for STM32F030 devices */
  344. #define USART_FLAG_TXE USART_ISR_TXE
  345. #define USART_FLAG_TC USART_ISR_TC
  346. #define USART_FLAG_RXNE USART_ISR_RXNE
  347. #define USART_FLAG_IDLE USART_ISR_IDLE
  348. #define USART_FLAG_ORE USART_ISR_ORE
  349. #define USART_FLAG_NE USART_ISR_NE
  350. #define USART_FLAG_FE USART_ISR_FE
  351. #define USART_FLAG_PE USART_ISR_PE
  352. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
  353. ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
  354. ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \
  355. ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
  356. ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE) || \
  357. ((FLAG) == USART_FLAG_nCTSS) || ((FLAG) == USART_FLAG_RTO) || \
  358. ((FLAG) == USART_FLAG_EOB) || ((FLAG) == USART_FLAG_ABRE) || \
  359. ((FLAG) == USART_FLAG_ABRF) || ((FLAG) == USART_FLAG_BUSY) || \
  360. ((FLAG) == USART_FLAG_CM) || ((FLAG) == USART_FLAG_SBK) || \
  361. ((FLAG) == USART_FLAG_RWU) || ((FLAG) == USART_FLAG_WU) || \
  362. ((FLAG) == USART_FLAG_TEACK)|| ((FLAG) == USART_FLAG_REACK))
  363. #define IS_USART_CLEAR_FLAG(FLAG) (((FLAG) == USART_FLAG_WU) || ((FLAG) == USART_FLAG_TC) || \
  364. ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_ORE) || \
  365. ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE) || \
  366. ((FLAG) == USART_FLAG_LBD) || ((FLAG) == USART_FLAG_CTS) || \
  367. ((FLAG) == USART_FLAG_RTO) || ((FLAG) == USART_FLAG_EOB) || \
  368. ((FLAG) == USART_FLAG_CM) || ((FLAG) == USART_FLAG_PE))
  369. /**
  370. * @}
  371. */
  372. /** @defgroup USART_Interrupt_definition
  373. * @brief USART Interrupt definition
  374. * USART_IT possible values
  375. * Elements values convention: 0xZZZZYYXX
  376. * XX: Position of the corresponding Interrupt
  377. * YY: Register index
  378. * ZZZZ: Flag position
  379. * @{
  380. */
  381. #define USART_IT_WU ((uint32_t)0x00140316) /*!< Not available for STM32F030 devices */
  382. #define USART_IT_CM ((uint32_t)0x0011010E)
  383. #define USART_IT_EOB ((uint32_t)0x000C011B) /*!< Not available for STM32F030 devices */
  384. #define USART_IT_RTO ((uint32_t)0x000B011A)
  385. #define USART_IT_PE ((uint32_t)0x00000108)
  386. #define USART_IT_TXE ((uint32_t)0x00070107)
  387. #define USART_IT_TC ((uint32_t)0x00060106)
  388. #define USART_IT_RXNE ((uint32_t)0x00050105)
  389. #define USART_IT_IDLE ((uint32_t)0x00040104)
  390. #define USART_IT_LBD ((uint32_t)0x00080206) /*!< Not available for STM32F030 devices */
  391. #define USART_IT_CTS ((uint32_t)0x0009030A)
  392. #define USART_IT_ERR ((uint32_t)0x00000300)
  393. #define USART_IT_ORE ((uint32_t)0x00030300)
  394. #define USART_IT_NE ((uint32_t)0x00020300)
  395. #define USART_IT_FE ((uint32_t)0x00010300)
  396. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  397. ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  398. ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  399. ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR) || \
  400. ((IT) == USART_IT_RTO) || ((IT) == USART_IT_EOB) || \
  401. ((IT) == USART_IT_CM) || ((IT) == USART_IT_WU))
  402. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  403. ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  404. ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  405. ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
  406. ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE) || \
  407. ((IT) == USART_IT_RTO) || ((IT) == USART_IT_EOB) || \
  408. ((IT) == USART_IT_CM) || ((IT) == USART_IT_WU))
  409. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_PE) || \
  410. ((IT) == USART_IT_FE) || ((IT) == USART_IT_NE) || \
  411. ((IT) == USART_IT_ORE) || ((IT) == USART_IT_IDLE) || \
  412. ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS) || \
  413. ((IT) == USART_IT_RTO) || ((IT) == USART_IT_EOB) || \
  414. ((IT) == USART_IT_CM) || ((IT) == USART_IT_WU))
  415. /**
  416. * @}
  417. */
  418. /** @defgroup USART_Global_definition
  419. * @{
  420. */
  421. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x005B8D81))
  422. #define IS_USART_DE_ASSERTION_DEASSERTION_TIME(TIME) ((TIME) <= 0x1F)
  423. #define IS_USART_AUTO_RETRY_COUNTER(COUNTER) ((COUNTER) <= 0x7)
  424. #define IS_USART_TIMEOUT(TIMEOUT) ((TIMEOUT) <= 0x00FFFFFF)
  425. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
  426. /**
  427. * @}
  428. */
  429. /**
  430. * @}
  431. */
  432. /* Exported macro ------------------------------------------------------------*/
  433. /* Exported functions ------------------------------------------------------- */
  434. /* Initialization and Configuration functions *********************************/
  435. void USART_DeInit(USART_TypeDef* USARTx);
  436. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
  437. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
  438. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
  439. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
  440. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  441. void USART_DirectionModeCmd(USART_TypeDef* USARTx, uint32_t USART_DirectionMode, FunctionalState NewState);
  442. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler); /* Not available for STM32F030 devices */
  443. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  444. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  445. void USART_MSBFirstCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  446. void USART_DataInvCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  447. void USART_InvPinCmd(USART_TypeDef* USARTx, uint32_t USART_InvPin, FunctionalState NewState);
  448. void USART_SWAPPinCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  449. void USART_ReceiverTimeOutCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  450. void USART_SetReceiverTimeOut(USART_TypeDef* USARTx, uint32_t USART_ReceiverTimeOut);
  451. /* STOP Mode functions ********************************************************/
  452. void USART_STOPModeCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  453. void USART_StopModeWakeUpSourceConfig(USART_TypeDef* USARTx, uint32_t USART_WakeUpSource); /* Not available for STM32F030 devices */
  454. /* AutoBaudRate functions *****************************************************/
  455. void USART_AutoBaudRateCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  456. void USART_AutoBaudRateConfig(USART_TypeDef* USARTx, uint32_t USART_AutoBaudRate);
  457. /* Data transfers functions ***************************************************/
  458. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
  459. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
  460. /* Multi-Processor Communication functions ************************************/
  461. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
  462. void USART_MuteModeWakeUpConfig(USART_TypeDef* USARTx, uint32_t USART_WakeUp);
  463. void USART_MuteModeCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  464. void USART_AddressDetectionConfig(USART_TypeDef* USARTx, uint32_t USART_AddressLength);
  465. /* LIN mode functions *********************************************************/
  466. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint32_t USART_LINBreakDetectLength); /* Not available for STM32F030 devices */
  467. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState); /* Not available for STM32F030 devices */
  468. /* Half-duplex mode function **************************************************/
  469. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  470. /* Smartcard mode functions ***************************************************/
  471. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState); /* Not available for STM32F030 devices */
  472. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState); /* Not available for STM32F030 devices */
  473. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime); /* Not available for STM32F030 devices */
  474. void USART_SetAutoRetryCount(USART_TypeDef* USARTx, uint8_t USART_AutoCount); /* Not available for STM32F030 devices */
  475. void USART_SetBlockLength(USART_TypeDef* USARTx, uint8_t USART_BlockLength); /* Not available for STM32F030 devices */
  476. /* IrDA mode functions ********************************************************/
  477. void USART_IrDAConfig(USART_TypeDef* USARTx, uint32_t USART_IrDAMode); /* Not available for STM32F030 devices */
  478. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState); /* Not available for STM32F030 devices */
  479. /* RS485 mode functions *******************************************************/
  480. void USART_DECmd(USART_TypeDef* USARTx, FunctionalState NewState);
  481. void USART_DEPolarityConfig(USART_TypeDef* USARTx, uint32_t USART_DEPolarity);
  482. void USART_SetDEAssertionTime(USART_TypeDef* USARTx, uint32_t USART_DEAssertionTime);
  483. void USART_SetDEDeassertionTime(USART_TypeDef* USARTx, uint32_t USART_DEDeassertionTime);
  484. /* DMA transfers management functions *****************************************/
  485. void USART_DMACmd(USART_TypeDef* USARTx, uint32_t USART_DMAReq, FunctionalState NewState);
  486. void USART_DMAReceptionErrorConfig(USART_TypeDef* USARTx, uint32_t USART_DMAOnError);
  487. /* Interrupts and flags management functions **********************************/
  488. void USART_ITConfig(USART_TypeDef* USARTx, uint32_t USART_IT, FunctionalState NewState);
  489. void USART_RequestCmd(USART_TypeDef* USARTx, uint32_t USART_Request, FunctionalState NewState);
  490. void USART_OverrunDetectionConfig(USART_TypeDef* USARTx, uint32_t USART_OVRDetection);
  491. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint32_t USART_FLAG);
  492. void USART_ClearFlag(USART_TypeDef* USARTx, uint32_t USART_FLAG);
  493. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint32_t USART_IT);
  494. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint32_t USART_IT);
  495. #ifdef __cplusplus
  496. }
  497. #endif
  498. #endif /* __STM32F0XX_USART_H */
  499. /**
  500. * @}
  501. */
  502. /**
  503. * @}
  504. */
  505. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/