Skip to content

MatrixPortal hangs on network I/O using Protomatter v.1.5.2 and later #56

@jonbo372

Description

@jonbo372

CircuitPython version

Adafruit CircuitPython 8.0.0-beta.6
Adafruit Matrix Portal M4
Nina FW 1.7.4
Adafruit Protomatter v1.5.2

Code/REPL

#include <Arduino.h>

#include <WiFiNINA.h>

// It is enough to include the Protomatter library for things to
// go south.
#include <Adafruit_Protomatter.h>

char ssid[] = "INSERT_YOUR_SSID_HERE";
char pass[] = "INSERT_YOUR_PASSWORD_HERE";

WiFiServer* server;

int clientCount = 0;

void attachToWifi() {
    uint8_t status = WiFi.status();
    while (status != WL_CONNECTED) {
        Serial.println("Waiting for network");
        status = WiFi.begin(ssid, pass);

        if (status == WL_CONNECTED) {
            Serial.println("We are connected");
            break;
        }

        delay(10000);
    }
}

/**
 * Copied/adapted from WifiNINA examples.
 */
void process() {
    WiFiClient client = server->available();

    if (client) {
        ++clientCount;

        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                if (c == '\n' && currentLineIsBlank) {
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/plain");
                    client.println("Connection: close");  // the connection will be closed after completion of the response
                    client.println();
                    client.print(clientCount);
                    client.println(" Hello World");
                    break;
                }
                if (c == '\n') {
                    currentLineIsBlank = true;
                } else if (c != '\r') {
                    currentLineIsBlank = false;
                }
            }
        }
        delay(1);
        client.stop();
    }
}

void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
    Serial.begin(9600);
    attachToWifi();
    server = new WiFiServer(80);
    server->begin();
}

void loop() {
    process();
    delay(50);
}

Behavior

Setup:

  1. Using WifiNINA as a simple web server
  2. Fetch content in a loop from the web server while [ true ]; do curl http://<insert_ip_here>; sleep 1; done
  3. After a short number of loops, the board will no longer process network traffic (usually less than 20)

Description

The observed behavior is the exact same one as reported in adafruit/circuitpython#6205 (except no USB disconnect). And as reported in that issue, it is enough to include the Adafruit_Protomatter.h file to observe this behavior. Downgrading to v1.5.1 seems to do the trick and there has been DMA related updates in the later versions (which seems to have been the root cause of the bug adafruit/samd-peripherals#42).

Additional information

Running platform.io with the following settings:

[env:adafruit_matrix_portal_m4]
platform = atmelsam
board = adafruit_matrix_portal_m4
framework = arduino

upload_port = /dev/ttyACM0

lib_deps = adafruit/Adafruit Protomatter@^1.5.2
           WiFiNINA=https://github.com/adafruit/WiFiNINA/archive/master.zip

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions