summaryrefslogtreecommitdiff
path: root/bsp/bluetrum
diff options
context:
space:
mode:
authoriysheng <[email protected]>2021-03-18 13:49:01 +0800
committeriysheng <[email protected]>2021-03-18 13:49:01 +0800
commita05801911eeeb16d636acd77b94a59f5a2580243 (patch)
treea9c310c2810b37293a8dc0fea23633213849e232 /bsp/bluetrum
parent6de81af04cbef6825f1d0d9921bacc59df2c7189 (diff)
[bsp][ab32vg1] Add support with uart2 and optimize serial port configuration with env tool
Diffstat (limited to 'bsp/bluetrum')
-rw-r--r--bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig27
-rw-r--r--bsp/bluetrum/ab32vg1-ab-prougen/board/ab32vg1_hal_msp.c16
-rw-r--r--bsp/bluetrum/libraries/hal_drivers/drv_usart.c40
-rw-r--r--bsp/bluetrum/libraries/hal_drivers/drv_usart.h2
-rw-r--r--bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_gpio_ex.h7
-rw-r--r--bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_uart.h1
-rw-r--r--bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_uart.c47
7 files changed, 123 insertions, 17 deletions
diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig b/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig
index 47adcc7b0f..01752dad94 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 4ab3893a4c..ebda0be6ef 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 8758058c85..4b790830fc 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 1c48cf77d2..53635d9500 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 9f41619be8..f99a34780e 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 c2eed3c51e..aae175c22f 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 3d3ecc3fe0..7f1f9cd6ff 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,11 +27,52 @@ 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.
*
* @param huart UART handle.
@@ -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);