Skip to content

zephyr-cp/wifi: route diagnostic output through the log subsystem - #11227

Open
mikeysklar wants to merge 2 commits into
adafruit:mainfrom
mikeysklar:zephyr-wifi/pr2-logging
Open

zephyr-cp/wifi: route diagnostic output through the log subsystem#11227
mikeysklar wants to merge 2 commits into
adafruit:mainfrom
mikeysklar:zephyr-wifi/pr2-logging

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

What

Routes the zephyr-cp Wi-Fi common-hal's diagnostic output through Zephyr's log
subsystem instead of raw printk, and fixes two defects that conversion exposed.

Why

The Wi-Fi path printed unconditionally on every net event. That output cannot be
turned down per module, and it corrupts the serial handshake that raw-REPL
tooling relies on, which makes REPL automation on this port flaky.

Two real bugs came out of the conversion:

  • The unhandled-event print truncated to 32 bits. mgmt_event is a
    uint64_t and was printed with %x. The event layer lives in the high bits,
    so every unhandled Wi-Fi event aliased to the same value.
  • NET_EVENT_IPV4_ADDR_ADD had no case. The callback for it was already
    registered upstream, so the event arrived and fell through to the
    unhandled-event path. The status bar therefore kept reading Wi-Fi: No IP
    after DHCP had bound, while wifi.radio.ipv4_address returned the real lease.

Two printks in start_scanning_networks() only restated the message raised on
the next line, so they are deleted rather than converted.

LOG_MODULE_REGISTER(cp_wifi, CONFIG_LOG_DEFAULT_LEVEL) follows the existing
precedent in ports/zephyr-cp/supervisor/usb.c.

Hardware tested

  • SiWx917-DK2605A (Zephyr board siwx917_dk2605a, SoC SiWG917M111MGTBA), two
    boards, one on macOS 15 and one on Ubuntu 24.04.
  • Verified as part of the full stack, on top of the SiWx917-DK2605A board
    definition from zephyr-cp: add the Silicon Labs SiWx917-DK2605A #11218 (not yet merged).

Not tested: any other zephyr-cp board. This file builds for every Wi-Fi board in
the port, so CI is the check for the rest.

How I tested it

Console output is quiet by default now instead of printing per event, and the
status bar shows the address once DHCP binds rather than No IP.

Scope

Only ports/zephyr-cp/common-hal/wifi/. printk is still used elsewhere in the
port; converting those is out of scope here.

Notes

No new translatable strings, and locale/circuitpython.pot is unchanged.

This is the first of three PRs splitting up the zephyr-cp Wi-Fi work. It is
stacked on #11223, so until that merges this diff also shows its one-line scan
subscription change.

AI assistance

Written with Claude Code. I reviewed the diff myself and verified the behaviour
on the hardware listed above.

The event handler has a NET_EVENT_WIFI_SCAN_RESULT case that queues each
AP as it arrives, but that event was never in the subscription mask, so
the case never ran and scans always returned zero networks.

RAW_SCAN_RESULT is in the mask but is not a substitute. It carries raw
beacon frames and only fires when CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS is
enabled, which it is not by default.

Measured on a Raspberry Pi Pico 2 W running raspberrypi_rpi_pico2_w_zephyr,
built from 069144c and flashed over SWD with pyOCD:

  len([1 for n in wifi.radio.start_scanning_networks()])

  before  0
  after   204

Same board, same probe, same script, with only this change reverted for
the before run.
The Wi-Fi common-hal printed on every net event with raw printk. That output
is unconditional, so it corrupts the serial handshake that raw-REPL tooling
relies on, and it cannot be turned down per module.

Register a cp_wifi log module and route the existing calls through it, at
CONFIG_LOG_DEFAULT_LEVEL as supervisor/usb.c already does. Two printks in
start_scanning_networks() only restated the message raised on the following
line, so they are dropped rather than converted.

Also fixes two defects the conversion exposed:

- The unhandled-event print passed a uint64_t mgmt_event to %x, truncating to
  32 bits. Since the layer lives in the high bits, every unhandled Wi-Fi event
  aliased to the same value.
- NET_EVENT_IPV4_ADDR_ADD was already subscribed but had no case, so it fell
  through to the unhandled-event path and the status bar kept reading "No IP"
  after DHCP bound, while wifi.radio.ipv4_address returned the real lease.
@mikeysklar
mikeysklar marked this pull request as ready for review August 23, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant