UART
1 Function Overview
UART (Universal Asynchronous Receiver and Transmitter) is a universal asynchronous receiver/transmitter used to implement full-duplex or half-duplex data exchange between different devices.the BK7258 has three UARTs, with UART0 currently being exclusively used by the CP side (for log output, AP side is prohibited from using it). The AP side only supports the use of UART1 and UART2.
UART-Related Theoretical Introduction: UART_driver
Note
1.UART0 is exclusively reserved for CP side (for log output use, AP side is prohibited from using it);
2.AP side is only allowed to use UART1 and UART2, and no other UARTs.
2 code path
- demo path:
cp\components\bk_cli\cli_uart.c
- source code path:
cp\middleware\driver\uart\uart_driver.c
4 UART PIN Descriptions
UART0 corresponds to uart0 on the development board, with the following hardware pins:
UART0 function
group 0
UART0_TX
GPIO11
UART0_RX
GPIO10
5 UART demo configuration
The supported commands for “demo” are as follows:
Command
Param
Description
uart_driver {init|deinit}
{init|deinit}:
init/deinit the uart resoure common
uart {id} init [baud_rate] [data_bits]
[parity] [stop_bits] [flow_ctrl]
[src_clk] [rx_dma_en] [tx_dma_en]
{id}:uart id,value range 1 ~ 2
init uart and set working parameters
{baud_rate}:uart baud rate
{data_bits}: support value range 5 ~ 8 bits
{parity}: support parity mode
{stop_bits}:the stop bits len
{flow_ctrl}: not support flow ctrl
{src_clk}:uart working clock source
{rx_dma_en}: enable uart rx dma
{tx_dma_en}: enable uart tx dma
uart_config
{id}
baud_rate {value}
{value}:support baud rate
set uart working parameters
data_bits {value}
{value}:support value range 5 ~ 8 bits
parity {value}
{value}:support parity none、 odd、 even
stop_bits {value}
{value}:support 1 or 2 bits
flow_ctrl {value}
{value}:support 0 or 1
rx_thresh {value}
{value}:support value range 0 ~ 255 bits
tx_thresh {value}
{value}:support value range 0 ~ 255 bits
rx_timeout{value}
{value}:support value range 0 ~ 3 bits
uart_int {id} {enable|disable|reg} {tx|rx}
{id}:uart id,value range 1 ~ 2
enable|disable uart tx|rx interrupt and register uart tx|rx handler
{enable|disable}:enable|disable tx|rx interrupt
{tx|rx}: register tx|rx interrupt handler
uart {id} {read|write}
{length}
{id}:uart id,value range 1 ~ 2
read specified length of data through uart
{read|write}: read|write operation
{length}: length to be read|write
Note
-1.The UART module’s clock source is 26M Hz, and the baud rate is derived from this 26M Hz clock source.;
-2.The calculation method is “divisor = (clock source value / baud rate) - 1”. The software then sets the divisor value to the UART register.;
-3.For example: If we want to set the baud rate to 115200, the divisor value is calculated as follows: (26000000 / 115200) - 1 = 224. The software sets 224 as the value for the UART register. Therefore, if we want to set a different baud rate, we only need to calculate the divisor value and set it to the UART register. (Note: The divisor value should be an integer type)