Skip to content
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

samd: Support WiFi using external esp32 based modules. #12464

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

robert-hh
Copy link
Contributor

Such like the u.blox W102, Adafruit Airlift products or just any ESP32 based hardware. The ESP32-WROOM with at least 2MB flash module is sufficient. The actual firmware support full WiFi with SSL on boards with a SAMD51x19 MCU external flash and basic WiFi without SSL for SAMD51x19 boards with the file system in internal flash. SAMD21x18 boards with external flash could as well provide basic WiFi.
The build was tested using the test script and performs identical to the Arduino Nano 2040 connect, which is not a surprise. The PR includes documentation.
For providing the firmware binaries requires required for the ESP32 modules I have made PR to micropython-lib in the espflash path. It seemed to be the best place for it.
This extension is based on the great work of @iabdalkader with the network_ninaw10 package and his support during the implementation.

This is a re-submit of PR #11219, which was closed since I renamed the branches. There is also a branch based on the esp-hosted firmware, which is similar for WiFi, but performs much better with BLE. See the notes down in PR #11219.

@github-actions
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@codecov
Copy link

codecov bot commented Sep 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.39%. Comparing base (a61c446) to head (0e46cdf).
Report is 11 commits behind head on master.

Current head 0e46cdf differs from pull request most recent head c2e9019

Please upload reports for the commit c2e9019 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12464      +/-   ##
==========================================
- Coverage   98.39%   98.39%   -0.01%     
==========================================
  Files         161      158       -3     
  Lines       21204    20938     -266     
==========================================
- Hits        20864    20601     -263     
+ Misses        340      337       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@robert-hh robert-hh force-pushed the samd_wifi_nina branch 3 times, most recently from 0e46cdf to 8020518 Compare September 23, 2023 13:30
@robert-hh
Copy link
Contributor Author

@dpgeorge The PR is simplified, in that the additional network.NINAW10 interface is dropped. So only the choice of using the Pin assignments of the board definition files is available. That seems acceptable, since most likely with the SAMD boards the matching NINAW10 boards are used. As a result of that change, there are no changes to the network_ninaw10.c file any more, and the changes to the drivers/nina*.c are mostly for supporting a port-specific variant of the wifi_nina_bsp.c file, like it's done for the esp_hosted driver of the Portenta C33 port.

@robert-hh
Copy link
Contributor Author

Support for BLE is prepared as well, but since ATM Jimmo is digging up BLE support in #8945, I'll wait a little bit. B.t.w.: Jimmo is working on other round-kick style PRs as well, like #12211 or #12443. Are these to be merged soon? Since they affect almost all ports, keeping WIP PRs in sync is a constant challenge.

@robert-hh
Copy link
Contributor Author

Rebased & conflicts resolved. @jimmo Is it possible to access the value of BOARD_VARIANT in manifest.py scripts?

@robert-hh
Copy link
Contributor Author

robert-hh commented Nov 17, 2023

Added build variants WLAN and WLAN_BLE. The latter supports WiFi and BLE.

There is another variant for WiFi and BLE support available based on the esp_hosted firmware for the ESP32. That one has a slightly better WiFi performance and much better BLE reliability, but the code size is ~70k larger, filling completely up the 512k code space of SAMD51x19 devices. The only devices that could comfortably support it are the Sparkfun SAMD51 and the no-yet-merged Adafruit Grand Central M4 device using the SAMD51x20 MCU with 1 M flash.

The plus side of the NINA solution, that it would even fit on a SAMD21 (useful or not) or SAMD51 w/o external flash, if SSL support is omitted. That's already foreseen in the build script.

Using the network.WLAN module with Pin settings defined in
mpconfigboard.h.

To allow for port specific WiFi configurations, the functions in
drivers/ninaw10/nina_wifi_bsp.c are declared as MP_WEAK.

Signed-off-by: robert-hh <robert@hammelrath.com>
Including:

ADAFRUIT_FEATHER_M4_EXPRESS
ADAFRUIT_ITSYBITSY_M4_EXPRESS
SPARKFUN_SAMD51_THING_PLUS
ADAFRUIT_METRO_M4_EXPRESS

Always build the Metro M4 board with WLAN, drop the variant for this
board.

Pin definitions are added as well for:

ADAFRUIT_FEATHER_M0_EXPRESS
ADAFRUIT_ITSYBITSY_M0_EXPRESS

which can support basic WLAN.

Signed-off-by: robert-hh <robert@hammelrath.com>
These were not covered yet and the mcu scheme can be useful for other
ports as well. Alternatively, the second rule could just be refer to
"**/manifest_*.py" instead of "ports/**/boards/**/manifest_*.py".

Signed-off-by: robert-hh <robert@hammelrath.com>
Use MICROPY_HW_NINA_CS instead of MICROPY_HW_NINA_GPIO1 in
nina_bt_hci.c and set RTS and CTS, if defined.

Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: robert-hh <robert@hammelrath.com>
Variant WLAN: Support for WiFi. For the Adafruit Metro M4 board, this
  is the default. At boards with small available flash, SSL is not
  supported.
Variant WLAN_BLE: Support for WiFi and BLE.

Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: robert-hh <robert@hammelrath.com>
Telling how to update the firmware of the WiFi/BLE module.

Signed-off-by: robert-hh <robert@hammelrath.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants