logo elektroda
logo elektroda
X
logo elektroda

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

sithyoda 33840 180
ADVERTISEMENT
  • #31 20845615
    p.kaczmarek2
    Moderator Smart Home
    It may sound complicated, but it's very easy.

    Let's consider this file:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/hal/w800/hal_wifi_w800.c
    There you can find AP setup function:
    Code: C / C++
    Log in, to see the code

    The demo_create_softap call is for W800/W600, when porting to new platform, you just replace it with the AP call for the new platform, so it creates AP.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #32 20847586
    sithyoda
    Level 7  

    I'm afraid, this is far beyond my C abilities.
    Maybe someone else can help out.
  • #34 20865232
    p.kaczmarek2
    Moderator Smart Home
    I could maybe try to help more, but I don't have any LN882HK devices, and from what I read here, it's possible that I would also need extra programming tool..
    Helpful post? Buy me a coffee.
  • #35 20866840
    sithyoda
    Level 7  

    I expect that there is a way to flash it via UART as well. But as long as I don't have an openbk image, I don't want to spend too much time on finding out how to do that.

    @p.kaczmarek2 I could prepare a virtual machine with KEIL IDE setup and an example project that compiles on a mouse click. Would you assist in adding openbk source files so that it compiles?
  • #36 20866928
    p.kaczmarek2
    Moderator Smart Home
    Sure, that's a good idea, just think how would you later send it to me?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #37 20866993
    sithyoda
    Level 7  

    Yup, we'll get that working. I'll send you the download link as soon as I have the VM ready.
  • #39 20874075
    p.kaczmarek2
    Moderator Smart Home
    What kind of tools are there? Any bootloader UART stuff?
    Helpful post? Buy me a coffee.
  • #40 20874405
    sithyoda
    Level 7  
    Just to keep the participants informed: I use this Segger J-Link V9 for flashing my LN882H. Bought the device some years ago for about 20 US$.
    It can handle lots of different chips and software support is great. In the meantime there might be even cheaper clones available.


    Hinzugefügt nach 2 [Stunden] 19 [Minuten]:

    voodoopt wrote:
    I ended up finding this repository with recent information and several SDKs.https://github.com/Ai-Thinker-Open/aithinker_dev_open_sdk

    Nice find.
    Were you able to compile one of the examples for ln882h chip?
  • #41 20876570
    voodoopt
    Level 9  

    I don't have programming skills.
    But the repository seems to have examples.
    application/wifi_demo/vendor/ln882h
  • ADVERTISEMENT
  • #43 20883354
    sweetlilmre
    Level 9  

    >>20826073

    Hi,

    @sithyoda

    I have the SDK setup with GCC and can build examples.
    I would like to try flashing this with my Segger J-Link Plus. I'm a little confused with your wiring diagram.
    VTRef from docs is supposed to be supplied with the target voltage, where you have it connected to the 3.3V input for the board.
    Are you setting something specifically to override standard VTRef behavior?

    I can just try and solder this up, but clarification would be helpful.
    I do have quite a bit of C experience and following this thread, I think I can probably get the OpenBeken firmware compiling for this board.

    I'll solder up the chip in the meantime.
    Thanks
    -(e)
  • #44 20883407
    sithyoda
    Level 7  

    @sweetlilmre Great news!
    Well, to be honest, I did not read a lot of the documentation from the Segger. I searched for a pinout and all I found was a schematic with pins VTRef and 5V.
    So I just measured the voltage of VTRef and found out that it's 3.3V on it (even though it's supposed to be an input). This is the reason I connected it to my WL2S module 3.3V.
    Gave it a shot and it worked right away.
  • ADVERTISEMENT
  • #45 20883431
    sweetlilmre
    Level 9  

    sithyoda wrote:
    @sweetlilmre Great news!
    Well, to be honest, I did not read a lot of the documentation from the Segger. I searched for a pinout and all I found was a schematic with pins VTRef and 5V.
    So I just measured the voltage of VTRef and found out that it's 3.3V on it (even though it's supposed to be an input). This is the reason I connected it to my WL2S module 3.3V.
    Gave it a shot and it worked right away.


    I've just wired mine up and the device is not detected. Seems like VTRef is not going to work for me on this J-Link Plus.
    Let me do some searching and see what I can find out.

    @sithyoda

    I've wired up TX1, 3.3V, and ground, but am getting junk on the serial line.
    What baud rate, etc., did you use? I assumed 115200.

    Answering my own question, the baud rate is 921600.

    That was unexpected.

    I can connect via JTAG now. I'm powering the device via a USB->Serial board and bridging VCC to VTRef (and GND between the board and the J-Link).

    -(e)
  • #46 20886163
    sweetlilmre
    Level 9  
    I've been experimenting further and attempting to dump the flash off the chip, first as a fallback mechanism and then for potential R.E. purposes.
    I have a 128KB dump, haven't looked too much further, but this seems promising.

    Happy New Year everyone
    -(e)

    Added after 6 [hours] 39 [minutes]:

    protectivedad wrote:

    I can put it into burning mode and get responses from it.


    I've been trying to get burning mode working by grounding GPIOA9. This results in no output from either TX1 or TX0. Do you have any pointers for me? Should I see something on boot / after grounding EN? (I haven't connected any RX lines yet, so can't enter anything, was expecting at least some output first)

    Thanks
    -(e)
  • #47 20887379
    protectivedad
    Level 7  

    sweetlilmre wrote:
    I've been trying to get burning mode working by grounding GPIOA9. This results in no output from either TX1 or TX0. Do you have any pointers for me? Should I see something on boot / after grounding EN? (I haven't connected any RX lines yet, so can't enter anything, was expecting at least some output first)

    I had posted about the AI-Thinker GitHub on the first page https://www.elektroda.com/rtvforum/topic4008545.html#20840280 but no one seemed too interested, so I never bothered to post about the other things. The UART programming tools can be found on gitee.com. Search for ln882h; the company has a dozen repos there. You can use git to clone them. I used Google Translate to translate the names and some spreadsheets (they like spreadsheets as a document source). One of the repos has a Windows command line program `LN882H_CMD_Tool.exe` that can be used to flash using UART. I used the tool, the AI-Thinker examples on GitHub with an updated SDK (version 2.0) from a gitee repo to compile firmware. I merged the MQTT/OTA samples to create firmware that would connect to my MQTT using TLS, allows me to control it using the MQTT and OTA new firmware onto the device. It's not Tasmota or OpenBeken, but it does what I need. I updated all my mini-switches, but I haven't used them yet. Good luck.

    Oh, it's been a while since I did this, so I forgot you will need to switch between UART0 and UART1 unless you have two TTY devices. The UART0 is for programming and AT commands, the UART1 is for log information during normal boot. Since AI-Thinker and the LN882H SDK use different logging, I was never able to consolidate them nicely, so I could use only one UART. If I go back to my firmware, I might clean it up and upload it, but I have other projects right now.

    Also, I had the problem where my "ENTER" only sent the '/n' and to get proper responses from the AT commands, you need both '/n/r' which caused me some headaches.
  • #48 20887640
    sithyoda
    Level 7  

    @protectivedad Of course I noticed your post and also gave it a try on a fresh installed Debian 12 machine.
    Unfortunately, it does not compile here, maybe due to a lack of experience on my side with such big projects.

    I was not yet able to find the LN882H_CMD_Tool.exe in the files. Would you please share it with us? I will then try to upload a compiled example from ln882's SDK via UART.
    If this works, the use of a J-Link wouldn't be necessary anymore.
  • Helpful post
    #49 20887799
    protectivedad
    Level 7  

    sithyoda wrote:
    @protectivedad Of course I noticed your post and also gave it a try on a fresh installed Debian 12 machine.

    I use Ubuntu 22.04, can't remember if I needed to do anything special. I found the AI-Thinker easier to compile and they had a lot more detailed examples.

    sithyoda wrote:
    I was not yet able to find the LN882H_CMD_Tool.exe in the files. Would you please share it with us? I will then try to upload a compiled example from ln882's SDK via UART.

    It's in https://gitee.com/lightningsemi/ln882h-document-collection. It is in a zip file in the "4." directory. If you translate the names, I believe it is "4. Burning Tools".

    I attached a machine-translated spreadsheet instructions.
  • #50 20887806
    sweetlilmre
    Level 9  
    sithyoda wrote:
    @protectivedad Of course I noticed your post and also gave it a try on a fresh installed Debian 12 machine.
    Unfortunately, it does not compile here, maybe due to lack of experience from my side with such big projects.

    I was not yet able to find the LN882H_CMD_Tool.exe in the files. Would you please share it with us? I will then try to upload a compiled example from ln882's SDK via UART.
    If this works, the use of a J-Link wouldn't be necessary anymore.


    This repo: https://gitee.com/lightningsemi/ln882h-document-collection
    The directory called: 4.烧录工具 has reference to "burning tools".

    There is a bulk burning tool: ln_download_tool_V2.0.1.zip with a manual (use Google Translate on the PDF).
    LN882H_CMD_Tool is in LN882H命令行工具_V1.0.16.zip. This allows all sorts of interesting communication with the chip.

    Thanks
    -(e)

    Added after 2 [minutes]:

    Damn @protectivedad beat me to it!

    Thanks for the translated Excel doc, I was busy doing that as I was replying! :)

    Added after 10 [minutes]:

    That repo also has the full English datasheet.


    Added after 3 [hours] 15 [minutes]:

    I dumped well over a megabyte of flash via the LN882H_CMD_Tool using a python script, at about 256 bytes a second LOL.
    The tool will only let you dump 256 byte blocks. I have no idea if this is a legitimate flash dump, but will be interesting to have a look at.
    It seems flash is not protected, which is good, but this dump differs significantly from the one I did via J-Link.

    At this point I think I'm ready to start flashing some new firmware and getting back to look at the openbeken build.
    -(e)
  • #51 20889185
    sweetlilmre
    Level 9  

    Further progress, I can flash via burn mode or J-Flash successfully off of binaries built under GCC.
    The "combo_mcu_basic_example" from the ln882 SDK works and connects to my AP.
    I've started looking into the SDK build system and putting together a CMakeLists.txt to try and include the OpenBeken app source.
    Once I can get something completely stubbed building, then I'll look into wrapping the HAL functions.

    -(e)
  • #52 20889213
    p.kaczmarek2
    Moderator Smart Home
    Great news! Is the burn mode possible via UART only?
    Helpful post? Buy me a coffee.
  • #53 20890799
    Princeton007
    Level 2  

    @p.kaczmarek2 I also had this module, and have replaced it with an ESP-02S and Tasmota. I don't need it, if you want to have the module, let me know, I can send it.
  • #54 20890800
    p.kaczmarek2
    Moderator Smart Home
    That would be great, of course, under assumption that we can get UART flashing working. I could help much more if I will be able test on physical device. Are you from Germany? I'm from Poland, so sending module in a letter shouldn't be that expensive.
    Helpful post? Buy me a coffee.
  • #55 20890819
    Princeton007
    Level 2  
    @p.kaczmarek2 I sent you a PN
  • #56 20890850
    p.kaczmarek2
    Moderator Smart Home
    Thank you, so it seems I will have this module soon, now the question is, can we flash it via UART?
    Helpful post? Buy me a coffee.
  • #57 20891066
    sweetlilmre
    Level 9  

    Hi,

    So by shorting GPIOA9 and using the tool mentioned above, you can flash over TX0/RX0.

    The module requires specific code loaded into RAM in order to flash it (either via UART or SWD). This is why the tool is required. A bootloader could be developed to enable flashing without the tool, but that is another story.

    I am away on leave at the moment but would like to discuss the porting process. Defining another platform seems to require many changes to add e.g. PLATFORM_LN822H to various .h and .c files, and not just sorting out the HAL layer. I've spent about 8h on this so far and made some progress, but there are many oddities, probably related to my lack of familiarity with the platform.

    -(e)
  • #58 20891087
    p.kaczmarek2
    Moderator Smart Home
    Are you saying that I still need SWD to flash it for the first time? So there is not bootloader left by Tuya?

    How can I help you with flashing process? The basic approach is to stub everything with #ifdef and then gradually fill the missing pieces of code, first with main call, then with every second timer, then log output and check if it prints, then with WiFi calls, etc. Feel free to ask any specific questions, I will do my best to help. I think you could also push your existing code to Github so I can give some feedback.
    Helpful post? Buy me a coffee.
  • #59 20891275
    sweetlilmre
    Level 9  

    No, I'm saying you can absolutely flash it via UART. You have to ground GPIOA9 and you have to use the download tool linked above.

    When I get back, I'll clone the App repo and push my changes up and we can discuss from there.

    Added after 2 [minutes]:

    Connect TX0 and RX0 to your USB UART, ground GPIOA9 and use LN882H_CMD_Tool to write the flash binary.

    Added after 1 [minutes]:

    Get the tool and instructions attached to this post:
    https://www.elektroda.com/rtvforum/topic4008545-30.html#20887799

    Added after 3 [minutes]:

    Format would be something like:
    LN882H_CMD_Tool.exe COMx download flash 115200 0x00000000 flashfile.bin

    Replace COMx with your comport and flashfile.bin with the binary to flash
  • #60 20891503
    p.kaczmarek2
    Moderator Smart Home
    And how to make original firmware backup?

    I will help you as soon as I get this chip.

    I've made backups of LN882HK repositories from gitee:
    List of compressed files from Gitee displayed in the browser.
    Helpful post? Buy me a coffee.

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