Skip to content

[beken-72xx] Support BK7238#360

Draft
kuba2k2 wants to merge 8 commits into
masterfrom
feature/bk7238
Draft

[beken-72xx] Support BK7238#360
kuba2k2 wants to merge 8 commits into
masterfrom
feature/bk7238

Conversation

@kuba2k2
Copy link
Copy Markdown
Member

@kuba2k2 kuba2k2 commented Feb 7, 2026

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

@kuba2k2 kuba2k2 added enhancement New feature or request new platform About support for new chips/platforms BK7231 Beken BK72xx family labels Feb 7, 2026
@kuba2k2 kuba2k2 mentioned this pull request Feb 7, 2026
@kuba2k2 kuba2k2 closed this Mar 29, 2026
@kuba2k2 kuba2k2 reopened this Mar 29, 2026
@kuba2k2
Copy link
Copy Markdown
Member Author

kuba2k2 commented Apr 8, 2026

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.78

Note 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.

@drwormy
Copy link
Copy Markdown

drwormy commented Apr 9, 2026

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!

@christopherwit
Copy link
Copy Markdown

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.
logs_ssw2_compile.txt. I'm lacking knowledge to fix this, but am very open to test instructions.

@kuba2k2
Copy link
Copy Markdown
Member Author

kuba2k2 commented Apr 13, 2026

Not sure what that's about... however, try clearing PlatformIO cache (~/.platformio/packages). Sometimes the wrong versions of some packages are left there. Also try deleting all instances of LibreTiny in ~/.platformio/platforms/libretiny.

@drwormy
Copy link
Copy Markdown

drwormy commented Apr 13, 2026

I was careful to also use an older version of Python - 3.12.10.

And work in a venv

@dext0r
Copy link
Copy Markdown

dext0r commented Apr 14, 2026

Flashed some Tuya relay on T1-2S-NL with no problem (simple esphome run). OTA also works. Great work!

python 3.13.5, esphome 2026.2.4

I: Connecting to 'Beken 72xx' on /dev/tty.usbserial-140 @ 115200
W: Unknown bootloader CRC - 0xF42F8C32 - please report this on GitHub issues!
I: |-- Success! Chip info: BK7238
I: Reading chip info...
I: Chip: BK7238
I: +-----------------------+-------------------------------------+
I: | Name                  | Value                               |
I: +-----------------------+-------------------------------------+
I: | Protocol Type         | FULL                                |
I: | Chip Type             | BK7238                              |
I: | Bootloader Type       | Unrecognized                        |
I: | Chip ID               | 0x7238                              |
I: | Boot Version String   | N/A                                 |
I: |                       |                                     |
I: | Flash ID              | 85 20 15                            |
I: | Flash Size (by ID)    | 2 MiB                               |
I: | Flash Size (detected) | 2 MiB                               |
I: |                       |                                     |
I: | Encryption Key        | 00f57700 00f57700 00f57700 00f57700 |
I: +-----------------------+-------------------------------------+

@christopherwit
Copy link
Copy Markdown

Not sure what that's about... however, try clearing PlatformIO cache (~/.platformio/packages). Sometimes the wrong versions of some packages are left there. Also try deleting all instances of LibreTiny in ~/.platformio/platforms/libretiny.

As of your recommendations I did both, but most likely deleting all LibreTiny versions did the trick.
It is now working on a T1-S2-NL (LSC 3202087.1 powerplug). Your work is much appreciated!

@tpmullan
Copy link
Copy Markdown

I added some code in this branch and wanted to share in case it helped: https://github.com/tpmullan/libretiny/tree/feature/bk7238

@kuba2k2
Copy link
Copy Markdown
Member Author

kuba2k2 commented Apr 17, 2026

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.

@tpmullan
Copy link
Copy Markdown

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.

@tpmullan
Copy link
Copy Markdown

I refreshed my branch against origin/feature/bk7238 and the useful delta is
fairly small. My branch builds on top of your BK7238 work and adds a few fixes
needed to build/test cleanly against BDK 3.0.78.

Main differences from origin/feature/bk7238:

  • Pins framework-beken-bdk to 3.0.78 instead of 3.0.33.
  • Raises BK7238's minimum BDK version from 3.0.56 to 3.0.78, matching the
    SDK version this PR is intended to support.
  • Fixes BK7238 PWM handling. BK7238 uses the BK7231N-style duty_cycle1/2/3
    fields, not the single duty_cycle field.
  • Moves custom_options parsing earlier so family builders can see config
    overrides before selecting SDK sources.
  • Applies custom_options.sys_config.h values during LoadConfig(), which
    allows test configs like CFG_SUPPORT_BLE = 0 to affect source selection
    properly.
  • Adds no-BLE fallback stubs for BLE/WiFi coexistence symbols that BDK still
    references when BLE is disabled.
  • Adds a weak ps_send_connection_loss() fallback because the BK7238
    low-voltage power-save path declares/calls it but the BK7238 source set does
    not provide it.
  • Adjusts clock calibration state so low-voltage timing does not depend
    directly on CAL_TICK_T.time_us.

Validation:

  • Built from a separate PlatformIO test project with:
    platform = file:///Users/tom/git/libretiny
  • Confirmed it resolves framework-beken-bdk @ 3.0.78.
  • Verified both:
    • default generic-bk7238 Arduino build
    • generic-bk7238 with CFG_SUPPORT_BLE = 0
  • I will be testing this on a light switch tonight.

Both builds complete successfully.

The main value of these changes is that BK7238 support no longer depends on
older SDK behavior or BLE-always-on assumptions, and the branch can be tested
directly against BDK 3.0.78.

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 23, 2026

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

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 23, 2026

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 sctrl_dpll_delay200us has a 200us busy wait that can't be avoided. We decreased the overhead by nearly 100x in ESPHome 2026.5.x and its still slow. That will be taken care of in esphome/esphome#15943

[04:39:18.457][I][runtime_stats:092]:   wdt_slow_path: hits=195 (5.9% of iters, avg=315.97us/hit)
[04:39:18.457][I][runtime_stats:087]:   main_loop_before_breakdown: sched=73.2ms, wdt=61.6ms, residual=0.0ms

@Cossid
Copy link
Copy Markdown
Collaborator

Cossid commented Apr 23, 2026

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.

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.

@viniciusvillas
Copy link
Copy Markdown

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

JSYK, I was able to make it work with esphome version 2026.2.4. Then I updated esphome to the latest available version - which for me appears as 2026.4.2 - and added the external_components to the YAML file as instructed. I've also ran esphome clean-all just to be safe.

Since these changes, the firmware doesn't compile anymore, stopping at:

In file included from src/esphome/components/network/util.h:15,
                 from src/esphome/components/api/api_connection.cpp:21:
src/esphome/components/wifi/wifi_component.h:15:10: fatal error: esphome/core/freertos_queue.h: No such file or directory
   15 | #include "esphome/core/freertos_queue.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pioenvs/test-switch-2/src/esphome/components/api/api_connection.cpp.o] Error 1

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! ;)

image

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 23, 2026

external_components:
  - source: github://pr#15942
    components: [wifi]
    refresh: 1s

You need to be running esphome dev for freertos_queue.h to exist

@viniciusvillas
Copy link
Copy Markdown

external_components:
  - source: github://pr#15942
    components: [wifi]
    refresh: 1s

You need to be running esphome dev for freertos_queue.h to exist

Ah, that explains it. Thank you!

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 23, 2026

Also you won't need the external comp after tonight's ESPHome nightly as that PR has been merged and will be in tonight

@0x3333
Copy link
Copy Markdown

0x3333 commented Apr 23, 2026

Will be possible to flash ESPHome over a OpenBeken firmware? Or we must flash using UART method?

@Cossid
Copy link
Copy Markdown
Collaborator

