[beken-72xx] Support BK7238#360
Conversation
|
BK7238 should already be supported in this PR. To use in ESPHome, put this in your YAML: bk72xx:
board: generic-bk7238-tuya # use this if you have a Tuya device, remove "-tuya" suffix if you don't (unlikely)
family: BK7231N # workaround for ESPHome not knowing what a BK7238 is, doesn't cause any problems
framework:
version: 0.0.0
source: https://github.com/libretiny-eu/libretiny#feature/bk7238
esphome:
platformio_options:
custom_versions.beken-bdk: 3.0.78Note that there are some problems in ESPHome 2026.3.x which make it harder to compile with BDK 3.0.78 (required for BK7238). If having issues, try ESPHome 2026.2.x instead. The most important difference between BK7231 and BK7238 (on Tuya devices) is the OTA protocol - it has been implemented, but everyone is welcome to test and report if it works correctly. |
|
Thanks!! It needed ESPhome 2026.2.0, and i needed to flash with BK7231EasyUARTFlasher (using esphome with run command couldnt find the device in bootloader mode). Through lots of trial and error the .rbl file worked when custom flashed with an offset of 0x11000 Now the raw device turns up in HA! |
|
Thanks for all your hard work! I tried my best to get through the compiler. Used bare config as mentioned above. And tried esphome versions 2026.2.4 and 2026.2.0 as mentioned by drwormy. Logfile of freertos related error is attached as I wasn't able to post it in decent formatted code block. |
|
Not sure what that's about... however, try clearing PlatformIO cache ( |
|
I was careful to also use an older version of Python - 3.12.10. And work in a venv |
|
Flashed some Tuya relay on T1-2S-NL with no problem (simple python 3.13.5, esphome 2026.2.4 |
As of your recommendations I did both, but most likely deleting all LibreTiny versions did the trick. |
|
I added some code in this branch and wanted to share in case it helped: https://github.com/tpmullan/libretiny/tree/feature/bk7238 |
|
I'm not sure why were these changes needed - were you perhaps testing with BDK 3.0.56, as your branch seems to suggest? I've been testing with BDK 3.0.78 (latest), which is the only one LibreTiny should and will support - apart from 3.0.33, of course. On 3.0.78 everything seems to work fine on BK7238, though I don't think I tried compiling with BLE support enabled - maybe this is what works only after applying some of your changes. Supporting every single version of BDK is not feasible, just because of how much they differ from one another. |
|
Yeah, I had been testing with that older one, I need to bump it up to latest. The BLE support was causing issues for me but the new version probably makes that easier. I will be messing with it more tonight. I had not checked the branch here in over a month and you got way further than when I originally saw. I did my best to merge everything and prefer your changes, but that made a mess on my side. I honestly not sure if anything I had would be helpful but figured it might be worth posting before throwing out all the work. |
|
I refreshed my branch against Main differences from
Validation:
Both builds complete successfully. The main value of these changes is that BK7238 support no longer depends on |
|
should work with latest esphome with the above #360 (comment) along with esphome/esphome#15942 as external_components:
- source: github://pr#15942
components: [wifi]
refresh: 1s |
|
not sure if its the hardware or the new SDK, but wifi behavior is A LOT better. connects faster, far less event loop blocking. And heap free is much better. Feeding the watchdog seems to be especially slow on this platform |
The 3.0.78 BDK should also work on BK7231T and BK7231N, so you should be able to do direct comparisons. On T1/BK7238, I'm having wifi connection issues after soft resets (or strangely, ever other soft reset), where the first scan/connect always times out after 30-60 seconds, then works correctly. I haven't tested yet to see if it's the same for bk7231T/N. |
JSYK, I was able to make it work with esphome version Since these changes, the firmware doesn't compile anymore, stopping at: This is not a big deal for me, but I thought it was worth sharing this issue. Also, OTA runs flawlessly, but, for some reason, doesn't actually overwrites the current firmware on the device. Thank you all for working on this! Cheers! ;)
|
You need to be running |
Ah, that explains it. Thank you! |
|
Also you won't need the external comp after tonight's ESPHome nightly as that PR has been merged and will be in tonight |
|
Will be possible to flash ESPHome over a OpenBeken firmware? Or we must flash using UART method? |
Probably depends on the device and what you did to get OpenBeken. OpenBeken only appears to handle the Beken OEM bootloader case for OTA, and if you UART flashed, it probably installed that bootloader, in which case you'll need to use a board in LibreTiny for generics like I don't think OpenBeken supports the Tuya bootloader at all, so if you UART flashed a Tuya device, you probably won't be able to use any of the Tuya/T1 boards. |
I flashed the device using UART, probably it has the Beken OEM bootloader. I'll try doing the OTA, and report back. |
I used the config: Flashed the |
|
Been doing some testing with. First flash works fine. As soon as I do a second flash I have to restore the boot loader to the original or it doesn't boot again than seems like wifi crash after enabling STA most of the time now |
Which board are you using? Right now there are two generics They have different bootloaders, partitions layouts, and OTA methods. The bootloader you've listed ( OTA support should be there for both methods, but I'm not sure there are any cross-contamination prevention yet (or if it's possible), I'll leave that to @kuba2k2 to comment on. |
NiceMCU XH-WB3S BK7238 |
|
I meant in ESPHome yaml |
|
|
I'll have to defer to @kuba2k2 then. Do you happen to know the size of the OTA bin (not the uf2)? |
|
This board is essentialy the same as What file are you flashing? The UF2 doesn't touch the bootloader at all. Are you flashing OTA or by UART? Is that everything that's printed after it The generated UF2 file has an OTA package that depends on the used board type ( |
|
I'm flashing over UART board https://www.ebay.com/itm/405245692462 No console output until I reload the boot loader doing I saved it earlier with earlier flash with esphome:
name: wb3s-bk7238-test
includes:
- bench_splitmix32.h
platformio_options:
custom_versions.beken-bdk: 3.0.78
bk72xx:
board: xh-wb3s
#family: BK7231N
framework:
version: 0.0.0
source: https://github.com/libretiny-eu/libretiny#feature/bk7238
logger:
hardware_uart: UART1
level: VERBOSE
#runtime_stats:
#api:
#ota:
# - platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "wb3s-bk7238-test-fallback"
ap_timeout: 120s
#captive_portal:
#web_server:
#debug:
# update_interval: 5s
interval:
- interval: 2s
then:
- lambda: |-
ESP_LOGI("alive", "tick @ %u ms, free=%u", (unsigned) millis(), (unsigned) ESP.getFreeHeap());
|
|
What file are you flashing? You'll have to post the dump after flashing for the 2nd time (preferably a full dump). |
|
edited above to show the full output |
|
Successfully flashed a TOMZN TOBL9-63M circuit breaker which contains a T1-U-HL board. using ESPHome 2026.5.0b2 with this flashed with ltchiptool running on a directory with this branch cloned. Have to retry a couple of times because i didnt want to desolder the board from PCB and i guess the tuya MCU chip introduced some communication interference because it uses the same UART OTA upgrade working great. I made a dump of the original ROM straight out of the box if you want it. |
|
So I was able to previously compile and flash esphome home to my S06 IR Blaster with T1-3S BK7238. I tried updating it to esphome 2026.5.1. with: esphome: bk72xx: I was able to compile, but not able to get it to do an OTA update from HA, or from command line. Trying to flash with BK7231EasyUARTFlasher (the rbl file) but did not boot, so i ended up putting OpenBK back on. It also has a OTA flash function and again, I could not get any esphone binaries to flash. Not sure what i am doing wrong / whats different from 2026.2.0. when i was using board: generic-bk7238-tuya # use this if you have a Tuya device, remove "-tuya" suffix if you don't (unlikely)
|
|
You'll need to restore your factory firmware backup before flashing ESPHome. Then OTA updates should work, provided that your device is a Tuya one and you use Flashing OpenBeken messes up the bootloader, which then becomes incompatible with what LibreTiny/ESPHome thinks is installed. |
|
OK, Thanks. The factory backup firmwares are 2048 KB. It is tuya based The esphome compiled are: which one should i flash?
|
|
You should flash the UF2 file using ltchiptool. ESPHome does this for you when you run "esphome run". |
|
Thanks. All sorted. The issue i have been having is being unable to get the uart flashing working with the esphome run command, and also tring to call it separately from a cmd line. Probably tried 100 times, where as BK7231Flasher would work every time to get into bootloader mode by powering up / down a few times. I didnt know about the win64 version at https://docs.libretiny.eu/docs/flashing/tools/ltchiptool/ which worked brilliantly, only if i "Get chip info" before attempting to write
|







This PR adds support for BK7238. It requires BDK 3.0.78 to function.