Bluetooth Porting Guide

Last Updated on : 2024-04-23 09:41:18download

This topic describes how to port a Bluetooth chip platform to TuyaOS, using nRF52832 as an example.


The process of porting your Bluetooth chip to TuyaOS is shown as follows:

Developer (You)TuyaFile a requestPrepare SDKand test casesProvide SDK and testcasesPort the SDKand self-testProvide the testresultsPerformproductdevelopmentArchive testresultsDeveloper (You)Tuya

Step 1: File a request

If your chip platform is not supported by the TuyaOS development framework, you can file a request for porting to TuyaOS. After your request is approved, you will receive the TuyaOS SDK-based development framework applicable to your desired chip platform. Then, adapt, debug, and verify the TuyaOS kernel APIs on your own. After porting is completed, you can proceed with product development.


Have the following ready prior to porting.

Fill out request

Fill out the porting request using the provided template and send it to your Tuya representative.

Porting request template

Title: Apply for Porting to TuyaOS – Bluetooth

  • Applicant: <Your Tuya IoT Development Platform account>

  • Organization: <Your organization name>

  • Contact: <Your phone number>

  • Reason: <Specify why you want to port to TuyaOS>

  • Development type: <Networked product/gateway/central control product/IPC/Zigbee/Bluetooth/NB-IoT>

  • Remarks: <Specify your special requirements if any>

Chip details:

  • Name: <Chip name, such as nRF52832>

  • Vendor: <Chip vendor, such as Nordic>

  • Model: <Chip model, such as nRF52832>

  • Architecture: <Chip architecture, such as Arm Cortex-M4>

  • Chip type: <Wireless SoC or MCU>

  • Communication type: <This field applies when you select wireless SoC. Options include Ethernet/Wi-Fi/Wi-Fi & Bluetooth LE/Bluetooth/Zigbee/Cellular/NB-IoT>

  • Bit width: <16-bit/32-bit/64-bit>

  • Operating system: <Linux/RTOS/Non-OS>

  • Endianness: <Little-endian/big-endian>

Development environment:

  • Development tool: such as Keil
  • Development tool version: such as v5.28.0.0. You can attach a screenshot.
  • Computer system: such as Windows 10 and later.
  • Instructions for setting up the development environment: step-by-step instructions that should be tested on a different computer. Ensure that your instructions include the specific location and software to install.
  • Step-by-step instructions for building and generating C libraries, as well as an example program. Ensure that your instructions include the required configuration options, potential errors, and their solutions.
  • The purpose of the above two steps: Tuya compiles parts of the Tuya SDK source code into libraries based on the provided instructions and includes these libraries in the delivered SDK. Tuya is unfamiliar with the development environment you use so we need the instructions on generating C libraries to help us to provide the SDK you need. See the instruction template.
  • Zip file: zip your files and name the compressed file as TuyaOS_SDK_company name_chip model, for example, TuyaOS_SDK_xxxx_nRF52832.

Please find attached the TuyaOS_SDK_xxxx_nRF52832 for development environment information and instructions.

Recipient: contact your Tuya representative (account manager or project manager) for the recipient’s email address.

After your request is approved, open Tuya Wind IDE and select the TuyaOS SDK mode and then the development framework, type development kit, and chip platform to download the development framework. For more information, see Environment Setup.

Note: The security-related C library will be compiled into a library file according to your development environment. The development environment information you provide helps us generate the correct library files for your project.

Step 2: Tuya prepares and provides SDK and test cases

Tuya prepares and provides the SDK for porting.

Review your request
Input chip model and
information into system
Generate the security library
Package the SDK
Publish the SDK with an allowlist
  1. Review your request.

  2. Tuya staff inputs your chip model and information into the system.

    Tuya staff generates the library files based on the information you provide in Step 1. Currently, only three core component libraries are included in the Bluetooth LE development kit. .\software\TuyaOS\libs stores the chip platforms imported by Tuya, whereas the chip platform adapted by you is located in .\software\TuyaOS\vendor\nrf52832_ble\sdk\lib.

  3. Generate the security library.

  4. Package files to generate an SDK. Package the library files, source files, and other materials to create an SDK.

  5. The SDK is published on the Tuya Wind IDE and has limited access through an allowlist. For information about how to get the SDK, see Environment Setup.