Cossid commented Apr 23, 2026

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.
It depends on what bootloader and partition layout your device has now.

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 generic-bk7238 which will continue to use that bootloader OTA method and you should be able to OTA, likely required a filename pattern match.

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.

@viniciusvillas
Copy link
Copy Markdown

Just confirming that everything works with esphome@dev, including OTA.
Below, pictures of my device (an incredible $2 module from AliExpress).
Thank you!!
image
Screenshot 2026-04-23 20-20-14
Screenshot 2026-04-23 20-19-37

@0x3333
Copy link
Copy Markdown

0x3333 commented Apr 24, 2026

Probably depends on the device and what you did to get OpenBeken. It depends on what bootloader and partition layout your device has now.

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 generic-bk7238 which will continue to use that bootloader OTA method and you should be able to OTA, likely required a filename pattern match.

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.

@0x3333
Copy link
Copy Markdown

0x3333 commented Apr 24, 2026

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 generic-bk7238 which will continue to use that bootloader OTA method and you should be able to OTA, likely required a filename pattern match.

I used the config:

...

bk72xx:
  board: generic-bk7238
  family: BK7231N # workaround for ESPHome not knowing what a BK7238
  framework:
    version: 0.0.0
    source: https://github.com/libretiny-eu/libretiny#feature/bk7238

esphome:
  <<: !include device-name.yaml
  platformio_options:
    custom_versions.beken-bdk: 3.0.78

...

Flashed the image_bk7238_app.ota.rbl using the webui in OpenBeken and success!

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 27, 2026

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
~/.platformio/penv/.libretiny/bin/ltchiptool flash write -d /dev/cu.usbserial-A50285BI -f bk7238 -s 0x0 -l 0x11000 bl-dump-board2-good.bin

than

  [10:37:20.674]BK7238_1.0.14                                                                                                                                                                                                             
  [10:37:20.674]REG:cpsr        spsr        r13         r14                                                                                                                                                                               
  [10:37:20.679]SVC:0x000000D3              0x00401C1C  0x000033A0                                                                                                                                                                        
  [10:37:20.685]IRQ:0x000000D2  0x00000010  0x00401E0C  0x10649209                                                                                                                                                                        
  [10:37:20.690]FIR:0x000000D1  0x00000010  0x00401FFC  0x40880020                                                                                                                                                                        
  [10:37:20.706]SYS:0x000000DF              0x0040192C  0x00000158                                                                                                                                                                        
  [10:37:20.706]ST:0x00000000                                                                                                                                                                                                             
  [10:37:20.711][I/FAL] Fal(V0.4.0)success                                                                                                                                                                                                
  [10:37:20.716][I/OTA] RT-Thread OTA package(V0.2.8-beken-1133282d-20220604) initialize success.                                                                                                                                         
  [10:37:20.737][E/OTA] (ota_main:178) App verify failed! Need to recovery factory firmware.                                                                                                                                              
                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                          
  [10:37:20.737]go os_addr(0x10000)..........                                                                                                                                                                                             
  [10:37:20.744][I][logger:049]: Log initialized                                                                                                                                                                                          
  [10:37:20.749][I][app:056]: Running through setup()     

seems like wifi crash after enabling STA most of the time now

[10:45:32.939][I][wifi_lt:134]: pre-WiFi.mode() tick 44/50 @ 4460 ms, free=192336
[10:45:33.039][I][wifi_lt:134]: pre-WiFi.mode() tick 45/50 @ 4560 ms, free=192336
[10:45:33.135][I][wifi_lt:134]: pre-WiFi.mode() tick 46/50 @ 4660 ms, free=192336
[10:45:33.239][I][wifi_lt:134]: pre-WiFi.mode() tick 47/50 @ 4760 ms, free=192336
[10:45:33.339][I][wifi_lt:134]: pre-WiFi.mode() tick 48/50 @ 4860 ms, free=192336
[10:45:33.435][I][wifi_lt:134]: pre-WiFi.mode() tick 49/50 @ 4960 ms, free=192336
[10:45:33.531][I][wifi_lt:139]: calling WiFi.mode(0x01) NOW

