Skip to content

ports/w60x: Add ports for W60X module based boards. #4679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 43 commits into from

Conversation

wdyichen
Copy link

@wdyichen wdyichen commented Apr 8, 2019

W600 is an embedded Wi-Fi SoC chip which is complying with IEEE802.11b/g/n international standard and which supports multi interface, multi protocol. It can be easily applied to smart appliances, smart home, health care, smart toy, wireless audio & video, industrial and other IoT fields. This SoC integrates Cortex-M3 CPU, Flash, RF Transceiver, CMOS PA, BaseBand. It applies multi interfaces such as SPI, UART, GPIO, I2C, PWM, I2S, 7816. It applies multi encryption and decryption protocol such as PRNG/SHA1/MD5/RC4/DES/3DES/AES/CRC/RSA.

Currently only port modules with WiFi,GPIO, UART, software SPI, I2C, PWM, WDT and Timer,more module ports will be added in the future.

These chips are widely available and can be purchased from various major distributors like Seeed, Taobao, etc, or directly from WinnerMicro.

W600 uses standard arm-none-eabi-gcc and openocd to compile and debug firmware.

W600 is available in the long term, and code are licensed under Apache license.

We will update the migration code frequently, especially when the SDK updates or fixes bugs.

add w60x port
@wdyichen wdyichen changed the title Adding W60X Chip Porting Code Add ports for W60X module based boards Apr 9, 2019
@wdyichen wdyichen changed the title Add ports for W60X module based boards ports/w60x: Add ports for W60X module based boards. Apr 23, 2019
@dpgeorge
Copy link
Member

Thanks for the submission. Since there is not much of a description here in the PR it's unclear what the intention is for this code, but I assume you want to add it to this repository.

For a new port to be added there are some things that must be considered. See eg #4557 for a previous discussion about another port.

What is the W60X? Is it popular and easily avaliable? Does it use an open-source toolchain? Will the chip be available in the long term? Will this port be maintained in the long term?

@wdyichen
Copy link
Author

Hi @dpgeorge , thank you for your interest. I modified the description of PR.

@mcauser
Copy link
Contributor

mcauser commented Apr 26, 2019

@wdyichen
Copy link
Author

A new development board was added: https://www.seeedstudio.com/W600-Arduino-IoT-Wi-Fi-Board-p-2926.html

@chrismas9
Copy link
Contributor

Is this port supported by Winner Micro, or is it a private contribution? What is the bug status of the W60x? ESP8266 and ESP32 have some issues like non linear analog that don't look like being fixed. Espressif seem to just delete broken features from the data sheet instead of fixing them. Having a better alternative for commercial and industrial use would be great.

What is the status of the 68 pin W601 and modules for it? The W600 doesn't have ADC so I think the W601 would be of interest to MicroPython users. It's only on the Chinese website. Do you know if there is an English data sheet for the W601?

It's good to see the WMIOT601 reference module has FCC approval.

@wdyichen
Copy link
Author

Hi @chrismas9 , thank you for your interest.

  1. This port is provided and maintained by WinnerMicro.
  2. The bugs we're talking about here are those that haven't been discovered yet. If they're proven, we'll fix them.
  3. Yes, W600 does not have ADC, W601 has ADC. But W600 can use RC circuit to collect ADC with IO, which is suitable for inaccurate occasions.
  4. W601 is already on sale. We have now updated the English documents: http://www.winnermicro.com/en/html/1/156/158/536.html.

@dpgeorge
Copy link
Member

Thanks @wdyichen for the information.

I didn't look at this PR in detail yet, because there is a lot to go through. But from what I did see so far I have the following questions:

  • threading is enabled, so does the W600 SDK provide an RTOS? Is this RTOS necessary for the WiFi and/or the TCP/IP stack to work?
  • it looks like the usocket module is based on the ESP32 implementation and calls into the lwIP high-level socket API, like lwip_connect(). Did you try to instead use the PCB-level API of lwIP via the extmod/modlwip.c module? Or is there a reason this is not possible (maybe related to the above question about threads)?
  • SSL/TLS is not enabled. In there a reason for this?
  • I see the W600 has 1MiB of internal flash. How much of this is used by the current MicroPython firmware you have here?
  • The heap size is set to 45k. Is it possible to increase this or is the rest of the RAM (288k it looks like in total) used by the WiFi and TCP/IP stack?

@wdyichen
Copy link
Author

wdyichen commented May 5, 2019

Thanks @dpgeorge .

Yes, w600sdk integrates FreeRTOS. At present, both LwIP stack and WiFi stack are.
In this porting code, MPY is just a task running in FreeRTOS,
In the process of transplantation, we found that usocket module can be seamlessly
integrated with our protocol stack, while using modlwip module needs some adaptation,
so we use usocket module

MBEDTLS applications have not been ported in W600 SDK, but SSL modules will be added in the future.

This migration code compiles 321KB firmware,
because a part of flash is used as the filesystem, so IMG firmware can not exceed 352KB at most.
W600 now has a 2Mflash version, which may be a better choice.

This 45K heap is only allocated to MPY applications, and WiFi and TCP / IP stacks do not use this part of heap memory.
W600 has block memory (160k + 128k), only the first 160K memory is used, while the latter 128K memory is reserved for WiFi and tcp/ip stacks.

@dpgeorge
Copy link
Member

dpgeorge commented May 7, 2019

MBEDTLS applications have not been ported in W600 SDK, but SSL modules will be added in the future.

It would be easy to just enable axtls or mbedtls within MicroPython, there is no need to have it come from the W600 SDK. But it requires a fair amount of flash space.

This migration code compiles 321KB firmware,
because a part of flash is used as the filesystem, so IMG firmware can not exceed 352KB at most.
W600 now has a 2Mflash version, which may be a better choice.

This was my concern, that there would not be enough flash space for a useful set of features (eg TLS included). Indeed the 2Mbyte flash version sounds like a better choice.

W600 has block memory (160k + 128k)

So, can more of this 160k be allocated to MicroPython applications, or is 45k the maximum?

@wdyichen
Copy link
Author

wdyichen commented May 7, 2019

  • Please forgive me how to use mbedtls in mpy.
    When I update the submodule, I see the source code of axtls, but there is no source code for mbedtls,
    so I think we may need to port mbedtls in the W600 SDK.

  • W600 has hardware encryption and decryption function, which can be replaced in mbedtls. The final code increment is about 25K+.
    At present, 1M flash is enough.

  • Because porting code compiles need to rely on w600 sdk, you can only use up to 45K+ of memory without modifying sdk code.
    If you modify the sdk code to reduce the memory occupied by wifi when compiling the firmware, you can still increase the memory used by mpy.

@nickzoic
Copy link
Contributor

I've got some of these modules somewhere around so I'll have a go at building and see if I can provide some feedback.

@wdyichen
Copy link
Author

w600 currently only supports gcc 4.x version, please refer to the url in README.

robert-hh and others added 19 commits April 25, 2020 10:55
Initialize & reset the file offset for the RETR command to 0. It was
not initialized before, causing sometimes faulty downloads.

Other fixes:
- avoid double slash in filenames
- some changes to response message texts
The actual implementations missed root pointers in the registers.
That caused gc_free() to raise am Assert sometimes during automatic
garbage collection, which stopped execution.
Thanks to Dave Hylands and @stinos for their execllent support.
The fix was suggested by Dave.

Note: The change to Makefile could be better. There must be existing
measures to call the proper assembler.
gccollect: Add registers to the root pointer scan
ftpserver.c: Initialize file offset (+ other minor changes)
- when calling uos.stat() on a file in a subdirectory with a relative path,
  the directory /flash was searched for that file. So with "testfile" in
  a directory "testdir", uos.stat("testfile") failed, when the current
  dir was "/flash/testdir". Fixed now.
