Gateway MCU Development

Last Updated on : 2024-07-22 07:49:00download

This topic describes how to develop a Tuya-enabled gateway with the MCU SDK. In this process, you need to complete product creation, hardware and software development, as well as functionality debugging.

Create a product

Log in to the Tuya Developer Platform and select the desired gateway product. For more information about product creation, see Create Products.

Gateway MCU Development

Currently, there are two solutions available: Wi-Fi (CR3L module) and Wi-Fi and Ethernet combo (THP23-X-M module).

  • The CR3L solution supports the downstream protocols including Bluetooth SIG mesh, Bluetooth, and others.

    Gateway MCU Development
  • The THP23-X-M solution supports the downstream protocols including Bluetooth SIG mesh, Zigbee, Bluetooth, and others.

    Gateway MCU Development

After you create a product, you can configure the function, panel, module, and firmware based on your requirements. Then, download the MCU SDK accordingly.

Create a sub-device

When developing a product, choose a solution other than No-Code Development. If your product has access to the protocol shown in the figure below, you are developing a sub-device.

Gateway MCU Development

Debug hardware

Select hardware

The platform recommends modules based on your solution.

CR3L module solution:

Gateway MCU Development

THP23-X-M module solution:

Gateway MCU Development

After you select the module and firmware, you can purchase modules online. Your hardware engineer can proceed with the board layout design. See the following documents:

Verify network connection

Before starting coding, you can use Tuya’s Module Debugging Assistant in MCU simulation mode to get familiar with the communication between the MCU and the CR3L module.

Gateway MCU Development

In the MCU simulation mode, the Module Debugging Assistant simulates the MCU and responds to commands from the module. After you pair the module with the mobile app, you can test whether the module can receive and send data point (DP) data correctly. The following steps describe how to pair the module and use the Module Debugging Assistant.

  1. Set up the peripheral circuit according to the schematic for a minimum system.

  2. Open the Module Debugging Assistant and import the debugging file. Choose Wi-Fi Gateway Protocol and MCU Simulation.

  3. Connect the module to your computer by using a USB to TTL converter. Set the Serial Port and Baud Rate. Click Open and then Start Debugging to start the data communication.

    If the module does not send data upon powering on, check whether the peripheral circuit of the module works as expected.

  4. Click RESET to put the module in pairing mode. The module supports two pairing modes: Bluetooth and AP mode. Pair the module with the mobile app as instructed by the guide.

    Gateway MCU Development

Develop software

Refer to the protocol documentation in the development document to understand how data is exchanged between the MCU and the module on the Module Debugging Assistant.

The protocol consists of the basic protocol and the function protocol.

  • The basic protocol is product-neutral and shared by the modules. It consists of commands for module initialization and extended functions. For more information, see MCU Integration Protocol.
  • The function protocol works to report and send commands based on the basic protocol and specifies the DP data format.

Tuya provides two options to implement the communication between your MCU and Tuya’s module.

Option 1: Interface with the protocol yourself

If your MCU does not have sufficient resources or porting SDK is not feasible, you can interface with the serial protocol yourself. For more information, see MCU Integration Protocol.

Option 2: Port the MCU SDK

  • If your MCU has sufficient resources, we recommend you port the MCU SDK for efficiency purposes. The MCU SDK is written in C language. You can directly import it to your project. The requirements for MCU resources:
    • 4 KB flash memory.
    • About 100 bytes of RAM are required, depending on the data length of the data point (DP). If you enable OTA updates, it must be greater than 260 bytes.
    • 9-level nested function.
  • If your MCU does not have sufficient resources, you can refer to the functions in the SDK for interfacing with Tuya’s protocol.

For more information, see MCU SDK Porting.

Debug functions

After you port the MCU SDK, you can use the module simulation mode in the Module Debugging Assistant to verify the code. In the module simulation mode, the Module Debugging Assistant automatically sends the initial data to the MCU to check whether the communication works properly. An error message will be returned if any issue occurs. After initialization, you can test different functions.

The module simulation mode only verifies the communication between the MCU and the module and does not provide real networking capability. After finishing the test, you can connect the MCU to the actual module and test pairing functionality and specific features.

Gateway MCU Development Gateway MCU Development

Debugging tools:

  • Device logs: Visit the Tuya Developer Platform and choose Product > Device Logs. Retrieve the backend log by device ID.

  • Technical ticket: Tuya provides online technical support. If the documentation cannot resolve your questions, you can submit a ticket to request technical support.