Repository navigation
Fix: Very Serious maintainability improvements in nd_network.h, network.cpp - #836
Conversation
On ESP32-P4 boards using an ESP32-C6 companion chip for WiFi, querying WiFi.macAddress() before the driver is initialized causes a fatal nullptr dereference. This adds an event-driven readiness flag (ARDUINO_EVENT_WIFI_READY) and caches the MAC address to avoid repeated queries.
d061395 to
8f7a4fc
Compare
|
This IS going to collide with #824. No ways around it. Let's land that one and I'll come back to repair this one. |
- Consolidate redundant MAC identity functions into a single GetMacAddress API using esp_efuse_mac_get_default() for radio-independent booting. (This is a fundamental diretion shift in this PR.) - Implement "Clean Facade" pattern in nd_network to isolate #ifdef soup headers and provide stable stubs for non-WiFi builds. (Rutger, this is basically the 'note to myself' from this morning.) - Keep up IWYU, alphabetize system headers, trailing whitespace patrol. - ESP32-P4 (tab5_demo) and standard ESP32 (mesmerizer) build parity.
|
PTAL I'd already started running with the ideas (and generally recoiling from the disgust at looking at the current state of nd_network.h - and even accepted that I helped make that mess - when I had the Aha moment of using a differnet API. https://docs.espressif.com/projects/esp-idf/en/v6.0/esp32p4/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t This API doesn't "flicker" while we're booting. By that time, I'd already implemented a whole bunch of the cleanups and fixes we spoke of earlier today. I told myself I'd limit this change to ONLY **/network and I didn't quite hit that goal (if I saw bad whitespace or an out-of-order include, I fixed it, much like I'd pick up trash when walking by) but I didn't sprinkle nd_network:: around the whole tree. Overall, I think this is a good balance of Thanks for the review. (You actually sort of already started on #824. I just struck while the iron was still hot and it was fresh in my head instead of making you copy-paste my own words to me.) With this change applied, tab5_demo (demo, not spectrum2 - that still needs SIOF fixed - boots and runs with microphone and screen. Lights at the end of the tunnel! |
Description
_This PR changed directions 2026-04-08. You may need to refresh your mental model. _
[Old] On ESP32-P4 boards using an ESP32-C6 companion chip for WiFi, querying
WiFi.macAddress()before the driver is initialized causes a fatalnullptrdereference (hosted_memcpycrash).[New] That is true. But I found another API that doesn't have this problem. It turns out that all ESP32s have a MAC address that's readable via the eFuse API (never mind that it's not actually set by blowing fuses...) that never changes and is suitable enough for our purposes of displaying a unique number in the debug console. But by the time we discovered that, I was deep into a cleanup that Rutger and I'd agreed upon earlier int he day.
We'd agreed upon direction (it was pretty clear) and I relied heavily on automation for the edits, but I babysat the process through probably a hundred edits and builds. Cue robot voice:
✦ This PR has evolved from a targeted bugfix for the ESP32-P4 into a foundational refactor of
the networking subsystem. By moving to an eFuse-direct identity model and implementing a
"Clean Facade" architectural pattern, we have eliminated boot-time indeterminacy ("crash" -- RJL) on the P4
while significantly reducing the technical debt across the entire project.
Summary of Changes
The original crash on the ESP32-P4 was caused by polling the MAC address via radio drivers
before the C6 companion chip was fully initialized. This PR resolves that by:
MAC address.
very first instruction of the bootloader.
nd_network::GetMacAddress(const char* separator) API.
Eiminates the "ifdef soup" leaking into headers and caller code:
rest of the app regardless of compile-time flags.
(ESP32-Nothing w/Radio) and tab5_demo (P4/C6) environments.
Technical Impact
Contributing requirements
mainas the target branch.