AliOS Things Developer Kit UART Operation Demo

Developer Kit Hardware

Development Environment


Introduction to UART

Source Code

#define UART_DATA_BYTES 14uart_dev_t opt_uart;
char readbuf[UART_DATA_BYTES] = {0};
static void init_uart(void)
opt_uart.port = 2;
opt_uart.config.baud_rate = 115200;
opt_uart.config.data_width = DATA_WIDTH_8BIT;
opt_uart.config.flow_control = FLOW_CONTROL_DISABLED;
opt_uart.config.mode = MODE_TX_RX;
opt_uart.config.parity = NO_PARITY;
opt_uart.config.stop_bits = STOP_BITS_1;
static void app_delayed_action(void *arg)
uint32_t recBytes = 0;
int ret = -1;
LOG("Uart opertion demo %s:%d %s\r\n", __func__, __LINE__, aos_task_name()); init_uart();

LOG("Uart init finished %s:%d %s\r\n", __func__, __LINE__, aos_task_name());
/* receive a message and sent out through the uart */
ret = hal_uart_recv_II(&opt_uart, readbuf, UART_DATA_BYTES, &recBytes, 10);
LOG("Uart receive finished %s:%d %s\r\n", __func__, __LINE__, aos_task_name()); if((ret == 0) && (recBytes > 0))
LOG("Read something %s:%d %s\r\n", __func__, __LINE__, aos_task_name());
hal_uart_send(&opt_uart, readbuf, recBytes, 10);
} else {
LOG("Read none %s:%d %s\r\n", __func__, __LINE__, aos_task_name());
aos_post_delayed_action(500, app_delayed_action, NULL);




Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store