Skip to content

Commit 14cd272

Browse files
pi-anlclaude
andcommitted
stm32/main: Initialize network before boot.py to fix LAN instantiation.
Move mod_network_init() to run before boot.py instead of after, allowing network interfaces like network.LAN() to be instantiated in boot.py. The previous order caused failures when users tried to create network interfaces in boot.py because the network subsystem wasn't initialized until after boot.py completed. This change is safe because: - LWIP is already initialized earlier in main() - mod_network_init() only initializes the NIC list - network.country() and network.hostname() still work correctly as they just set global variables that are used later 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrew Leech <[email protected]>
1 parent d6db47c commit 14cd272

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

ports/stm32/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,12 @@ void stm32_main(uint32_t reset_mode) {
589589
// reset config variables; they should be set by boot.py
590590
MP_STATE_PORT(pyb_config_main) = MP_OBJ_NULL;
591591

592+
#if MICROPY_PY_NETWORK
593+
// Initialize network subsystem before boot.py runs so that network
594+
// interfaces can be instantiated in boot.py (LWIP was already initialized earlier)
595+
mod_network_init();
596+
#endif
597+
592598
// Run optional frozen boot code.
593599
#ifdef MICROPY_BOARD_FROZEN_BOOT_FILE
594600
pyexec_frozen_module(MICROPY_BOARD_FROZEN_BOOT_FILE, false);
@@ -626,10 +632,6 @@ void stm32_main(uint32_t reset_mode) {
626632
servo_init();
627633
#endif
628634

629-
#if MICROPY_PY_NETWORK
630-
mod_network_init();
631-
#endif
632-
633635
// At this point everything is fully configured and initialised.
634636

635637
// Run main.py (or whatever else a board configures at this stage).

ports/stm32/mpnetworkport.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/runtime.h"
3333
#include "py/mphal.h"
3434
#include "shared/netutils/netutils.h"
35+
#include "eth.h"
3536
#include "systick.h"
3637
#include "pendsv.h"
3738
#include "extmod/modnetwork.h"

0 commit comments

Comments
 (0)