Developer device

更新时间:
复制 MD 格式

The IoT Platform provides a software development kit (SDK) that handles the communication protocols between devices and the platform. Use this SDK to develop firmware that connects your physical devices to the Internet of Things (IoT). This topic describes how to develop and flash device firmware, using the TG7100B development board and the AliOS Things-based Bluetooth Mesh SDK (V1.2.6) as an example.

Prerequisites

Prepare the development environment

  1. Set up the development environment for the SDK.

    Set up the device SDK development environment on a 64-bit Ubuntu system. You can use an editor such as vim to edit code. If you use Windows 10, you can download and install Ubuntu 18.04 LTS from the Microsoft Store. For other operating systems, you must install virtual machine (VM) software. For more information, see the relevant online documentation.

  2. Install the runtime libraries for Ubuntu 16.04 (64-bit).

    Run the following commands in order.

    sudo apt-get update
    sudo apt-get -y install libssl-dev:i386
    sudo apt-get -y install libncurses-dev:i386
    sudo apt-get -y install libreadline-dev:i386
  3. Install the dependency packages for Ubuntu 16.04 (64-bit).

    Run the following commands in order.

    sudo apt-get update
    sudo apt-get -y install git wget make flex bison gperf unzip
    sudo apt-get -y install gcc-multilib
    sudo apt-get -y install libssl-dev
    sudo apt-get -y install libncurses-dev
    sudo apt-get -y install libreadline-dev
    sudo apt-get -y install python python-pip
  4. Install the Python dependency packages.

    Run the following commands in order.

    python -m pip install setuptools
    python -m pip install wheel
    python -m pip install aos-cube
    python -m pip install esptool
    python -m pip install pyserial
    python -m pip install scons
    Note After the installation is complete, run the aos-cube --version command to check the version number of aos-cube. The version number must be 0.5.11 or later.

    If you encounter network issues during installation, you can use a local mirror.

    ### Install or upgrade pip
    python -m pip install --trusted-host=mirrors.aliyun.com -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip
    ### Install third-party packages and aos-cube using pip
    pip install --trusted-host=mirrors.aliyun.com -i https://mirrors.aliyun.com/pypi/simple/   setuptools
    pip install --trusted-host=mirrors.aliyun.com -i https://mirrors.aliyun.com/pypi/simple/   wheel
    pip install --trusted-host=mirrors.aliyun.com -i https://mirrors.aliyun.com/pypi/simple/   aos-cube

Develop the device firmware

  1. Download the device SDK code.
    The Bluetooth Mesh SDK is developed in C. This SDK is currently available only to authorized users. To request permission, see Obtain the SDK.
  2. Upload the downloaded ZIP package to your development environment and decompress the package.
  3. In the SDK root directory, run the compile command.

    This example shows how to compile the `light_ctl` program on the TG7100B development board. Run one of the following commands.

    • ./build.sh bluetooth.light_ctl tg7100b 1
    • aos make bluetooth.light_ctl@tg7100b

    The following output indicates that the compilation is successful.

                            AOS MEMORY MAP
    |=================================================================|
    | MODULE                                  | ROM       | RAM       |
    |=================================================================|
    | newlib_stub                             | 0         | 270       |
    | kv                                      | 0         | 3615      |
    | bt_common                               | 0         | 7705      |
    | crc                                     | 0         | 128       |
    | mcu_tg7100b                             | 0         | 38556     |
    | rhino                                   | 0         | 19885     |
    | vfs                                     | 0         | 860       |
    | libgcc                                  | 0         | 8552      | 
    | ref_impl                                | 0         | 1972      |
    | bt_mesh                                 | 0         | 54456     |
    | bt_host                                 | 0         | 43334     |
    | cli                                     | 0         | 9039      |
    | yloop                                   | 0         | 1205      |
    | board_tg7100b                           | 0         | 965       |
    | libc_nano                               | 0         | 13100     |
    | genie_service                           | 0         | 24533     |
    | auto_component                          | 0         | 2         |
    | driver_bt                               | 0         | 18408     |
    | osal                                    | 0         | 950       |
    | log                                     | 0         | 428       |
    | armv6m                                  | 0         | 336       |
    | light_ctl                               | 0         | 2841      |
    | *fill*                                  | 0         | 938       |
    |=================================================================|
    | TOTAL (bytes)                           | 0         | 252078    |
    |=================================================================|
    [INFO] Create bin files
    sign all partitions with key:def_otp
    ----------------------------------------------------------------
                   bomtb, 0, 0, 0x11002100, 0x00001000, 0x11003100, bomtb
                    FCDS, 0, 0, 0x11004000, 0x00001000, 0x11005000
                    imtb, 0, 0, 0x11005000, 0x00002000, 0x11007000, imtb
                      kv, 0, 0, 0x11007000, 0x00002000, 0x11009000
                    boot, 0, 0, 0x11009000, 0x00005000, 0x1100e000, boot
                  jumptb, 1, 2, 0x1100e000, 0x00001000, 0x1100f000, jumptb
                    prim, 1, 2, 0x1100f000, 0x00012000, 0x11021000, prim
                    misc, 0, 0, 0x11021000, 0x00039000, 0x1105a000
                   xprim, 1, 2, 0x1105a000, 0x00026000, 0x11080000, xprim
       bomtb,       16 bytes
        boot,    17696 bytes
      jumptb,     1024 bytes
        prim,    70996 bytes
       xprim,   140172 bytes
        imtb,     8192 bytes
    ----------------------------------------------------------------
    [out/bluetooth.light_ctl@tg7100b/binary/fota.bin]FULL==>:jumptb,size:1024,[isforce:0]
    [out/bluetooth.light_ctl@tg7100b/binary/fota.bin]FULL==>:prim,size:70996,[isforce:0]
    [out/bluetooth.light_ctl@tg7100b/binary/fota.bin]FULL==>:xprim,size:140172,[isforce:0]
    Build complete
    Making .gdbinit
    build time is 9min 48s
  4. Check the compilation result.
    After the compilation succeeds, the total_image.hexf file is generated in the out/bluetooth.light_ctl@tg7100b/binary directory. This file is the firmware that you need to flash to the device. The fota.bin file is the firmware for over-the-air (OTA) updates.

Flash the firmware

  1. Connect the TG7100B development board to your computer with a USB cable and open the TG71XX Programmer.exe flashing tool.
    If the hardware driver is not installed on your computer, follow the prompts to install it.
  2. Select the UART Setting check box in the upper-right corner and set the parameters for the development board's serial port as shown in the following figure.

    After the driver is installed, the TG71XX Programmer.exe tool automatically detects your serial port number. In this example, the port is COM3.

    设置串口
  3. Click Connect.
    The following log appears in the Log area.
    *******************************
    Current port: COM3
    Current baudrate: 115200
    Current stopBits: 1
    Current parity: No
    Serial opened!!
    *******************************
  4. Choose Flash_writer > HEX, and double-click the blank area (marked as ③ in the figure) to upload the file to be flashed.
    上传烧录文件
  5. On the Single tab in the lower-left corner, select MAC from the TYPE list and configure the MAC address.

    Set the MAC address to the device's DeviceName. For more information, see Add a device.

    配置MAC地址
  6. Confirm that the DIP switch on the TG7100 development board is set to VDD (marked as ① in the figure), and press the reset button (marked as ② in the figure) to reset the hardware.
    开发板图示

    The following log is printed in the Log area.

    UART RX : cmd>>:
  7. At the top of the Flash_writer tab, click Erase to erase the flash memory.

    The following log indicates that the flash is erased.

    Send erase successfully!
    Receive #OK!
    Erase successfully!
  8. At the top of the Flash_writer tab, click Write to flash the firmware.

    The following log indicates that the firmware is flashed.

    ============Write hexf File [10/10]============
    Send cpbin successfully!
    UART RX ASCII: by hex mode:
    Receive image request!
    Send image successful! Waiting to receive checksum...
    Send checksum successfully!
    UART RX ASCII: checksum is: 0x0041c6a4
    #OK>>:
    Receive #OK!
    Write images successfully!
    write address: 0x4000, value: 0xB276A87A
    write address: 0x4004, value: 0x0000FA28
    Write registers successfully!
Note For more information about the TG7100B chip and the TG7100B development board, see TG7100B.

Flash the device certificate

  1. Disconnect the TG71XX Programmer.exe flashing tool, set the DIP switch on the development board to GND, and press the reset button on the board.
  2. Open the SecureCRT serial debugging tool, choose File > Quick Connect, and set the parameters for the development board's serial port as shown in the following figure.
    Note The port number must be the same as the one automatically detected by the TG71XX Programmer.exe tool. You can also determine the port number by right-clicking This PC and choosing Manage > System Tools > Device Manager > Ports (COM & LPT). The path to Device Manager may vary based on your operating system. Use the path that is applicable to your computer.
  3. Click Connect.
  4. (Optional) Run the AT+MESHMAC? command to view the device's MAC address.
    # +MESHMAC: 28:xx:xx:xx:xx:b2
    OK
  5. Run the AT+FACTYTEST command to enter factory test mode.
    The following result is returned.
    # OK
    DUT Start
  6. Run the following command to flash the device certificate.
    AT+TRITUPLE=<product id>,<Device Secret>,<Device Name>           
    Note
    • The product id, Device Secret, and Device Name (MAC address) parameters in the command are obtained from the device certificate that was generated when you added the device.
    • After you enter the command in the serial port tool, add a carriage return (CR) and a line feed (LF).

    The following result is returned.

    55xxx10 aaded522xxxxxxxc88105d10e81d 28xxxxxxxb2
    OK

What to do next

Debug the device connection