- when calling rename with an absolute path for the second file, this
  path was appended to the current dir name, instead of taking that
  absolute path name. So with "testfile" in a directory "testdir",
  uos.rename("testfile", "/flash/newfile") failed, when the current
  dir was "/flash/testdir". Fixed now.
- when given a relative path, chdir appended that new path to the
  actual current dir and did not normlize the path name. So when the
  current dir was /flash/testdir, uos.chdir("..") caused to current dir
  to get /flash/testdir/.. With that change, current dir will then be
  /flash.

The test file for coverage tests are changed too.
Normalize path names

Path names supplied with ftp commands will be normalized, causing:

excess slash characters to be removed
. path elements to be removed
.. path elements backing up the path one level

Removed:

commented out code
code for WIN32

Optimize LIST and NLIST:

Both commands use the same function now, which is told by
a parameter which format to use. This function do_list() now
also receives a buffer for temporary strings, reducing it's stack
usage.

Checks:

Check, that the resulting path created by build_full_path()
does not exceed the buffer size.

Test, that the target given with CWD exists and is a dir

Bug fixes:
- do not call chdir(). Just change the session->current_dir
variable
- use the full path name as target for rename
extmod/vfs_lfsx.c: Fix a few minor error in vfs_lfsx
tools/ftpserver.c: Refactoring of ftpserver.c
That was missing and caused import to fail sometimes if
the module was located in a subdirectory. Fixed by Damien George.

Also: Some reformatting done by uncrustify.
parenthesis-typo caused tls_reg_read() to hang on invalid register
Added to w600, a port specific module, similar to the other ports.
dht_readinto(). For a DHT module to work properly, the OPEN_DRAIN
mode of UART has to be added to (is already coded by @e-tobi).
Changes made in cooperation with @e-tobi.

mp_hal_tick_us() and mp_hal_ticks_cpu()

The values are now derived from the watchdoc timer, resulting in
a 1µs resultion of mp_hal_tick_us and 40MHz ticks of
mp_hal_ticks_cpu. However, there are drawbacks:

- the watchdog cannot be used any more
- the largest span for ticks_diff in combination with tick_us is
  about 107 seconds (precise: 2**32 / 40 microseconds).
- the ticks counter is reset on every task switch, call to
  sleep(), sleep_ms(), or sleep_us(x) with x >= 4000 and every line
  entered in REPL. There may be more cases in which that happens.

But at least some functions do work, which required determining short
time spans. Like the DHTxx module.

mp_hal_delay_us()

The delay is based on the ticks_cpu timer. For times < 4000µs this is done
by busy waiting, beyond that time mp_hal_delay_ms() is used, which
has en error of +/- 2 ms.
With that change, ticks_us() will have the full range of +/- 2**30
microseconds. That requires a change to the SDK too, because of a bug
in the SDK, not allowing to register an alternative IRQ handler
to the watchdog interrupt. Therefore the file wm_watchdog.c
is moved into the local repository and changes accordingly.
- call vTaskSuspend() instead of vTaskDelete()
  vTaskDelete() assumes, that the stack buffer was allocated within
  tasks.c. But the stack buffer is allocated form the MP heap. Freeing
  it the wrong way causes memory corruption.
- have all threads the same priority. Otherwise the following threads
  will execute with much slower pace.
- Remove usage of thread_cnt. It was only used to give threads
  different priorities, which seemed to be a bad decision anyhow.
- Do a hard reset with Ctrl-D if threads had been started.
  That will close all tasks and free the heap.
- call tls_os_time_delay(1) in the MICROPY_EVENT_POLL_HOOK macro
  giving time for a task switch.

Note:
This variant provides the stack for the threads (= RTOS tasks) from the
micropython heap. That prohibits using xTaskDelete(), because that
assumes, that the stack is provided by the RTOS heap, an xTaskDelete()
frees that using RTOS methods, causing the both heaps to get corrupted.
When using xTaskSuspend is is unclear, whether the thread stack buffer
can be released. At the moment, it is kept.
I can provide another variant, which is taking the task stack buffer
from the RTOS heap. Since that is very limited, only one thread can be
started at 4k stack size, or two threads at 2k stack size. The RTOS
heap can be increased by changing the setting in FreeRTOSConfig.h. But
that is a change to the SDK I want to avoid.
extmod/vfs_lfsx.c: Setting the full path in import_stat()
mphalport.c et al: fix us-timing support
mpthreadport.c: Refactor threading to a working state
The path strings have to be added to qstrdefsport.h such that get
properly expanded.
qstrdefsport.h, main.c: Fix adding paths to sys.path
tannewt added a commit to tannewt/circuitpython that referenced this pull request May 3, 2021
Add DAC* and RTL_* pin assignments to Wio Terminal board.
@snorkman88
Copy link

Hi @wdyichen what is the status of this port? Is there a stable version of it?
Thanks!

@dpgeorge dpgeorge added the ports Relates to multiple ports, or a new/proposed port label Jan 21, 2022
@dpgeorge
Copy link
Member

There has not been much interest in this MCU/port in the past 2 years. Also, it is a lot of work to add a new port to MicroPython due to the ongoing maintenance effort. So I will close this pull request.

Feel free to maintain this port in a separate repository and keep it up to date with MicroPython. If there is enough interest in it, the issues with gcc version can be resolved, and someone is willing and able to maintain it, then we can reconsider getting it into this repository.

Thanks for your efforts!

@dpgeorge dpgeorge closed this Nov 25, 2022
@robert-hh
Copy link
Contributor

There is a recent port for the W60X device kept recent here: https://github.com/robert-hh/micropython/tree/w60x and some pre-built images here: https://github.com/robert-hh/Shared-Stuff. The work of extending this PR's version was done by @e-tobi and me, with support and feedback by @wdyichen .
The branch is updated regularly, especially when there are major changes to the code base of new revisions. The W60x is quite nice and a good alternative to the ESP8266. It's a pity that only the 1MB version is available. But it has sufficient many GPIO ports to add an external flash chip. The library for the device is OK, but the build set-up is not compatible to MP. Therefore I never considered to make a PR.

@dpgeorge
Copy link
Member

Thanks @robert-hh for pointing out your fork/branch (at least I didn't know of it). It's good to hear that something has come of this work.

@wdyichen
Copy link
Author

Thanks @dpgeorge @robert-hh for attention. I am no longer supporting this project due to job changes. We may port mpy to new chips in the future.

@LexxM3
Copy link

LexxM3 commented Dec 19, 2022

Thanks @dpgeorge @robert-hh for attention. I am no longer supporting this project due to job changes. We may port mpy to new chips in the future.

@wdyichen, is the situation that you (personally) are not supporting the W600/W601 or is the situation that Winner Micro is no longer supporting and/or manufacturing the W600/W601?

I've recently come across these devices and I am in agreement with others such as @robert-hh that W600/W601 at current cost levels or below very much has a place in the market. I apologize if this is obvious, but the reason it has not had a significant pick up seems almost entirely due to this shallow and intermittent software support. Myself, @robert-hh, and others would be happy to take over and continue the support at this stage based on @robert-hh's work, but we need to know whether that's a waste of effort because Winner Micro has abandoned this chip entirely. If you cannot answer this, @wdyichen, perhaps you can motivate someone at Winner Micro to do so promptly. Perhaps as further motivation for Winner Micro to be communicative and transparent is that such approach will maintain credibility for the company within the developer community for other and future devices (whereas lack of it may well not).

@wdyichen
Copy link
Author

wdyichen commented Dec 20, 2022

@wdyichen, is the situation that you (personally) are not supporting the W600/W601 or is the situation that Winner Micro is no longer supporting and/or manufacturing the W600/W601?

It's just that I personally don't support it. winnermicro still makes and supports the chip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ports Relates to multiple ports, or a new/proposed port
Projects
None yet
Development

Successfully merging this pull request may close these issues.