#include "user_uart.h" #include "driver_dma.h" static UART_HandleTypeDef Uart1_handle; static UART_HandleTypeDef Uart0_handle; uint8_t TxBuffer8[256]; uint8_t RxBuffer8[256]; /********************************************************************* * @fn uart0_isr_ram * * @brief UART0 interruption, when uart0 FIFO received charaters, this ISR will be called * * * @param None * * * @return None */ __attribute__((section("ram_code"))) void uart1_isr(void) { uint32_t isr_id; volatile struct_UART_t * const uart_reg_ram = (volatile struct_UART_t *)UART1_BASE; isr_id = uart_reg_ram->FCR_IID.IID; if(((isr_id & 0x04) == 0x04) || ((isr_id & 0x0c) == 0x0c)) //receciver data available or character timeout indication { while(uart_reg_ram->LSR.LSR_BIT.DR) { uint8_t data = (uint8_t)uart_reg_ram->DATA_DLL.DATA; //app_at_recv_c(data); //printf("%c",data); uart_transmit(&Uart1_handle, &data, 1); } } else if((isr_id & 0x06) == 0x06)//receiver line status interrupt { uint32_t tmp = uart_reg_ram->LSR.LSR_DWORD; uart_reg_ram->FCR_IID.FCR = isr_id; uart_reg_ram->IER_DLH.IER.ELSI = 0; } //printf("uart1_isr\r\n"); } __attribute__((section("ram_code"))) void uart0_isr(void) { uint32_t isr_id; volatile struct_UART_t * const uart_reg_ram = (volatile struct_UART_t *)UART0_BASE; isr_id = uart_reg_ram->FCR_IID.IID; if(((isr_id & 0x04) == 0x04) || ((isr_id & 0x0c) == 0x0c)) //receciver data available or character timeout indication { while(uart_reg_ram->LSR.LSR_BIT.DR) { uint8_t data = (uint8_t)uart_reg_ram->DATA_DLL.DATA; uart_transmit(&Uart0_handle, &data, 1); } } else if((isr_id & 0x06) == 0x06) { uint32_t tmp = uart_reg_ram->LSR.LSR_DWORD; uart_reg_ram->FCR_IID.FCR = isr_id; uart_reg_ram->IER_DLH.IER.ELSI = 0; } } /********************************************************************* * @fn at_init * * @brief Initializate gAT_env elements and assign UART0 pins * * * @param None * * * @return None */ void user_uart_init(void) { uint32_t i; // system_set_port_pull(GPIO_PA2,GPIO_PULL_UP,true); // system_set_port_mux(GPIO_PORT_A, GPIO_BIT_2, PORTA2_FUNC_UART1_RXD); // system_set_port_mux(GPIO_PORT_A, GPIO_BIT_3, PORTA3_FUNC_UART1_TXD); GPIO_InitTypeDef GPIO_Handle; __SYSTEM_GPIO_CLK_ENABLE(); __SYSTEM_UART1_CLK_ENABLE(); __SYSTEM_UART0_CLK_ENABLE(); #if 0 GPIO_Handle.Pin = GPIO_PIN_2|GPIO_PIN_3; GPIO_Handle.Mode = GPIO_MODE_AF_PP; GPIO_Handle.Pull = GPIO_PULLUP; GPIO_Handle.Alternate = GPIO_FUNCTION_5;//串口用 gpio_init(GPIO_A, &GPIO_Handle); #endif GPIO_Handle.Pin = GPIO_PIN_0|GPIO_PIN_1; GPIO_Handle.Mode = GPIO_MODE_AF_PP; GPIO_Handle.Pull = GPIO_PULLUP; GPIO_Handle.Alternate = GPIO_FUNCTION_5;//串口用 gpio_init(GPIO_A, &GPIO_Handle); GPIO_Handle.Pin = GPIO_PIN_6|GPIO_PIN_7; GPIO_Handle.Mode = GPIO_MODE_AF_PP; GPIO_Handle.Pull = GPIO_PULLUP; GPIO_Handle.Alternate = GPIO_FUNCTION_5;//串口用 gpio_init(GPIO_C, &GPIO_Handle); for (i = 0; i < 256; i++) { TxBuffer8[i] = i; } Uart1_handle.UARTx = Uart1; Uart1_handle.Init.BaudRate = 115200; Uart1_handle.Init.DataLength = UART_DATA_LENGTH_8BIT; Uart1_handle.Init.StopBits = UART_STOPBITS_1; Uart1_handle.Init.Parity = UART_PARITY_NONE; Uart1_handle.Init.FIFO_Mode = UART_FIFO_ENABLE;// UART_FIFO_ENABLE ; uart_init_ex(&Uart1_handle); //uart1_isr_int(&Uart1_handle); NVIC_EnableIRQ(UART1_IRQn); NVIC_SetPriority(UART1_IRQn, 6); //uart_transmit_IT(&Uart1_handle, TxBuffer8, 256); uart_transmit(&Uart1_handle, TxBuffer8, 256); //uart_receive_IT(&Uart1_handle, RxBuffer8, 1); __UART_INT_RX_ENABLE(Uart1_handle.UARTx); for (i = 0; i < 256; i++) { TxBuffer8[i] = i; } Uart1_handle.UARTx = Uart0; Uart1_handle.Init.BaudRate = 115200; Uart1_handle.Init.DataLength = UART_DATA_LENGTH_8BIT; Uart1_handle.Init.StopBits = UART_STOPBITS_1; Uart1_handle.Init.Parity = UART_PARITY_NONE; Uart1_handle.Init.FIFO_Mode = UART_FIFO_ENABLE;// UART_FIFO_ENABLE ; uart_init_ex(&Uart0_handle); //uart1_isr_int(&Uart1_handle); NVIC_EnableIRQ(UART0_IRQn); NVIC_SetPriority(UART0_IRQn, 6); //uart_transmit_IT(&Uart1_handle, TxBuffer8, 256); uart_transmit(&Uart0_handle, TxBuffer8, 256); //uart_receive_IT(&Uart1_handle, RxBuffer8, 1); __UART_INT_RX_ENABLE(Uart0_handle.UARTx); }