Repository navigation
Conversation
With usb_mode = gadget, a Pi Zero (W), Zero 2 W, 3A+ or 4B connected to a computer appears there as a USB MIDI device called "mt32-pi", using Circle's CUSBMIDIGadget. Other models log a warning and fall back to host mode, as their USB controller sits behind the onboard hub. - The USB controller is now created in CMT32Pi::Initialize() as either CUSBHCIDevice or CMT32PiUSBMIDIGadget, since both can't share it. - The gadget subclass sets our USB IDs (pid.codes test IDs for now) and manufacturer/product strings. - Link libusbgadget.a. - Backport two Circle develop fixes (patches/circle-51.1.1-usb-midi-gadget.patch): reuse the MIDI interface after reconfiguration (otherwise a second enumeration fails an assertion) and invalidate DMA receive buffers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013W5uqwthuKxfKoH5S4ft1C
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013W5uqwthuKxfKoH5S4ft1C
Circle builds lib/usb/gadget empty for RASPPI=5, so src/usbmidigadget.o left pi5-64 with undefined references to CUSBMIDIGadget. The gadget class and its use in CMT32Pi::Initialize() are now under #if RASPPI <= 4; on the Pi 5, usb_mode = midi_device logs the existing warning and uses host mode. Pi 1-4 kernels compile the same code as before. mt32-pi.cfg: say that the Pi 5 falls back to host mode and that usb_mode has no effect with usb = off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012SetuMHhTUS7PvQSJZLUsy
CMT32Pi now owns its USB controller (host or gadget) through CUSBController, so the fake Circle gets usbcontroller.h, a CUSBHCIDevice that derives from it with Circle's constructor, a CUSBMIDIGadget that never comes up, usb.h's DESCRIPTOR_STRING and a CMachineInfo that reports a Zero 2 W. src/usbmidigadget.cpp joins the harness sources, and CSystem uses the five-argument CMT32Pi constructor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012SetuMHhTUS7PvQSJZLUsy
The patch backported Circle #720 and #722 but skipped #721 between them
("Complete bulk transfer cancellation before buffer reuse"). The MIDI
gadget's OUT endpoint cancels its transfer on deactivation and re-arms the
same buffer, the path #720 makes more common. Circle 51.1.1's gadget
sources match develop just before the series, so the patch is now
upstream's diff for all three commits, unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012SetuMHhTUS7PvQSJZLUsy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #24 by @waagbo, rebased onto
main(0.18.0) with the fixes it needed there. Thanks to waagbo for the feature: their two commits are kept unchanged at the bottom of this branch.What it does
usb_mode = midi_deviceinmt32-pi.cfgmakes a Pi Zero (W), Zero 2 W, 3A+ or 4B appear as a class-compliant USB MIDI device called "mt32-pi" when it's plugged into a computer, so no MIDI interface is needed. The default stayshost, and boards whose USB controller sits behind a hub (2B, 3B, 3B+), and now the Pi 5, log a warning and fall back to host mode. It uses Circle'sCUSBMIDIGadget;CMT32Pinow creates either the host controller or the gadget inInitialize(), because they can't share the controller.Changes on top of #24
lib/usb/gadgetempty forRASPPI=5, so Add support for USB MIDI Device Mode #24 leftpi5-64with undefined references toCUSBMIDIGadget. The gadget class and its use are now under#if RASPPI <= 4; Pi 1–4 kernels compile the same code as Add support for USB MIDI Device Mode #24.usbcontroller.h, aCUSBHCIDevicethat derives from it, aCUSBMIDIGadgetthat never comes up,usb.handmachineinfo.h;src/usbmidigadget.cppjoins the harness sources andCSystemuses the five-argument constructor. Without thishost-tests-*andthread-safetyfail to compilemt32pi.cpp.developjust before the series, so the patch is now upstream's diff for all three, unchanged.[Unreleased](not 0.18.0);mt32-pi.cfgnotes the Pi 5 fallback and thatusb_modedoes nothing withusb = off.Timing
CUSBHCIDeviceis created on the heap inCMT32Pi::Initialize()instead of as aCKernelmember, before the main loop starts.USBMIDIPacketHandler(), which enqueues intom_MIDIRxBuffer. #721's busy-waits (≤10 ms each,LOGPANICon a hardware timeout) are only inCancelTransfer(), which runs when the host suspends or reconfigures the device, not while notes are flowing.Testing
thread_safetytarget builds (only the two warnings already onmain).pi5-64links again and its kernel holds the host-mode fallback warning but none of the gadget strings;make mrproperreverses the Circle patch cleanly.Before merging
usb_mode = midi_deviceand Cakewalk on Windows: enumeration, Laura Bow 2 including theAMONRA.SYXupload, PC reboot and cable replug (the #720 path). Thenusb_mode = hostwith a USB MIDI adapter on the Zero 2 W and the Pi 5, since host-mode setup moved.1209:0001, which must not ship in a release.1209:3200is requested in Describe pim-32's need for a new pid pidcodes/pidcodes.github.com#1348; branchusb-pid-3200(one commit on top of this one) switches to it, for its own PR once pid.codes merges. Don't change the PID after release: Windows caches drivers by VID/PID.https://claude.ai/code/session_012SetuMHhTUS7PvQSJZLUsy
Generated by Claude Code