UART Works in DLPS Mode
This sample code guide is designed to help users easily and comprehensively understand UART sample.
This sample demonstrates how UART works in DLPS mode.
This sample code demonstrates the communication between chip and PC terminal.
It realizes the function that transmits and receives data through UART and wakes up the system by UART after entering DLPS mode.
System will enter DLPS mode automatically while it is in idle state.
When some data is sent to chip, UART_RX_PIN
will be pulled down to low level and wake up system to rebuild communication between PC terminal and chip.
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.dlps_uart_demo();
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 ###\r\n. Observe that the string appears on the PC terminal program.
After the data transmission is completed, the system is in idle state, it will enter DLPS mode.
Use PC terminal program to send data to chip, which is used to wake up system and then data can be transmitted normally.
Use PC terminal program to send data to chip, chip will send the data same as the data received back to PC terminal.
After the data transmission is completed, the system is in idle state and will re-enter DLPS mode.
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\uart\dlps\dlps_uart_demo.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_ENABLE, PAD_OUT_HIGH); 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, UART2_TX); Pinmux_Config(UART_RX_PIN, UART2_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
RX Trigger Level
Call
UART_INTConfig()
to enable received data available interruptUART_INT_RD_AVA
and RX idle timeout interruptUART_INT_IDLE
.Call
NVIC_Init()
to enable NVIC of UART.
DLPS Mode Initialization
Call
power_check_cb_register()
to register inquiry callback function to DLPS Framework. This function will be called each time before entering DLPS to decide whether DLPS is allowed to enter. DLPS will be disallowed if any inquiry callback function returns false.Call
io_dlps_register()
to initialize IO store/restore and do not need to worry about which IO peripheral requires specific handling.Call
power_stage_cb_register()
to register callbacks to DLPS enter stage. Functionuart_dlps_enter
will be executed while entering from DLPS:Call
Pad_ControlSelectValue()
to switchUART_TX_PIN
to software mode.Call
Pad_ControlSelectValue()
to switchUART_RX_PIN
to software mode.Call
System_WakeUpPinEnable()
to to enable the wake-up function ofUART_RX_PIN
.
Call
power_stage_cb_register()
to register callbacks to DLPS exit stage. Functionuart_dlps_exit
will be executed while exiting from DLPS:Call
Pad_ControlSelectValue()
to switchUART_TX_PIN
to PINMUX mode.Call
Pad_ControlSelectValue()
to switchUART_RX_PIN
to PINMUX mode.Call
System_WakeUpInterruptValue()
to check wake up pin interrupt status. If it is found that the system is woken up byUART_RX_PIN
, setallowedSystemEnterDlps
to false to not allow the system to enter DLPS mode.
Call
bt_power_mode_set()
to set Bluetooth MAC deep sleep mode.Call
power_mode_set()
to switch the system to DLPS mode.
Functional Implementation
Send Data
Transmit ### Welcome to use RealTek Bumblebee ###\r\n to the PC terminal:
Call
UART_SendData()
to continuously write data to the TX FIFO. The number of data continuously written to the TX FIFO must not exceed the size of the TX FIFO.Call
UART_GetFlagState()
to checkUART_FLAG_THR_EMPTY
flag state and wait TX FIFO to be empty.Repeat the above process to send all data to TX FIFO in batches.
Interrupt Handle
Use the PC program to send the first data to the chip. This data is used to wake up the system, and then the data can be transmitted normally. Then use the PC program to send the second data to the chip, the chip will trigger UART interrupts. UART interrupt handle flow is shown in the following figure.

UART Interrupt Handle Flow
Call
UART_GetIID()
to get the interrupt ID.If the RX FIFO level reached the RX trigger level set in
UART_InitTypeDef::rxTriggerLevel
,UART_INT_ID_RX_LEVEL_REACH
interrupt first is triggered first:Call
UART_GetRxFIFOLen()
to get the data length in RX FIFO.Call
UART_ReceiveData()
to receive data from RX FIFO.
There’s at least 1 UART data in the RX FIFO but no character has been input to the RX FIFO or read from it for the last time of 4 characters.
UART_INT_ID_RX_TMEOUT
interrupt is triggered:Call
UART_GetRxFIFOLen()
to get the data length in RX FIFO.Call
UART_ReceiveData()
to receive data from RX FIFO.
If No data is received in RX idle timeout time after the RX FIFO is empty (data is received before), the
UART_FLAG_RX_IDLE
interrupt is triggered:Call
UART_GetFlagState()
to checkUART_FLAG_RX_IDLE
interrupt flag state.Call
UART_INTConfig()
to disableUART_INT_IDLE
interrupt.Send a message to the task, and after the task receives the message, it will return the same data received plus string \r\n to PC terminal.
set
allowedSystemEnterDlps
to true to allow the system to enter DLPS mode.Call
UART_INTConfig()
to enableUART_INT_IDLE
interrupt.