Step 3: Porting the SDK

Try TuyaOS

Before porting, you can try the chip platforms imported by Tuya to familiarize yourself with how the TuyaOS framework works. This can help you debug and troubleshoot your project later.

Steps to try TuyaOS:

Read the TuyaOS Quick Start and follow the instructions to download the development kit and explore the TuyaOS features.

Three key milestones in the process of porting to TuyaOS:

  1. Put the files in the designated location.

  2. Add the source and header files and the building succeeds.

  3. Implement and test the APIs successfully.

.\software\TuyaOS\vendor stores all the files for porting. Do not modify files and code in other locations.

Port the SDK

Steps to port the SDK:

  1. Open the SDK obtained in Step 2.

  2. Put the chip vendor SDK in .\software\TuyaOS\vendor\xxxx_ble\sdk.

  3. Add all source and library files in the folders shown below to the example project provided by the chip vendor.

    .\software\TuyaOS\apps\tuyaos_demo_ble_peripheral //tuyaos_demo_ble_peripheral The file name may be different
    .\software\TuyaOS\components\……\src //"\software\TuyaOS\components" All subfolders under the folder.
    .\software\TuyaOS\libs // If empty, do not add.
  4. Add the header file directory shown below to the example project provided by the chip vendor.

    .\software\TuyaOS\components\……\include //"\software\TuyaOS\components" All subfolders under the folder.
    .\software\TuyaOS\include //"\software\TuyaOS\include" All subfolders containing header files under the folder.
    .\software\TuyaOS\vendor\nrf52832_ble\sdk\lib //".\software\TuyaOS\vendor\nrf52832_ble\sdk\lib" All subfolders containing header files under the folder.
  5. Alter the code until it is built successfully.

  6. With the header files in .\software\TuyaOS\include\vendor\adapter and the API reference in \software\TuyaOS\vendor\ats2835x_bt_le\tuyaos_doc, implement the TKL APIs stored in the source files as shown below.


    It is not necessary to implement all the APIs. Refer to the chip platforms imported by Tuya and implement the APIs accordingly.

    If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.

Step 4: Compete self-test and provide results

Self-test your implementation using the provided test cases and refer to the chip platforms imported by Tuya. After all implemented features match the imported chip platforms and all test cases are passed, send the test results to your Tuya representative.

If you encounter any issues during testing:

Step 5: Perform product development

After completing the porting and self-test, you can develop a product on your own or provide the SDK to third-party developers for product development.

To help other developers use the chip platform you have imported, it is recommended to document the platform feature descriptions. See Bluetooth LE–nRF52832 for the documentation structure.

Step 6: Tuya archives test results

Tuya archives the test results and your documentation of platform feature descriptions.

Considerations for RTOS chips

Most Bluetooth chips do not support RTOS, so the process above is for non-RTOS chips.

To integrate with a RTOS Bluetooth chip using TuyaOS Bluetooth LE SDK v3.9.0, follow these steps. Click to download the required file.

  1. Replace the folder tuyaos_demo_ble_peripheral in \software\TuyaOS\apps.

  2. Replace tuya_ble_port.c and tuya_ble_main.c in \software\TuyaOS\components\tal_ble_protocol\src.

  3. Add tkl_thread.c and tkl_queue.c in \software\TuyaOS\vendor\xxxx_ble\tuyaos\system, where xxxx_ble is determined by the chip platform to integrate.

  4. Implement the APIs in tkl_thread.c and tkl_queue.c based on your chip platform. The example is the implementation for FR801x.

  5. If the chip’s RAM is insufficient, you can use OS-related APIs to re-implement the APIs in tkl_memory.c. Otherwise, it is not advisable to make any changes.

  6. The remaining steps are the same as those for porting non-RTOS chips. See steps 1 to 6 in the previous section.

Except for fr801x_ble_os, all the chip platforms imported by Tuya are non-RTOS chips. Download the development kit for fr801x_ble_os:

  • Development Mode: TuyaOS OS Development

  • Type Development Kit: Sub-Device Development/Bluetooth Device Development Kit

  • Platform: Wireless SoC/FREQCHIP/Bluetooth/FR8018HA

  • TuyaOS Version: TuyaOS 3.9.4

Before downloading, contact the product manager to have your account added to the allowlist.