logo elektroda
logo elektroda
X
logo elektroda

NiceMCU XH-WB3S BK7238 Flashing, Testing, Pinout, Development, Porting

divadiow 7686 223
ADVERTISEMENT
  • ADVERTISEMENT
  • #2 21289375
    divadiow
    Level 35  
    well, BK7238 was actually correct. boo
    Sparkle IoT model XH-WB3S electronic board connected to a USB port on a blue surface.

    Flash ID 852015 - 2Mb - Encryption key set is 84e97000 84e97000 84e97000 84e97000
  • #3 21289396
    p.kaczmarek2
    Moderator Smart Home
    Very interesting, is it flashable with OBK?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 21302635
    divadiow
    Level 35  
    Code: Text
    Log in, to see the code


    SparkleIoT just direct you to their Arduino guides when asking about an SDK

    Added after 12 [minutes]:

    can OBK be made with Arduino? I don't know what this would entail.
  • #8 21302728
    insmod
    Level 26  
    >>21302635 No need to do it with arduino, all the headers and libraries are there.
    You would need to create the makefile, as well as adjusting beken HALs.
    Btw, found an interesting function in the source, maybe it is portable to openbeken (for ds18b20/dht)?
    
    void  delayMicroseconds(uint32_t us)
    {
        uint64_t m = (uint64_t)rtos_get_time_us();
        if(us){
            uint64_t e = (m + us);
            if(m > e){ //overflow
                while((uint64_t)rtos_get_time_us() > e){
                   __asm ( "NOP" );
                }
            }
            while((uint64_t)rtos_get_time_us() < e){
               __asm ( "NOP" );
            }
        }
    }
    
  • #9 21303557
    p.kaczmarek2
    Moderator Smart Home
    We would also need to check the dependency - rtos_get_time_us;
    https://github.com/search?q=repo%3Aopenshwprojects%2FOpenBK7231T%20rtos_get_time_us&type=code
    https://github.com/search?q=repo%3Aopenshwprojects%2FOpenBK7231N%20rtos_get_time_us&type=code
    Can't seem to find that, so we would need to check their source of rtos_get_time_us as well?
    Helpful post? Buy me a coffee.
  • #10 21303577
    DeDaMrAz
    Level 20  
    insmod wrote:
    Btw, found an interesting function in the source, maybe it is portable to openbeken (for ds18b20/dht)?


    Or anything else with precise timing requirement that has been giving us trouble for a long time.

    Good find!
  • #11 21303656
    p.kaczmarek2
    Moderator Smart Home
    The timings issues are due to the flash cache mechanism so I don't think the presented approach can work better. We would need to get ramfunc (execution of function from RAM) working in order to get precise bit-bat execution for things like WS2812B on any pin. Luckily, WS2812 are now handled through SPI DMA so they work reliably without the need for ramfunc.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #13 21324957
    insmod
    Level 26  
    Got a NiceMCU BK7238 board, my encryption key is different (84f67900 84f67900 84f67900 84f67900).
    Flash id from GUI flasher is 152085, which is not found in the database (err: Failed to find flash def for device MID!)
    BKFIL reads successfully, and flash id from there is different (Got FLashMID: 0x154285)
    Another XH-WB3S has (84fa7200 84fa7200 84fa7200 84fa7200) enc keys, and the same flash id as the previous one.
    So, each chip have a different encryption key. If openbeken is ported - everyone will have to build it from the source themselves.
  • #14 21325471
    divadiow
    Level 35  
    yes, I actually bought two and my second has key 84e46c00 84e46c00 84e46c00 84e46c00

    I believe @piotrszulc1 has one too.

    attaching T1 toolchain from elsewhere on the webs. Shamelessly re-posting to Elektroda for people's references. Credit to user Cossid.

    Includes T1 (BK7238)
    https://airtake-public-data-1254153901.cos.ap...myqcloud.com/smart/embed/pruduct/T1_0.0.3.zip
    https://airtake-public-data-1254153901.cos.ap...myqcloud.com/smart/embed/pruduct/T3_2.0.2.zip
    https://airtake-public-data-1254153901.cos.ap...myqcloud.com/smart/embed/pruduct/T5_0.0.8.zip

    only attaching T1 because the others are too large.
  • #15 21327365
    insmod
    Level 26  
    Just tried flashing unencrypted OTA file - bootloader blocked it. ([E/OTA] (ota_main:125) none encryption Not allow!)
    So, no ota.
    Also, available bootloaders from there aren't booting (bootloader_bk7238_uart1_v1.0.14.bin and bootloader_bk7238_uart2_v1.0.14.bin).

    Got it to compile in arduino, had to manually call beken_packager. But the resulting binary works, bootloader version is the same.
  • Helpful post
    #16 21327420
    insmod
    Level 26  
    >>21325471 Separate toolchain isn't really needed. It's just arm-none-eabi (at least for bk7238). https://dl2.bekencorp.com/tools/toolchain/arm/

    edit: standard tuya ota keys apparently are enough. I even tried to change them, but bootloader somehow is able to chew through them as well.
    Though my manually generated rbl file fails to update, even though i specified app partition.
    [E/OTA] (rt_ota_upgrade:957) The partition (beken_onchip_crc) has no space (unless 1183840) for upgrade.
    [E/OTA] (ota_main:144) OTA upgrade failed!
    
  • #17 21327466
    p.kaczmarek2
    Moderator Smart Home
    Nice, it seems I need to get BK7238 as well. Was any BK7238 already found in a smart device?
    Helpful post? Buy me a coffee.
  • Helpful post
    #18 21327474
    insmod
    Level 26  
    >>21327466 https://www.elektroda.com/rtvforum/topic4064640.html#21159086
    But it is cheaper to get a devboard. I got a board for ~1.5$ and 2 modules for ~0.7$ each. And working with a devboard is much easier, unlike tr6260 module i got. I don't even need to reset it before flashing, ch340 on board does it itself.

    Btw, ota is working, i just otaized the wrong image (uart image instead of original one).

    Added after 6 [hours] 28 [minutes]:

    Tried porting openbeken - stuck at flashvars
    first boot:
    BK7238_1.0.14
    REG:cpsr        spsr        r13         r14
    SVC:0x000000D3              0x00401AD4  0x000011D4
    IRQ:0x000000D2  0x00000010  0x00401E0C  0x000032EC  
    FIR:0x000000D1  0x00000010  0x00401FFC  0x11E03ACD  
    SYS:0x000000DF              0x0040192C  0x00000158  
    ST:0x00000000
    [I/FAL] Fal(V0.4.0)success
    [I/OTA] RT-Thread OTA package(V0.2.8-beken-1133282d-20220604) initialize success.
    
    
    go os_addr(0x10000)..........
       %  ѵstart addr:0x415418, size:175080
    [Flash]id:0x852015
    --write status reg:4004,2--
    [Flash]init over
    sctrl_sta_ps_init
    SDK Rev: 3.0.70 c825378
    [THD]app:[tcb]417718 [stack]415710-417710:8192:5
    [THD]extended_app:[tcb]417f88 [stack]417780-417f80:2048:4
    [THD]idle:[tcb]4183f8 [stack]417ff0-4183f0:1024:0
    [THD]timer_thd:[tcb]419180 [stack]418578-419178:3072:2
    OSK Rev: F-3.0.44 c825378
    cset:0 0 0 0
    Entering initLog()...
    [THD]log_serial:[tcb]419a48 [stack]419240-419a40:2048:2
    Debug:CMD:Adding command loglevel
    Debug:CMD:Adding command logfeature
    Debug:CMD:Adding command logtype
    Debug:CMD:Adding command logdelay
    Debug:CMD:Adding command logport
    Commands registered!
    initLog() done!
    Info:MAIN:Main_Init_Before_Delay
    Debug:CFG:flash vars not initialised - reading
    --write status reg:0,2--
    --write status reg:7c,2--
    Error:CFG:flash_vars_valid - not our magic, erase
    Debug:CFG:flash vars erase at offset 0 len 8192
    --write status reg:0,2--
    Debug:CFG:flash vars erase block at addr 0x1E3000
    Debug:CFG:flash vars erase block at addr 0x1E4000
    --write status reg:7c,2--
    Debug:CFG:flash erased
    --write status reg:0,2--
    --write status reg:7c,2--
    Debug:CFG:header written
    Debug:CFG:header written 4
    Debug:CFG:flash vars not initialised - reading
    --write status reg:0,2--
    --write status reg:7c,2--
    --write status reg:0,2--
    --write status reg:7c,2--
    Info:CFG:new flash vars
    --write status reg:0,2--
    --write status reg:7c,2--
    Debug:CFG:new offset 84, boot_count 0, success count 0
    Debug:CFG:flash initialised
    --write status reg:0,2--
    

    next
    BK7238_1.0.14
    REG:cpsr        spsr        r13         r14
    SVC:0x000000D3              0x00401C1C  0x000033A0
    IRQ:0x000000D2  0x00000010  0x00401E0C  0xFAB087BD  
    FIR:0x000000D1  0x00000010  0x00401FFC  0x91E0AACF  
    SYS:0x000000DF              0x0040192C  0x00000158  
    ST:0x00000000
    [I/FAL] Fal(V0.4.0)success
    [I/OTA] RT-Thread OTA package(V0.2.8-beken-1133282d-20220604) initialize success.
    
    
    go os_addr(0x10000)..........
       %  ѵstart addr:0x415418, size:175080
    [Flash]id:0x852015
    [Flash]init over
    sctrl_sta_ps_init
    SDK Rev: 3.0.70 c825378
    [THD]app:[tcb]417718 [stack]415710-417710:8192:5
    [THD]extended_app:[tcb]417f88 [stack]417780-417f80:2048:4
    [THD]idle:[tcb]4183f8 [stack]417ff0-4183f0:1024:0
    [THD]timer_thd:[tcb]419180 [stack]418578-419178:3072:2
    OSK Rev: F-3.0.44 c825378
    cset:0 0 0 0
    Entering initLog()...
    [THD]log_serial:[tcb]419a48 [stack]419240-419a40:2048:2
    Debug:CMD:Adding command loglevel
    Debug:CMD:Adding command logfeature
    Debug:CMD:Adding command logtype
    Debug:CMD:Adding command logdelay
    Debug:CMD:Adding command logport
    Commands registered!
    initLog() done!
    Info:MAIN:Main_Init_Before_Delay
    Debug:CFG:flash vars not initialised - reading
    --write status reg:0,2--
    --write status reg:7c,2--
    --write status reg:0,2--
    

    After ~15 seconds it reboots
    stuck at
    ddev_read(flash_hdl, (char*)data, len - 1, start_addr);


    Added after 1 [hours] 2 [minutes]:

    Works if flashvars are disabled. AP and STA works, setting hostname is not (default: wlan0). Everything else is using bk7231n functions. Disabled functions: drv_ir, drv_ir2, powersave.
    User interface of OpenBK7238 with technical data.

    Added after 1 [minutes]:

    Test binary, flash at 0x0
  • #19 21328139
    insmod
    Level 26  
    GPIO and PWM are working, as is OTA.
  • #22 21328782
    divadiow
    Level 35  
    maybe development with that SDK could lead to BK7231U/S/Q support and BK7251/BK7252 ;)
  • #23 21328903
    insmod
    Level 26  
    Uploaded arduino sdk draft on github. Won't develop it further (as it lack certain things like xTimerPendFunctionCall etc. And while mqtt to lwip is not hard to add, freertos can't be simply recompiles, as it is a customized one).
    >>21328770 This sdk should also support N, and it contains rtos_get_time_us. delay_us, here we come. Wonder if bk7231 i makefile is bk7231t, so a possibility to migrate to it fully, while adding support to bk7231s/u and bk7238.
    Btw, why would we need bk7251/7252? I have only seen them in cameras.
  • ADVERTISEMENT
  • #24 21328911
    divadiow
    Level 35  
    insmod wrote:
    Btw, why would we need bk7251/7252? I have only seen them in cameras.


    Yeh, no reason really, I was getting carried away.

    Added after 1 [minutes]:

    insmod wrote:
    Wonder if bk7231 i makefile is bk7231t, so a possibility to migrate to it fully, while adding support to bk7231s/u and bk7238.


    This is a newer version of BDK used by LT/EspHome (I think) which does support N, T, U etc (to varying degrees?)
  • #25 21328940
    insmod
    Level 26  
    Btw, should matter be developed? This sdk supports it, and beken matter source is publicly available (https://gitlab.bekencorp.com/wifi_pub/matter/connectedhomeip)
    The same sdk, but with history is available here https://gitee.com/belonpeter/beken_freertos_sdk_release/tree/SDK_3.0.70.1
    Can be cloned without registration.

    Added after 2 [hours] 11 [minutes]:

    Several questions before porting.
    Several functions differ from tuya sdks, so they needs to be addressed.
    Assuming the sdk is more or less the same, as arduino bk7238, they should share the problems.
    Looking at the new sdk, several issues can already be solved - powersave, logging.
    Deep sleep is something different - it will have 2 modes - normal mode (600uA), with no need to reconnect to wifi, and idle mode (20uA), but wifi will need to reconnect and i am assuming it is how currently coded in obk. Allow selection via parameter in cmd? But then on obk boot it will try to reconnect in normal mode.
    Partitions differ. I assume they will have to be changed to the current ones?
    Flash vars will probably freeze too.
    SPI DMA
    drv_ir/drv_ir2 (as far as i remember they failed to compile due to something in i2c headers).
    And i haven't tested LFS on bk7238, so unsure if it works ok.
  • #26 21329116
    DeDaMrAz
    Level 20  
    @insmod

    drv_ir2 was a development test for N platform and it can be ignored pretty much (@pkaczmarek2 may share more on that).

    Late for this party but I just ordered 2 boards for 7238 for some testing.
  • #27 21329697
    p.kaczmarek2
    Moderator Smart Home
    Very good progress @insmod , I will try to help soon once my board arrives:
    Screenshot of order confirmation for NiceMCU WB3S modules on the WAVGAT online store platform.


    insmod wrote:
    Btw, should matter be developed? This sdk supports it, and beken matter source is publicly available (https://gitlab.bekencorp.com/wifi_pub/matter/connectedhomeip)
    The same sdk, but with history is available here https://gitee.com/belonpeter/beken_freertos_sdk_release/tree/SDK_3.0.70.1
    Can be cloned without registration.

    Sure, we can have that as a build option in obk_config.h

    insmod wrote:

    logging


    insmod wrote:

    Deep sleep is something different - it will have 2 modes - normal mode (600uA), with no need to reconnect to wifi, and idle mode (20uA), but wifi will need to reconnect and i am assuming it is how currently coded in obk. Allow selection via parameter in cmd? But then on obk boot it will try to reconnect in normal mode.

    We can add command argument for that, but from my experience, people don't want 600uA power save, they already say that devices drains battery fast.


    insmod wrote:

    Partitions differ. I assume they will have to be changed to the current ones?

    Depends on the advantages and disadvantages of each option, for BK7231T vs BK7231N we have two partition tables that are slightly different.

    insmod wrote:

    Flash vars will probably freeze too.

    Why do they freeze?
    I remember that we might have had similiar issue and we added a delayed init and it increased (?) the stability.


    insmod wrote:

    SPI DMA

    Not top priority but good to have. The existing SPI code could also be improved...


    insmod wrote:

    drv_ir/drv_ir2 (as far as i remember they failed to compile due to something in i2c headers).

    Are you sure it's I2C? IR requires only a quick timer in both cases. Like 50us one.
    Helpful post? Buy me a coffee.
  • #28 21331114
    insmod
    Level 26  
    I encountered a very weird bug when porting beken sdk.
    Something is wrong with http, and i don't know what the problem is.
    For example the index page cuts off here NiceMCU XH-WB3S BK7238 Flashing, Testing, Pinout, Development, Porting
    And looking through the inspector is this
    <br>Built on Dec  3 2024 18:22:46 version BK7238_Test

    With no futher data received.
    When trying to access the device through IP (without /index), chromium reports ERR_EMPTY_RESPONSE. Same is for the web app.
    At first, i thought it is something wrong with lwip (default is 2.0.2, and 2.1.2 is not connecting to wifi), but after i ported 2.1.3 from bk7231N sdk, the problem persists.
    Also, if opening some pages it looks almost alright, save "Online for". The page is received fully.
                <br>
                Built on Dec  3 2024 18:22:46 version BK7238_Test<br>
                Online for  <span id="onlineFor" data-initial="180">-</span>
                <br>
                Device MAC: C8:47:8C:30:0E:AC<br>Short name: obk8C300EAC, Chipset BK7238
            </div>
        </body>
    </html>

    Any ideas?
    https://github.com/NonPIayerCharacter/OpenBK7...mmit/9a557468eb5e910c39f3e3b6cdaf97b7f74028e4
  • #29 21331248
    p.kaczmarek2
    Moderator Smart Home
    My dev board is ordered but not yet shipped so my options are limited, but I remember having similiar issue in the past.

    Check the postany source code in the new_http.c , I remember we were trying to buffer TCP packets due to the similiar issue in the past:
    Screenshot of Visual Studio editor with the new_http.c file open.
    The following is not enabled on BL602, as it was not needed. Try using BL602 path, maybe?

    Compare settings of your LWIP and our LWIP:
    https://github.com/openshwprojects/OpenBK7231...378/func/lwip_intf/lwip-2.1.3/port/lwipopts.h
    Assuming that you didn't port them...

    Does the problem still happen if you try to create a test only, simple TCP server and connect to it with Putty? I mean, is problem a generic, TCP-related one, or only occurs in our HTTP server?
    Helpful post? Buy me a coffee.
  • #30 21331410
    insmod
    Level 26  
    >>21331248 BL602 method works, now pages are fully displayed and web app is working.
    As for lwip - there is nothing to compare, i did say i ported it from N sdk, so settings are the same.

Topic summary

The discussion centers on the NiceMCU XH-WB3S development board featuring the BK7238 SoC, initially suspected to be BK7231T but confirmed as BK7238. Users share experiences with flashing, testing, and porting firmware, including challenges with encryption keys, flash IDs, and bootloader compatibility. The BK7238 uses 2MB flash with varying encryption keys per chip, complicating universal firmware flashing. Tools like BKFIL and Easy Flasher (EF) are used for backup and restore, with EF supporting full flash erase and restore including bootloader. Flash ID support was extended to include missing flash chips to avoid CRC errors. Arduino SDK and Beken FreeRTOS SDK (version 3.0.70.1 and newer 3.0.76) are referenced for development, with partial support for BK7238 and related chips (BK7231N, BK7231U, BK7252). Porting efforts include adapting delay functions for 160MHz BK7238, resolving flashvars alignment issues due to 64-bit time_t, and addressing HTTP server and TCP socket stability problems in LWIP. OTA updates are functional but require correct image types and bootloader versions. Power save modes and their impact on peripherals like BL0937 energy meter and DS18B20 sensors are discussed, with some instability noted under power save. SPI flashing and UART flashing methods are compared, with SPI preferred for some devices. BK7231U (CC8000 chip) support is emerging, with builds available but some undefined references and boot issues. BK7252 camera module support is experimental, with encrypted flash complicating firmware use. Users report issues with DS18B20 sensor timing on BK7238 due to delay_us inaccuracies, partially fixed by new SDK delay implementations. Logging and MQTT load affect system stability and sensor reading consistency. The community shares flash dumps, toolchain links, and SDK forks to aid development and testing. Overall, the thread provides detailed technical insights into BK7238-based NiceMCU boards' flashing, SDK porting, peripheral support, and firmware development challenges and progress.
Summary generated by the language model.
ADVERTISEMENT