bsp_uart_debug.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "include.h"
  2. #include "driver_gpio.h"
  3. #include "driver_uart.h"
  4. #include "bsp_uart_debug.h"
  5. #if BSP_UART_DEBUG_EN
  6. void bsp_uart_debug_init(void)
  7. {
  8. uart_init_typedef uart_init_struct;
  9. gpio_init_typedef gpio_init_structure;
  10. /************************** 时钟使能 ***************************/
  11. clk_gate0_cmd(CLK_GATE0_UART, CLK_EN);
  12. /************************* GPIO初始化 *************************/
  13. gpio_init_structure.gpio_pin = UART_DEBUG_PIN_SEL;
  14. gpio_init_structure.gpio_fen = GPIO_FEN_PER;
  15. gpio_init_structure.gpio_fdir = GPIO_FDIR_MAP;
  16. gpio_init_structure.gpio_mode = GPIO_MODE_DIGITAL;
  17. gpio_init(UART_DEBUG_PORT_SEL, &gpio_init_structure);
  18. /*********************** Crossbar映射 ************************/
  19. gpio_func_mapping_config(UART_DEBUG_PORT_SEL, UART_DEBUG_PIN_SEL, GPIO_CROSSBAR_IN_UARTRX);
  20. gpio_func_mapping_config(UART_DEBUG_PORT_SEL, UART_DEBUG_PIN_SEL, GPIO_CROSSBAR_OUT_UARTTX);
  21. /************************** 使能串口 **************************/
  22. uart_init_struct.baud = UART_DEBUG_BAUD;
  23. uart_init_struct.mode = UART_SEND_RECV_MODE;
  24. uart_init_struct.word_len = UART_WORD_LENGTH_8b;
  25. uart_init_struct.stop_bits = UART_STOP_BIT_1BIT;
  26. uart_init_struct.one_line_enable = UART_ONE_LINE;
  27. uart_init_struct.clock_source = UART_SYSTEM_CLOCK;
  28. uart_init(UART, &uart_init_struct);
  29. uart_cmd(UART, ENABLE);
  30. }
  31. #endif // BSP_UART_DEBUG_EN