Last Updated on : 2024-06-18 08:51:25download
This topic describes the basics of the chip platform used in TuyaOS development. For more information, visit Tuya Developer Forum.
The datasheet can be found in hardware\bk3431q\chip_manual\BK3431Q Datasheet V1.3.pdf
.
GPIO
Two specification options are provided: 32 pins and 40 pins. There are up to 24 GPIO pins that can be configured as input or output. GPIO pins can be reused for another feature. For more information, see 2 Pin Information and 3.1 GPIO in hardware\GR551x\chip_manual\BK3431Q Datasheet V1.3.pdf
.
The table below shows the mapping between pin numbers and pin names.
TUYA_GPIO_NUM definition | Pin |
---|---|
TUYA_GPIO_NUM_0 to TUYA_GPIO_NUM_07 | P00 to P07 |
TUYA_GPIO_NUM_10 to TUYA_GPIO_NUM_17 | P10 to P17 |
TUYA_GPIO_NUM_20 to TUYA_GPIO_NUM_27 | P20 to P27 |
TUYA_GPIO_NUM_30 to TUYA_GPIO_NUM_37 | P30 to P37 |
UART
The BK3431Q platform has two non-configurable UART interfaces: UART0 and UART2. The table below shows the default pin definitions.
UART | Feature | Pin | Description |
---|---|---|---|
UART0 | TX | P00 | Used to flash firmware and license and connect to a host for testing. The baud rate defaults to 9600. |
UART0 | RX | P01 | - |
UART2 | TX | P16 | Used to print logs. The baud rate defaults to 115200. |
UART2 | RX | P17 | - |
SPI
The BK3431Q platform has one SPI interface, supporting controller and peripheral modes, operating at speeds up to 8 MHz, with a frequency range of 31.25 kHz to 8 MHz.
The SPI controller interface is used by default. You can connect the MISO and MOSI signals together (that is, short the P06 and P05) to perform a loopback test. The default pin definitions:
SPI | Feature | Pin |
---|---|---|
SPI0 | CS | P07 |
SPI0 | CLK | P04 |
SPI0 | SDI | P05 |
SPI0 | SDO | P06 |
I2C
The BK3431Q platform has one I2C interface, supporting 100 kHz and 400 kHz. The SDK configuration only supports I2C controller mode and 7-bit addresses. To display SDK information (TuyaOS demo), the OLED is pre-initialized. I2C0 is used by default.
I2C | Feature | Pin |
---|---|---|
I2C0 | SCL | P02 |
I2C0 | SDA | P03 |
PWM
The BK3431Q platform supports 6-channel PWM output, channels 0 to 5. The SDK uses a 16 MHz main crystal oscillator as the default clock, operating within a frequency range of 245 Hz to 8 MHz. The table below lists the mapping between the channel and the default pin.
Channel | Pin |
---|---|
0 | P10 |
1 | P11 |
2 | P12 |
3 | P13 |
4 | P14 |
5 | P15 |
ADC
10-bit ADC, 10 channels (eight external test channels and two internal signal channels), supporting single and continuous modes. The external channel supports a voltage range of 0 to 1.0V (version G) or 1.2V (version D) with an accuracy of ±30 mV. The table below lists the mapping between the channel and the pin.
Channel | Pin |
---|---|
0 | P30 |
1 | P31 |
2 | P32 |
3 | P33 |
4 | P34 |
5 | P35 |
6 | P36 |
7 | P37 |
8 | VCCBAT-pin |
9 | Temperature sensor, internal channel |
Key control
Pin: P12
Startup time detection pin
Pin: P10
Set this pin to high after entering the main
function.
Download Keil from the Arm Keil website. mdk528a.exe is recommended. During installation, keep all the default settings.
If you are prompted to install a driver, continue with Install.
When opening Keil, if you are prompted to install a software pack, close the window.
After Keil is installed, add the path of the UV4.exe
file to the environment variable. For example, TUYAOS_COMPILE_TOOL
: C:\Keil_v5\UV4
, as shown below.
Install the legacy pack for Arm7, Arm9, and Cortex-R devices.
Two flashing tool installers are available in .\pc\tools\bk3431q\flash\
.
BekenHIDTool
: SPI-based flashing tool.bk_writer
: UART-based flashing tool.Disable the testing feature.
#define TUYA_SDK_TEST 0
Disable Tuya logging.
#define ENABLE_LOG 0
#define BOARD_ENABLE_LOG 0
After a full compilation of the whole project, open the .map
file. You will get the RAM and flash footprint.
The build output is located in .\software\TuyaOS\.log\output\app
. BK3431Q firmware consists of three parts: boot + stack + app.
tuyaos_demo_ble_peripheral_merge_crc.bin
= boot + stack + app, the production firmware, supporting SPI-based flashing only.
tuyaos_demo_ble_peripheral_oad.bin
= app, the application or OTA update firmware, supporting UART-based flashing.
tuyaos_demo_ble_peripheral_stack_oad.bin
= stack + app, supporting UART-based flashing. Unless you need to upgrade the stack, this file is generally unnecessary.
Find the flashing tool at .\pc\tools\bk3431q\flash
.
Find the firmware flashing guide at .\hardware\\bk3431q\module_manual\BK3431Q_flashing_guide.docx
.
Use a logic analyzer to measure the signal time difference between the VCC pin and the startup time detection pin.
Detection pins: peripheral → startup time detection pin
Startup time: From power-on to the execution of the main
function, it takes about six milliseconds.
Adjust flash partitions
In the original project, you can modify the following macros to adjust the default flash partitions.
// Flash
#ifndef BOARD_FLASH_TUYA_INFO_START_ADDR
#define BOARD_FLASH_TUYA_INFO_START_ADDR (0x7B000)
#endif
#ifndef BOARD_FLASH_SDK_TEST_START_ADDR
#define BOARD_FLASH_SDK_TEST_START_ADDR (0x77000)
#endif
#ifndef BOARD_FLASH_OTA_START_ADDR
#define BOARD_FLASH_OTA_START_ADDR (0x44000)
#endif
#ifndef BOARD_FLASH_OTA_END_ADDR
#define BOARD_FLASH_OTA_END_ADDR (0x64000)
#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 (0x7F000)
#endif
Test method
Disconnect all external cables except for the serial cable connected to the host. You can connect a USB to TTL converter to the serial port on the board. Connect the TX and RX of the USB serial port to P01
and P00
respectively.
Connect to an ammeter that can provide 3.3V of power, with its positive and negative terminals connected to the +3V pin and the GND pin on the board respectively.
You can measure the power consumption in different modes using power management in the host software.
Power consumption
Measure the average power consumption of typical one-second advertising.
Measure the average power consumption in deep sleep mode. Turn off all peripherals and advertising, maintain RTC and RAM data, and enable GPIO wake-up.
Hardware testing: A development board has a 16 MHz crystal oscillator with a frequency tolerance of ±20 ppm and connects to an external 32K crystal oscillator. The host software directs the hardware to enter low power mode 1 (with advertising), with the local clock running for 15 hours, experiencing a drift of about two to three seconds.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback