MCU Development for Gateway

Last Updated on : 2022-11-24 09:20:00download

This article is mainly an overview of the MCU development process of Tuya Gateway general solution.

Development Process

The development process mainly includes: product creation-hardware debugging-software development-functional debugging.

Create Product

Log in to the IoT Workbench and create a product. Select the product category according to the actual needs, and select Wi-Fi for the networking method. After the product is created, you can select the functions, panels, modules, and firmware according to the actual needs of the product and then download it to the MCU development kit.

The specific steps to create a product can refer to: Product Creation-IoT Platform Operation

MCU Development for Gateway

Sub-device creation: When creating a product, select a non-exempt development plan. If you can choose the protocol shown below, it is the sub-device plan.
MCU Development for Gateway

Hardware debugging

Hardware selection

When creating a product selection module, the platform will recommend some common module models. At present, the gateway MCU access solution can only be provided by Wi-Fi gateway module-WRG1.

MCU Development for Gateway

After selecting the module and firmware, you can purchase module samples online.

The hardware engineer can enter the drawing board stage, and the related materials for hardware development can be viewed in the document center:

Data manual link: Wi-Fi Gateway Module-WRG1 Datasheet

Module minimum schematic: Wi-Fi Gateway Module-WRG1 minimal system schematic diagram
PCB data: Common module package library

Distribution Network Verification

After getting the module, users do n’t need to worry about writing code first. It is recommended to use the module debugging assistant (MCU simulation mode) provided by Tuya to connect with the WRG1 module first. When verifying the module, users can be familiar with The protocol interaction process will greatly improve the efficiency of development and debugging later.

MCU Development for Gateway

Tuya module debugging assistant-MCU simulation mode. The assistant will simulate the MCU to automatically reply the module’s correct protocol data. After the module is networked with a mobile phone, the DP data can be reported and issued. The following briefly introduces the main steps of the assistant and module distribution network operation. Before using it, you need to know the instructions of Tuya Module Debugging Assistant in advance. Users who use the assistant for the first time can read in advance: Module Debugging Assistant Instruction

step1. According to the minimum system schematic diagram, set up the module peripheral circuit, and simple test can directly fly the wire.

step2. Set device capabilities,open the Tuya module debugging assistant in the development kit and import the debugging file. Protocol selection Wi-Fi gateway protocol, MCU simulation mode.

step3. Connect the serial port of the module to the computer through the USB to TTL tool. The assistant selects the corresponding serial port and baud rate. Open the serial port and click Start. You will see that the module and the host computer automatically perform the initialization process protocol interaction.

Note: If no data is sent after power on, please check if the peripheral circuit of the module is correct.

step4. Click Reset Module, the module enters the network distribution mode. The module supports two modes of network configuration: EZ and AP mode (the difference between EZ mode and AP mode). The reset button will switch the network configuration mode. According to the status prompt, the App performs the corresponding network configuration operation. For the network configuration operation, you can read the instruction of the App. Attach a demo video of the network distribution in two modes: Wi-Fi module network distribution demonstration video.

MCU Development for Gateway

Software Development

In the process of hardware debugging, the user saw that the module and the MCU have a series of serial protocol protocol interaction data. For the understanding of these data, please refer to the protocol document in the development kit.

The agreement is mainly divided into two parts: the basic agreement and the functional agreement. The basic protocol has nothing to do with the product. It is a common protocol of the module, including module initialization instructions and some extended function instructions. The function protocol part is mainly based on the command word of the report of the basic protocol, and has explained the DP data content format in detail.
The complete content of the basic protocol, the document center is kept updated in real time, you can click the link to view: Tuya Cloud Gateway Access Protocol

There are two ways for MCU to interface with Tuya module: transplant the MCU SDK or connect the protocol by yourself.

  • Self-docking agreement

    When MCU resources are limited or the MCU SDK is not suitable for porting, customers can choose to connect the serial port protocol by themselves. The detailed explanation of serial port protocol can refer to: Tuya Cloud Gateway Access Protocol Analysis

  • Porting MCU SDK

    If the MCU resources are sufficient, it is generally recommended that users directly port the MCU SDK for efficient and convenient development. The MCU SDK in the development kit is a C-based protocol application code provided by Tuya, which can be directly added to the MCU project. The MCU SDK requires MCU hardware resources: 4K bytes of Flash; RAM is related to the length of the DP point data, about 100 bytes (if OTA function is required, it must be greater than 260 bytes); the number of function nesting levels is 9 levels. If users with insufficient resources can connect the protocol by themselves, the functions in the SDK package can still be used as a reference.

MCU SDK porting tutorial, please refer to: Tuya Wi-Fi Gateway MCU_SDK Instructions

Functional debugging

After porting the MCU SDK code development, you can use the Tuya module debugging assistant-module simulation mode to verify the correctness of the MCU code. The usage method is similar to the MCU simulation mode. In the simulation module mode, the assistant will automatically send the initialization data stream to verify that the MCU response is correct and give corresponding prompts for the incorrect data. After the initial interaction is passed, you can manually click to test other extended functions.

Note: Tuya module debugging assistant module simulation mode, without networking function, only used to verify the correctness of MCU serial protocol transmission and reception. After the test is completed, the MCU can be connected to the actual module and network.

MCU Development for Gateway

MCU Development for Gateway

Debugging common tool links:

Background log query entry: IoT Workbench-Operation Center. You can query related device background log data based on the device ID.

Tuya Online Support Portal: Tuya provides online support services. If the problem documents cannot be answered, you can Ask questions directly online, and the professional and technical team will answer your questions.