drv_uart.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*
  2. * Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Change Logs:
  19. * Date Author Notes
  20. * 2019-01-23 wangyq the first version
  21. * 2019-11-01 wangyq update libraries
  22. * 2021-04-20 liuhy the second version
  23. */
  24. #include <rthw.h>
  25. #include <rtthread.h>
  26. #include <rtdevice.h>
  27. #include "board.h"
  28. #include "es_conf_info_uart.h"
  29. #ifdef RT_USING_SERIAL
  30. /* es32 uart driver */
  31. struct es32_uart
  32. {
  33. uart_handle_t huart;
  34. IRQn_Type irq;
  35. };
  36. /* es32 usart driver */
  37. struct es32_usart
  38. {
  39. usart_handle_t huart;
  40. IRQn_Type irq;
  41. };
  42. #ifdef BSP_USING_UART0
  43. /* UART0 device driver structure */
  44. struct es32_uart uart0 =
  45. {
  46. {UART0},
  47. UART0_IRQn
  48. };
  49. struct rt_serial_device serial0;
  50. void UART0_Handler(void)
  51. {
  52. /* enter interrupt */
  53. rt_interrupt_enter();
  54. if (UART0->RIF & 0x01)
  55. {
  56. rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND);
  57. }
  58. /* leave interrupt */
  59. rt_interrupt_leave();
  60. }
  61. #endif /* BSP_USING_UART0 */
  62. #ifdef BSP_USING_UART1
  63. /* UART1 device driver structure */
  64. struct es32_uart uart1 =
  65. {
  66. {UART1},
  67. UART1_IRQn
  68. };
  69. struct rt_serial_device serial1;
  70. void UART1_Handler(void)
  71. {
  72. /* enter interrupt */
  73. rt_interrupt_enter();
  74. if (UART1->RIF & 0x01)
  75. {
  76. rt_hw_serial_isr(&serial1, RT_SERIAL_EVENT_RX_IND);
  77. }
  78. /* leave interrupt */
  79. rt_interrupt_leave();
  80. }
  81. #endif /* BSP_USING_UART1 */
  82. #ifdef BSP_USING_UART2
  83. /* UART2 device driver structure */
  84. struct es32_uart uart2 =
  85. {
  86. {UART2},
  87. BS16T1_UART2_IRQn
  88. };
  89. struct rt_serial_device serial2;
  90. void BS16T1_UART2_Handler(void)
  91. {
  92. /* enter interrupt */
  93. rt_interrupt_enter();
  94. if (UART2->RIF & 0x01)
  95. {
  96. rt_hw_serial_isr(&serial2, RT_SERIAL_EVENT_RX_IND);
  97. }
  98. /* leave interrupt */
  99. rt_interrupt_leave();
  100. }
  101. #endif /* BSP_USING_UART2 */
  102. #ifdef BSP_USING_UART3
  103. /* UART3 device driver structure */
  104. struct es32_uart uart3 =
  105. {
  106. {UART3},
  107. BS16T2_UART3_IRQn
  108. };
  109. struct rt_serial_device serial3;
  110. void BS16T2_UART3_Handler(void)
  111. {
  112. /* enter interrupt */
  113. rt_interrupt_enter();
  114. if (UART3->RIF & 0x01)
  115. {
  116. rt_hw_serial_isr(&serial3, RT_SERIAL_EVENT_RX_IND);
  117. }
  118. /* leave interrupt */
  119. rt_interrupt_leave();
  120. }
  121. #endif /* BSP_USING_UART3 */
  122. #ifdef BSP_USING_USART0
  123. /* USART0 device driver structure */
  124. struct es32_usart usart0 =
  125. {
  126. {USART0},
  127. USART0_IRQn
  128. };
  129. struct rt_serial_device serial4;
  130. void USART0_Handler(void)
  131. {
  132. /* enter interrupt */
  133. rt_interrupt_enter();
  134. if (USART0->STAT & USART_FLAG_RXNE)
  135. {
  136. rt_hw_serial_isr(&serial4, RT_SERIAL_EVENT_RX_IND);
  137. }
  138. /* leave interrupt */
  139. rt_interrupt_leave();
  140. }
  141. #endif /* BSP_USING_USART0 */
  142. #ifdef BSP_USING_USART1
  143. /* USART1 device driver structure */
  144. struct es32_usart usart1 =
  145. {
  146. {USART1},
  147. USART1_IRQn
  148. };
  149. struct rt_serial_device serial5;
  150. void USART1_Handler(void)
  151. {
  152. /* enter interrupt */
  153. rt_interrupt_enter();
  154. if (USART1->STAT & USART_FLAG_RXNE)
  155. {
  156. rt_hw_serial_isr(&serial5, RT_SERIAL_EVENT_RX_IND);
  157. }
  158. /* leave interrupt */
  159. rt_interrupt_leave();
  160. }
  161. #endif /* BSP_USING_USART1 */
  162. static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
  163. {
  164. gpio_init_t gpio_initstructure;
  165. struct es32_uart *uart;
  166. RT_ASSERT(serial != RT_NULL);
  167. RT_ASSERT(cfg != RT_NULL);
  168. uart = (struct es32_uart *)serial->parent.user_data;
  169. /* Initialize tx pin */
  170. gpio_initstructure.mode = GPIO_MODE_OUTPUT;
  171. gpio_initstructure.odos = GPIO_PUSH_PULL;
  172. gpio_initstructure.pupd = GPIO_PUSH_UP;
  173. gpio_initstructure.odrv = GPIO_OUT_DRIVE_NORMAL;
  174. gpio_initstructure.flt = GPIO_FILTER_DISABLE;
  175. gpio_initstructure.type = GPIO_TYPE_TTL;
  176. if((uint32_t)(uart->huart.perh) > (uint32_t)UART3) /*根据外设物理地址区分UART和USART*/
  177. {
  178. /*USART*/
  179. struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
  180. #ifdef BSP_USING_USART0
  181. if(usart == (&usart0))
  182. {
  183. #if defined(ES_USART0_TX_GPIO_FUNC)&&defined(ES_USART0_TX_GPIO_PORT)&&defined(ES_USART0_TX_GPIO_PIN)
  184. gpio_initstructure.func = ES_USART0_TX_GPIO_FUNC;
  185. ald_gpio_init(ES_USART0_TX_GPIO_PORT, ES_USART0_TX_GPIO_PIN, &gpio_initstructure);
  186. #endif
  187. #if defined(ES_USART0_RX_GPIO_FUNC)&&defined(ES_USART0_RX_GPIO_PORT)&&defined(ES_USART0_RX_GPIO_PIN)
  188. /* Initialize rx pin ,the same as txpin except mode */
  189. gpio_initstructure.mode = GPIO_MODE_INPUT;
  190. gpio_initstructure.func = ES_USART0_RX_GPIO_FUNC;
  191. ald_gpio_init(ES_USART0_RX_GPIO_PORT, ES_USART0_RX_GPIO_PIN, &gpio_initstructure);
  192. #endif
  193. ald_cmu_perh_clock_config(CMU_PERH_USART0, ENABLE);
  194. }
  195. #endif /* usart0 gpio init */
  196. #ifdef BSP_USING_USART1
  197. if(usart == (&usart1))
  198. {
  199. #if defined(ES_USART1_TX_GPIO_FUNC)&&defined(ES_USART1_TX_GPIO_PORT)&&defined(ES_USART1_TX_GPIO_PIN)
  200. gpio_initstructure.func = ES_USART1_TX_GPIO_FUNC;
  201. ald_gpio_init(ES_USART1_TX_GPIO_PORT, ES_USART1_TX_GPIO_PIN, &gpio_initstructure);
  202. #endif
  203. #if defined(ES_USART1_RX_GPIO_FUNC)&&defined(ES_USART1_RX_GPIO_PORT)&&defined(ES_USART1_RX_GPIO_PIN)
  204. /* Initialize rx pin ,the same as txpin except mode */
  205. gpio_initstructure.mode = GPIO_MODE_INPUT;
  206. gpio_initstructure.func = ES_USART1_RX_GPIO_FUNC;
  207. ald_gpio_init(ES_USART1_RX_GPIO_PORT, ES_USART1_RX_GPIO_PIN, &gpio_initstructure);
  208. #endif
  209. ald_cmu_perh_clock_config(CMU_PERH_USART1, ENABLE);
  210. }
  211. #endif /* usart1 gpio init */
  212. usart->huart.init.mode = USART_MODE_TX_RX;
  213. usart->huart.init.baud = cfg->baud_rate;
  214. usart->huart.init.word_length = (usart_word_length_t)(cfg->data_bits - 8);
  215. usart->huart.init.stop_bits = ((cfg->stop_bits == STOP_BITS_1) ? USART_STOP_BITS_1 : USART_STOP_BITS_2);
  216. usart->huart.init.parity = (usart_parity_t)(cfg->parity == PARITY_NONE ? cfg->parity : (4 - cfg->parity) );
  217. usart->huart.init.fctl = USART_HW_FLOW_CTL_NONE;
  218. ald_usart_init(&usart->huart);
  219. /*
  220. BIT_ORDER_LSB BIT_ORDER_MSB
  221. NRZ_NORMAL NRZ_INVERTED
  222. 无相关寄存器*/
  223. /* enable rx int */
  224. ald_usart_interrupt_config(&usart->huart, USART_IT_RXNE, ENABLE);
  225. }
  226. else
  227. {
  228. /*UART*/
  229. #ifdef BSP_USING_UART0
  230. if(uart == (&uart0))
  231. {
  232. #if defined(ES_UART0_TX_GPIO_FUNC)&&defined(ES_UART0_TX_GPIO_PORT)&&defined(ES_UART0_TX_GPIO_PIN)
  233. gpio_initstructure.func = ES_UART0_TX_GPIO_FUNC;
  234. ald_gpio_init(ES_UART0_TX_GPIO_PORT, ES_UART0_TX_GPIO_PIN, &gpio_initstructure);
  235. #endif
  236. #if defined(ES_UART0_RX_GPIO_FUNC)&&defined(ES_UART0_RX_GPIO_PORT)&&defined(ES_UART0_RX_GPIO_PIN)
  237. /* Initialize rx pin ,the same as txpin except mode */
  238. gpio_initstructure.mode = GPIO_MODE_INPUT;
  239. gpio_initstructure.func = ES_UART0_RX_GPIO_FUNC;
  240. ald_gpio_init(ES_UART0_RX_GPIO_PORT, ES_UART0_RX_GPIO_PIN, &gpio_initstructure);
  241. #endif
  242. ald_cmu_perh_clock_config(CMU_PERH_UART0, ENABLE);
  243. }
  244. #endif /* uart0 gpio init */
  245. #ifdef BSP_USING_UART1
  246. if(uart == (&uart1))
  247. {
  248. #if defined(ES_UART1_TX_GPIO_FUNC)&&defined(ES_UART1_TX_GPIO_PORT)&&defined(ES_UART1_TX_GPIO_PIN)
  249. gpio_initstructure.func = ES_UART1_TX_GPIO_FUNC;
  250. ald_gpio_init(ES_UART1_TX_GPIO_PORT, ES_UART1_TX_GPIO_PIN, &gpio_initstructure);
  251. #endif
  252. #if defined(ES_UART1_RX_GPIO_FUNC)&&defined(ES_UART1_RX_GPIO_PORT)&&defined(ES_UART1_RX_GPIO_PIN)
  253. /* Initialize rx pin ,the same as txpin except mode */
  254. gpio_initstructure.mode = GPIO_MODE_INPUT;
  255. gpio_initstructure.func = ES_UART1_RX_GPIO_FUNC;
  256. ald_gpio_init(ES_UART1_RX_GPIO_PORT, ES_UART1_RX_GPIO_PIN, &gpio_initstructure);
  257. #endif
  258. ald_cmu_perh_clock_config(CMU_PERH_UART1, ENABLE);
  259. }
  260. #endif /* uart1 gpio init */
  261. #ifdef BSP_USING_UART2
  262. if(uart == (&uart2))
  263. {
  264. #if defined(ES_UART2_TX_GPIO_FUNC)&&defined(ES_UART2_TX_GPIO_PORT)&&defined(ES_UART2_TX_GPIO_PIN)
  265. gpio_initstructure.func = ES_UART2_TX_GPIO_FUNC;
  266. ald_gpio_init(ES_UART2_TX_GPIO_PORT, ES_UART2_TX_GPIO_PIN, &gpio_initstructure);
  267. #endif
  268. #if defined(ES_UART2_RX_GPIO_FUNC)&&defined(ES_UART2_RX_GPIO_PORT)&&defined(ES_UART2_RX_GPIO_PIN)
  269. /* Initialize rx pin ,the same as txpin except mode */
  270. gpio_initstructure.mode = GPIO_MODE_INPUT;
  271. gpio_initstructure.func = ES_UART2_RX_GPIO_FUNC;
  272. ald_gpio_init(ES_UART2_RX_GPIO_PORT, ES_UART2_RX_GPIO_PIN, &gpio_initstructure);
  273. #endif
  274. ald_cmu_perh_clock_config(CMU_PERH_UART2, ENABLE);
  275. }
  276. #endif /* uart2 gpio init */
  277. #ifdef BSP_USING_UART3
  278. if(uart == (&uart3))
  279. {
  280. #if defined(ES_UART3_TX_GPIO_FUNC)&&defined(ES_UART3_TX_GPIO_PORT)&&defined(ES_UART3_TX_GPIO_PIN)
  281. gpio_initstructure.func = ES_UART3_TX_GPIO_FUNC;
  282. ald_gpio_init(ES_UART3_TX_GPIO_PORT, ES_UART3_TX_GPIO_PIN, &gpio_initstructure);
  283. #endif
  284. #if defined(ES_UART3_RX_GPIO_FUNC)&&defined(ES_UART3_RX_GPIO_PORT)&&defined(ES_UART3_RX_GPIO_PIN)
  285. /* Initialize rx pin ,the same as txpin except mode */
  286. gpio_initstructure.mode = GPIO_MODE_INPUT;
  287. gpio_initstructure.func = ES_UART3_RX_GPIO_FUNC;
  288. ald_gpio_init(ES_UART3_RX_GPIO_PORT, ES_UART3_RX_GPIO_PIN, &gpio_initstructure);
  289. #endif
  290. ald_cmu_perh_clock_config(CMU_PERH_UART3, ENABLE);
  291. }
  292. #endif /* uart3 gpio init */
  293. uart->huart.init.mode = UART_MODE_UART;
  294. uart->huart.init.baud = cfg->baud_rate;
  295. uart->huart.init.word_length = (uart_word_length_t)(cfg->data_bits - 5);
  296. uart->huart.init.stop_bits = (uart_stop_bits_t)cfg->stop_bits;
  297. uart->huart.init.parity = (uart_parity_t)(cfg->parity == PARITY_EVEN ? UART_PARITY_EVEN : cfg->parity);
  298. uart->huart.init.fctl = UART_HW_FLOW_CTL_DISABLE;
  299. ald_uart_init(&uart->huart);
  300. if (cfg->bit_order == BIT_ORDER_MSB)
  301. {
  302. UART_MSB_FIRST_ENABLE(&uart->huart);
  303. }
  304. else
  305. {
  306. UART_MSB_FIRST_DISABLE(&uart->huart);
  307. }
  308. if (cfg->invert == NRZ_INVERTED)
  309. {
  310. UART_DATA_INV_ENABLE(&uart->huart);
  311. }
  312. else
  313. {
  314. UART_DATA_INV_DISABLE(&uart->huart);
  315. }
  316. /* enable rx int */
  317. ald_uart_interrupt_config(&uart->huart, UART_IT_RXRD, ENABLE);
  318. }
  319. return RT_EOK;
  320. }
  321. static rt_err_t es32f0x_control(struct rt_serial_device *serial, int cmd, void *arg)
  322. {
  323. struct es32_uart *uart;
  324. RT_ASSERT(serial != RT_NULL);
  325. uart = (struct es32_uart *)serial->parent.user_data;
  326. if((uint32_t)(uart->huart.perh) > (uint32_t)UART3) /*根据外设物理地址区分UART和USART*/
  327. {
  328. /*USART*/
  329. struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
  330. switch (cmd)
  331. {
  332. case RT_DEVICE_CTRL_CLR_INT:
  333. /* disable rx irq */
  334. NVIC_DisableIRQ(usart->irq);
  335. /* disable interrupt */
  336. ald_usart_interrupt_config(&usart->huart, USART_IT_RXNE, DISABLE);
  337. break;
  338. case RT_DEVICE_CTRL_SET_INT:
  339. /* enable rx irq */
  340. NVIC_EnableIRQ(usart->irq);
  341. /* enable interrupt */
  342. ald_usart_interrupt_config(&usart->huart, USART_IT_RXNE, ENABLE);
  343. break;
  344. }
  345. }
  346. else
  347. {
  348. /*UART*/
  349. switch (cmd)
  350. {
  351. case RT_DEVICE_CTRL_CLR_INT:
  352. /* disable rx irq */
  353. NVIC_DisableIRQ(uart->irq);
  354. /* disable interrupt */
  355. ald_uart_interrupt_config(&uart->huart, UART_IT_RXRD, DISABLE);
  356. break;
  357. case RT_DEVICE_CTRL_SET_INT:
  358. /* enable rx irq */
  359. NVIC_EnableIRQ(uart->irq);
  360. /* enable interrupt */
  361. ald_uart_interrupt_config(&uart->huart, UART_IT_RXRD, ENABLE);
  362. break;
  363. }
  364. }
  365. return RT_EOK;
  366. }
  367. static int es32f0x_putc(struct rt_serial_device *serial, char c)
  368. {
  369. struct es32_uart *uart;
  370. RT_ASSERT(serial != RT_NULL);
  371. uart = (struct es32_uart *)serial->parent.user_data;
  372. if((uint32_t)(uart->huart.perh) > (uint32_t)UART3) /*根据外设物理地址区分UART和USART*/
  373. {
  374. /*USART*/
  375. struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
  376. while (!(usart->huart.perh->STAT & USART_STAT_TXEMPIF_MSK)) ;
  377. WRITE_REG(usart->huart.perh->DATA, c);
  378. }
  379. else
  380. {
  381. /*UART*/
  382. while (!(uart->huart.perh->SR & 0x40)) ;
  383. WRITE_REG(uart->huart.perh->TBR, c);
  384. }
  385. return 1;
  386. }
  387. static int es32f0x_getc(struct rt_serial_device *serial)
  388. {
  389. int ch = -1;
  390. struct es32_uart *uart;
  391. RT_ASSERT(serial != RT_NULL);
  392. uart = (struct es32_uart *)serial->parent.user_data;
  393. if((uint32_t)(uart->huart.perh) > (uint32_t)UART3) /*根据外设物理地址区分UART和USART*/
  394. {
  395. /*USART*/
  396. struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
  397. if (usart->huart.perh->STAT & USART_STAT_RXNEIF_MSK)
  398. {
  399. ch = (uint8_t)(usart->huart.perh->DATA & 0xFF);
  400. }
  401. }
  402. else
  403. {
  404. /*UART*/
  405. if (uart->huart.perh->SR & 0x01)
  406. {
  407. ch = (uint8_t)(uart->huart.perh->RBR & 0xFF);
  408. }
  409. }
  410. return ch;
  411. }
  412. static const struct rt_uart_ops es32f0x_uart_ops =
  413. {
  414. es32f0x_configure,
  415. es32f0x_control,
  416. es32f0x_putc,
  417. es32f0x_getc,
  418. };
  419. int rt_hw_uart_init(void)
  420. {
  421. #if (defined(BSP_USING_UART0)||defined(BSP_USING_UART1)||defined(BSP_USING_UART2)||defined(BSP_USING_UART3))
  422. struct es32_uart *uart;
  423. #endif
  424. #if (defined(BSP_USING_USART0)||defined(BSP_USING_USART1))
  425. struct es32_usart *usart;
  426. #endif
  427. #ifdef BSP_USING_UART0
  428. uart = &uart0;
  429. serial0.ops = &es32f0x_uart_ops;
  430. serial0.config = (struct serial_configure)ES_UART0_CONFIG;
  431. /* register UART0 device */
  432. rt_hw_serial_register(&serial0, ES_DEVICE_NAME_UART0,
  433. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  434. uart);
  435. #endif /* BSP_USING_UART0 */
  436. #ifdef BSP_USING_UART1
  437. uart = &uart1;
  438. serial1.ops = &es32f0x_uart_ops;
  439. serial1.config = (struct serial_configure)ES_UART1_CONFIG;
  440. /* register UART1 device */
  441. rt_hw_serial_register(&serial1, ES_DEVICE_NAME_UART1,
  442. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  443. uart);
  444. #endif /* BSP_USING_UART1 */
  445. #ifdef BSP_USING_UART2
  446. uart = &uart2;
  447. serial2.ops = &es32f0x_uart_ops;
  448. serial2.config = (struct serial_configure)ES_UART2_CONFIG;
  449. /* register UART2 device */
  450. rt_hw_serial_register(&serial2, ES_DEVICE_NAME_UART2,
  451. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  452. uart);
  453. #endif /* BSP_USING_UART2 */
  454. #ifdef BSP_USING_UART3
  455. uart = &uart3;
  456. serial3.ops = &es32f0x_uart_ops;
  457. serial3.config = (struct serial_configure)ES_UART3_CONFIG;
  458. /* register UART3 device */
  459. rt_hw_serial_register(&serial3, ES_DEVICE_NAME_UART3,
  460. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  461. uart);
  462. #endif /* BSP_USING_UART3 */
  463. #ifdef BSP_USING_USART0
  464. usart = &usart0;
  465. serial4.ops = &es32f0x_uart_ops;
  466. serial4.config = (struct serial_configure)ES_USART0_CONFIG;
  467. /* register USART0 device */
  468. rt_hw_serial_register(&serial4, ES_DEVICE_NAME_USART0,
  469. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  470. usart);
  471. #endif /* BSP_USING_USART0 */
  472. #ifdef BSP_USING_USART1
  473. usart = &usart1;
  474. serial5.ops = &es32f0x_uart_ops;
  475. serial5.config = (struct serial_configure)ES_USART1_CONFIG;
  476. /* register USART1 device */
  477. rt_hw_serial_register(&serial5, ES_DEVICE_NAME_USART1,
  478. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  479. usart);
  480. #endif /* BSP_USING_USART1 */
  481. return 0;
  482. }
  483. INIT_BOARD_EXPORT(rt_hw_uart_init);
  484. #endif