Skip to content

extmod: Create a common cyw43 config header, apply mDNS fix in it. #17092

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

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

Conversation

projectgus
Copy link
Contributor

@projectgus projectgus commented Apr 8, 2025

Summary

  • First commit creates a new extmod/cyw43_config_common.h header with the common macros from ports which use CYW43 Wi-fi driver. There's more refactoring that could be done here (for example a cyw43_sdio_common.h header) but I've limited myself to macros that are the same, or that appear effectively the same, on every port.
  • Second commit moves the rp2 LWIP mDNS resolver fix added in ports/rp2: Fix rp2 mDNS issue via new cyw43 driver hooks. #17057 into the new header, so it's now also applied on stm32 and mimxrt ports which use the CYW43 driver.

Testing

  • Connected a PYBD_SF2 to my local network, verified I could look up the host via mDNS.
  • Ran the multi_wlan tests with a RPI_PICO_W board and a PYBD_SF2 as the two nodes. This uncovered two pre-existing issues (not added in this PR):
    • The stm32 port logs DHCPS: updates when running as the AP, so the test fails on the additional output (at least easy to manually check for).
    • On both ports, the cyw43 driver doesn't like being a STA first and then switching to become an AP (even though the unit tests de-activate the unused interface). To run the two tests in sequence then I needed to trigger a hard reset in between. Will investigate more when time permits.
  • I have not been able to test mimxrt as I have no suitable hardware. If I understand ports/mimxrt: Add CYW43 WiFi/BT support. #11397 correctly then no such widely available board exists, the only mimxrt+cyw43 users have added a CYW43 module to custom hardware or an eval board.

Trade-offs and Alternatives

  • Could keep the per-port config headers but it makes it harder to verify consistent behaviour between the different ports, and to apply non-port-specific changes like the mDNS resolver fix.

@projectgus projectgus added port-stm32 extmod Relates to extmod/ directory in source port-mimxrt port-rp2 labels Apr 8, 2025
@projectgus
Copy link
Contributor Author

@dpgeorge BTW I haven't forgotten our discussion about network_cyw43.h. I have a proposed refactor that covers this, but it turned out independent from this one.


#define CYW43_INCLUDE_LEGACY_F1_OVERFLOW_WORKAROUND_VARIABLES (1)
#define CYW43_WIFI_NVRAM_INCLUDE_FILE "wifi_nvram_43439.h"
#define CYW43_IOCTL_TIMEOUT_US (1000000)
#define CYW43_SLEEP_MAX (10)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't moved this macro into the common header because it's 50 in the mimxrt & stm32 ports, and 10 here in rp2. I'm unsure if this difference is necessary or a historical accident.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just controls how often the the cyw43 poll gets scheduled via pendsv (at least in stm32, mimxrt, alif). I'd say on a slower chip maybe 50 is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Perhaps just have the default at 50 and in RP2 undef and redefine it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! What I'm unsure is whether it was set to 10 on rp2 to fix some problem (or improve performance), or whether it's simply an accident that it's been set to 10 here. I haven't done any tests to compare 50 vs 10 on rp2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Perhaps just have the default at 50 and in RP2 undef and redefine it.

Good idea. I've gone even further and removed it from all the ports except rp2, as 50 is the default in the driver repo. I suspect it could also be set to 50 in the rp2 port without any impact (maybe even lower sleep consumption), but haven't tested this.

Copy link

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.53%. Comparing base (e53f262) to head (2e687fe).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17092      +/-   ##
==========================================
- Coverage   98.54%   98.53%   -0.01%     
==========================================
  Files         169      169              
  Lines       21890    21890              
==========================================
- Hits        21572    21570       -2     
- Misses        318      320       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented Apr 8, 2025

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_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@projectgus projectgus added this to the release-1.26.0 milestone Apr 8, 2025
}
}

#define CYW43_EVENT_POLL_HOOK mp_event_handle_nowait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For stm32 and mimxrt this was MICROPY_EVENT_POLL_HOOK which does something different, especially in the stm32 port (see the old one in stm32 port). The same for the delay functions which called this macro. I know that eventually we'll use the new functions, but I'd suggest you leave this macro and the delay functions in the port config files for now, to avoid changing the behavior, unless it's time to remove this macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch, I mis-remembered the macro compatibility as being different! Will fix.

Copy link
Contributor Author

@projectgus projectgus Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've swapped this around so stm32 should be using the same hook as before.

mimxrt should be using mostly the same hooks, although it previously had cyw43_delay_us and cyw43_delay_ms aliased directly to mp_hal_delay_us and mp_hal_delay_ms and now it uses the inline function definitions instead. This seems like either a no-change or a small improvement, but I'm not able to test it to verify.

@projectgus projectgus force-pushed the refactor/cyw43_common_config branch from 83718b1 to df7dfc0 Compare April 15, 2025 01:35
@iabdalkader
Copy link
Contributor

Note that the old cywbt.c driver will be replaced with a new BTHCI Uart backend that's been recently added to cyw43 driver, which requires some additional config option (no big changes, see #16848). The new Alif port already uses the new BTHCI backend, and it could be switch to the common config: https://github.com/micropython/micropython/blob/master/ports/alif/cyw43_configport.h

@dpgeorge
Copy link
Member

Sorry @projectgus but this now needs rebasing after merging #16848.

@Gadgetoid
Copy link
Contributor

Some possible overlap between this and d6cfdca from #16057 ?

@projectgus projectgus force-pushed the refactor/cyw43_common_config branch 2 times, most recently from 12be4d6 to 09f64bb Compare May 1, 2025 02:24
@projectgus
Copy link
Contributor Author

The new Alif port already uses the new BTHCI backend, and it could be switch to the common config

Sorry @projectgus but this now needs rebasing after merging #16848.

I've rebased on top the BTHCI changes, and migrated the Alif port to the common cyw43 config. All ports build after updating, but I only have hardware to test stm32 PYBD_SF2 (confirmed Wi-Fi & BLE both work but didn't run complete tests).

I think the BTHCI macros could also be put into the common config but have left it out of this PR for now, same as SDIO.

@projectgus
Copy link
Contributor Author

projectgus commented May 1, 2025

Some possible overlap between this and d6cfdca from #16057 ?

I think some overlap, but as those changes are scoped to rp2 I think they're more or less a subset of these.

EDIT: Oops it was a while since I looked, I think that change is mostly breaking out the mpconfig layer of CYW43 config. Whereas this change is refactoring the driver-facing layer of CYW43 config (i.e. the layer that translates the mpconfig settings to the driver). So mostly orthogonal.

@projectgus projectgus requested review from iabdalkader and dpgeorge and removed request for iabdalkader May 1, 2025 06:33
projectgus added 2 commits May 2, 2025 12:33
This is only a surface level refactor, some deeper refactoring would be
possible with (for example) the SDIO interface in mimxrt and stm32, or the
BTHCI interface which is is similar on supported ports. But sticking to
cases where the macros are the same across all ports.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This means the fix from dd1465e will also apply to stm32 and mimxrt ports
that use CYW43.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
@projectgus projectgus force-pushed the refactor/cyw43_common_config branch from 09f64bb to 2e687fe Compare May 2, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source port-mimxrt port-rp2 port-stm32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants