network.LAN() hard-faults (silent reset, no exception) standalone on OpenMV N6 — works fine via IDE

Board/Firmware: OpenMV N6 (STM32N657X0), OpenMV be63fec4fb; MicroPython cf80cce8a0 (v5.00, latest)

Issue: A script using network.LAN() / lan.active(True) runs fine every time via the IDE Play button (including its failed-connect/retry path), but hard-faults when saved as main.py and run standalone after a cold reset (no IDE attached). No catchable exception is printed — just a truncated traceback and an immediate reset:

Repro:

Save as main.py, reset standalone (no IDE) → hard fault at/near lan.active(True). Run same script via IDE → works.

Ruled out: boot delay + auto-negotiation delay before active(True) (fault just moves later); code bug (identical retry/error-handling logic works fine repeatedly via IDE); power source (same USB port/cable both tests).

Source note: network_lan.c’s active(True) only raises a catchable OSError if eth_start() returns an error code. Since no exception ever prints, the fault is happening below that — inside eth_start()/HAL_ETH_Init() on the N6 ETH HAL, during standalone cold-boot bring-up.

Ask: Is this a known N6 Ethernet standalone-boot issue? Happy to provide more debug info or test a candidate fix.

Hi, I’ve currently developing OTA software using the N6 where we have scripts doing OTA using the LAN without the IDE attached at all.

Can you give me the example script that causes the error? Also, please install the latest development firmware. There’s no inherit issue with using the LAN without the IDE.

And… you are testing this with an ethernet cable attached right? Or are you calling active without an ethernet cable attached?

Thanks for the quick response!

I’m testing with an Ethernet cable attached. Additionally, the device firmware is up to date. I’ve copied the code causing the error below.

# Untitled - By: xxxxx - Wed Aug 5 2026


#
# AprilTags Max Res Example
#
# This example shows the power of the OpenMV Cam to detect April Tags
# on the OpenMV Cam M7. The M4 versions cannot detect April Tags.

import csi
import time
import math
import network
import socket

TARGET_TAGS = [1, 2, 3, 4]
RESET_AFTER = 10000

time.sleep_ms(2000)
# 1. Initialize the WIZnet W5500 Ethernet Shield
# This uses the SPI bus built into the OpenMV shield headers
lan = None
while lan is None:
    try:
        lan = network.LAN()
        lan.config(low_power=False)
        # time.sleep(3.0)  # let the PHY finish auto-negotiation before activating
        # lan.active(True)
        while not lan.isconnected:
            time.sleep(1.0)
            print("waiting for PHY")
    except Exception as e:
        print(f"{e}: FAILED to init Ethernet, retrying...")
        lan = None
        time.sleep_ms(500)

# 2. Obtain an IP address
# If plugged into a router, it uses DHCP. If plugged directly to PC, see note below.
print("Configuring Ethernet connection...")


# 3. Configure target connection (Your Computer's Ethernet IP)
SERVER_IP = "10.0.0.2"  # <--- REPLACE WITH YOUR COMPUTER'S ETHERNET IP
SERVER_PORT = 8080
DELAY = 2

while True:
    client = None
    try:
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.settimeout(5.0)

        print(f"Attempting to connect to {SERVER_IP}:{SERVER_PORT}...")
        client.connect((SERVER_IP, SERVER_PORT))
        print("Connected to computer over Ethernet!")
        break
    except Exception as e:
        print(f"{e}: FAILED to connect")
        if client:
            client.close()
        time.sleep(DELAY)


csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.QVGA)

# AprilTags works on a maximum of < 64K pixels.
csi0.snapshot(time=1000)
csi0.auto_gain(False)  # must turn this off to prevent image washout...
csi0.auto_whitebal(False)  # must turn this off to prevent image washout...

clock = time.clock()

# Note! Unlike find_qrcodes the find_apriltags method does not need lens correction on the image to work.

# Please use the TAG36H11 tag family for this script - it's the recommended tag family to use.
current_time = time.time()
last_seen = {tag_id: current_time for tag_id in TARGET_TAGS}
elapsed_time = {tag_id: current_time for tag_id in TARGET_TAGS}


while True:
    current_time = time.time()
    img = csi0.snapshot()

    for tag in img.find_apriltags():
        img.draw_detection(tag, color1=127)
        print_args = (tag.name, tag.id, (180 * tag.rotation) / math.pi)
        if tag.id in TARGET_TAGS:
            last_seen[tag.id] = current_time
    for tag in TARGET_TAGS:
        elapsed_time[tag] = current_time - last_seen[tag]

    # print("Tag Family %s, Tag ID %d, rotation %f (degrees)" % print_args)
    print(last_seen)
    print(elapsed_time)
    message = f"{last_seen} \n {elapsed_time}"
    try:
        client.send(message.encode('utf-8'))
        time.sleep(1)
    except Exception as e:
        print("Wired link lost:", e)
        break

client.close()

Hi, a few things jump out in the script you posted — I don’t think it’s the one that was working via the IDE:

  1. lan.active(True) is commented out. As posted, the interface never comes up, so connect() can only fail. This script can’t work via the IDE either — which tells me the version on the camera’s flash may not match what you were running with the Play button.

  2. while not lan.isconnected: is missing parentheses. lan.isconnected is a bound method object, which is always truthy, so not lan.isconnected is always False — the “waiting for PHY” loop never runs at all. It should be:

while not lan.isconnected():
    time.sleep(1.0)
    print("waiting for PHY")

Keep in mind the IDE’s Play button runs the script in the editor buffer, while a standalone boot runs whatever main.py was last saved to the camera — and if an SD card is inserted, main.py on the SD card is what runs, not internal flash. It’s very common for these to get out of sync while iterating. Add a print("VERSION X") at the top, save, and bump it each edit so you know exactly which copy is executing.

Also, note what a crash actually looks like on the camera: an uncaught Python exception in main.py prints a traceback over the USB serial port and then drops the board to the REPL — no reset. Since main.py starts running before your serial terminal can attach, you’ll only catch the tail end of that traceback, which looks like a “truncated traceback.” A true hard fault, on the other hand, resets the board immediately with no output at all.

To tell those apart:

  1. Put time.sleep_ms(5000) as the very first line of main.py and save it.
  2. Power the camera standalone and attach a serial terminal during those 5 seconds, before anything runs.
  3. Watch what happens:
    • Full traceback followed by nothing (board still enumerated, sitting at the REPL) → it’s a Python error in the script. Post the traceback here.
    • Output stops dead and the USB port disappears/re-enumerates → a genuine reset, and I’ll dig into it on my end.

You can also add this right after the sleep — it tells us what kind of reset preceded the boot:

import machine
print(machine.reset_cause())

If you can post the exact script that runs fine via the IDE (with the version print added), I’ll run it standalone on an N6 with Ethernet here and try to reproduce.