Skip to content

Commit 47bace5

Browse files
committed
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 Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 1539033 commit 47bace5

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
@@ -606,6 +606,12 @@ void stm32_main(uint32_t reset_mode) {
606606
// reset config variables; they should be set by boot.py
607607
MP_STATE_PORT(pyb_config_main) = MP_OBJ_NULL;
608608

609+
#if MICROPY_PY_NETWORK
610+
// Initialize network subsystem before boot.py runs so that network
611+
// interfaces can be instantiated in boot.py (LWIP was already initialized earlier)
612+
mod_network_init();
613+
#endif
614+
609615
// Run optional frozen boot code.
610616
#ifdef MICROPY_BOARD_FROZEN_BOOT_FILE
611617
pyexec_frozen_module(MICROPY_BOARD_FROZEN_BOOT_FILE, false);
@@ -643,10 +649,6 @@ void stm32_main(uint32_t reset_mode) {
643649
servo_init();
644650
#endif
645651

646-
#if MICROPY_PY_NETWORK
647-
mod_network_init();
648-
#endif
649-
650652
// At this point everything is fully configured and initialised.
651653

652654
// 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)