Wiznet / RP2040-HAT-MicroPython

53 stars 22 forks source link

Hard lock when using 2ed core with DHT22 sensor #23

Open GM-Script-Writer-62850 opened 1 year ago

GM-Script-Writer-62850 commented 1 year ago

I suspect this is a clock de-sync issue

Hardware: W5500_EVB_PICO Firmware: rp2_w5500_20221111_v2.0.0.uf2

When this happens everything freezes and no errors are reported in Thonny and a power cycle is required on the PICO note that rp2_w5500_20221111_v2.0.0.uf2 will run just fine for usually weeks (my record with production code is 2-3 months with a minimum of a few days) while the W5500_EVB_PICO-20230426-v1.20.0.uf2 will run for maybe hours at most

This is all it takes:

from machine import Pin,SPI
from time import sleep,time
import network
import _thread
import dht # example hardware wiring: https://microcontrollerslab.com/wp-content/uploads/2022/02/Raspberry-Pi-Pico-with-DHT22-connection-diagram.jpg

def read_sensor():
    dev=dht.DHT22(Pin(6))
    dev.measure()
    print("Temperature:",dev.temperature()," C; Humidity:",dev.humidity())

def enable_NIC():
    spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18))
    nic = network.WIZNET5K(spi,Pin(17),Pin(20)) #spi,cs,reset pin
    nic.active(True)
    return nic

nic=enable_NIC()

_thread.start_new_thread(read_sensor,())

while True:
    print('heartbeat',time())
    sleep(3)

Even if you nic.active(False) before_thread is started then nic.active(True) it when _thread is completed it will still hard lock

Here is my upsteam report: https://github.com/micropython/micropython/issues/10448

At this time i am using W5500_EVB_PICO-20230426-v1.20.0.uf2 and have everything running using uasyncio on core 0, i would prefer to have my sensors read using core 1 but that make it unstable, this production code does not work on rp2_w5500_20221111_v2.0.0.uf2 due to issue #14 (this also affects using uasyncio urequests)

I have no issues doing this same thing using a PICO W having the second core deal with the sensors works all day every day

GM-Script-Writer-62850 commented 2 months ago

Seems to be resolved upstream in micropython 1.3, i suspect 1.22 fixed it