@Cossid
Copy link
Copy Markdown
Collaborator

Cossid commented Apr 27, 2026

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 ~/.platformio/penv/.libretiny/bin/ltchiptool flash write -d /dev/cu.usbserial-A50285BI -f bk7238 -s 0x0 -l 0x11000 bl-dump-board2-good.bin

than

  [10:37:20.674]BK7238_1.0.14                                                                                                                                                                                                             
  [10:37:20.674]REG:cpsr        spsr        r13         r14                                                                                                                                                                               
  [10:37:20.679]SVC:0x000000D3              0x00401C1C  0x000033A0                                                                                                                                                                        
  [10:37:20.685]IRQ:0x000000D2  0x00000010  0x00401E0C  0x10649209                                                                                                                                                                        
  [10:37:20.690]FIR:0x000000D1  0x00000010  0x00401FFC  0x40880020                                                                                                                                                                        
  [10:37:20.706]SYS:0x000000DF              0x0040192C  0x00000158                                                                                                                                                                        
  [10:37:20.706]ST:0x00000000                                                                                                                                                                                                             
  [10:37:20.711][I/FAL] Fal(V0.4.0)success                                                                                                                                                                                                
  [10:37:20.716][I/OTA] RT-Thread OTA package(V0.2.8-beken-1133282d-20220604) initialize success.                                                                                                                                         
  [10:37:20.737][E/OTA] (ota_main:178) App verify failed! Need to recovery factory firmware.                                                                                                                                              
                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                          
  [10:37:20.737]go os_addr(0x10000)..........                                                                                                                                                                                             
  [10:37:20.744][I][logger:049]: Log initialized                                                                                                                                                                                          
  [10:37:20.749][I][app:056]: Running through setup()     

Which board are you using?

Right now there are two generics generic-bk7238 and generic-bk7238-tuya as well as some tuya specific boards (T1-3S, etc).

They have different bootloaders, partitions layouts, and OTA methods.
I'm guessing it might be possible if you're using the wrong board that it could be contaminating the app partition because of the different offsets.

The bootloader you've listed (BK7238_1.0.14) appears to be the Beken OEM bootloader.

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.

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 27, 2026

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 ~/.platformio/penv/.libretiny/bin/ltchiptool flash write -d /dev/cu.usbserial-A50285BI -f bk7238 -s 0x0 -l 0x11000 bl-dump-board2-good.bin
than

  [10:37:20.674]BK7238_1.0.14                                                                                                                                                                                                             
  [10:37:20.674]REG:cpsr        spsr        r13         r14                                                                                                                                                                               
  [10:37:20.679]SVC:0x000000D3              0x00401C1C  0x000033A0                                                                                                                                                                        
  [10:37:20.685]IRQ:0x000000D2  0x00000010  0x00401E0C  0x10649209                                                                                                                                                                        
  [10:37:20.690]FIR:0x000000D1  0x00000010  0x00401FFC  0x40880020                                                                                                                                                                        
  [10:37:20.706]SYS:0x000000DF              0x0040192C  0x00000158                                                                                                                                                                        
  [10:37:20.706]ST:0x00000000                                                                                                                                                                                                             
  [10:37:20.711][I/FAL] Fal(V0.4.0)success                                                                                                                                                                                                
  [10:37:20.716][I/OTA] RT-Thread OTA package(V0.2.8-beken-1133282d-20220604) initialize success.                                                                                                                                         
  [10:37:20.737][E/OTA] (ota_main:178) App verify failed! Need to recovery factory firmware.                                                                                                                                              
                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                          
  [10:37:20.737]go os_addr(0x10000)..........                                                                                                                                                                                             
  [10:37:20.744][I][logger:049]: Log initialized                                                                                                                                                                                          
  [10:37:20.749][I][app:056]: Running through setup()     

Which board are you using?

NiceMCU XH-WB3S BK7238
https://www.elektroda.com/rtvforum/topic4092465.html

