micropython / micropython/micropython-lib

usb-midi-device crashes esp32-s3 when OUT USB packets sent at line rate

Open
#1,162 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

Splitting this issue out from #1158 where it was independently discovered by @agatti while investigating a related issue.

The issue can be reproduced by setting up a CPython program that transmits MIDI data to the device as quickly as possible. For example:

import rtmidi2
out = rtmidi2.MidiOut()
# Port 1 is 'Espressif Device:Espressif Device MIDI 1 24:0' in my case
out.open_port(1)
while True:
    out.send_pitchbend(0, 0)  # channel, pitch
    out.send_noteon(0, 48, 100)
    out.send_noteoff(0, 48)
    print(".", end="")

(Note that only the second two messages are currently processed by the MIDI device class, pitchbend messages are discarded.)

If running midi_example.py on the ESP32-S3, the exhibited behaviour is a few messages may be processed normally and then the handler fails with nonsense errors such as:

Traceback (most recent call last):
  File "usb/device/midi.py", line 168, in _on_rx
  File "usb/device/core.py", line 859, in pend_read
AttributeError: 'Buffer' object has no attribute '_b'
Traceback (most recent call last):
  File "usb/device/core.py", line 342, in _xfer_cb
  File "usb/device/midi.py", line 156, in _rx_cb
  File "usb/device/core.py", line 827, in finish_write
AttributeError: 'Buffer' object has no attribute '_b'

and/or possibly a hard crash.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with midi_example.py on an ESP32-S3 using the provided rtmidi2 line-rate sender. Start by tracing the receive and transfer callbacks in usb/device/midi.py and usb/device/core.py, especially the paths shown in the traceback. Done means sustained MIDI input no longer produces Buffer attribute errors or a hard crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.