- Finding encryption keys - what to do if LibreTiny doesn't boot because of incorrect flash encryption keys
Beken BK7231 is a family of Wi-Fi and BLE microcontrollers, of which most popular are BK7231N and BK7231T.
- ARM968E-S (ARMv5TE) CPU (120 MHz)
- 256 KiB SRAM
- built-in 2 MiB SPI flash with XiP
- 802.11b/g/n Wi-Fi
- BK7231U Datasheet v0.71 (Machine-translated to English)
- BL2028N Datasheet v1.0 (BL2028N is a "clone" of BK7231N)
- BK72XX SDK User Manual 3.0.3 (Machine-translated to English)
- BEKEN WiFi SDK API Reference 3.0.27 (Machine-translated to English)
- Beken SDK documentation (online)
encrypt v0.3source code (Encryption routines and FPGA code used on the chip)
- BK7231 OpenOCD debugging (From Elektroda.pl user
Finding your board
You need to know which board your device uses. Head to Supported Boards to find it. A good number of popular boards have their dedicated support and documentation pages in LibreTiny. Otherwise, you have to use one of the Generic boards that matches the CPU model of your device.
This is probably the most important part of the docs - flashing firmware to the chip.
This is why you're here. Please read this section carefully, and only then start flashing firmware.
BK7231 has two UART ports - UART2 (sometimes called LOG_UART) and UART1. The UART1 port is used for flashing (and external components, such as TuyaMCU) and has no text output. The UART2 port is used for log viewing only.
You need to find which pins correspond to UART1 TX and RX. If your board is supported, you'll find the pinout on its documentation page. Otherwise (and for generic boards), you'll have to find the pinout online.
For best experience, you should have two USB<->UART adapters plugged in:
- One for flashing, preferably a real FT232RL or a good alternative. This connects to UART1 of the chip.
- One for log output - BK72xx outputs messages on a separate port. You can have a terminal session continuously open on this adapter. This connects to UART2 of the chip - but it's not necessary for flashing.
Connect UART1 of the BK7231 to the USB-TTL adapter:
|TX1 (GPIO11 / P11)
|RX1 (GPIO10 / P10)
Using a good, stable 3.3V power supply is crucial. Most flashing issues are caused by either voltage drops during intensive flash operations, or bad/loose wires. The UART adapter's 3.3V power regulator is usually not enough.
Instead, a regulated bench power supply, or a linear 1117-type regulator is recommended.
"CEN" pin is the RESET pin - connecting it to GND will keep the chip in "reset" state. Disconnecting it will allow the chip to start back up.
If you're having issues with using CEN pin (or if it's not accessible on your device) you can toggle the 3.3V power instead. Removing power will keep it in "reset", and applying it back will start it again.
The download mode is entered when the chip communicates with the flasher program. Hence, the first step is running the flasher program (described below). While the program is trying to establish communication, the chip has to be rebooted. In order to do that, you need to bridge CEN pin to GND with a wire.
Keep in mind that BK7231T (not N) will exit the download mode when it can't communicate with the flasher (or when the flasher finishes its work). It's not possible to forcefully enter download mode without it.
After linking with the chip, the flasher program will begin writing (or reading) the firmware automatically. If that doesn't happen, try resetting the chip again until it works.
If you're getting a
No response received (or similar) error, this means that:
- the power supply is too weak (read above)
- you're resetting the chip too quickly, i.e. you resetted it after the program started communicating with it
The recommended tool to flash (or dump firmware) is
Read Using ltchiptool to learn the flashing procedure
BK7231N can't be software-bricked, because it has a ROM that contains the download mode. BK7231T doesn't contain it, so be careful with this one.
ltchiptool's Beken flashing program is based on bk7231tools. Refer to the guide for information how to use it, but keep in mind that using the ltchiptool GUI is probably just easier.
If you have a recent version of LibreTiny already installed on the chip, you don't need to perform any steps to enter download mode. Instead, Auto-download-reboot will reboot the chip automatically, as soon as it notices the flasher program. This is enabled by default, so you don't have to configure anything.
Single UART adapter usage
If you only have a single adapter, or just want to use the UART1 (upload) port only, you can change the logging port of LibreTiny firmware.
Refer to Options & config (
Serial output section). Set
1, which will use UART1 for all output.
Firmware output files
These files are present in the build directory after successful compilation:
|UF2 package for UART and OTA upload
|Beken OTA package (e.g. OpenBeken)
|Tuya OTA package (incl. Cloudcutter)
|App partition - flashable at 0x11000
|Encrypted app image - not for flashing
|RBL header - not for flashing
SPI flashing (unbricking BK7231T)
These tools are not recommended and are kept here for reference only. Don't use them, please.
There are many chip variations in this SoC family:
- BK7231 - marked BK7231QN40, so we're calling it "BK7231Q" to reduce confusion
The "officially existing" ones are BK7231Q, BK7231N and BK7231U. These are supported by Beken SDKs, such as
bk7231s_alios_sdk also existed at some point.
- BK7231N is substantially different than the other chips, so running T code on N (and vice versa) is not directly possible.
- BK7231Q does not have eFuse and BLE
- there are some references to U meaning USB support
- T seems to be exclusive to Tuya boards (that would explain the name); in the T SDK from Tuya,
CFG_SOC_NAMEis set to
- T's bootloader greets with
makeallows selecting for which MCU the code should be compiled
make bk7231doesn't compile at all
make bk7231udoesn't run on T with Tuya's bootloader (1.0.5), though it works just fine after replacing the bootloader with one of these included with
bdk_freertos(1.0.8) (yes, even
- after making a few changes to
driver/intc(so it looks more like the code from T SDK)
bdk_freertosruns just fine