@Cossid
Copy link
Copy Markdown
Collaborator

Cossid commented Apr 27, 2026

I meant in ESPHome yaml

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 27, 2026

bk72xx:
  board: xh-wb3s

@Cossid
Copy link
Copy Markdown
Collaborator

Cossid commented Apr 27, 2026

I'll have to defer to @kuba2k2 then.

Do you happen to know the size of the OTA bin (not the uf2)?

@kuba2k2
Copy link
Copy Markdown
Member Author

kuba2k2 commented Apr 27, 2026

This board is essentialy the same as generic-bk7238.

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 doesn't boot again?

The generated UF2 file has an OTA package that depends on the used board type (-tuya vs non-Tuya).

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 27, 2026

I'm flashing over UART

board https://www.ebay.com/itm/405245692462

No console output until I reload the boot loader doing ~/.platformio/penv/.libretiny/bin/ltchiptool flash write -d /dev/cu.usbserial-A50285BI -f bk7238 -s 0x0 -l 0x11000 bl-dump-board2-good.bin, than I get UART output.

I saved it earlier with ~/.platformio/penv/.libretiny/bin/ltchiptool flash read -d /dev/cu.usbserial-A50285BI bk7238 bl-dump-board2-good.bin -s 0x0 -l 0x11000

 % ~/.platformio/penv/.libretiny/bin/ltchiptool flash write -d /dev/cu.usbserial-A50285BI -f bk7238 -s 0x0 -l 0x11000 bl-dump-board2-good.bin    

