Web Uart
Tool Introduction
Web Uart
The Web Uart is a web serial tool to send and receive serial data, in which some special customization is made for the ZigBee application of mboard module to configure the ZigBee function of mboard.
Usage Description
Hardware Connection
Connect the module to the PC via the USB to UART converter board. If you use the official base board + module board, since the mboard baseboard comes with the USB to serial chip CP2102, there is only need to download and install the CP2102 driver and then connect to the PC via the USB port. CP2102 driver download link
Official base board:
Open Web Uart
Click "install" to install the webpage app as a native app on your computer/mobile phone, and automatically add desktop shortcuts, users can also fix the app to the taskbar. With offline storage and background synchronization technology, the webpage can be used without internet connection.
Use the software
- Select baudrate, do not change the configuration for the first time using, it is 115200 by default.
- Click "Connect", select the uart port to be communicated.
Abnormality Processing
If you get an abnormality while using it, check the hardware and refresh the page and try again.
ZigBee Device Configuration
A typical ZigBee mesh network is shown as below. When a new device accesses the network, there should be a coordinator device in the network:
Using mboard to build ZigBee network as below:
If using the old version BDT tool to download, it needs to download the following firmware to the local computer. If using Web BDT, the firmware can be download to the chip online.
- Download Mars_B91_ZigBee_C.bin to one module board (coordinator).
- Download Mars_B91_ZigBee_R.bin to other module boards (router).
- Power up the coordinator device, the LED on the module board lights up indicating that other device access is allowed (in 3 minutes).
- Power up the router device, the LED on the router device flashes indicating the the network access is successful.
- After successful networking, broadcast or fixed-point data transmission can be realized by sending data via UART (UART sends one data up to 64 bytes).
The default configuration of firmware is as below.
Interfaces | Function description |
---|---|
TX/RX | UART TX/RX, 8 data bits, 1 stop bit, no parity test, baudrate is 115200 by default |
PC2 | It can be connected to the main control MCU, or the keypad, which needs to be kept unpressed during power-on initialization. For coordinator, click: allow to enter the network for a limited time; double-click: close the network authorization. For rounter, click: broadcast to send its own network address; double-click: broadcast user-defined device ID number; long-press: reset to factory settings. |
PD2,PD1 | Mode Configuration Control IO (can dynamically switch modes during use, switching interval is consistent with the time of long press of the key, the default is two seconds): 00: Broadcast transmitting mode, any data received by uart will be broadcasted through ZigBee protocol, and the device that receives the data will print out the data through uart. 01: Command mode, see later description for function code example. 10: Positioning mode, router collects the positioning data of the mobile module and sends it to coordinator periodically. 11: Moving mode, router periodically broadcasts a custom ID number. |
Description
- When a device broadcasts its own ID number, it broadcasts data with header 5A A5;
- When the device broadcasts its own short address, the broadcast data will have header A5 5A in it;
- When the device broadcasts its own long address, the broadcast data will have the header A5 A5;
- When the setup command answer is turned on (off by default), in COMMAND mode, send the setup-related command command, and the answer returned by the device will have the tail 5A 5A in it.
Factory default settings of the device:
Function | Default setting | Function | Default setting |
---|---|---|---|
UART echo | off | UART baudrate | 115200 |
Command response to the setup command (suffix 5A A5) | Not added | Device ID | 0x00 |
Period for a device to broadcast its own ID | 2 seconds | PWM setting | No |
Short press detection time | 200 miniseconds | Long press detection time | 2 seconds |
Coordinator-limited entry time after a keystroke | 180 seconds | / | / |
Trigger IO on network entry | GPIO_PA5 | Trigger level of the trigger IO at the time of network entry | Low voltage level |
Trigger IO at crash | GPIO_PA6 | Trigger level of the trigger IO at the time of crash | Low voltage level |
The system structure of transparent transimission mode is as below.
Hint
The following is the description for other mdoes. You can ignore the following contents if you use ZigBee transparent transmission mode only.
Configuration of ZigBee devices in command mode
The array of gpio_group and pwm_group are defined as below:
const gpio_pin_e gpio_group[] = {
GPIO_PD3,GPIO_PE0,GPIO_PA5,GPIO_PA6,
GPIO_PA7,GPIO_PB2,GPIO_PB3,GPIO_PB4,
GPIO_PB5
};
const pwm_pin_e pwm_group[][2] = {
{PWM_PWM0_PB4,0},
{PWM_PWM1_PB5,1},
{PWM_PWM3_N_PD3,3},
{PWM_PWM3_PE0,3}
};
When configured as command mode, the command format is as follows (return is the data returned by UART after turning off the echo and command response, and after executing the command; except for the function code 0x00, the length of other control commands is fixed; the set value can be saved when power failure):
Code | Example | Example description | Return | Support |
---|---|---|---|---|
0x00 | 00 5C 29 11 22 33 | Send data 11 22 33 to device with network address 0x5c29 | NULL | ALL |
0x01 | 01 | Turn on echo function | NULL | ALL |
0x02 | 02 | Turn off echo function | NULL | ALL |
0x03 | 03 00 25 80 | Set UART baud rate to 0x2580 (9600, effective after reset) | NULL | ALL |
0x04 | 04 B4 | Set the limited entry time to 0xB4 seconds | NULL | Coordinator |
0x05 | 05 10 | Set the device ID number to 0x10 | NULL | Router |
0x06 | 06 05 | Set the period of broadcast ID to 0x05 seconds | NULL | Router |
0x07 | 07 28 | Set short press detection time to 0x28 milliseconds (effective after reset) | NULL | ALL |
0x08 | 08 01 F4 | Set short press detection time to 0x01F4 milliseconds (effective after reset) | NULL | ALL |
0x09 | 09 | Broadcasting its own short address | NULL | ALL |
0x0A | 0A | Broadcasting its own long address | NULL | ALL |
0x0B | 0B | Broadcasting custom ID number | NULL | Router |
0x0C | 0C 00 01 | Set pin gpio_group[0x00] as 0x01 high level | NULL | ALL |
0x0D | 0D 01 | Read voltage level of pin gpio_group[0x01] | 01(high level) | ALL |
0x0E | 0E 02 00 | Set pin gpio_group[0x02] to 0x00 (low) level when the device is (allowed) on the network | NULL | ALL |
0x0F | 0F 03 00 | Set pin gpio_group[0x03] to 0x00 (low) level when the device is crashed | NULL | ALL |
0x10 | 10 00 00 00 27 10 32 | Set pin pwm_group[0x00] to PWM function with a frequency of 0x00002710HZ and a duty cycle of 0x32% | NULL | ALL |
0x11 | 11 | Turn off all set PWM function | NULL | ALL |
0x12 | 12 | Restart the last configured PWM function | NULL | ALL |
0x13 | 13 | Return 0x01 indicating that it is in correct mode | 01 | ALL |
0x14 | 14 | Display custom ID number | 10 | Router |
0x15 | 15 | Display the period of broadcasting custom ID | 05 | Router |
0x16 | 16 | Display the limited network access time (in seconds) | B4 | Coordinator |
0x17 | 17 | Return 0x01 indicating that echo function is turned on | 00 | ALL |
0x18 | 18 | Display PAN_ID | 06 10 | ALL |
0x19 | 19 | Dispaly long address of coordinator | A4 C1 38 D1 97 0B 25 3C | Router |
0x1A | 1A | Dispaly long address of this device | A4 C1 38 8E D6 90 F7 E0 | ALL |
0x1B | 1B | Dispaly short address of this device | 44 20 | ALL |
0x1C | 1C | Display type of this device 00:D_COORDINATOR 01:ROUTER 02:END_DEV | 01 | ALL |
0x1D | 1D | Display the short press time (2B) and long press time (1B) of the key in seconds. | C8 07 D0 | ALL |
0x1E | 1E | Display the trigger IO number (gpio_group) and trigger level at the time of network entry and crash | 02 00 03 00 | ALL |
0x1F | 1F | Display PWM pin number (pwm_group, 1B, ff means unselected) period (4B) and duty cycle (1B) | 00 00 00 27 10 32 | ALL |
0x20 | 20 | Display all data | Detailed as below. | ALL |
0x21 | 21 | Command response to open setup command (suffix 5A A5) | 5A 5A | ALL |
0x22 | 22 | Command response to close setup command (suffix 5A A5)) | NULL | ALL |
0x30 | 30 | Set parameters to default values | 5A 5A | ALL |
0x31 | 31 | Reset the chip | NULL | ALL |
0x32 | 32 | Restore factory settings | NULL | ALL |
In command mode, after turning off the echo function and command response, send the command 0x20 and the UART will return all the setting-related data.
- example: 01 01 C2 00 06 10 A4 C1 38 D1 97 0B 25 3C A4 C1 38 8E D6 90 F7 E0 44 20 14 00 00 02 C8 07 D0 02 00 03 00 00 00 00 27 10 32 00 01
- segment description:
Description | Length | Example | Example description |
---|---|---|---|
Current mode | 1 | 01 | The current is command mode. |
Baudrate after reset | 3 | 01 C2 00 | Baudrate after reset is 0x01c200. |
PAN ID | 2 | 06 10 | PAN ID为0x0610 |
coordinator long address | 8 | A4 C1 38 D1 97 0B 25 3C | 0xA4C138D1970B253C |
Itself long address | 8 | A4 C1 38 8E D6 90 F7 E0 | 0XA4C1388ED690F7E0 |
Itself short address | 2 | 44 20 | 0X4420 |
Limited entry time | 1 | 14 | Limited entry time is 0x14 seconds |
Echo function | 1 | 00 | 00:echo disabled 01:echo enabled |
Device ID | 1 | 00 | Device ID is 0x00 |
ID broadcast period | 1 | 02 | Period of broadcast device ID is 0x02 seconds. |
Short press detection time | 1 | C8 | Short press detection time is 0xC8 miniseconds. |
Long press detection time | 2 | 07 D0 | Long press detection time is 0x07D0 miniseconds. |
Trigger IO number (gpio_group) and trigger level when entering the network | 1+1 | 02 00 | Entry network trigger IO is gpio_group[2], trigger level is 0x00 |
Trigger IO number (gpio_group) and trigger level in case of crash | 1+1 | 03 00 | Crash trigger IO is gpio_group[3], trigger level is 0x00 |
PWM pin pwm_group number (ff means unselected) period and duty cycle | 1+4+1 | 00 00 00 27 10 32 | Set pwm_group[0x00] pin to PWM function Frequency 0x00002710Hz, duty cycle 0x32% |
Command response to the setup command (suffix 5A A5) | 1 | 00 | 00: not added;01: added |
Device type | 1 | 01 | 00:D_COORDINATOR 01:ROUTER 02:END_DEV |
Load app bin with BootLoader program
Note
- BootLoader and tools do not detect the loaded bin file.
- Because the compatibility between web uart and cp2102 driver is not good enough, you need to plug and unplug the device every time when connecting to the uart via web.
- The main control chip of Mars_B91 is TLSR9218A, the size of Flash is 1MB, the app bin is stored from the 0x8000 address of Flash, so its size can't be larger than 992KB.
Steps of Use
- Download the boot bin to the flash 0 address via a download tool (e.g. BDT or WEB BDT).
- Press SW1 and then power up/reset the board, it will enter the receive app bin mode. If SW1 is not found to be pressed at the first time after the chip is reset, it will take the command from address 0x8000 to execute (no matter if there is no correct bin here).
- After entering the receive app bin mode, it will not detect the state of the key again, the LED on the core board will blink once every 1 second.
- Install the driver of USB to TTL UART chip, Mars_B91 base board uses CP2102.
- Open Telink Web UART web tool, configure the baud rate to 500000 and connect the UART.
- Click the Update Firmware button, select the bin to be loaded, the button will show the loading progress. If the program is loaded successfully, the button will show Success at the end, and the MCU will jump to the 0x8000 address for execution.
- Test app bin.
BOOT Program Flow Introduction
- In the boot program, a 100KB UART receive buffer is allocated. The web tool segments the app bin file into 100KB packets for transmission. After sending each 100KB of data, the tool does not wait for a response from the MCU but instead waits for a fixed period of time. During this time, the MCU writes the data into Flash (the write time should be shorter than the waiting time) before the next data packet is sent. Finally, a 5-byte checksum packet is sent, containing the CRC32 value calculated by the web tool. The MCU compares this value with its own calculated CRC32. If they match, it jumps to address 0x8000 to fetch and execute instructions; if they don't match, it clears the state and waits to receive the app bin again. The MCU will then send a confirmation packet back to the web tool, including the total received length and CRC value. The web tool compares these with its own calculated values and displays the final status on the page.
- Areas for improvement: (1) After sending each data packet, the tool should wait for the MCU to send a status packet and take actions such as retransmission based on the packet data. (2) The baud rate used to send the app bin should ideally be adjustable: Initialize the MCU UART baud rate at 115200. During the firmware update via the web tool, the tool should use the 115200 baud rate to send the baud rate that will be used for sending the firmware. The MCU should then change its baud rate before entering the app bin receive mode.