Skip to content

MAX3421E

pschatzmann edited this page Nov 24, 2026 · 2 revisions

Boards with no USB peripheral of their own -- classic ESP32 being the main one this library targets, but also SAMD21/SAMD51, nRF52840, and RP2040 (as an alternative to its native controller) -- can still act as a USB host by wiring up a MAX3421E host-shield chip over SPI. Adafruit_TinyUSB_Arduino already ships this driver (CFG_TUH_MAX3421, Adafruit_USBH_Host); this library just needs a way to hand it a device to auto-mount, same as the native-controller path.

Supported boards

Whatever architecture Adafruit_USBH_Host's interrupt-wiring code (tuh_max3421_int_api in Adafruit_USBH_Host.cpp) supports: SAMD, nRF52 (Adafruit variants), ESP32 (every variant -- classic, S2, S3, C3, C6, H2, P4, ...), and RP2040. Anything else hits a hard #error "MAX3421e host is not supported by this architecture" at compile time.

ESP8266 is not supported and will not be -- it's a different, non-ESP-IDF Arduino core (Xtensa LX106, no FreeRTOS), and Adafruit_TinyUSB_Arduino has no config, port, or interrupt-wiring code for it at all. Adding it would mean writing a new low-level TinyUSB MCU port from scratch, not just wiring up existing MAX3421E support -- a much bigger undertaking with no existing precedent upstream. If you need cheap Wi-Fi + USB host, use a classic ESP32 instead.

Which chips need this vs. use it optionally

  • No USB peripheral at all (classic ESP32, ESP32-C3/C6/H2, SAMD, nRF52, ...): MAX3421E is the only way to get USB host. This is the default and only mode there.
  • Has a native USB-OTG peripheral (ESP32-S2/S3/P4): the native host controller is the default (see ESP32_NATIVE.md). On S2/S3 it uses the core's own TinyUSB, which has no MAX3421E driver; to use a MAX3421E there anyway, build with -DUSBHOSTMSC_USE_ADAFRUIT_TINYUSB -DCFG_TUH_MAX3421=1 (Adafruit TinyUSB Library path).
  • RP2040: native dual-role controller is the default (usbstack=tinyusb_host); MAX3421E is available as an alternative but isn't this library's primary RP2040 path -- see extras/adafruit_tinyusb_stm32_host.patch's sibling examples in Adafruit_TinyUSB_Arduino if you need it.

Wiring

MAX3421E needs 5 pins: SPI (SCK/MOSI/MISO, or just an existing SPI instance), CS, and INT. There's no universal default -- it depends on your breakout and how you've wired it. CFG_TUH_MAX3421_ENDPOINT_TOTAL and friends are already sized by Adafruit_TinyUSB_Arduino's tusb_config_esp32.h; nothing in this library needs adjusting there.

API

#include "SPI.h"
#include "USBHostMSC.h"

// SPI bus, CS pin, INT pin -- match your wiring.
Adafruit_USBH_Host usbHost(&SPI, /*cs=*/10, /*intr=*/9);

USBHostMSC msc(usbHost);          // instead of the plain USBHostMSC msc;
// USBMscFatFS fatFs;
// USBHostMSC msc(usbHost, &fatFs);  // fsBackend still works the same way

void setup() {
  Serial.begin(115200);
  msc.onMount(onMount);
  msc.begin();                    // rhport defaults to 1 for MAX3421E
}

void loop() { msc.task(); }

The USBHostMSC(Adafruit_USBH_Host&, ...) constructor only exists when CFG_TUH_MAX3421 is set (i.e. automatically on classic ESP32 and other no-native-USB boards); begin() detects it was used and calls Adafruit_USBH_Host::begin() (which does the SPI/CS/INT bring-up itself) instead of tusb_init() directly. rhport is 1 by convention -- see Adafruit's own MAX3421E examples -- since rhport 0 is reserved for a chip's native peripheral where one exists.

See examples/USBHostMSC_MAX3421E_Info for a complete sketch.

Licensing

The MAX3421E driver (hcd_max3421.c, Adafruit_USBH_Host.cpp) ships as part of Adafruit_TinyUSB_Arduino itself (MIT), not as anything vendored into this library -- no additional licensing concerns beyond what's already covered in the main README.

Clone this wiki locally