I: Connecting to 'Beken 7238' on /dev/cu.usbserial-A50285BI @ 115200
W: Unknown bootloader CRC - 0xB397B8F6 - please report this on GitHub issues!
I: |-- Success! Chip info: BK7238
I: Writing 'bl-dump-board2-good.bin'
I: |-- Start offset: 0x0
I: |-- Write length: 68 KiB
I: |-- Skipped data: 0 B (auto-detected)
  [################################################################]  100%          
I: |-- Finished in 8.548 s
bdraco@Mac esphome %   python3.14 -m esphome logs wb3s-bk7238-test.yaml                                                                                                                                                                                         

INFO ESPHome 2026.5.0-dev
INFO Reading configuration wb3s-bk7238-test.yaml...
WARNING WiFi AP is configured but neither captive_portal nor web_server is enabled. The AP will not be usable for configuration or monitoring. Add 'captive_portal:' or 'web_server:' to your configuration.
INFO Starting log output from /dev/cu.usbserial-A50285BI with baud rate 115200


[10:58:35.707]BK7238_1.0.14
[10:58:35.707]REG:cpsr        spsr        r13         r14
[10:58:35.712]SVC:0x000000D3              0x00401C1C  0x000033A0
[10:58:35.718]IRQ:0x000000D2  0x00000010  0x00401E0C  0x00543A23  
[10:58:35.723]FIR:0x000000D1  0x00000010  0x00401FFC  0xC3504A04  
[10:58:35.738]SYS:0x000000DF              0x0040192C  0x00000158  
[10:58:35.738]ST:0x00000000
[10:58:35.744][I/FAL] Fal(V0.4.0)success
[10:58:35.749][I/OTA] RT-Thread OTA package(V0.2.8-beken-1133282d-20220604) initialize success.


[10:58:35.764]go os_addr(0x10000)..........
[10:58:35.771][I][logger:049]: Log initialized
[10:58:35.776][I][app:056]: Running through setup()
[10:58:35.782][V][app:057]: Sorting components by setup priority
[10:58:35.787][V][component:236]: Setup logger
[10:58:35.792][V][component:248]: Setup logger took 0ms
[10:58:35.792][V][component:236]: Setup preferences
[10:58:35.803][V][scheduler:217]: Scheduler interval for (null) is 60000ms, offset 3613ms
[10:58:35.809][V][component:248]: Setup preferences took 6ms
[10:58:35.809][V][component:236]: Setup interval
[10:58:35.819][V][scheduler:217]: Scheduler interval for iid:0 is 2000ms, offset 281ms
[10:58:35.825][V][component:248]: Setup interval took 8ms
[10:58:35.825][V][component:236]: Setup wifi
[10:58:35.830][C][wifi:645]: Starting
[10:58:35.835][V][wifi_lt:117]: Enabling STA
[10:58:35.851][I][wifi_lt:134]: pre-WiFi.mode() tick 0/50 @ 54 ms, free=192336
[10:58:35.945][I][wifi_lt:134]: pre-WiFi.mode() tick 1/50 @ 160 ms, free=192336
[10:58:36.046][I][wifi_lt:134]: pre-WiFi.mode() tick 2/50 @ 260 ms, free=192336
[10:58:36.141][I][wifi_lt:134]: pre-WiFi.mode() tick 3/50 @ 360 ms, free=192336
[10:58:36.245][I][wifi_lt:134]: pre-WiFi.mode() tick 4/50 @ 460 ms, free=192336
[10:58:36.346][I][wifi_lt:134]: pre-WiFi.mode() tick 5/50 @ 560 ms, free=192336
[10:58:36.442][I][wifi_lt:134]: pre-WiFi.mode() tick 6/50 @ 660 ms, free=192336
[10:58:36.545][I][wifi_lt:134]: pre-WiFi.mode() tick 7/50 @ 760 ms, free=192336
[10:58:36.646][I][wifi_lt:134]: pre-WiFi.mode() tick 8/50 @ 860 ms, free=192336
[10:58:36.741][I][wifi_lt:134]: pre-WiFi.mode() tick 9/50 @ 960 ms, free=192336
[10:58:36.845][I][wifi_lt:134]: pre-WiFi.mode() tick 10/50 @ 1060 ms, free=192336
[10:58:36.946][I][wifi_lt:134]: pre-WiFi.mode() tick 11/50 @ 1160 ms, free=192336
[10:58:37.042][I][wifi_lt:134]: pre-WiFi.mode() tick 12/50 @ 1260 ms, free=192336
[10:58:37.145][I][wifi_lt:134]: pre-WiFi.mode() tick 13/50 @ 1360 ms, free=192336
[10:58:37.245][I][wifi_lt:134]: pre-WiFi.mode() tick 14/50 @ 1460 ms, free=192336
[10:58:37.346][I][wifi_lt:134]: pre-WiFi.mode() tick 15/50 @ 1560 ms, free=192336
[10:58:37.442][I][wifi_lt:134]: pre-WiFi.mode() tick 16/50 @ 1660 ms, free=192336
[10:58:37.545][I][wifi_lt:134]: pre-WiFi.mode() tick 17/50 @ 1760 ms, free=192336
[10:58:37.646][I][wifi_lt:134]: pre-WiFi.mode() tick 18/50 @ 1860 ms, free=192336
[10:58:37.742][I][wifi_lt:134]: pre-WiFi.mode() tick 19/50 @ 1960 ms, free=192336
[10:58:37.844][I][wifi_lt:134]: pre-WiFi.mode() tick 20/50 @ 2060 ms, free=192336
[10:58:37.945][I][wifi_lt:134]: pre-WiFi.mode() tick 21/50 @ 2160 ms, free=192336
[10:58:38.046][I][wifi_lt:134]: pre-WiFi.mode() tick 22/50 @ 2260 ms, free=192336
[10:58:38.142][I][wifi_lt:134]: pre-WiFi.mode() tick 23/50 @ 2360 ms, free=192336
[10:58:38.245][I][wifi_lt:134]: pre-WiFi.mode() tick 24/50 @ 2460 ms, free=192336
[10:58:38.346][I][wifi_lt:134]: pre-WiFi.mode() tick 25/50 @ 2560 ms, free=192336
[10:58:38.431][I][wifi_lt:134]: pre-WiFi.mode() tick 26/50 @ 2660 ms, free=192336
[10:58:38.542][I][wifi_lt:134]: pre-WiFi.mode() tick 27/50 @ 2760 ms, free=192336
[10:58:38.645][I][wifi_lt:134]: pre-WiFi.mode() tick 28/50 @ 2860 ms, free=192336
[10:58:38.746][I][wifi_lt:134]: pre-WiFi.mode() tick 29/50 @ 2960 ms, free=192336
[10:58:38.842][I][wifi_lt:134]: pre-WiFi.mode() tick 30/50 @ 3060 ms, free=192336
[10:58:38.944][I][wifi_lt:134]: pre-WiFi.mode() tick 31/50 @ 3160 ms, free=192336
[10:58:39.045][I][wifi_lt:134]: pre-WiFi.mode() tick 32/50 @ 3260 ms, free=192336
[10:58:39.146][I][wifi_lt:134]: pre-WiFi.mode() tick 33/50 @ 3360 ms, free=192336
[10:58:39.242][I][wifi_lt:134]: pre-WiFi.mode() tick 34/50 @ 3460 ms, free=192336
[10:58:39.345][I][wifi_lt:134]: pre-WiFi.mode() tick 35/50 @ 3560 ms, free=192336
[10:58:39.446][I][wifi_lt:134]: pre-WiFi.mode() tick 36/50 @ 3660 ms, free=192336
[10:58:39.541][I][wifi_lt:134]: pre-WiFi.mode() tick 37/50 @ 3760 ms, free=192336
[10:58:39.644][I][wifi_lt:134]: pre-WiFi.mode() tick 38/50 @ 3860 ms, free=192336
[10:58:39.745][I][wifi_lt:134]: pre-WiFi.mode() tick 39/50 @ 3960 ms, free=192336
[10:58:39.846][I][wifi_lt:134]: pre-WiFi.mode() tick 40/50 @ 4060 ms, free=192336
[10:58:39.942][I][wifi_lt:134]: pre-WiFi.mode() tick 41/50 @ 4160 ms, free=192336
[10:58:40.045][I][wifi_lt:134]: pre-WiFi.mode() tick 42/50 @ 4260 ms, free=192336
[10:58:40.145][I][wifi_lt:134]: pre-WiFi.mode() tick 43/50 @ 4360 ms, free=192336
[10:58:40.246][I][wifi_lt:134]: pre-WiFi.mode() tick 44/50 @ 4460 ms, free=192336
[10:58:40.342][I][wifi_lt:134]: pre-WiFi.mode() tick 45/50 @ 4560 ms, free=192336
[10:58:40.445][I][wifi_lt:134]: pre-WiFi.mode() tick 46/50 @ 4660 ms, free=192336
[10:58:40.546][I][wifi_lt:134]: pre-WiFi.mode() tick 47/50 @ 4760 ms, free=192336
[10:58:40.642][I][wifi_lt:134]: pre-WiFi.mode() tick 48/50 @ 4860 ms, free=192336
[10:58:40.744][I][wifi_lt:134]: pre-WiFi.mode() tick 49/50 @ 4960 ms, free=192336
[10:58:40.840][I][wifi_lt:139]: calling WiFi.mode(0x01) NOW

diff --git a/esphome/components/wifi/wifi_component_libretiny.cpp b/esphome/components/wifi/wifi_component_libretiny.cpp
index 59efa4f842..0f71673566 100644
--- a/esphome/components/wifi/wifi_component_libretiny.cpp
+++ b/esphome/components/wifi/wifi_component_libretiny.cpp
@@ -129,7 +129,18 @@ bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
     mode |= 0b01;
   if (enable_ap)
     mode |= 0b10;
+
+  for (int i = 0; i < 50; i++) {
+    ESP_LOGI(TAG, "pre-WiFi.mode() tick %d/50 @ %u ms, free=%u", i, (unsigned) millis(),
+             (unsigned) ESP.getFreeHeap());
+    App.feed_wdt();
+    delay(100);
+  }
+  ESP_LOGI(TAG, "calling WiFi.mode(0x%02x) NOW", mode);
+  App.feed_wdt();
   bool ret = WiFi.mode(static_cast<wifi_mode_t>(mode));
+  ESP_LOGI(TAG, "WiFi.mode() returned %d", (int) ret);
+  App.feed_wdt();
 
   if (!ret) {
     ESP_LOGW(TAG, "Setting mode failed");

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());

@kuba2k2
Copy link
Copy Markdown
Member Author

kuba2k2 commented Apr 27, 2026

What file are you flashing?

You'll have to post the dump after flashing for the 2nd time (preferably a full dump).

@bdraco
Copy link
Copy Markdown
Contributor

bdraco commented Apr 27, 2026

edited above to show the full output

@grunjol
Copy link
Copy Markdown

grunjol commented May 19, 2026

Successfully flashed a TOMZN TOBL9-63M circuit breaker which contains a T1-U-HL board.

using ESPHome 2026.5.0b2 with this

esphome:
  name: ${devicename}
  friendly_name: ${friendly_name}
  platformio_options:
    custom_versions.beken-bdk: 3.0.78

bk72xx:
  board: t1-u
  family: BK7238 
  framework: 
    version: 0.0.0
    source: https://github.com/libretiny-eu/libretiny#feature/bk7238
...

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.

@0x3333
Copy link
Copy Markdown

0x3333 commented May 19, 2026

I'm using version 2026.5.0-dev (2026-05-12 22:00:24 -0300), but the device is unstable, it disconnect a lot. I have 2 devices, different places, same issue. It works, but irregular sometimes. Every 4 minutes it become unavailable, does it ring a bell?

image

@grunjol
Copy link
Copy Markdown

grunjol commented May 19, 2026

image

I am still testing it, last night put it offline a couple of minutes and left it running all night, no connection problems
have to admit the breaker is 5mts from the AP and -50dbm signal

@0x3333
Copy link
Copy Markdown

0x3333 commented May 19, 2026

Mine is like 10m from the AP that is in the ceiling.

image

@drwormy
Copy link
Copy Markdown

drwormy commented May 26, 2026

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:
name: home-ir-blaster
platformio_options:
custom_versions.beken-bdk: 3.0.78

bk72xx:
board: t1-3s
family: BK7238
framework:
version: 0.0.0
source: https://github.com/libretiny-eu/libretiny#feature/bk7238

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)
family: BK7231N # workaround for ESPHome not knowing what a BK7238 is, doesn't cause any problems

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!

