Community Blog AliOS Things Developer Kit UART Operation Demo

AliOS Things Developer Kit UART Operation Demo

This brief tutorial shows you how to use the AliOS Things Developer Kit development board to produce outputs using the UART of the backplane J903.

This demo shows you how to use AliOS Things Developer Kit development board to produce outputs through the Universal Asynchronous Receiver/Transmitter (UART) of the backboard J903. We will be introducing the relevant code and implementation effects in this article.

Developer Kit Hardware

Developer Kit is hardware development board based on AliOS, with a variety of peripherals. The hardware is equipped with Audio Codec, eight sensors, 8-bits digital camera, LCD display, sixes LEDs, PCIe module, USB OTG FS, and Wi-Fi module. Because the software is embedded with the AliOS system, the local data uploading to the Ali-cloud can be realized through Wi-Fi. The Developer Kit provides a convenient way for developers to learn about the development environment in combination with practical applications.

To learn more about the Developer Kit, visit https://github.com/alibaba/AliOS-Things/wiki/AliOS-Things-Developer-Kit-Brief

Development Environment

  1. System: Win10 x 64
  2. IDE: Visual Studio Code
  3. Development board: Developer Kit
  4. Others: Breadboard line and USB-to-TTL serial port line


To follow this tutorial, you should be able to have the following:

  1. Ability to compile the AliOS-Things developer branch and to apply and write it under examples.
  2. Ability to read the helloworld application under the developer branch.

Introduction to UART

MCU has six UARTs


UART1 is used inside the system, UART3 communicates with Wi-Fi module BK7231, and UART2 is connected to Zigbee/LoRa on the J903 backboard


Source Code

  1. In the system, the six UARTs are defined in boarddeveloperkithalhal_uart_stm32l4.h
  2. The UART that communicates with BK7231 is defined in boarddeveloperkitaosatcmd_config_platform.h. If you change the AT_UART_PORT value of 3, Wi-Fi cannot work properly (give it a try).
  3. The read and write reference of UART is in exampledeviceIOdeviceIO.c
#define UART_DATA_BYTES 14

uart_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());

    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);

  1. init_uart defines the port to operate UART and initializes the relevant information. port = 2 means operating the PORT_UART2 defined in hal_uart_stm32l4.h;
  2. UART_DATA_BYTES defines the length of the read and returns the output synchronously after reading.


The USB-to-TTL line is connected to J903 RX/PA3 and TX/PA2. The following figure shows that this UART is UART2


The serial port tool opens the serial port and sends Hello world! rn, a total of 14 bytes, and the serial port returns the sending content. If only Hello is sent, the result is returned in 14 bytes, which is specifically "HelloHelloHell".

Learn more about the UART demo by visiting the Developer Kit UART demo GitHub page.

0 0 0
Share on


24 posts | 5 followers

You may also like



24 posts | 5 followers

Related Products

  • IoT Platform

    Provides secure and reliable communication between devices and the IoT Platform which allows you to manage a large number of devices on a single IoT Platform.

    Learn More
  • IoT Solution

    A cloud solution for smart technology providers to quickly build stable, cost-efficient, and reliable ubiquitous platforms

    Learn More
  • Global Internet Access Solution

    Migrate your Internet Data Center’s (IDC) Internet gateway to the cloud securely through Alibaba Cloud’s high-quality Internet bandwidth and premium Mainland China route.

    Learn More