Wiznet / RP2040-HAT-MicroPython

54 stars 22 forks source link

v1.0.0 firmware - multicore threads seem to block each other. #1

Closed jshayward closed 2 years ago

jshayward commented 2 years ago

Using the v1.0.0 firmware, threads appear to block each other instead of running concurrently. I created a TCP server app using one core to receive and one to send. The receiving core blocked the sending core.

The following sample program appears to run for a while on core0 and then switch and run for a while on core1 (see output below). Running this same program using the standard RP2 PICO MicroPython firmware produces the expected output (below).

I need to build an app that receives commands to control sensors and also sends changes in sensors using the ethernet port and that will require both threads so any assistance would be appreciated.

import machine, time, _thread

led = machine.Pin(25, machine.Pin.OUT)

def Core0():
    count = 0
    while count < 5:
        for blink in range(5):
            led.on()
            time.sleep(1.0)
            led.off()
            time.sleep(1.0)
        count += 1
        print('cp0')
    print('Core0 finished')

core1running = True
def Core1():
    global core1running
    count = 0
    while count < 5:
        for blink in range(5):
            led.on()
            time.sleep(0.9)
            led.off()
            time.sleep(0.9)
        count += 1
        print('cp1')
    print('Core1 finished')
    core1running = False

_thread.start_new_thread(Core1, ( ))
Core0()

while core1running:
    time.sleep(1)
print('Done')

Output using Wiznet firmware:

cp0
cp0
cp0
cp1
cp1
cp1
cp0
cp0
Core0 finished
cp1
cp1
Core1 finished
Done

Output using RP PICO firmware:

cp1
cp0
cp1
cp0
cp1
cp0
cp1
cp0
cp1
Core1 finished
cp0
Core0 finished
Done
irinakim12 commented 2 years ago

I'll try to check this issue.

irinakim12 commented 2 years ago

refer to https://github.com/Wiznet/RP2040-HAT-MicroPython/releases/tag/v1.0.5