UART TX Data in GDMA Mode
This sample code guide is designed to help users easily and comprehensively understand UART sample. This sample demonstrates how UART sends data in GDMA mode. This sample code demonstrates the communication between chip and PC terminal. Chip transmits some data to PC terminal.
Requirements
For hardware requirements, please refer to the Requirements.
In addition, it is necessary to install serial port assistant tools such as PuTTY or UartAssist on the PC terminal.
Wiring
Connect P3_1 (UART TX Pin) to the RX pin of the FT232 and P3_0 (UART RX Pin) to the TX pin of the FT232.
The hardware connection of UART sample code is shown in the figure below.

UART Sample Code Hardware Connection Diagram
Configurations
The following macros can be configured to modify pin definitions.
#define UART_TX_PIN P3_1
#define UART_RX_PIN P3_0
The entry function is as follows, call this function in
main()
to run this sample code. For more details, please refer to the Initialization.uart_tx_gdma();
Building and Downloading
For building and downloading, please refer to the Building and Downloading.
Experimental Verification
Preparation Phase
Start a PC terminal program like PuTTY or UartAssist and connect to the used COM port with the following UART settings:
Baud rate: 115200.
8 data bits.
1 stop bit.
No parity.
No hardware flow control.
Testing Phase
Press the Reset button on the EVB, chip starts with transmitting ### Welcome to use RealTek Bumblebee ###rn. Observe that the string appears on the PC terminal program.
Code Overview
This section introduces the code and process description for initialization and corresponding function implementation in the sample.
Source Code Directory
For project directory, please refer to Source Code Directory.
Source code directory:
sdk\src\sample\io_demo\gdma\uart_tx\uart_tx_gdma.c
.
UART Initialization
The initialization flow for peripherals can refer to Initialization Flow.
UART initialization flow is shown in the following figure.

UART Initialization Flow Chart
Call
Pad_Config()
andPinmux_Config()
to initialize the pin.static void board_uart_init(void) { Pad_Config(UART_TX_PIN, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_DISABLE, PAD_OUT_LOW); Pad_Config(UART_RX_PIN, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_UP, PAD_OUT_DISABLE, PAD_OUT_LOW); Pinmux_Config(UART_TX_PIN, UART0_TX); Pinmux_Config(UART_RX_PIN, UART0_RX); }
Call
RCC_PeriphClockCmd()
to enable the UART clock and function.Initialize the UART peripheral:
Define the
UART_InitTypeDef
typeuartInitStruct
, and callUART_StructInit()
to pre-filluartInitStruct
with default values.Modify the
uartInitStruct
parameters as needed. The UART initialization parameter configuration is shown in the table below.Call
UART_Init()
to initialize the UART peripheral.
UART Initialization Parameters UART Hardware Parameters
Setting in the
uartInitStruct
UART
div
20
ovsr
12
ovsr_adj
0x252
Parity Check
Stop Bit
Data Format
Hardware Flow Control
GDMA Enable
TX Waterlevel
15
TX GDMA Enable
GDMA Initialization
GDMA initialization flow is shown in the following figure.

GDMA Initialization Flow Chart
Call
RCC_PeriphClockCmd()
to enable the GDMA clock and function.Call
GDMA_channel_request
to request an unused GDMA channel.Initialize the GDMA peripheral:
Define the
GDMA_InitTypeDef
typeGDMA_InitStruct
, and callGDMA_StructInit()
to pre-fillGDMA_InitStruct
with default values.Modify the
GDMA_InitStruct
parameters as needed. The GDMA initialization parameter configuration is shown in the table below.Call
GDMA_Init()
to initialize the GDMA peripheral.
GDMA Initialization Parameters GDMA Hardware Parameters
Setting in the
GDMA_InitStruct
VariablesGDMA
Channel Num
UART_TX_DMA_CHANNEL_NUM
Transfer Direction
Buffer Size
strLen
Source Address Increment or Fix
Destination Address Increment or Fix
Source Data Size
Destination Data Size
Source Burst Transaction Length
Destination Burst Transaction Length
Source Address
(uint32_t)(GDMA_SendBuffer)
Destination Address
(uint32_t)(&(UART->RB_THR))
Destination Handshake
Call
NVIC_Init()
to enable NVIC of GDMA.Call
GDMA_INTConfig()
to enable GDMA transfer complete interruptGDMA_INT_Transfer
.Call
GDMA_Cmd()
to enable GDMA.
Functional Implementation
GDMA Interrupt Handle
When GDMA transfer completion to the destination, GDMA_INT_Transfer
interrupt is triggered:
Call
GDMA_ClearINTPendingBit()
to clearGDMA_INT_Transfer
interrupt.