diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig b/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig index 47adcc7b0f0e5ac9b1a91541ad402be18a4a5d3a..01752dad9428b7b74af918f80b0d1db0549c2c86 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig @@ -2,12 +2,6 @@ menu "Hardware Drivers Config" menu "Onboard Peripheral Drivers" - config BSP_USING_USB_TO_USART - bool "Enable USB TO USART (uart0)" - select BSP_USING_UART - select BSP_USING_UART0 - default y - menuconfig BSP_USING_AUDIO bool "Enable Audio Device" select RT_USING_AUDIO @@ -34,11 +28,22 @@ menu "Onboard Peripheral Drivers" endmenu menu "On-chip Peripheral Drivers" - - menuconfig BSP_USING_UART0 - bool "Enable UART0" - select RT_USING_SERIAL - default y + menuconfig BSP_USING_UART + bool "Enable UART" + if BSP_USING_UART + config BSP_USING_UART0 + bool "Enable UART0" + select RT_USING_SERIAL + default y + config BSP_USING_UART1 + bool "Enable UART1" + select RT_USING_SERIAL + default n + config BSP_USING_UART2 + bool "Enable UART2" + select RT_USING_SERIAL + default n + endif config BSP_USING_SDIO bool "Enable SDIO" diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/ab32vg1_hal_msp.c b/bsp/bluetrum/ab32vg1-ab-prougen/board/ab32vg1_hal_msp.c index 4ab3893a4c3a00ac4793c60e65c02de45b03d8a4..ebda0be6ef8d1438c1866650760a4426df68931e 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/ab32vg1_hal_msp.c +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/ab32vg1_hal_msp.c @@ -35,6 +35,22 @@ void hal_uart_mspinit(struct uart_handle *huart) gpio_init.af_con = GPIO_AFEN | GPIO_AFCON0 | UT1RXMAP_AF; hal_gpio_init(GPIOA_BASE, &gpio_init); /* Interrupt */ + } else if (huart->instance == UART2_BASE) { + gpio_init.pin = GPIO_PIN_2; + gpio_init.dir = GPIO_DIR_OUTPUT; + gpio_init.de = GPIO_DIGITAL; + gpio_init.alternate = GPIO_AF_MAP_Gx(UT2TXMAP_AF, GPIO_AF_G2); + gpio_init.af_con = GPIO_AFEN | GPIO_AFCON1 | UT2TXMAP_AF; + hal_gpio_init(GPIOB_BASE, &gpio_init); + + gpio_init.pin = GPIO_PIN_1; + gpio_init.pull = GPIO_PULLUP; + gpio_init.dir = GPIO_DIR_INPUT; + gpio_init.de = GPIO_DIGITAL; + gpio_init.alternate = GPIO_AF_MAP_Gx(UT2RXMAP_AF, GPIO_AF_G2); + gpio_init.af_con = GPIO_AFEN | GPIO_AFCON1 | UT2RXMAP_AF; + hal_gpio_init(GPIOB_BASE, &gpio_init); + /* Interrupt */ } } diff --git a/bsp/bluetrum/libraries/hal_drivers/drv_usart.c b/bsp/bluetrum/libraries/hal_drivers/drv_usart.c index 8758058c85488c44d46096b906228a83e68b1b3d..4b790830fcdefa31aac75ee7ff00a01358e53a3e 100644 --- a/bsp/bluetrum/libraries/hal_drivers/drv_usart.c +++ b/bsp/bluetrum/libraries/hal_drivers/drv_usart.c @@ -21,20 +21,40 @@ enum { +#ifdef BSP_USING_UART0 UART0_INDEX, +#endif +#ifdef BSP_USING_UART1 UART1_INDEX, +#endif +#ifdef BSP_USING_UART2 + UART2_INDEX, +#endif }; static struct ab32_uart_config uart_config[] = { +#ifdef BSP_USING_UART0 { .name = "uart0", .instance = UART0_BASE, + .mode = UART_MODE_TX_RX | UART_MODE_1LINE, }, +#endif +#ifdef BSP_USING_UART1 { .name = "uart1", .instance = UART1_BASE, + .mode = UART_MODE_TX_RX, + }, +#endif +#ifdef BSP_USING_UART2 + { + .name = "uart2", + .instance = UART2_BASE, + .mode = UART_MODE_TX_RX, } +#endif }; static struct ab32_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] = {0}; @@ -48,7 +68,7 @@ static rt_err_t ab32_configure(struct rt_serial_device *serial, struct serial_co uart = rt_container_of(serial, struct ab32_uart, serial); uart->handle.instance = uart->config->instance; uart->handle.init.baud = cfg->baud_rate; - uart->handle.init.mode = UART_MODE_TX_RX; + uart->handle.init.mode = uart->config->mode; switch (cfg->data_bits) { @@ -152,14 +172,24 @@ static void uart_isr(int vector, void *param) { rt_interrupt_enter(); +#ifdef BSP_USING_UART0 if(hal_uart_getflag(UART0_BASE, UART_FLAG_RXPND)) //RX one byte finish { rt_hw_serial_isr(&(uart_obj[UART0_INDEX].serial), RT_SERIAL_EVENT_RX_IND); } - // if(hal_uart_getflag(UART1_BASE, UART_FLAG_RXPND)) //RX one byte finish - // { - // rt_hw_serial_isr(&(uart_obj[UART1_INDEX].serial), RT_SERIAL_EVENT_RX_IND); - // } +#endif +#ifdef BSP_USING_UART1 + if(hal_uart_getflag(UART1_BASE, UART_FLAG_RXPND)) //RX one byte finish + { + rt_hw_serial_isr(&(uart_obj[UART1_INDEX].serial), RT_SERIAL_EVENT_RX_IND); + } +#endif +#ifdef BSP_USING_UART2 + if(hal_uart_getflag(UART2_BASE, UART_FLAG_RXPND)) //RX one byte finish + { + rt_hw_serial_isr(&(uart_obj[UART2_INDEX].serial), RT_SERIAL_EVENT_RX_IND); + } +#endif rt_interrupt_leave(); } diff --git a/bsp/bluetrum/libraries/hal_drivers/drv_usart.h b/bsp/bluetrum/libraries/hal_drivers/drv_usart.h index 1c48cf77d2a68470d68aaca967ce344b7cfd6f30..53635d95008bceb2137e02f370c57580fde5db4a 100644 --- a/bsp/bluetrum/libraries/hal_drivers/drv_usart.h +++ b/bsp/bluetrum/libraries/hal_drivers/drv_usart.h @@ -20,6 +20,8 @@ struct ab32_uart_config { const char *name; hal_sfr_t instance; + uint8_t mode; + uint8_t reserve[3]; // struct dma_config *dma_rx; // struct dma_config *dma_tx; }; diff --git a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_gpio_ex.h b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_gpio_ex.h index 9f41619be801c97158a9d81aa9b20a308355df51..f99a34780e6c34c440accd539263f86d97f70dc3 100644 --- a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_gpio_ex.h +++ b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_gpio_ex.h @@ -33,8 +33,15 @@ * G1: tx:PA7 rx:PA6 * G2: tx:PA4 rx:PA3 * G3: tx:PF2 rx:map to tx + * + * UART2: + * G1: tx:PE3 rx:PE2 + * G2: tx:PB2 rx:PB1 */ +#define UT2RXMAP_AF (8u) +#define UT2TXMAP_AF (4u) + #define UT1RXMAP_AF (28u) #define UT1TXMAP_AF (24u) #define HSUTRXMAP_AF (20u) diff --git a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_uart.h b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_uart.h index c2eed3c51e1fc55f0d2880106fc97c8b877d0b76..aae175c22f4bf5f163cb6c9abebe98db30c13d36 100644 --- a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_uart.h +++ b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_uart.h @@ -78,6 +78,7 @@ struct uart_handle */ #define UART_MODE_TX (0x00u) /*!< TX mode */ #define UART_MODE_TX_RX (0x01u) /*!< RX and TX mode */ +#define UART_MODE_1LINE (0x02u) /*!< oneline mode */ /** * @} diff --git a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_uart.c b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_uart.c index 3d3ecc3fe029c11c714cd4d553aea52df19bad34..7f1f9cd6ffd28b5877c5eb8916069495d8643938 100644 --- a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_uart.c +++ b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_uart.c @@ -27,10 +27,51 @@ void hal_uart_setbaud(hal_sfr_t uartx, uint32_t baud) uint32_t baud_cfg; uartx[UARTxCON] |= UART_CLK_SRC1; - baud_cfg = (26000000/2)/baud; //1.5M + baud_cfg = (26000000/2)/baud; uartx[UARTxBAUD] = (baud_cfg << 16) | baud_cfg; } +/** + * @brief Set the UART misc paramter. + * + * @param uartx This parameter can be UARTxN where x can be (0.2). + * @param param uart config paramter pointer. + */ +void hal_uart_setparam(hal_sfr_t uartx, struct uart_init *param) +{ + switch (param->word_len) + { + case UART_WORDLENGTH_8B: + uartx[UARTxCON] &= ~UART_BIT9_ENABLE; + break; + case UART_WORDLENGTH_9B: + uartx[UARTxCON] |= UART_BIT9_ENABLE; + break; + default: + break; + } + + switch (param->stop_bits) + { + case UART_STOPBITS_1: + uartx[UARTxCON] &= ~UART_SB2_ENABLE; + break; + case UART_STOPBITS_2: + uartx[UARTxCON] |= UART_SB2_ENABLE; + break; + default: + break; + } + + if (param->mode & UART_MODE_1LINE) + { + uartx[UARTxCON] |= UART_1LINE_ENABLE; + } + else + { + uartx[UARTxCON] &= ~UART_1LINE_ENABLE; + } +} /** * @brief Initialize the UART mode. * @@ -157,11 +198,15 @@ void uart_config_all(struct uart_handle *huart) hal_rcu_periph_clk_enable(RCU_UART0); } else if (huart->instance == UART1_BASE) { hal_rcu_periph_clk_enable(RCU_UART1); + } else if (huart->instance == UART2_BASE) { + hal_rcu_periph_clk_enable(RCU_UART2); } else { return; /* Not support! */ } + hal_uart_deinit(huart->instance); hal_uart_setbaud(huart->instance, huart->init.baud); + hal_uart_setparam(huart->instance, &huart->init); if (huart->init.mode != UART_MODE_TX) { hal_uart_control(huart->instance, UART_RX_ENABLE, HAL_ENABLE);