gd32f30x_usart.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*!
  2. \file gd32f30x_usart.h
  3. \brief definitions for GD32F30x
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-02-10, V1.0.1, firmware for GD32F30x
  8. */
  9. #ifndef GD32F30X_USART_H
  10. #define GD32F30X_USART_H
  11. #include "gd32f30x.h"
  12. /* USARTx(x=0,1,2)/UARTx(x=3,4) definitions */
  13. #define USART1 USART_BASE /*!< USART1 base address */
  14. #define USART2 (USART_BASE+0x00000400U) /*!< USART2 base address */
  15. #define UART3 (USART_BASE+0x00000800U) /*!< UART3 base address */
  16. #define UART4 (USART_BASE+0x00000C00U) /*!< UART4 base address */
  17. #define USART0 (USART_BASE+0x0000F400U) /*!< USART0 base address */
  18. /* registers definitions */
  19. #define USART_STAT0(usartx) REG32((usartx) + 0x00U) /*!< USART status register 0 */
  20. #define USART_DATA(usartx) REG32((usartx) + 0x04U) /*!< USART data register */
  21. #define USART_BAUD(usartx) REG32((usartx) + 0x08U) /*!< USART baud rate register */
  22. #define USART_CTL0(usartx) REG32((usartx) + 0x0CU) /*!< USART control register 0 */
  23. #define USART_CTL1(usartx) REG32((usartx) + 0x10U) /*!< USART control register 1 */
  24. #define USART_CTL2(usartx) REG32((usartx) + 0x14U) /*!< USART control register 2 */
  25. #define USART_GP(usartx) REG32((usartx) + 0x18U) /*!< USART guard time and prescaler register */
  26. #define USART_CTL3(usartx) REG32((usartx) + 0x80U) /*!< USART control register 3 */
  27. #define USART_RT(usartx) REG32((usartx) + 0x84U) /*!< USART receiver timeout register */
  28. #define USART_STAT1(usartx) REG32((usartx) + 0x88U) /*!< USART status register 1 */
  29. /* bits definitions */
  30. /* USARTx_STAT0 */
  31. #define USART_STAT0_PERR BIT(0) /*!< parity error flag */
  32. #define USART_STAT0_FERR BIT(1) /*!< frame error flag */
  33. #define USART_STAT0_NERR BIT(2) /*!< noise error flag */
  34. #define USART_STAT0_ORERR BIT(3) /*!< overrun error */
  35. #define USART_STAT0_IDLEF BIT(4) /*!< IDLE frame detected flag */
  36. #define USART_STAT0_RBNE BIT(5) /*!< read data buffer not empty */
  37. #define USART_STAT0_TC BIT(6) /*!< transmission complete */
  38. #define USART_STAT0_TBE BIT(7) /*!< transmit data buffer empty */
  39. #define USART_STAT0_LBDF BIT(8) /*!< LIN break detected flag */
  40. #define USART_STAT0_CTSF BIT(9) /*!< CTS change flag */
  41. /* USARTx_DATA */
  42. #define USART_DATA_DATA BITS(0,8) /*!< transmit or read data value */
  43. /* USARTx_BAUD */
  44. #define USART_BAUD_FRADIV BITS(0,3) /*!< fraction part of baud-rate divider */
  45. #define USART_BAUD_INTDIV BITS(4,15) /*!< integer part of baud-rate divider */
  46. /* USARTx_CTL0 */
  47. #define USART_CTL0_SBKCMD BIT(0) /*!< send break command */
  48. #define USART_CTL0_RWU BIT(1) /*!< receiver wakeup from mute mode */
  49. #define USART_CTL0_REN BIT(2) /*!< receiver enable */
  50. #define USART_CTL0_TEN BIT(3) /*!< transmitter enable */
  51. #define USART_CTL0_IDLEIE BIT(4) /*!< idle line detected interrupt enable */
  52. #define USART_CTL0_RBNEIE BIT(5) /*!< read data buffer not empty interrupt and overrun error interrupt enable */
  53. #define USART_CTL0_TCIE BIT(6) /*!< transmission complete interrupt enable */
  54. #define USART_CTL0_TBEIE BIT(7) /*!< transmitter buffer empty interrupt enable */
  55. #define USART_CTL0_PERRIE BIT(8) /*!< parity error interrupt enable */
  56. #define USART_CTL0_PM BIT(9) /*!< parity mode */
  57. #define USART_CTL0_PCEN BIT(10) /*!< parity check function enable */
  58. #define USART_CTL0_WM BIT(11) /*!< wakeup method in mute mode */
  59. #define USART_CTL0_WL BIT(12) /*!< word length */
  60. #define USART_CTL0_UEN BIT(13) /*!< USART enable */
  61. /* USARTx_CTL1 */
  62. #define USART_CTL1_ADDR BITS(0,3) /*!< address of USART */
  63. #define USART_CTL1_LBLEN BIT(5) /*!< LIN break frame length */
  64. #define USART_CTL1_LBDIE BIT(6) /*!< LIN break detected interrupt eanble */
  65. #define USART_CTL1_CLEN BIT(8) /*!< CK length */
  66. #define USART_CTL1_CPH BIT(9) /*!< CK phase */
  67. #define USART_CTL1_CPL BIT(10) /*!< CK polarity */
  68. #define USART_CTL1_CKEN BIT(11) /*!< CK pin enable */
  69. #define USART_CTL1_STB BITS(12,13) /*!< STOP bits length */
  70. #define USART_CTL1_LMEN BIT(14) /*!< LIN mode enable */
  71. /* USARTx_CTL2 */
  72. #define USART_CTL2_ERRIE BIT(0) /*!< error interrupt enable */
  73. #define USART_CTL2_IREN BIT(1) /*!< IrDA mode enable */
  74. #define USART_CTL2_IRLP BIT(2) /*!< IrDA low-power */
  75. #define USART_CTL2_HDEN BIT(3) /*!< half-duplex enable */
  76. #define USART_CTL2_NKEN BIT(4) /*!< NACK enable in smartcard mode */
  77. #define USART_CTL2_SCEN BIT(5) /*!< smartcard mode enable */
  78. #define USART_CTL2_DENR BIT(6) /*!< DMA request enable for reception */
  79. #define USART_CTL2_DENT BIT(7) /*!< DMA request enable for transmission */
  80. #define USART_CTL2_RTSEN BIT(8) /*!< RTS enable */
  81. #define USART_CTL2_CTSEN BIT(9) /*!< CTS enable */
  82. #define USART_CTL2_CTSIE BIT(10) /*!< CTS interrupt enable */
  83. /* USARTx_GP */
  84. #define USART_GP_PSC BITS(0,7) /*!< prescaler value for dividing the system clock */
  85. #define USART_GP_GUAT BITS(8,15) /*!< guard time value in smartcard mode */
  86. /* USARTx_CTL3 */
  87. #define USART_CTL3_RTEN BIT(0) /*!< receiver timeout enable */
  88. #define USART_CTL3_SCRTNUM BITS(1,3) /*!< smartcard auto-retry number */
  89. #define USART_CTL3_RTIE BIT(4) /*!< interrupt enable bit of receive timeout event */
  90. #define USART_CTL3_EBIE BIT(5) /*!< interrupt enable bit of end of block event */
  91. #define USART_CTL3_RINV BIT(8) /*!< RX pin level inversion */
  92. #define USART_CTL3_TINV BIT(9) /*!< TX pin level inversion */
  93. #define USART_CTL3_DINV BIT(10) /*!< data bit level inversion */
  94. #define USART_CTL3_MSBF BIT(11) /*!< most significant bit first */
  95. /* USARTx_RT */
  96. #define USART_RT_RT BITS(0,23) /*!< receiver timeout threshold */
  97. #define USART_RT_BL BITS(24,31) /*!< block length */
  98. /* USARTx_STAT1 */
  99. #define USART_STAT1_RTF BIT(11) /*!< receiver timeout flag */
  100. #define USART_STAT1_EBF BIT(12) /*!< end of block flag */
  101. #define USART_STAT1_BSY BIT(16) /*!< busy flag */
  102. /* constants definitions */
  103. /* define the USART bit position and its register index offset */
  104. #define USART_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
  105. #define USART_REG_VAL(usartx, offset) (REG32((usartx) + (((uint32_t)(offset) & 0xFFFFU) >> 6)))
  106. #define USART_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
  107. #define USART_REGIDX_BIT2(regidx, bitpos, regidx2, bitpos2) (((uint32_t)(regidx2) << 22) | (uint32_t)((bitpos2) << 16)\
  108. | (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos)))
  109. #define USART_REG_VAL2(usartx, offset) (REG32((usartx) + ((uint32_t)(offset) >> 22)))
  110. #define USART_BIT_POS2(val) (((uint32_t)(val) & 0x1F0000U) >> 16)
  111. /* register offset */
  112. #define USART_STAT0_REG_OFFSET 0x00U /*!< STAT0 register offset */
  113. #define USART_STAT1_REG_OFFSET 0x88U /*!< STAT1 register offset */
  114. #define USART_CTL0_REG_OFFSET 0x0CU /*!< CTL0 register offset */
  115. #define USART_CTL1_REG_OFFSET 0x10U /*!< CTL1 register offset */
  116. #define USART_CTL2_REG_OFFSET 0x14U /*!< CTL2 register offset */
  117. #define USART_CTL3_REG_OFFSET 0x80U /*!< CTL3 register offset */
  118. /* USART flags */
  119. typedef enum
  120. {
  121. /* flags in STAT0 register */
  122. USART_FLAG_CTS = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 9U), /*!< CTS change flag */
  123. USART_FLAG_LBD = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 8U), /*!< LIN break detected flag */
  124. USART_FLAG_TBE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 7U), /*!< transmit data buffer empty */
  125. USART_FLAG_TC = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 6U), /*!< transmission complete */
  126. USART_FLAG_RBNE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 5U), /*!< read data buffer not empty */
  127. USART_FLAG_IDLE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 4U), /*!< IDLE frame detected flag */
  128. USART_FLAG_ORERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 3U), /*!< overrun error */
  129. USART_FLAG_NERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 2U), /*!< noise error flag */
  130. USART_FLAG_FERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 1U), /*!< frame error flag */
  131. USART_FLAG_PERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 0U), /*!< parity error flag */
  132. /* flags in STAT1 register */
  133. USART_FLAG_BSY = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 16U), /*!< busy flag */
  134. USART_FLAG_EB = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 12U), /*!< end of block flag */
  135. USART_FLAG_RT = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 11U), /*!< receiver timeout flag */
  136. }usart_flag_enum;
  137. /* USART interrupt flags */
  138. typedef enum
  139. {
  140. /* interrupt flags in CTL0 register */
  141. USART_INT_FLAG_PERR = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 8U, USART_STAT0_REG_OFFSET, 0U), /*!< parity error interrupt and flag */
  142. USART_INT_FLAG_TBE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 7U, USART_STAT0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt and flag */
  143. USART_INT_FLAG_TC = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 6U, USART_STAT0_REG_OFFSET, 6U), /*!< transmission complete interrupt and flag */
  144. USART_INT_FLAG_RBNE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 5U, USART_STAT0_REG_OFFSET, 5U), /*!< read data buffer not empty interrupt and flag */
  145. USART_INT_FLAG_RBNE_ORERR = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 5U, USART_STAT0_REG_OFFSET, 3U), /*!< read data buffer not empty interrupt and overrun error flag */
  146. USART_INT_FLAG_IDLE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 4U, USART_STAT0_REG_OFFSET, 4U), /*!< IDLE line detected interrupt and flag */
  147. /* interrupt flags in CTL1 register */
  148. USART_INT_FLAG_LBD = USART_REGIDX_BIT2(USART_CTL1_REG_OFFSET, 6U, USART_STAT0_REG_OFFSET, 8U), /*!< LIN break detected interrupt and flag */
  149. /* interrupt flags in CTL2 register */
  150. USART_INT_FLAG_CTS = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 10U, USART_STAT0_REG_OFFSET, 9U), /*!< CTS interrupt and flag */
  151. USART_INT_FLAG_ERR_ORERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT0_REG_OFFSET, 3U), /*!< error interrupt and overrun error */
  152. USART_INT_FLAG_ERR_NERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT0_REG_OFFSET, 2U), /*!< error interrupt and noise error flag */
  153. USART_INT_FLAG_ERR_FERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT0_REG_OFFSET, 1U), /*!< error interrupt and frame error flag */
  154. /* interrupt flags in CTL3 register */
  155. USART_INT_FLAG_EB = USART_REGIDX_BIT2(USART_CTL3_REG_OFFSET, 5U, USART_STAT1_REG_OFFSET, 12U), /*!< interrupt enable bit of end of block event and flag */
  156. USART_INT_FLAG_RT = USART_REGIDX_BIT2(USART_CTL3_REG_OFFSET, 4U, USART_STAT1_REG_OFFSET, 11U), /*!< interrupt enable bit of receive timeout event and flag */
  157. }usart_interrupt_flag_enum;
  158. /* USART interrupt enable or disable */
  159. typedef enum
  160. {
  161. /* interrupt in CTL0 register */
  162. USART_INT_PERR = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 8U), /*!< parity error interrupt */
  163. USART_INT_TBE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt */
  164. USART_INT_TC = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 6U), /*!< transmission complete interrupt */
  165. USART_INT_RBNE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 5U), /*!< read data buffer not empty interrupt and overrun error interrupt */
  166. USART_INT_IDLE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 4U), /*!< IDLE line detected interrupt */
  167. /* interrupt in CTL1 register */
  168. USART_INT_LBD = USART_REGIDX_BIT(USART_CTL1_REG_OFFSET, 6U), /*!< LIN break detected interrupt */
  169. /* interrupt in CTL2 register */
  170. USART_INT_CTS = USART_REGIDX_BIT(USART_CTL2_REG_OFFSET, 10U), /*!< CTS interrupt */
  171. USART_INT_ERR = USART_REGIDX_BIT(USART_CTL2_REG_OFFSET, 0U), /*!< error interrupt */
  172. /* interrupt in CTL3 register */
  173. USART_INT_EB = USART_REGIDX_BIT(USART_CTL3_REG_OFFSET, 5U), /*!< end of block interrupt */
  174. USART_INT_RT = USART_REGIDX_BIT(USART_CTL3_REG_OFFSET, 4U), /*!< receive timeout interrupt */
  175. }usart_interrupt_enum;
  176. /* USART invert configure */
  177. typedef enum
  178. {
  179. /* data bit level inversion */
  180. USART_DINV_ENABLE, /*!< data bit level inversion */
  181. USART_DINV_DISABLE, /*!< data bit level not inversion */
  182. /* TX pin level inversion */
  183. USART_TXPIN_ENABLE, /*!< TX pin level inversion */
  184. USART_TXPIN_DISABLE, /*!< TX pin level not inversion */
  185. /* RX pin level inversion */
  186. USART_RXPIN_ENABLE, /*!< RX pin level inversion */
  187. USART_RXPIN_DISABLE, /*!< RX pin level not inversion */
  188. }usart_invert_enum;
  189. /* USART receiver configure */
  190. #define CTL0_REN(regval) (BIT(2) & ((uint32_t)(regval) << 2))
  191. #define USART_RECEIVE_ENABLE CTL0_REN(1) /*!< enable receiver */
  192. #define USART_RECEIVE_DISABLE CTL0_REN(0) /*!< disable receiver */
  193. /* USART transmitter configure */
  194. #define CTL0_TEN(regval) (BIT(3) & ((uint32_t)(regval) << 3))
  195. #define USART_TRANSMIT_ENABLE CTL0_TEN(1) /*!< enable transmitter */
  196. #define USART_TRANSMIT_DISABLE CTL0_TEN(0) /*!< disable transmitter */
  197. /* USART parity bits definitions */
  198. #define CTL0_PM(regval) (BITS(9,10) & ((uint32_t)(regval) << 9))
  199. #define USART_PM_NONE CTL0_PM(0) /*!< no parity */
  200. #define USART_PM_EVEN CTL0_PM(2) /*!< even parity */
  201. #define USART_PM_ODD CTL0_PM(3) /*!< odd parity */
  202. /* USART wakeup method in mute mode */
  203. #define CTL0_WM(regval) (BIT(11) & ((uint32_t)(regval) << 11))
  204. #define USART_WM_IDLE CTL0_WM(0) /*!< idle line */
  205. #define USART_WM_ADDR CTL0_WM(1) /*!< address match */
  206. /* USART word length definitions */
  207. #define CTL0_WL(regval) (BIT(12) & ((uint32_t)(regval) << 12))
  208. #define USART_WL_8BIT CTL0_WL(0) /*!< 8 bits */
  209. #define USART_WL_9BIT CTL0_WL(1) /*!< 9 bits */
  210. /* USART stop bits definitions */
  211. #define CTL1_STB(regval) (BITS(12,13) & ((uint32_t)(regval) << 12))
  212. #define USART_STB_1BIT CTL1_STB(0) /*!< 1 bit */
  213. #define USART_STB_0_5BIT CTL1_STB(1) /*!< 0.5 bit */
  214. #define USART_STB_2BIT CTL1_STB(2) /*!< 2 bits */
  215. #define USART_STB_1_5BIT CTL1_STB(3) /*!< 1.5 bits */
  216. /* USART LIN break frame length */
  217. #define CTL1_LBLEN(regval) (BIT(5) & ((uint32_t)(regval) << 5))
  218. #define USART_LBLEN_10B CTL1_LBLEN(0) /*!< 10 bits */
  219. #define USART_LBLEN_11B CTL1_LBLEN(1) /*!< 11 bits */
  220. /* USART CK length */
  221. #define CTL1_CLEN(regval) (BIT(8) & ((uint32_t)(regval) << 8))
  222. #define USART_CLEN_NONE CTL1_CLEN(0) /*!< there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame */
  223. #define USART_CLEN_EN CTL1_CLEN(1) /*!< there are 8 CK pulses for an 8 bit frame and 9 CK pulses for a 9 bit frame */
  224. /* USART clock phase */
  225. #define CTL1_CPH(regval) (BIT(9) & ((uint32_t)(regval) << 9))
  226. #define USART_CPH_1CK CTL1_CPH(0) /*!< first clock transition is the first data capture edge */
  227. #define USART_CPH_2CK CTL1_CPH(1) /*!< second clock transition is the first data capture edge */
  228. /* USART clock polarity */
  229. #define CTL1_CPL(regval) (BIT(10) & ((uint32_t)(regval) << 10))
  230. #define USART_CPL_LOW CTL1_CPL(0) /*!< steady low value on CK pin */
  231. #define USART_CPL_HIGH CTL1_CPL(1) /*!< steady high value on CK pin */
  232. /* USART DMA request for receive configure */
  233. #define CLT2_DENR(regval) (BIT(6) & ((uint32_t)(regval) << 6))
  234. #define USART_DENR_ENABLE CLT2_DENR(1) /*!< DMA request enable for reception */
  235. #define USART_DENR_DISABLE CLT2_DENR(0) /*!< DMA request disable for reception */
  236. /* USART DMA request for transmission configure */
  237. #define CLT2_DENT(regval) (BIT(7) & ((uint32_t)(regval) << 7))
  238. #define USART_DENT_ENABLE CLT2_DENT(1) /*!< DMA request enable for transmission */
  239. #define USART_DENT_DISABLE CLT2_DENT(0) /*!< DMA request disable for transmission */
  240. /* USART RTS configure */
  241. #define CLT2_RTSEN(regval) (BIT(8) & ((uint32_t)(regval) << 8))
  242. #define USART_RTS_ENABLE CLT2_RTSEN(1) /*!< RTS enable */
  243. #define USART_RTS_DISABLE CLT2_RTSEN(0) /*!< RTS disable */
  244. /* USART CTS configure */
  245. #define CLT2_CTSEN(regval) (BIT(9) & ((uint32_t)(regval) << 9))
  246. #define USART_CTS_ENABLE CLT2_CTSEN(1) /*!< CTS enable */
  247. #define USART_CTS_DISABLE CLT2_CTSEN(0) /*!< CTS disable */
  248. /* USART IrDA low-power enable */
  249. #define CTL2_IRLP(regval) (BIT(2) & ((uint32_t)(regval) << 2))
  250. #define USART_IRLP_LOW CTL2_IRLP(1) /*!< low-power */
  251. #define USART_IRLP_NORMAL CTL2_IRLP(0) /*!< normal */
  252. /* USART data is transmitted/received with the LSB/MSB first */
  253. #define CTL3_MSBF(regval) (BIT(11) & ((uint32_t)(regval) << 11))
  254. #define USART_MSBF_LSB CTL3_MSBF(0) /*!< LSB first */
  255. #define USART_MSBF_MSB CTL3_MSBF(1) /*!< MSB first */
  256. /* function declarations */
  257. /* initialization functions */
  258. /* reset USART */
  259. void usart_deinit(uint32_t usart_periph);
  260. /* configure USART baud rate value */
  261. void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval);
  262. /* configure USART parity function */
  263. void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg);
  264. /* configure USART word length */
  265. void usart_word_length_set(uint32_t usart_periph, uint32_t wlen);
  266. /* configure USART stop bit length */
  267. void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen);
  268. /* USART normal mode communication */
  269. /* enable USART */
  270. void usart_enable(uint32_t usart_periph);
  271. /* disable USART */
  272. void usart_disable(uint32_t usart_periph);
  273. /* configure USART transmitter */
  274. void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig);
  275. /* configure USART receiver */
  276. void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig);
  277. /* data is transmitted/received with the LSB/MSB first */
  278. void usart_data_first_config(uint32_t usart_periph, uint32_t msbf);
  279. /* configure USART inverted */
  280. void usart_invert_config(uint32_t usart_periph, usart_invert_enum invertpara);
  281. /* enable receiver timeout */
  282. void usart_receiver_timeout_enable(uint32_t usart_periph);
  283. /* disable receiver timeout */
  284. void usart_receiver_timeout_disable(uint32_t usart_periph);
  285. /* configure receiver timeout threshold */
  286. void usart_receiver_timeout_threshold_config(uint32_t usart_periph, uint32_t rtimeout);
  287. /* USART transmit data function */
  288. void usart_data_transmit(uint32_t usart_periph, uint32_t data);
  289. /* USART receive data function */
  290. uint16_t usart_data_receive(uint32_t usart_periph);
  291. /* multi-processor communication */
  292. /* configure address of the USART */
  293. void usart_address_config(uint32_t usart_periph, uint8_t addr);
  294. /* enable mute mode */
  295. void usart_mute_mode_enable(uint32_t usart_periph);
  296. /* disable mute mode */
  297. void usart_mute_mode_disable(uint32_t usart_periph);
  298. /* configure wakeup method in mute mode */
  299. void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmethod);
  300. /* LIN mode communication */
  301. /* LIN mode enable */
  302. void usart_lin_mode_enable(uint32_t usart_periph);
  303. /* LIN mode disable */
  304. void usart_lin_mode_disable(uint32_t usart_periph);
  305. /* LIN break detection length */
  306. void usart_lin_break_dection_length_config(uint32_t usart_periph, uint32_t lblen);
  307. /* send break frame */
  308. void usart_send_break(uint32_t usart_periph);
  309. /* half-duplex communication */
  310. /* half-duplex enable */
  311. void usart_halfduplex_enable(uint32_t usart_periph);
  312. /* half-duplex disable */
  313. void usart_halfduplex_disable(uint32_t usart_periph);
  314. /* synchronous communication */
  315. /* clock enable */
  316. void usart_synchronous_clock_enable(uint32_t usart_periph);
  317. /* clock disable */
  318. void usart_synchronous_clock_disable(uint32_t usart_periph);
  319. /* configure usart synchronous mode parameters */
  320. void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl);
  321. /* smartcard communication */
  322. /* guard time value configure in smartcard mode */
  323. void usart_guard_time_config(uint32_t usart_periph,uint32_t guat);
  324. /* smartcard mode enable */
  325. void usart_smartcard_mode_enable(uint32_t usart_periph);
  326. /* smartcard mode disable */
  327. void usart_smartcard_mode_disable(uint32_t usart_periph);
  328. /* NACK enable in smartcard mode */
  329. void usart_smartcard_mode_nack_enable(uint32_t usart_periph);
  330. /* NACK disable in smartcard mode */
  331. void usart_smartcard_mode_nack_disable(uint32_t usart_periph);
  332. /* smartcard auto-retry number configure */
  333. void usart_smartcard_autoretry_config(uint32_t usart_periph, uint32_t scrtnum);
  334. /* block length configure */
  335. void usart_block_length_config(uint32_t usart_periph, uint32_t bl);
  336. /* IrDA communication */
  337. /* enable IrDA mode */
  338. void usart_irda_mode_enable(uint32_t usart_periph);
  339. /* disable IrDA mode */
  340. void usart_irda_mode_disable(uint32_t usart_periph);
  341. /* configure the peripheral clock prescaler */
  342. void usart_prescaler_config(uint32_t usart_periph, uint8_t psc);
  343. /* configure IrDA low-power */
  344. void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp);
  345. /* hardware flow communication */
  346. /* configure hardware flow control RTS */
  347. void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig);
  348. /* configure hardware flow control CTS */
  349. void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig);
  350. /* configure USART DMA for reception */
  351. void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd);
  352. /* configure USART DMA for transmission */
  353. void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd);
  354. /* flag functions */
  355. /* get flag in STAT0/STAT1 register */
  356. FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag);
  357. /* clear flag in STAT0/STAT1 register */
  358. void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag);
  359. /* interrupt functions */
  360. /* enable USART interrupt */
  361. void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag);
  362. /* disable USART interrupt */
  363. void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag);
  364. /* get USART interrupt and flag status */
  365. FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag);
  366. /* clear interrupt flag in STAT0/STAT1 register */
  367. void usart_interrupt_flag_clear(uint32_t usart_periph, uint32_t flag);
  368. #endif /* GD32F30x_USART_H */