1. Hardware Environment
This document introduces basic information related to the chip platform during TuyaOS development. For more information about TuyaOS, please refer to the TuyaOS Developer Forum.
1.1 Chip Manual
Obtain the chip manual from the path: hardware\nRF52832\chip_manual\nRF52832_PS_v1.7.pdf
.
Alternatively, visit the Nordic Semiconductor official website to get the latest version.
1.2 Development Board
Obtain the development board from the Tuya Developer Platform. The material code for the development board is 2.03.99.00045
. This development board reuses the hardware of the Tuya low-power Bluetooth Dongle.
Image Description: An image shows a blue development board with various components, connectors, buttons, and silkscreen labels. Key components visible include the Nordic Semiconductor chip, USB connector, power switch, and several user buttons.
Schematics: Download link available.
Alternatively, you can use Nordic's official development board and refer to the official documentation for the latest usage instructions.
1.3 Hardware Peripherals
UART
This platform only supports one UART0 serial port, used for authorization and host communication testing.
Peripheral | Function | Pin |
---|---|---|
UART 0 | TX | P0.06 |
UART 0 | RX | P0.08 |
SPI
Since peripherals with the same register address can only use one, SPI supports SPI1 and SPI2.
Peripheral | Function | Pin |
---|---|---|
SPI1 | CS | P0.05 |
SPI1 | CLK | P0.04 |
SPI1 | SDI | P0.02 |
SPI1 | SDO | P0.03 |
SPI2 | CS | P0.28 |
SPI2 | CLK | P0.29 |
SPI2 | SDI | P0.30 |
SPI2 | SDO | P0.31 |
The TWI master shares registers and other resources with other peripherals that have the same ID as the TWI master. Therefore, you must disable all peripherals that have the same ID as the TWI master before the TWI master can be configured and used.
IIC
Since peripherals with the same register address can only use one, IIC supports IIC0.
Peripheral | Function | Pin |
---|---|---|
IIC0 | SCL | P0.16 |
IIC0 | SDA | P0.15 |
PWM
Channel | Pin |
---|---|
0 | P0.28 |
1 | P0.29 |
2 | P0.30 |
3 | P0.31 |
ADC
Channel | Pin |
---|---|
0 | P0.02 |
1 | P0.03 |
2 | P0.04 |
3 | P0.05 |
4 | P0.28 |
5 | P0.29 |
6 | P0.30 |
7 | P0.31 |
Buttons
Button Pin: P0.14
Short press wakes up the device.
Long press for 3s resets the device to factory settings.
Startup time detection pin: P0.05
2. Software Environment
The software environment involves installing Keil and the nRF52832 dependency environment.
2.1 Keil
- Visit the Arm Keil official website to install the Keil software. Use default configurations for all installation steps. The
mdk528a.exe
version is recommended. - If prompted to install drivers during installation, select 'Install'.
- When opening Keil, if a device pack installation prompt appears, close it manually.
- After installing Keil, add the path of the
UV4.exe
file to the environment variables. For example:
Variable: TUYAOS_COMPILE_TOOL
Value: C:\Keil_v5\UV4
The result is shown in the figure below.
Image Description: A table showing Environment Variables with columns for 'Variable' and 'Value'. Entries include 'Path', 'TEMP', 'TMP', and 'TUYAOS_COMPILE_TOOL' with example paths.
2.2 nRF Command Line Tools
The nRF command line tools include J-Link drivers and various command line tools developed by Nordic. These include J-Link drivers, nrfjprog
, nrfutil
, and mergehex
.
Taking Windows as an example, the steps to install the nRF command line tools are as follows:
- Go to the Nordic official website to download the nRF command line tools.
- Select your chip platform and the required tool version. For example, download the win32 version to get an executable file like
nRF5x-Command-Line-Tools_9_8_1_Installer.exe
. - Double-click the
.exe
file to install. Accept the license terms and conditions. During installation, do not change the default options; proceed with the default installation.
Image Description: A screenshot shows the installation wizard for Microsoft Visual C++ 2015-2019 Redistributable (x64). It displays the license terms and a checkbox 'I accept the license terms and conditions (A)' which needs to be checked before clicking 'Install'.
Image Description: A screenshot shows the nRF-Command-Line-Tools Setup wizard. It displays the End-User License Agreement with a checkbox 'I accept the terms in the License Agreement' which needs to be checked before clicking 'Next'.
If the following interface appears, you must select 'select all'.
2.3 ARM CMSIS
- Click to download ARM CMSIS.
- Install according to the prompts.
2.4 Device Family Pack
- Click to download the Device family pack.
- Install according to the prompts.
Warning: Do not let Keil automatically download the Device Family Pack, as this may lead to compilation failures.
2.5 J-Link
- Go to the Segger official website to download J-Link.
- Select the appropriate version (e.g., V6.88c for testing) and install according to the prompts.
3. Development Software
3.1 Enable Scan Function
In tkl_bluetooth.c
:
#define TKL_BLUETOOTH_SUPPORT_SCAN (1)
3.2 Calculate Flash and RAM Usage
1. Disable test function:
#define TUYA_SDK_TEST 0
2. Disable Tuya Log:
#define ENABLE_LOG 0
#define BOARD_ENABLE_LOG 0
3. Disable original factory Log:
List of log options: NRF_LOG_BACKEND_RTT_ENABLED
, NRF_LOG_BACKEND_UART_ENABLED
, NRF_LOG_ENABLED
, NRF_LOG_STR_FORMATTER_TIMESTAMP_FORMAT_ENABLED
.
4. Disable scan function:
#define TKL_BLUETOOTH_SUPPORT_SCAN (0)
5. After performing a full re-compilation, open the .map
file. The RAM and Flash usage is as follows:
Total RO Size (Code + RO Data): 62260 (60.80kB)
Total RW Size (RW Data + ZI Data): 37408 (36.53kB)
Total ROM Size (Code + RO Data + RW Data): 62416 (60.95kB)
Note: Approximately 10KB of RW space is actually placed in Flash, so the actual RAM usage is about 26KB.
If the scan function is enabled:
#define TKL_BLUETOOTH_SUPPORT_SCAN (1)
After performing a full re-compilation, open the .map
file. The RAM and Flash usage is as follows:
Total RO Size (Code + RO Data): 63628 (62.14kB)
Total RW Size (RW Data + ZI Data): 37520 (36.64kB)
Total ROM Size (Code + RO Data + RW Data): 63792 (62.30kB)
4. Firmware Burning
4.1 Connection Description
Using J-Link in SW mode, the connection method is as follows:
J-Link | Device |
---|---|
VCC | VCC |
GND | GND |
DIO | DIO |
CLK | CLK |
4.2 Firmware Description
Image Description: A file explorer window shows firmware files. Key files include load_softdevice_bootloader_app.bat
, tuyaos_demo_ble_peripheral.bin
(101 KB), tuyaos_demo_ble_peripheral.hex
(284 KB), and tuyaos_demo_ble_peripheral_merge.hex
(717 KB). Labels indicate tuyaos_demo_ble_peripheral.bin
is 'OTA固件' (OTA firmware) and tuyaos_demo_ble_peripheral_merge.hex
is '生产固件' (Production firmware).
4.3 Burning Method One
1. In Visual Studio Code, right-click on apps\tuyaos_demo_ble_peripheral
in the left directory pane and select 'Show in File Explorer'.
Image Description: A context menu in Visual Studio Code shows options like 'New File', 'New Folder', 'Show in File Explorer' (with shortcut Shift+Alt+R), 'Open in Integrated Terminal', etc.
2. Navigate to the tuyaos_demo_ble_peripheral\_build\hex
directory.
3. Double-click the load_softdevice_bootloader_app.bat
script to burn the Tuya firmware.
Note: This is a full firmware burn. Authorization is required after burning.
4.4 Burning Method Two
Download using Keil's 'Download' button (only application layer can be downloaded).
4.5 Burning Method Three
Use J-Flash for burning. You need to learn the J-Flash burning process yourself.
4.6 Burning Method Four
Use the desktop version of nRF Connect for burning. Please refer to the nRF Connect Desktop User Guide.
5. Platform Features
5.1 Startup Time
Test Method: Measure the time difference of voltage level changes on the VCC pin and the startup time detection pin using a logic analyzer.
Detection Pin: Peripherals > Startup time detection pin.
Image Description: A logic analyzer display shows four channels. Channel 0 (VCC) shows a stable voltage. Channel 1 (GPIO) shows a signal transition. The display includes measurements like 'Talling' (time to fall), 'Trising' (time to rise), 'Tmean' (average time), and 'Tand' (time delay), with specific values like 4.916576 ms for 'Tmean'.
5.2 Flash Partition
Flash Partition Table:
Address | Size | Partition Name |
---|---|---|
0x7F000 | 4K | bootloader settings |
0x7E000 | 4K | MBR settings |
0x7C000 | 8K | unknown |
0x78000 | 16K | bootloader |
0x74000 | 16K | tuya_ble_sdk_info |
0x66000 | 56K | unused |
0x46000 | 128K | OTA |
0x26000 | 128K | application |
0x01000 | 148K | softdevice |
0x00000 | 4K | MBR |
512K | Total |
Partition Adjustment Method:
Modify the following macros in the original project to adjust the default Flash partitions:
// Flash
#ifndef BOARD_FLASH_BULK_DATA_START_ADDR
#define BOARD_FLASH_BULK_DATA_START_ADDR (0x70000)
#endif
#ifndef BOARD_FLASH_TUYA_INFO_START_ADDR
#define BOARD_FLASH_TUYA_INFO_START_ADDR (0x74000)
#endif
// #ifndef BOARD_FLASH_OTA_INFO_ADDR
// #define BOARD_FLASH_OTA_INFO_ADDR (0x7C000)
// #endif
#ifndef BOARD_FLASH_OTA_START_ADDR
#define BOARD_FLASH_OTA_START_ADDR (0x46000)
#endif
#ifndef BOARD_FLASH_OTA_END_ADDR
#define BOARD_FLASH_OTA_END_ADDR (0x66000)
#endif
#ifndef BOARD_FLASH_OTA_SIZE
#define BOARD_FLASH_OTA_SIZE (BOARD_FLASH_OTA_END_ADDR - BOARD_FLASH_OTA_START_ADDR)
#endif
// #ifndef BOARD_FLASH_MAC_START_ADDR
// #define BOARD_FLASH_MAC_START_ADDR (0)
// #endif
5.3 Power Consumption
TuyaOS BLE SDK enables DCDC mode, which can achieve lower power consumption.
When Tuya BLE SDK does not enable DCDC mode, the power consumption is higher.
The power consumption tested here is the average power consumption during a typical 1s broadcast.
Image Description: A power consumption graph shows a waveform over time. The Y-axis represents current (from 100 nA to 100 mA) and power (from 100 pW to 53.80 μW). The graph displays spikes and dips, with specific readings noted such as '16.13 μA 1.50 μWh' and '100.51 s 53.80 μW'.