Skip to content

samd: RGBMatrix causing DMA hangs #6489

@dhalbert

Description

@dhalbert

This is a distillation of #6205; thanks to the commenters in that issue. The use of RGBMatrix is causing a DMA hang when used in conjunction with ESP32SPI. This line is looping forever:
https://github.com/adafruit/samd-peripherals/blob/d3b20192cf94fdea68a412596e082108ba5ebbf0/samd/dma.c#L207

        while ((dma_transfer_status(SHARED_TX_CHANNEL) & 0x3) == 0) {}

RGBMatrix uses ProtoMatter, which does significant work to send data to the RGB matrix in an ISR. If RGBMatrix is not used, the hang does not happen.

Test program:

import board
import busio
from digitalio import DigitalInOut
import displayio
import adafruit_requests as requests
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_display_text.bitmap_label import Label
from adafruit_matrixportal.matrix import Matrix
from adafruit_bitmap_font import bitmap_font

from secrets import secrets

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

esp = adafruit_esp32spi.ESP_SPIcontrol(board.SPI(), esp32_cs, esp32_ready, esp32_reset)

requests.set_socket(socket, esp)
esp.connect_AP(secrets["ssid"], secrets["password"])
print("Connected")

font = bitmap_font.load_font("lib/5x7.bdf")
led_board = Matrix().display
parent_group = displayio.Group()
textbox1 = Label(font=font, anchor_point=(0.0,0.0), anchored_position= (0,0))
parent_group.append(textbox1)
led_board.show(parent_group)

counter = 0
while True:
    r = requests.get("http://192.168.1.222:8000")
    textbox1.text = r.text
    counter += 1
    print(f'{counter} fetches')

Server that returns random-length results, for use with the test program above:

from flask import Flask, request
import logging
import random
import sys

app = Flask(__name__)

@app.get('/')
def get_response():
    return 'x' * random.randrange(750, 1500)

app.logger.setLevel(logging.INFO)
app.run(host="0.0.0.0", port=8000)

In general, within a few hundred fetches, the hang occurs, though the occurrence is otherwise random.

(Note that when RGBMatrix is not used, an ESP32SPI web fetch can still fail, due to an interrmittent communication error with the ESP32. However, that does not cause a hang. I will characterize and write up that bug in another issue.)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions