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
- You have set up the development environment and installed the required dependency packages. For more information, see Prepare the development environment.
- The Bluetooth Mesh SDK for AliOS Things is available. For more information, see Obtaining the SDK.
Prepare the development environment
- 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.
- 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 - 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 - 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 sconsNote 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
- 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.
- Upload the downloaded ZIP package to your development environment and decompress the package.
- 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 1aos 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 - 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
- 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.
- 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.
- Click Connect.
The following log appears in the Log area.
******************************* Current port: COM3 Current baudrate: 115200 Current stopBits: 1 Current parity: No Serial opened!! ******************************* - Choose , and double-click the blank area (marked as ③ in the figure) to upload the file to be flashed.
- 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.
- 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>>: - 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! - 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!
Flash the device certificate
- 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.
- Open the SecureCRT serial debugging tool, choose , 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 . The path to Device Manager may vary based on your operating system. Use the path that is applicable to your computer.
- Click Connect.
- (Optional) Run the AT+MESHMAC? command to view the device's MAC address.
# +MESHMAC: 28:xx:xx:xx:xx:b2 OK - Run the AT+FACTYTEST command to enter factory test mode.
The following result is returned.
# OK DUT Start - 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