Elektroda.com
Elektroda.com
X

W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial

p.kaczmarek2 7704 16
This content has been translated flag-pl » flag-en View the original version here.
  • W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Hello, today I will present how to tame another Chinese WiFi + Bluetooth microcontroller, the W800-C400 produced by WinnerMicro. At the moment, you can buy it for about 3$, while the development board costs about 5$ and both of these prices already include the shipment. Of course, I will not use such a board here, but continuing my tradition I will use an IoT / Tuya device just built on the W800-C400, more specifically the RGB LED strip controller.
    The WinnerMicro chips themselves have already been mentioned several times in the "News" section of our forum, you can also check out these topics:
    HLK-W801 board with microcontroller based on Alibaba Xuantie XT804 core
    Air602 - Module with Wi-Fi on SoC Winner Micro W600
    W806 - prototype board with WinnerMicro W806 for PLN 8
    NOTE - this topic assumes basic knowledge of C and basically focuses on just starting the W800-C400, without explaining the basics. In addition, I also expect that the user can look for himself in the code or on the Internet, for example, create a thread on this platform and so on ...

    RGB LED strip controller used
    For starters, I recommend reading the previous topic in the series:
    WiFi / IR LED strip - WX300P - music mode - hidden buttons [W800-C400]
    As a reminder, photos of the tile:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial

    What else will you need?
    When you buy a dedicated development board, you don't need it (because it is already on dev board), but as I will program it in IoT device, so I will also need an external USB to UART converter. Basically like in ESP and all similar microcontrollers ...
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Here are the necessary connections:
    - RX converter to TX PCB
    - Converter TX to PCB RX
    - mass to mass
    - 5V power supply from USB to the board's power input (not 3.3V, because it will burn the board. There is a step down converter on the board, I give 5V to its input)
    - in addition, on this UART USB converter I give a jumper between VDD and 3.3V to select the logical levels of 3.3V
    - [optional] we can also solder the cable to the RESET pad from the board and reset the board by touching it to the ground, it will reboot, but you can also simply reset it by disconnecting the power supply ...

    This is what it looks like in practice:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorialW800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Let me remind you - I take 5V directly from the USB, not from the "5V" pin on this dongle, because the 5V pin there is used to select logical levels and it never wanted to act reliably as a power source.


    SDK repository from Github
    The W800 SDK is available for free on the web. Just download them. I used the SDK available at:
    https://github.com/List-View/wm_sdk_w800
    There is also a firmware upload program - compiled Windows binary, wm_tool.exe.
    I used a GUI addon for GIT - SourceTree to download the repository.

    IDE and W800-C400 compiler
    In addition to the SDK, you need to download the compiler and development environment separately.
    You have everything ready in the form of one installer for Windows. The IDE is simply a wrapper for Eclipse, which you may already know from other microcontrollers or even from writing Java applications.
    IDE is called CDS and download them from here:
    https://occ.t-head.cn/community/download
    This requires registration!
    The file I downloaded was named: cds-windows-mingw-elf_tools-V5.2.11-20220512-2012.zip
    After installation, we should get a path of this type:
    
    W:\C-Sky\CDS
    

    Folder content:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Now open the IDEs folder:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    cds-wb-win32.exe runs our development environment.
    For formalities, the CDS version I used is:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Quote:

    C-Sky Development Suite for CK-CPU C / C ++ Developers (V5.2.11 B20220512)

    csky-elf-tools Version: gcc version 6.3.0 (T-HEAD C-SKY Tools V3.10.29 Minilibc abiv1 B20210423)
    csky-elfabiv2-tools Version: gcc version 6.3.0 (T-HEAD C-SKY Tools V3.10.29 Minilibc abiv2 B20210423)
    riscv64-unknown-elf-tools Version: gcc version 10.2.0 (Xuantie-900 elf newlib gcc Toolchain V2.4.0 B-20220427)
    cskysim Version: cskysim v3.8.15 (QEMU V6.1.0) B20220414
    CPF Version: cpf version 3.4.4 B20220414
    DebugServer Version: 5.14.03 (Build: May 12 2022)

    Copyright (c) 2010-2022 Hangzhou C-Sky Microsystems Co., ltd. All rights reserved.
    Visit https://occ.t-head.cn/


    First compilation in CDS
    You already have an open IDE - now you are opening the project.
    Project-> Open Multi Project Workspace
    Open the project file from the downloaded SDK: W: \ GIT \ wm_sdk_w800 \ tools \ w800 \ projects \ SDK_Project \ project \ CDS
    The project will be imported and you will get the following effect:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    In Project Explorer, you can now view files with C code:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    You can compile via build:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    It should go without problems:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Here are the results:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial


    Uploading a firmware by wm_tool.exe
    wm_tool.exe is in the tools folder of the downloaded SDK.
    This is, of course, a command line utility.
    It's like "esptool.py", you could say, simplified to say, how someone knows ESP.
    It allows, among others. upload the firmware via UART.
    Here the usage information of wm_tool.exee:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    To upload the firmware, give the path to the FLS file and select our COM port (virtual):
    wm_tool.exe -c COM9 -dl W: \ GIT \ wm_sdk_w800 \ bin \ w800 \ w800.fls
    So we execute this command and get:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Now you have to reboot the device - either via the RESET signal or by cutting and connecting the power supply.
    It is programmed:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    There is no need to worry about the 0% progress visible for the entire programming time, the program just does not refresh this counter.

    Structure of a demonstration project
    Let's analyze what is happening and where.
    Of course, I won't go into what happens before "main" call, because here I am describing the basics.
    main calls CreateDemoTask :
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    CreateDemoTask is in wm_demo_console_task.c :
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    This is basically the UART command line from which you can run demos.
    Wm_demo_console_task.c also has its parsing, command tokenization, and so on.
    In turn, wm_demo_console.h has a table of all demos and their commands:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    There is also a configuration file - wm_demo.h.
    And here CAUTION - demos are by default disabled, they must be enabled by changing one OFF to ON :
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    It is supposed to be DEMO_ON, the default is OFF. Without this, the demo console will not start!
    You also need to run separate demos that interest us:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    It's time to recompile the firmware and upload to the W800.

    Demonstration program
    After uploading the firmware , you must perform a RESET (reboot) for the program to start working.
    Now communicate with the device on baud 115200.
    At the start you get:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    (maybe apart from the hello world message, I wrote it myself in main () for the test)
    Let's send the "demohelp" command, but without the CRLF (newline, carriage backspace):
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Well, it's the same message, but it works.
    Let's try t-scan:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    It works!
    Out of curiosity - the demo code is in wm_scan_demo.c.
    Here is the most important excerpt:
    Code: c
    Log in, to see the code

    Let's try to run a demo of creating a WiFi access point:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Was there a problem? Yes, but the message does not explain it.
    A glance at the demo table shows that you still need to provide some arguments:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Let's take a look at the appropriate file, what are the arguments ...
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    There is a bit of it. You still need to scroll down to find out exactly what we need to enter, what the next numerical values mean, e.g. the encrypt parameter:
    Code: c
    Log in, to see the code

    You have been triggering a command, but it's not that simple either.
    I tried like this:
    
     t-softap MyTestWiFi Password123 25 0 0
    

    But it didn't work.
    A glance at command parsing explained it all. Parentheses and commas:
    
    t-softap(MyTestWiFi,Password123,25,0,0)
    

    Very interesting command format, I don't see it often.
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    It works:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial


    GPIO, PWM, Flash and others
    There are many demos for the basic usage of this microcontroller. You can easily find demos for GPIO, PWM, Flash memory access and much more.
    For example, wm_gpio_demo.c:
    Code: c
    Log in, to see the code

    Or wm_flash_demo.c:
    Code: c
    Log in, to see the code

    Or you can also look at other SDKs, for example for the Arduino port, here:
    https://github.com/w600/arduino/blob/master/cores/w600/core_w600_wiring_pwm.c
    (This is for the W600 but these platforms are somewhat similar)

    Firmware update via WiFi
    The last thing I will show is the firmware update via WiFi, i.e. OTA - Over The Air upgrade.
    In this case, the OTA client is ready, it is more precisely the HTTP client that downloads the firmware file from the given URL.
    So we must have a server. You could use the Xampp package from Apache, for example, but why complicate things?
    A more convenient option is Node-red because it can be scripted to serve us a file directly from the compilation folder via a virtual path.
    Alone Node-red I won't describe here, but this is what my nodes look like:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Node catches the GET request and then processes it in the Function node:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    Here, I take the name of the file from the path and retrieve it from the disk. It is important that the ReadFile node reads it as a binary buffer and not, for example, UTF8:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    After making changes to Node-Red, remember to click Deploy.
    From now on, my machine has an HTTP Node-red server and after entering the address:
    
    http://192.168.0.118:1880/w800/w800_ota.img
    

    returns the given file to me from the folder with the SDK.
    Now the question is what on the side of the SDK ... one function is enough:
    Code: c
    Log in, to see the code

    The system will download the update automatically and restart the W800.
    Ready!

    Practical advices
    I won't cover C programming itself here, but there are a few things worth mentioning. First of all, this SDK is based on FreeRTOS, which is missing a few things - it's worth configuring yourself.
    - in FreeRTOSConfig.h I recommend to enable mutexes - #define configUSE_MUTEXES 1
    - in FreeRTOSConfig.h I recommend to turn on heap management, because without it we have to point to the heap ourselves when creating a thread - #define configUSE_HEAP2 1
    - but the heap_4 (with defragmentation) algorithm would be better, not present in the heap_2 SDK, but this one is not available ... if we allocate memory often, it would be worth moving the SDK to newer FreeRTOS
    - in FreeRTOSConfig.h I recommend increasing the size of the buffer for heap allocation - #define configTOTAL_HEAP_SIZE ((size_t) 48 * 1024)
    - the SDK includes the lwip2.0.3 library (Lightweight TCP / IP stack), but only basic functionalities such as sockets, DHCP are used from it. If we want to use, for example, the MQTT client, it should be added separately to the sources
    - remember that if we have an IDE (these magic CDS), we do not need to edit the Makefile, just add the file to the project in CDS, it is already included in the compilation
    - MQTT with lwip 2.0.3 (or there 2.0.2) has the problem that I have already mentioned several times in other topics, that it does not take into account the MQTT password / username. You should add a few missing lines or copy the corrected version from me:
    https://raw.githubusercontent.com/openshwprojects/OpenBK7231T/2c3af1f719cb5d52f3a9442bc0ec4439cac1d389/platforms/bk7231t/bk7231t_os/beken378/func/lwip_intftt/lwip_intftt/lwip_appq.2
    - WinnerMicro build configuration is in wm_config.h


    W800 port for OpenBeken
    Of course my firmware (Tasmota / Esphome replacement) for other WiFi platforms found in IoT devices it has already been ported to the W800. There weren't a lot of problems with that. At the moment it looks like this:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    The pin configurator, MQTT, also works:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    And OTA:
    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial
    My firmware port for this platform is fully functional at the moment

    Summary
    Another WiFi / Bluetooth microcontroller running - and this time it wasn't that hard at all. It is true that I do not know any reliable English source about it, but the SDK did not have such a mess that it would not be able to run it. Even the update of the firmware via WiFi was achieved (OTA), and this is something very useful for both development and end users.
    I liked the fact that there were no problems with the compiler and toolchain, everything was ready in one install, including the IDE.
    The related W600 also has its own port for Arduino, available here:
    https://github.com/w600/arduino
    but I haven't tested it yet and I don't know how much the W600 differs from the W800 either. Nevertheless, I also plan to add W600 support to my firmware, all in good time.
    That's it for now, and now I will ask if anyone has played with the platforms yet W600 or W800 ? I don't think I'm going to go any further, I developed the W800 just enough to be able to pair my WX300P LED strip from Home Assistant, but who knows ...
    I attach some interesting materials about the W800 / W600, including a repo packed with a flasher (wm_tool.exe) in a zip, as well as materials from the manufacturer that I did not describe here, including a slightly newer SDK (2021 12 03)

    Cool? Ranking DIY
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 5843 posts with rating 5827, helped 279 times. Been with us since 2014 year.
  • #2
    khoam
    Level 42  
    Quote:
    Of course, my firmware (Tasmota / Esphome replacement)

    This is not a replacement for ESPHome or Tasmota as they are dedicated to ESP systems only. Tasmota can be a "replacement" for ESPHome or vice versa.
    In addition, this OpenBekon does not even have 5% Tasmot functionality - perhaps in some small part it has similar functionality on other MCUs, but this does not entitle the use of the term "replacement".
  • #3
    miszcz310
    Level 23  
    Okay, that's fine. I just have this question. Is there any way to make gdb talk about this? In the sense of some j-tag, or something like that? Is it just "debugging" like printf on uart?
  • #4
    p.kaczmarek2
    Moderator Smart Home
    I started my adventure with the W800 two days ago, so it is difficult for me to say something more about J-TAG or GDB in combination with it. You have to look in Chinese documentation. When searching, you can also include materials about the W801, because it is basically the same system (W800 is a reduced version).

    Basically, I would rather not worry about the lack of such debugging, I do not associate the future with these uncertain systems, I just add support for these platforms to my firmware to help Tasmota / Esphome firmware users who bought them expecting there will be ESP inside. In the case of this LED strip, even such a user would not be able to solder the module, moreover, it is probably known that soldering (and buying a new module with ESP) costs money. I also work with these users on an ongoing basis and add functionalities that are actually required by them, also remotely. Some time ago I implemented one driver for a user from Australia, they program its sockets via the Internet via OTA.

    EDIT: A glance at the IDE used tells me that they have OpenOCD (debugger) and even QEmu (emulator) support, but I can't be sure it's functional. I didn't have such problems with porting that I had to debug deeper.
  • #5
    khoam
    Level 42  
    miszcz310 wrote:
    Is there any way to make gdb talk about this?

    CK-LINK. But the available documentation on the net on this subject is only in Chinese. The debugger itself can be done by yourself. Project on STM32: Link Link
  • #6
    miszcz310
    Level 23  
    Dear!
    Thank you very much for the answers, the module has been ordered and the search has started (for some possible non-Chinese documentation).
    I also realized that I actually did offtop, so sorry and best regards!
  • #7
    blakadder
    Level 6  
    Successfully flashed to a HLK-W801-KIT_V1.1 development board. Had to erase flash first when using `wm_tool.exe -c COM3 -eo all` otherwise the chip stayed in download state sending `C`'s

    Also completed a flash using the WinnerMicro GUI tool Upgrade_Tools_V1.4.18.exe, sadly in chinese only, using 2000000 baud rate.

    There are some errors in the Configure Module section in the web UI.

    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial

    This development board has LEDs connected to some PBs that are not exposed for configuration in the UI.

    Webapp, on the other hand, shows the pins but the configuration doesn't seem to do anything.

    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial

    Attachment has the schematic for V1.0 of the board. Downloaded from ]Link
  • #8
    blakadder
    Level 6  
    HLK-W800-PLUS development board. Came with demo Tuya firmware which was recognised and added in the Smart Life app.

    Flashed with OpenW800 firmware v1.1.2.44.

    Has an onboard RGB LED that doesn't work with this pin assignment (pin connections checked with multimeter)

    W800-C400 WiFi/BT microcontroller programming - wm_sdk_w800 tutorial

    Also has a, previously unknown to me, CHT8305C I2C temperature sensor. Datasheet in attachments.
  • #9
    p.kaczmarek2
    Moderator Smart Home
    Thanks for testing. I might have this board somewhere around, or a similar one.
    Does the led work in "Relay" or "LED" mode (the simple digital output pin)?

    Regarding previous post - I will look into it, this board might have less pins in description than the total number of pins specified, easy fix.
  • #10
    blakadder
    Level 6  
    When I configure them as relays the RGB channels can be turned on or off but using PWM or inverted PWM does not work.
  • #11
    iprak
    Level 6  
    I have been playing with a less powerful W600 device. I have got the firmware updated with the demo app. The device fails to go into sta mode, scanning networks returns nothing (no error). I initially though that the chip was damaged but access point works. Any suggestions on what I could try next?

    Update: I was able to resolve that. Apparently uploading the firmware via python tool was not sufficient. Using wm_tool with full erase cleared up the glitch and now the t-scan in demo works.
  • #12
    p.kaczmarek2
    Moderator Smart Home
    @blakadder was right. PWM was not working in older builds due to organizational error. PWM is now fixed. W600 support is coming soon thanks to @iprak efforts. Stay tuned!
  • #14
    p.kaczmarek2
    Moderator Smart Home
    blakadder wrote:

    Also has a, previously unknown to me, CHT8305C I2C temperature sensor. Datasheet in attachments.

    CHT8305C driver will be added to OBK in today's update.

    mtd wrote:
    Hello. Do you have this microcontroller warm during standby? I mean exactly this one
    https://www.elektroda.pl/rtvforum/topic3905452.html.

    Yes, it gets warm, but we have a fix for that (tested on BK7231N/BK7231T and W600 - not sure about W800 yet, but it should also work) - a powersave command, which will put OBK into a power saving mode. Big thanks to @btsimonh and @iprak
    NOTE: tls_wifi_set_psflag(1, 0); might not be enabled for W800 for current platform, you might need to enable it or wait for me to find W800 dev board (I will enable it in the following days).
  • #15
    aronkahrsus
    Level 1  
    >>20220854
    Is this fixed? Still having troubles with pwm, i works with rel but not with PWM nor PWM_n
  • #16
    p.kaczmarek2
    Moderator Smart Home
    Hello @aronkahrsus , I think that @iprak was fixing something on WinnerMicro platform, but if not, I will try to find my dev board and fix it.
  • #17
    p.kaczmarek2
    Moderator Smart Home
    @aronkahrsus some more PWM issues were fixed today (2023-06-14):
    https://www.elektroda.com/rtvforum/viewtopic.php?p=20616695#20616695

    Update your binaries.