@kuba2k2
Copy link
Copy Markdown
Member Author

kuba2k2 commented May 26, 2026

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 generic-bk7238-tuya, or t1-3s, or any other t1-* board. For non-Tuya devices, generic-bk7238 should be used instead.

Flashing OpenBeken messes up the bootloader, which then becomes incompatible with what LibreTiny/ESPHome thinks is installed.

@drwormy
Copy link
Copy Markdown

drwormy commented May 26, 2026

OK, Thanks.

The factory backup firmwares are 2048 KB. It is tuya based

The esphome compiled are:
2427392 firmware.bin
1150832 image_bk7238_app.0x011000.rbl
717036 raw_firmware.bin

which one should i flash?

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 generic-bk7238-tuya, or t1-3s, or any other t1-* board. For non-Tuya devices, generic-bk7238 should be used instead.

Flashing OpenBeken messes up the bootloader, which then becomes incompatible with what LibreTiny/ESPHome thinks is installed.

@kuba2k2
Copy link
Copy Markdown
Member Author

kuba2k2 commented May 26, 2026

You should flash the UF2 file using ltchiptool. ESPHome does this for you when you run "esphome run".

@drwormy
Copy link
Copy Markdown

drwormy commented May 27, 2026

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

You should flash the UF2 file using ltchiptool. ESPHome does this for you when you run "esphome run".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BK7231 Beken BK72xx family enhancement New feature or request new platform About support for new chips/platforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants