| | |
| | | |
| | | #include "mk_io.h" |
| | | #include "board.h" |
| | | #include "Usart.h" |
| | | extern struct UART_CFG_T test_uart_cfg; |
| | | extern void uart_receive_callback(void *dev, uint32_t err_code); |
| | | extern void (*Usart0ParseDataCallback)(uint8_t); |
| | | extern void Usart0ParseDataHandler(uint8_t data); |
| | | struct UART_CFG_T test_uart_cfg = |
| | | { |
| | | .parity = UART_PARITY_NONE, |
| | | .stop = UART_STOP_BITS_1, |
| | | .data = UART_DATA_BITS_8, |
| | | .flow = UART_FLOW_CONTROL_NONE, |
| | | .rx_level = UART_RXFIFO_CHAR_1, |
| | | .tx_level = UART_TXFIFO_EMPTY, |
| | | .baud = BAUD_115200, |
| | | .dma_en = true, |
| | | .int_rx = false, |
| | | .int_tx = false, |
| | | }; |
| | | |
| | | void boot_deinit(void) |
| | | { |
| | | //将boot中串口返回普通gpio |
| | | // UART0 TX/RX |
| | | io_pin_mux_set(IO_PIN_5, IO_FUNC0); |
| | | io_pin_mux_set(IO_PIN_6, IO_FUNC0); |
| | | // UART1 RX/TX |
| | | io_pin_mux_set(IO_PIN_10, IO_FUNC0); |
| | | io_pin_mux_set(IO_PIN_9, IO_FUNC0); |
| | | uart_close(UART_ID1);//解绑原来串口1 |
| | | uart_close(UART_ID0);//解绑原来串口0 |
| | | } |
| | | |
| | | void board_pins_config(void) |
| | | { |
| | | #if UCI_INTF_PORT == 1 |
| | | |
| | | // SPI0 MOSI/MISO/CLK/CS |
| | | io_pin_mux_set(IO_PIN_11, IO_FUNC2); |
| | | io_pin_mux_set(IO_PIN_12, IO_FUNC2); |
| | | io_pin_mux_set(IO_PIN_13, IO_FUNC2); |
| | | io_pin_mux_set(IO_PIN_14, IO_FUNC2); |
| | | |
| | | // setting for idle and sleep mode |
| | | io_pull_set(IO_PIN_11, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | io_pull_set(IO_PIN_12, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | io_pull_set(IO_PIN_13, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | io_pull_set(IO_PIN_14, IO_PULL_UP, IO_PULL_UP_LEVEL2); |
| | | |
| | | #if UCI_CHECK_SE_EN |
| | | // SPI1 MISO/MOSI/CLK/CS |
| | | io_pin_mux_set(IO_PIN_5, IO_FUNC2); |
| | | io_pin_mux_set(IO_PIN_6, IO_FUNC2); |
| | | io_pin_mux_set(IO_PIN_7, IO_FUNC2); |
| | | io_pin_mux_set(IO_PIN_8, IO_FUNC0); |
| | | #endif |
| | | |
| | | #else |
| | | |
| | | //增加SPI初始化 |
| | | //SPI0/MOSI/MISO/CLK/CS |
| | | io_pin_mux_set(LORA_CS, IO_FUNC0); |
| | | io_pin_mux_set(LORA_MOSI, IO_FUNC2); |
| | | io_pin_mux_set(LORA_MISO, IO_FUNC2); |
| | | io_pin_mux_set(LORA_CLK, IO_FUNC2); |
| | | io_pin_mux_set(LORA_IRQ, IO_FUNC0); |
| | | io_pin_mux_set(LORA_NRST, IO_FUNC0); |
| | | //初始化lora引脚 |
| | | // UART0 TX/RX |
| | | io_pin_mux_set(IO_PIN_5, IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_6, IO_FUNC4); |
| | | |
| | | // // UART1 RX/TX已修改复用引脚为ADC留出空间调试串口 |
| | | io_pin_mux_set(IO_PIN_10, IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_9, IO_FUNC4); |
| | | |
| | | // UART1 RX/TX GPS端口 |
| | | // io_pin_mux_set(IO_PIN_14, IO_FUNC4); |
| | | // io_pin_mux_set(IO_PIN_13, IO_FUNC4); |
| | | // Single ADC, If IO0 is set to negative input, the positive input is Vref, and vice versa |
| | | io_pin_mux_set(IO_PIN_0, IO_FUNC1); |
| | | io_pull_set(IO_PIN_0, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | //5V输入检测,下拉GPIO |
| | | gpio_pin_set_dir(INPUT_5V_Pin , GPIO_DIR_IN, 0); |
| | | io_pull_set(INPUT_5V_Pin , IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | } |
| | | void Uart1GpsRecDebugSend(void) |
| | | { |
| | | io_pin_mux_set(IO_PIN_14, IO_FUNC0);//把原先uart变为普通GPIO |
| | | io_pin_mux_set(IO_PIN_13, IO_FUNC0); |
| | | uart_close(UART_ID1);//解绑原来串口1 |
| | | // UART1 RX/TX已修改复用引脚为ADC留出空间调试串口 |
| | | // io_pin_mux_set(IO_PIN_10,IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_14,IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_9,IO_FUNC4); |
| | | // uart_open(UART_ID1, &test_uart_cfg); |
| | | board_debug_console_open(TRACE_PORT_UART1); |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);//开启dma |
| | | } |
| | | void uart1_change_from_gps_to_debug(void) |
| | | { |
| | | io_pin_mux_set(IO_PIN_14, IO_FUNC0);//把原先uart变为普通GPIO |
| | | io_pin_mux_set(IO_PIN_13, IO_FUNC0); |
| | | uart_close(UART_ID1);//解绑原来串口1 |
| | | // UART1 RX/TX已修改复用引脚为ADC留出空间调试串口 |
| | | io_pin_mux_set(IO_PIN_10,IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_9,IO_FUNC4); |
| | | // uart_open(UART_ID1, &test_uart_cfg); |
| | | board_debug_console_open(TRACE_PORT_UART1); |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);//开启dma |
| | | |
| | | } |
| | | void uart1_change_from_debug_to_gps(void) |
| | | { |
| | | io_pin_mux_set(IO_PIN_10,IO_FUNC0);//把原先uart变为普通GPIO |
| | | io_pin_mux_set(IO_PIN_9,IO_FUNC0); |
| | | uart_close(UART_ID1);//解绑原来串口1 |
| | | // UART1 RX/TX GPS端口 |
| | | #endif |
| | | |
| | | #if TRACE_EN |
| | | #if BOARD_TYPE == MK8000_EVK |
| | | |
| | | // UART1 RX/TX |
| | | io_pin_mux_set(IO_PIN_14, IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_13, IO_FUNC4); |
| | | uart_open(UART_ID1, &test_uart_cfg); |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);//开启dma |
| | | |
| | | io_pin_mux_set(IO_PIN_1, IO_FUNC4); |
| | | |
| | | // //PA引脚开启 |
| | | io_pin_mux_set(IO_PIN_9, IO_FUNC6); |
| | | io_pin_mux_set(IO_PIN_10, IO_FUNC6); |
| | | |
| | | #elif BOARD_TYPE == MK8000_DK |
| | | |
| | | // UART1 TX/RX |
| | | io_pin_mux_set(IO_PIN_9, IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_10, IO_FUNC4); |
| | | |
| | | #endif |
| | | #endif |
| | | } |
| | | void Board_LORA_NVIC_Init(GPIO_IRQ_HANDLER_T irq_handler) //LORA 中断配置 |
| | | { |
| | | // io_pin_mux_set(_4G_USART_RX_Pin,IO_FUNC0);//把原先io 变为普通GPIO |
| | | gpio_pin_set_dir(LORA_IRQ , GPIO_DIR_IN, 0); |
| | | io_pull_set(LORA_IRQ, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | gpio_enable_irq(LORA_IRQ, GPIO_IRQ_TYPE_RISING_EDGE, irq_handler); |
| | | } |
| | | void uart0_Init_normal(void) |
| | | { |
| | | Usart0ParseDataCallback = Usart0ParseDataHandler;//确认与蓝牙串口0处理回调 |
| | | uart_open(UART_ID0, &test_uart_cfg); |
| | | |
| | | } |