A bundled STM32F10x Std Periph and CMSIS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

414 lines
16 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_usart.h
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file contains all the functions prototypes for the USART
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32F10x_USART_H
  24. #define __STM32F10x_USART_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f10x.h"
  30. #include "stm32f10x_assert.h"
  31. /** @addtogroup STM32F10x_StdPeriph_Driver
  32. * @{
  33. */
  34. /** @addtogroup USART
  35. * @{
  36. */
  37. /** @defgroup USART_Exported_Types
  38. * @{
  39. */
  40. /**
  41. * @brief USART Init Structure definition
  42. */
  43. typedef struct
  44. {
  45. uint32_t USART_BaudRate; /*!< This member configures the USART communication baud rate.
  46. The baud rate is computed using the following formula:
  47. - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate)))
  48. - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5 */
  49. uint16_t USART_WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  50. This parameter can be a value of @ref USART_Word_Length */
  51. uint16_t USART_StopBits; /*!< Specifies the number of stop bits transmitted.
  52. This parameter can be a value of @ref USART_Stop_Bits */
  53. uint16_t USART_Parity; /*!< Specifies the parity mode.
  54. This parameter can be a value of @ref USART_Parity
  55. @note When parity is enabled, the computed parity is inserted
  56. at the MSB position of the transmitted data (9th bit when
  57. the word length is set to 9 data bits; 8th bit when the
  58. word length is set to 8 data bits). */
  59. uint16_t USART_Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
  60. This parameter can be a value of @ref USART_Mode */
  61. uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
  62. or disabled.
  63. This parameter can be a value of @ref USART_Hardware_Flow_Control */
  64. } USART_InitTypeDef;
  65. /**
  66. * @brief USART Clock Init Structure definition
  67. */
  68. typedef struct
  69. {
  70. uint16_t USART_Clock; /*!< Specifies whether the USART clock is enabled or disabled.
  71. This parameter can be a value of @ref USART_Clock */
  72. uint16_t USART_CPOL; /*!< Specifies the steady state value of the serial clock.
  73. This parameter can be a value of @ref USART_Clock_Polarity */
  74. uint16_t USART_CPHA; /*!< Specifies the clock transition on which the bit capture is made.
  75. This parameter can be a value of @ref USART_Clock_Phase */
  76. uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  77. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  78. This parameter can be a value of @ref USART_Last_Bit */
  79. } USART_ClockInitTypeDef;
  80. /**
  81. * @}
  82. */
  83. /** @defgroup USART_Exported_Constants
  84. * @{
  85. */
  86. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  87. ((PERIPH) == USART2) || \
  88. ((PERIPH) == USART3) || \
  89. ((PERIPH) == UART4) || \
  90. ((PERIPH) == UART5))
  91. #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  92. ((PERIPH) == USART2) || \
  93. ((PERIPH) == USART3))
  94. #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  95. ((PERIPH) == USART2) || \
  96. ((PERIPH) == USART3) || \
  97. ((PERIPH) == UART4))
  98. /** @defgroup USART_Word_Length
  99. * @{
  100. */
  101. #define USART_WordLength_8b ((uint16_t)0x0000)
  102. #define USART_WordLength_9b ((uint16_t)0x1000)
  103. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
  104. ((LENGTH) == USART_WordLength_9b))
  105. /**
  106. * @}
  107. */
  108. /** @defgroup USART_Stop_Bits
  109. * @{
  110. */
  111. #define USART_StopBits_1 ((uint16_t)0x0000)
  112. #define USART_StopBits_0_5 ((uint16_t)0x1000)
  113. #define USART_StopBits_2 ((uint16_t)0x2000)
  114. #define USART_StopBits_1_5 ((uint16_t)0x3000)
  115. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
  116. ((STOPBITS) == USART_StopBits_0_5) || \
  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 ((uint16_t)0x0000)
  126. #define USART_Parity_Even ((uint16_t)0x0400)
  127. #define USART_Parity_Odd ((uint16_t)0x0600)
  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 ((uint16_t)0x0004)
  138. #define USART_Mode_Tx ((uint16_t)0x0008)
  139. #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
  140. /**
  141. * @}
  142. */
  143. /** @defgroup USART_Hardware_Flow_Control
  144. * @{
  145. */
  146. #define USART_HardwareFlowControl_None ((uint16_t)0x0000)
  147. #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100)
  148. #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200)
  149. #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300)
  150. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
  151. (((CONTROL) == USART_HardwareFlowControl_None) || \
  152. ((CONTROL) == USART_HardwareFlowControl_RTS) || \
  153. ((CONTROL) == USART_HardwareFlowControl_CTS) || \
  154. ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup USART_Clock
  159. * @{
  160. */
  161. #define USART_Clock_Disable ((uint16_t)0x0000)
  162. #define USART_Clock_Enable ((uint16_t)0x0800)
  163. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
  164. ((CLOCK) == USART_Clock_Enable))
  165. /**
  166. * @}
  167. */
  168. /** @defgroup USART_Clock_Polarity
  169. * @{
  170. */
  171. #define USART_CPOL_Low ((uint16_t)0x0000)
  172. #define USART_CPOL_High ((uint16_t)0x0400)
  173. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
  174. /**
  175. * @}
  176. */
  177. /** @defgroup USART_Clock_Phase
  178. * @{
  179. */
  180. #define USART_CPHA_1Edge ((uint16_t)0x0000)
  181. #define USART_CPHA_2Edge ((uint16_t)0x0200)
  182. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
  183. /**
  184. * @}
  185. */
  186. /** @defgroup USART_Last_Bit
  187. * @{
  188. */
  189. #define USART_LastBit_Disable ((uint16_t)0x0000)
  190. #define USART_LastBit_Enable ((uint16_t)0x0100)
  191. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
  192. ((LASTBIT) == USART_LastBit_Enable))
  193. /**
  194. * @}
  195. */
  196. /** @defgroup USART_Interrupt_definition
  197. * @{
  198. */
  199. #define USART_IT_PE ((uint16_t)0x0028)
  200. #define USART_IT_TXE ((uint16_t)0x0727)
  201. #define USART_IT_TC ((uint16_t)0x0626)
  202. #define USART_IT_RXNE ((uint16_t)0x0525)
  203. #define USART_IT_IDLE ((uint16_t)0x0424)
  204. #define USART_IT_LBD ((uint16_t)0x0846)
  205. #define USART_IT_CTS ((uint16_t)0x096A)
  206. #define USART_IT_ERR ((uint16_t)0x0060)
  207. #define USART_IT_ORE ((uint16_t)0x0360)
  208. #define USART_IT_NE ((uint16_t)0x0260)
  209. #define USART_IT_FE ((uint16_t)0x0160)
  210. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  211. ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  212. ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  213. ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
  214. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  215. ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  216. ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  217. ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
  218. ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
  219. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  220. ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
  221. /**
  222. * @}
  223. */
  224. /** @defgroup USART_DMA_Requests
  225. * @{
  226. */
  227. #define USART_DMAReq_Tx ((uint16_t)0x0080)
  228. #define USART_DMAReq_Rx ((uint16_t)0x0040)
  229. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
  230. /**
  231. * @}
  232. */
  233. /** @defgroup USART_WakeUp_methods
  234. * @{
  235. */
  236. #define USART_WakeUp_IdleLine ((uint16_t)0x0000)
  237. #define USART_WakeUp_AddressMark ((uint16_t)0x0800)
  238. #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
  239. ((WAKEUP) == USART_WakeUp_AddressMark))
  240. /**
  241. * @}
  242. */
  243. /** @defgroup USART_LIN_Break_Detection_Length
  244. * @{
  245. */
  246. #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000)
  247. #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020)
  248. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
  249. (((LENGTH) == USART_LINBreakDetectLength_10b) || \
  250. ((LENGTH) == USART_LINBreakDetectLength_11b))
  251. /**
  252. * @}
  253. */
  254. /** @defgroup USART_IrDA_Low_Power
  255. * @{
  256. */
  257. #define USART_IrDAMode_LowPower ((uint16_t)0x0004)
  258. #define USART_IrDAMode_Normal ((uint16_t)0x0000)
  259. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \
  260. ((MODE) == USART_IrDAMode_Normal))
  261. /**
  262. * @}
  263. */
  264. /** @defgroup USART_Flags
  265. * @{
  266. */
  267. #define USART_FLAG_CTS ((uint16_t)0x0200)
  268. #define USART_FLAG_LBD ((uint16_t)0x0100)
  269. #define USART_FLAG_TXE ((uint16_t)0x0080)
  270. #define USART_FLAG_TC ((uint16_t)0x0040)
  271. #define USART_FLAG_RXNE ((uint16_t)0x0020)
  272. #define USART_FLAG_IDLE ((uint16_t)0x0010)
  273. #define USART_FLAG_ORE ((uint16_t)0x0008)
  274. #define USART_FLAG_NE ((uint16_t)0x0004)
  275. #define USART_FLAG_FE ((uint16_t)0x0002)
  276. #define USART_FLAG_PE ((uint16_t)0x0001)
  277. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
  278. ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
  279. ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \
  280. ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
  281. ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
  282. #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))
  283. #define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) &&\
  284. ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \
  285. || ((USART_FLAG) != USART_FLAG_CTS))
  286. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0044AA21))
  287. #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
  288. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
  289. /**
  290. * @}
  291. */
  292. /**
  293. * @}
  294. */
  295. /** @defgroup USART_Exported_Macros
  296. * @{
  297. */
  298. /**
  299. * @}
  300. */
  301. /** @defgroup USART_Exported_Functions
  302. * @{
  303. */
  304. void USART_DeInit(USART_TypeDef* USARTx);
  305. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
  306. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
  307. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
  308. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
  309. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  310. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
  311. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
  312. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
  313. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
  314. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  315. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
  316. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  317. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
  318. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
  319. void USART_SendBreak(USART_TypeDef* USARTx);
  320. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);
  321. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);
  322. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  323. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  324. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  325. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  326. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  327. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
  328. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
  329. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
  330. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
  331. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
  332. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
  333. #ifdef __cplusplus
  334. }
  335. #endif
  336. #endif /* __STM32F10x_USART_H */
  337. /**
  338. * @}
  339. */
  340. /**
  341. * @}
  342. */
  343. /**
  344. * @}
  345. */
  346. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/