logo elektroda
logo elektroda
X
logo elektroda

Flashing OpenBeken Firmware on WL2S Module with Lightning LN882HK Chip for ELIVCO LSPA9

sithyoda 32295 180
ADVERTISEMENT
  • #91 20902912
    sweetlilmre
    Level 9  

    @GUTEK@ wrote:
    p.kaczmarek2 wrote:
    I don't have a device to test this yet, but the results are very promising. Who can help with testing?
    I have an aftermarket switch on this chip, to be exact:
    Close-up of a circuit board with visible electronic components. With programming this I won't help, but once you have something ready I can upload and test it.


    Can you try my flash dumping tool on this and share the files?
    -(e)
  • ADVERTISEMENT
  • #92 20903369
    voodoopt
    Level 9  

    I also have this chip.
    How can I do this flash dump? Can you help?
  • #93 20903464
    p.kaczmarek2
    Moderator Smart Home
    A letter has arrived today:
    Electronic module with labels on a black background. Electronic module on yellow fabric background.
    Let's see what I can do with that module. I hope I won't brick it too early, as it's my only one so far!
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #96 20904121
    @GUTEK@
    Level 31  
    >>20902912

    I did a memory dump with your script in python. It takes a very long time to do, about an hour.

    This is a new device, not yet paired with the app. It works with the Cozylife app instead of SmartLife.
  • #97 20904300
    p.kaczmarek2
    Moderator Smart Home
    LN882HK + OpenBeken blink LED (GPIO works!):
    Flashing LED on a breadboard connected to a sensor with wires.
    Helpful post? Buy me a coffee.
  • #98 20904908
    sweetlilmre
    Level 9  

    @GUTEK@ wrote:
    >>20902912

    I did a memory dump with your script in Python. It takes a very long time to do, about an hour.

    This is a new device, not yet paired with the app. It works with the Cozylife app instead of SmartLife.


    Thank you!

    Added after 49 [seconds]:

    p.kaczmarek2 wrote:
    LN882HK + OpenBeken blink LED (GPIO works!):
    Flashing LED on a breadboard connected to a sensor with wires.


    Excellent! We are making progress :)
    -(e)
  • #99 20905873
    p.kaczmarek2
    Moderator Smart Home
    Flash save works! Now only STA creation code is missing for basic functionality.

    I also released flashing guide:
    How to flash LN882H with open source Tasmota/Esphome style firmware - backup procedure included[/size]
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #100 20905937
    sithyoda
    Level 7  
    I just picked a brand new WL2S board from another LSPA9 module and was able to dump the original firmware (dump attached).
    So I guess I soldered everything correctly to the board.

    Unfortunately, I'm still not able to flash OBK. After 3 seconds of heavy rx/tx traffic, the LEDs on my CP2102 module get dark and about 20 seconds later I get: "Fail. Error downloading file."
    After removing A9 and rebooting to normal, I see an SSID called "SmartLife-392D", so I'd say the original flash was not touched at all.

    So I flashed it with my J-Link SWD and can confirm, that this method works. I'm ready to start my tests.
  • #101 20908318
    gloorung
    Level 6  

    Could this be because the baud rate is too high? I had the same error, but the following command solved it for me:

    LN882H_CMD_Tool.exe COMx download flash 115200 0x0 flashimage.bin

    I was able to finish the download and connect to the AP.
  • #102 20908420
    sithyoda
    Level 7  

    Yes, changing the baud rate did the trick.
    Damn, I could have figured that out myself.
  • #103 20908491
    p.kaczmarek2
    Moderator Smart Home
    We're planning to look into STA (connecting to WiFi) support this Monday. This means you can get basic OBK working somewhere in the middle of the week. Then, from the most important functionality, only OTA will be missing.

    Many other features are also missing, like PWM, but I don't think that you need PWM for LSPA9...
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #104 20909469
    sithyoda
    Level 7  

    Thanks, really looking forward to STA implementation.
    Then I will re-solder the module back into the LSPA9 and check what's working.
    OTA would be very nice too, as we wouldn't need to solder anymore for an upgrade.
  • #105 20909558
    p.kaczmarek2
    Moderator Smart Home
    From what I heard, @sweetlilmre got STA working. We will get you a binary soon, but maybe we'll get OTA working first.
    Helpful post? Buy me a coffee.
  • #106 20910704
    sweetlilmre
    Level 9  
    Hi,

    Here is another test image with STA capability and the IO code that @p.kaczmarek2 added.
    I will look at fleshing out the HAL network code and then move onto something else, possibly OTA.

    -(e)
  • #107 20910709
    sweetlilmre
    Level 9  
    >>20908420

    Out of interest, what is the max baud rate you can program at? 115200 must take forever :)
  • #108 20911089
    sithyoda
    Level 7  

    @sweetlilmre Thanks for that. STA works great so far. I will solder the WL2S board back to my LSPA9 tomorrow and see what I can get to work.
    Flashing via UART and 115200 baud takes about 40-45 seconds, which seems reasonable for this amount of data.
  • #109 20911146
    p.kaczmarek2
    Moderator Smart Home
    Considering how close is OTA, I would think twice before soldering back anything.
    https://github.com/sweetlilmre/ln882h/blob/7d...components/ln_at_cmd/ota/ln_at_cmd_ota.c#L247
    Helpful post? Buy me a coffee.
  • #110 20911764
    divadiow
    Level 34  
    Here is my dump and flash images from this device - https://www.elektroda.com/rtvforum/topic4014743.html#20911009

    It took approximately 1 hour 20 minutes to dump, about which chatgpt says:

    For a file of 4,186,112 bytes to be downloaded over serial in approximately 1 hour and 20 minutes, the speed would be around 6977 baud
    so not quick. Being an LN882HKI, I was expecting a 2mb bin, but it's 4mb, so :shrug:

    Screenshot showing a WiFi network named OpenLN882H_C2B4F46E.

    OpenLN882H user interface with configuration and management options.

    A1/P2 is Rel
    B3/P19 is LED_n
    B8/P24 is Btn
  • #111 20911972
    p.kaczmarek2
    Moderator Smart Home
    Can you submit a full template so we can add it to our list?
    https://openbekeniot.github.io/webapp/devicesList.html
    Helpful post? Buy me a coffee.
  • #112 20911994
    divadiow
    Level 34  
    Yes. It took me ages to find the relay for some reason.

    Code: JSON
    Log in, to see the code
  • #113 20912035
    sweetlilmre
    Level 9  
    divadiow wrote:
    Here is my dump and flash images from this device - https://www.elektroda.com/rtvforum/topic4014743.html#20911009

    It took approximately 1 hour 20 minutes to dump, about which chatgpt says:

    For a file of 4,186,112 bytes to be downloaded over serial in approximately 1 hour and 20 minutes, the speed would be around 6977 baud
    so not quick. Being an LN882HKI, I was expecting a 2mb bin, but it's 4mb, so :shrug:



    The script will dump until it errors. I thought there was 4MB flash on these units, possibly it's wrapping or doing something strange.
    You can always specify a range parameter eg 0x200000 for the script.

    -(e)


    Added after 1 [hours] 27 [minutes]:

    Ok confirmed, from 0x00200000 onwards this is a mirror of the data from 0x00000000 to 0x00200000

    (same for this dump: https://www.elektroda.com/rtvforum/topic4008545-90.html#20905937)

    So for future you can specify 0x00200000 as the flash size in the dumping tool.
    I will put this in GH somewhere and probably amend the script to default to 0x00200000.

    Thank you for the dump.

    -(e)
  • #114 20912470
    divadiow
    Level 34  

    Oh cool.

    Thanks for checking. What did you use to analyze the dump, by the way?

    I wonder what would happen if I tried to flash it back to that dump.
  • #115 20912503
    sweetlilmre
    Level 9  

    divadiow wrote:
    Oh cool.

    Thanks for checking. What did you use to analyze the dump, by the way?

    I wonder what would happen if I tried to flash it back to that dump.


    If you chop the file size to 0x00200000 (2MiB or 2097152 bytes) and discard the remainder, it should work.
    In fact, if you could test this, that would be fantastic.

    I would:
    - Split the file in 2 using something like HxD at the 0x00200000 mark,
    - Take the first file and examine it; there should be tons of FF bytes at the end
    - Trim this file to the last 4K boundary that contains FF's
    - Reflash and see what happens

    But just splitting off everything above 0x00200000 should do the trick

    -(e)
  • #116 20912510
    divadiow
    Level 34  
    Sure. Will have a go tonight

    Added after 5 [hours] 41 [minutes]:

    >>20912503

    ah yes. I see the code repeat, and...

    success!

    I made a new bin of 0 - 0x00200000 code only then trimmed FF down to and including 0x000B8000 because 0x000B8000 is the next 4k (I think?). FF starts here:

    Screenshot of a hex editor displaying data inside a binary file with a highlighted value.
    Screenshot of a hexadecimal editor with open binary files showing stored data as FF strings.

    I flashed the trimmed bin, which only took a few seconds, then repowered with no BOOT low. The Cozylife log output as expected

    [17:40:15.414] - serial type is general
    [17:40:15.478] - Open COM9 Success
    [17:40:18.348] - ------  wifi_mcu_basic_example  ------
    [17:40:18.884] - TCP/IP initialized.
    [17:40:18.887] - LN882H SDK Ver: 2.1_rc1 [build time:Nov 28 2023 09:34:26][0x02010001]
    [17:40:18.889] -     ____               _     _  __
    [17:40:18.890] -    / ___|___ _____   _| |   (_)/ _| ___
    [17:40:18.895] -   | |   / _ \_  / | | | |   | | |_ / _ \
    [17:40:18.897] -   | |__| (_) / /| |_| | |___| |  _|  __/
    [17:40:18.898] -    \____\___/___|\__, |_____|_|_|  \___|
    [17:40:18.900] -                  |___/
    [17:40:18.900] - cozylife_app_info
    [17:40:18.901] - CozyLife SDK Version: 0.6.0
    [17:40:18.902] - CozyLife SDK Build Nov 28 2023 09:34:21
    [17:40:18.903] - cozylife_app_info
    [17:40:18.905] - Product Id: iy9fT1
    [17:40:18.906] - Firmware Version: 1.0.2
    [17:40:18.911] - Firmware Build Nov 28 2023 09:34:28
    [17:40:18.912] - device id:
    [17:40:18.914] - 1609473600 [L] [     lib_log] udplog_init on: 0, 192.168.2.2:7789
    [17:40:19.128] - 1609473600 [L] [     lib_ble] ble mac: f0:bf:b2:c2:50:00
    [17:40:19.131] - [BLIB_I]BLIB Ver: 1.0.5 [build time:Aug  7 2023 17:33:27][0x010005ff]
    [17:40:19.134] - 1609473600 [L] [     lib_ble] bt_event_bleenabled
    [17:40:19.137] - [WLIB_I]cap_comp = 0, xtal_capbank_tab:[0]:40 [1]:35 [2]:35 [3]:35 [4]:50 [5]:70 [6]:70 [7]:70
    [17:40:19.139] - [WLIB_I][original]phy_tab_1f:0x4C, phy_tab_20:0x3C
    [17:40:19.143] - [WLIB_I][efuse]phy_tab_1f:0x4C, phy_tab_20:0x3C
    [17:40:19.147] - [WLIB_I][flash]phy_tab_1f:0x4C, phy_tab_20:0x3C, tx_pwr_comp_all=0, tx_pwr_comp_b=0, tx_pwr_comp_gn=0
    [17:40:19.150] - [WLIB_I]==>temp_sect:2,phy_tab_1f:0x4C,phy_tab_20:0x3C
    [17:40:19.151] - [WLIB_I]<==temp_sect:2,phy_tab_1f:0x4C,phy_tab_20:0x3C
    [17:40:19.156] - [WLIB_I]LN882H WiFi Lib Ver: 1.3.0 [build time:Oct  8 2023 11:17:49][0x010300ff][for Cozylife Commit-a353a99a]
    [17:40:19.157] - [WLIB_I]STA_Startup.
    [17:40:19.160] - [WLIB_I]Disconnected.
    [17:40:19.160] - [WLIB_E]HwEr:UKI:0
    [17:40:19.161] - STA startup!


    and the device LED was flashing waiting for new pairing. I paired with the Cozylife app to confirm details and operation of relay was as expected. RESULT!

    Smart Switch app interface with power toggle button and status Socket closed.
    Screenshot of device information from the app, showing device ID, signal strength, and firmware version.
    Device adding app screen with nearby device search in pairing mode.
  • #117 20913432
    sweetlilmre
    Level 9  
    Excellent!
    Devices can be restored to stock :)

    -(e)
  • #119 20913952
    p.kaczmarek2
    Moderator Smart Home
    No, as there are no flash vars (there is only flashconfig implemented). We could add flash vars very easily but we kinda wanted to consider doing it in more optimal way so it's still pending
    Helpful post? Buy me a coffee.
  • #120 20914464
    divadiow
    Level 34  

    Somehow I messed up the wifi and it was no longer broadcasting OpenLNxxx, even after re-flashing and reboots. Flashing back to stock also made it discoverable in the Cozylife app (maybe this is just the bluetooth bit?), but it would not complete the setup on any of my 2.4Ghz networks (always with wifi setup failed type error in app). Switched firmware back and forth a few times.

    Finally fixed with an erase of flash then a fresh OpenLN flash.

    -power up with BOOT low as normal
    -switch to RAMCODE mode with
    LN882H_CMD_Tool.exe COM9 download ram 0x20000000 .ConfigLN882H_RAM_BIN.bin

    -confirm boot mode changed to ramcode mode with
    LN882H_CMD_Tool.exe COM9 mode read

    -erase all flash with
    LN882H_CMD_Tool.exe COM9 flash erase_all

    -flash OpenLN as normal with
    LN882H_CMD_Tool.exe COM9 download flash 2000000 0x0 flashimage.bin


    Added after 19 [minutes]:

    different mac address now

    Screenshot of OpenLN882H_C25E1088 interface with configuration options.

Topic summary

The discussion revolves around flashing OpenBeken firmware on the ELIVCO LSPA9 module, which utilizes the WL2S microcontroller and the LIGHTNING LN882HK chip. Users share their experiences with UART and JTAG flashing methods, debugging issues, and the challenges of obtaining and compiling the necessary firmware. Several users successfully managed to flash the firmware, enabling functionalities such as WiFi connectivity and relay control. The conversation also touches on power consumption, temperature management, and the implementation of power-saving features. Additionally, users discuss the integration of the BL0937 power metering chip and the development of a comprehensive template for the device.
Summary generated by the language model.
ADVERTISEMENT