cyclicredundancy
Posts: 1
Joined: Fri Apr 26, 2013 7:24 am

Support for MAX3421E USB host controller

Mon Jan 01, 2018 12:31 am

I am trying to figure out if the raspberry pi has linux drivers for the maxim MAX3421E SPI USB host controller.
https://www.maximintegrated.com/en/prod ... 3421E.html
This is the same chip used in the various USB host shield boards:
https://www.circuitsathome.com/arduino_ ... _projects/

Googling around randomly.... I see that there seems to be code in the linux kernel for this:
https://github.com/torvalds/linux/blob/ ... 3421-hcd.c

And the same code is also there in the raspberry pi kernel source tree:
https://github.com/raspberrypi/linux/bl ... 3421-hcd.c

Is there some way for me to figure out if that driver is supported in Raspbian which is running kernel version 4.9.72 ?

Will the driver be compiled as a module?
I tried a grep and could not locate it under /lib/modules , so does that mean it is not compiled by default?

$ find /lib/modules/ | grep hcd
/lib/modules/4.9.59-v7+/kernel/drivers/usb/usbip/vhci-hcd.ko
/lib/modules/4.9.72+/kernel/drivers/usb/usbip/vhci-hcd.ko
/lib/modules/4.9.72-v7+/kernel/drivers/usb/usbip/vhci-hcd.ko
/lib/modules/4.9.59+/kernel/drivers/usb/usbip/vhci-hcd.ko

If the driver is not preset if it fairly straightforward to add support for it, or build it on my own?
The last time I tried to build a linux kernel was sometime in 2001 :-p so I will pretty much be starting from scratch.

Thanks!

kernel config:
https://cateee.net/lkddb/web-lkddb/USB_MAX3421_HCD.html
email list post where support for this driver was requested to be pulled into the kernel:
https://www.spinics.net/lists/linux-usb/msg104882.html

broe23
Posts: 902
Joined: Thu Jan 28, 2016 9:35 pm
Location: Central IL
Contact: Website

Re: Support for MAX3421E USB host controller

Mon Jan 01, 2018 7:19 am

Does Raspbian not see that controller?
Ren: Now listen, Cadet. I've got a job for you. See this button? Ren: Don't touch it! It's the History Eraser button, you fool! Stimpy: So what'll happen? Ren: That's just it. We don't know. Maybe something bad, maybe something good.

User avatar
rpdom
Posts: 17716
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Support for MAX3421E USB host controller

Mon Jan 01, 2018 9:27 am

You can check the kernel config, which is now held in a module, so you need to load that first, then check the config file.

Code: Select all

pi@raspi7:~ $ sudo modprobe configs
pi@raspi7:~ $ zgrep MAX3421 /proc/config.gz 
# CONFIG_USB_MAX3421_HCD is not set
So that looks like it isn't available in the kernel that I'm currently running (4.9.35-v7+).

You'd need to make a custom kernel to add support.

cezar.santanna
Posts: 5
Joined: Thu Jun 23, 2016 7:25 pm

Re: Support for MAX3421E USB host controller

Sat Jun 30, 2018 9:34 pm

Does any one get any success using this chip as USB HOST?

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Thu Sep 27, 2018 2:37 pm

Bump. Has anyone had any experience at all with this chip on the PI?

dconnx
Posts: 1
Joined: Tue Feb 19, 2019 9:56 am

Re: Support for MAX3421E USB host controller

Tue Feb 19, 2019 9:58 am

Hi, Did anyone get anywhere (with getting a MAX3421 recognised as a USB controller on the RP SPI bus) ? I'm interested in this too. thanks Derek

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Tue Feb 19, 2019 1:34 pm

Yes I have it working on a pi zero w. Do you have any specific questions?

billoo2378
Posts: 2
Joined: Tue Feb 19, 2019 7:08 pm

Re: Support for MAX3421E USB host controller

Tue Feb 19, 2019 7:16 pm

The MAX3421E USB peripheral/host controller contains the digital logic and analog circuitry necessary to implement a full-speed USB peripheral or a full-/low-speed host compliant to USB specification rev 2.0. A built-in transceiver features ±15kV ESD protection and programmable USB connect and disconnect.

billoo2378
Posts: 2
Joined: Tue Feb 19, 2019 7:08 pm

Re: Support for MAX3421E USB host controller

Wed Feb 20, 2019 11:48 am

:P The MAX3421E USB peripheral/host controller contains the digital logic and analog circuitry necessary to implement a full-speed USB peripheral or a full-/low-speed host compliant to USB specification rev 2.0. A built-in transceiver features ±15kV ESD protection and programmable USB connect and disconnect. An internal serial interface engine (SIE) handles low-level USB protocol details such as error checking and bus retries. The MAX3421E operates using a register set accessed by an SPI interface that operates up to 26MHz. Any SPI master (microprocessor, ASIC, DSP, etc.) can add USB peripheral or host functionality using the simple 3- or 4-wire SPI interface. :P :P :P

scarlyon
Posts: 2
Joined: Sun Jun 23, 2019 10:24 am

Re: Support for MAX3421E USB host controller

Sun Jun 23, 2019 11:49 am

emw wrote:
Tue Feb 19, 2019 1:34 pm
Yes I have it working on a pi zero w. Do you have any specific questions?
Hi.

I am going to use a barcode scanner with MAX3421E as I can't use the original USB port.

Could you please guide me on how to use that?

Cheers.

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Mon Jun 24, 2019 3:48 pm

here are my notes:

''' Note this was originally done with the 4.14 kernel and should be updated for newer versions'''

Code: Select all

 
sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
sudo apt-get install bc libncurses5-dev bison flex libssl-dev
rpi-source
This may take a while

back porting is not required for kernel 4.19

cd linux/drivers/usb/host/
mv max3421-hcd.c max3421-hcd.c.old

The next line gets the new version of max3421-hcd.c with device tree support

wget https://raw.githubusercontent.com/torva ... 3421-hcd.c


Code: Select all

cd ~/linux
make menuconfig
-> set <M> MAX3421 HCD (USB-over-SPI) support

Code: Select all

scripts/diffconfig
should respond with 'USB_MAX3421_HCD n -> m'

Code: Select all

grep MAX3421 .config
should respond with 'CONFIG_USB_MAX3421_HCD=m'

Code: Select all

make prepare
make SUBDIRS=drivers/usb/host/ modules

Code: Select all

sudo make SUBDIRS=drivers/usb/host/ modules_install
above line may create warning

Code: Select all

sudo depmod

Code: Select all

 cd ~/linux/arch/arm/boot/dts/overlays/
create the file max3421-spi0-overlay.dts

Code: Select all

/dts-v1/;
 /plugin/;
 
 / {
         compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
 
         fragment@0 {
         target = <&spidev0>;
                 __overlay__ {
                         status = "disabled";
                 };
         };
 
         /* the interrupt pin of the usb-controller */
         fragment@2 {
                 target = <&gpio>;
                 __overlay__ {
                         usb2_pins: usb2_pins {
                                 brcm,pins = <25>;
                                 brcm,function = <0>; /* input */
                         };
                 };
         };
 
 
         fragment@3 {
                 target = <&spi0>;
                 __overlay__ {
 
                         #address-cells = <1>;
                         #size-cells = <0>;
                         pinctrl-names = "default";
                         pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
                         cs-gpios = <&gpio 8 1>;
                         status = "okay";
 
                         maxim3421: usb@2 {
                                 compatible = "maxim,max3421";
                                 reg = <0>; /* CE0 */
                                 maxim,vbus-en-pin = <3 1>;
                                 interrupt-parent = <&gpio>;
                                 interrupts = <25 8>; /* low irq */
                                 #gpio-controller;
                                 #gpio-cells = <2>;
                                 spi-max-frequency = <10000000>;
                         };
                 };
         };
 
 };
then

Code: Select all

 sudo dtc -@ -I dts -O dtb -o /boot/overlays/max3421-spi0.dtbo max3421-spi0-overlay.dts
this will include 3 warnings '/boot/overlays/max3421-spi0.dtbo: Warning (unit_address_vs_reg): Node /fragment@0 has a unit name, but no reg property'


Code: Select all

 sudo nano /boot/config.txt
  • uncomment
    #dtparam=spi=on
  • add
    dtoverlay=max3421-spi0
    dtoverlay=dwc2



reboot

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Mon Jun 24, 2019 3:53 pm

You will also need some hardware, and the above may vary slightly on how/what hardware you use. I used a sparkfun board with a minor power modification (5v is provided from pi rather than lm 1117).

Sparkfun Max3421 to pi wiring
RX
TX
2
3
4
5
6
7

8
9 INT to Pin 22 (GPIO25)
10 SS to Pin 24 (GPIO 8)
11 MOSI to Pin 19 (GPIO 10)
12 MISO to Pin 21 (GPIO9)
13 SCLK to Pin 23 (GPIO11)
G
AREF


AIN5
AIN4
AIN3
AIN2
AIN1
AIN 0

VIN
G
G to Pin 15 (GND)
+5 to Pin 2 (+5)
+3.3
RST


The modification to the board is a jumper wire from +5 (on connector above) to +term of tantalum capacitor beside USB connector

metronom
Posts: 2
Joined: Sat Apr 25, 2020 10:52 am

Re: Support for MAX3421E USB host controller

Sat Apr 25, 2020 11:20 am

Hello all,

Thanks a lot for the detailed instructions! I've followed them on my Raspberry Pi Zero with partial success: Any peripheral connected to the port interfaced by MAX3421E gets recognized, but is unusable.

Example: If I connect a simple thumb drive, it gets listed in lsusb. But it is unmounteable.
dmesg tells me the following:
[ 25.474706] usb usb2: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 4.19
[ 25.474730] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 25.474743] usb usb2: Product: MAX3421 USB Host-Controller Driver
[ 25.474755] usb usb2: Manufacturer: Linux 4.19.97+ max3421
[ 25.474766] usb usb2: SerialNumber: spi0.0
[ 25.909447] usb 2-1: new full-speed USB device number 2 using max3421-hcd
[ 26.116687] usb 2-1: not running at top speed; connect to a high speed hub
[ 26.143644] usb 2-1: New USB device found, idVendor=0409, idProduct=005a, bcdDevice= 1.00
[ 26.143671] usb 2-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
So the MAX3421E drivers seem to work.
[ 26.979448] usb 2-1.4: new full-speed USB device number 4 using max3421-hcd
[ 27.149575] usb 2-1.4: not running at top speed; connect to a high speed hub
[ 27.199799] usb 2-1.4: New USB device found, idVendor=12f7, idProduct=1e23, bcdDevice= 1.10
[ 27.199825] usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 27.199839] usb 2-1.4: Product: TRAVELDRIVE 005B
[ 27.199850] usb 2-1.4: Manufacturer: Memorex
[ 27.199860] usb 2-1.4: SerialNumber: 077B0B350BC4
[ 27.201936] usb-storage 2-1.4:1.0: USB Mass Storage device detected
[ 27.206749] scsi host0: usb-storage 2-1.4:1.0
[ 35.730761] usbcore: registered new interface driver uas
It even recognizes my thumb drive. But then:
[ 66.809414] usb 2-1-port4: cannot reset (err = -110)
[ 67.849467] usb 2-1-port4: cannot reset (err = -110)
[ 68.889922] usb 2-1-port4: cannot reset (err = -110)
[ 69.929512] usb 2-1-port4: cannot reset (err = -110)
[ 70.969426] usb 2-1-port4: cannot reset (err = -110)
[ 70.969444] usb 2-1-port4: Cannot enable. Maybe the USB cable is bad?
[ 72.009543] usb 2-1-port4: cannot disable (err = -110)
[ 73.049495] usb 2-1-port4: cannot reset (err = -110)
[ 74.090251] usb 2-1-port4: cannot reset (err = -110)
[ 75.129531] usb 2-1-port4: cannot reset (err = -110)
[ 76.169562] usb 2-1-port4: cannot reset (err = -110)
[ 77.209737] usb 2-1-port4: cannot reset (err = -110)
[ 77.209755] usb 2-1-port4: Cannot enable. Maybe the USB cable is bad?
[ 78.249525] usb 2-1-port4: cannot disable (err = -110)
[ 79.289588] usb 2-1-port4: cannot reset (err = -110)
[ 80.329495] usb 2-1-port4: cannot reset (err = -110)
[ 81.369540] usb 2-1-port4: cannot reset (err = -110)
[ 82.409539] usb 2-1-port4: cannot reset (err = -110)
[ 83.449567] usb 2-1-port4: cannot reset (err = -110)
[ 83.449585] usb 2-1-port4: Cannot enable. Maybe the USB cable is bad?
[ 84.489466] usb 2-1-port4: cannot disable (err = -110)
[ 85.529593] usb 2-1-port4: cannot reset (err = -110)
[ 86.569439] usb 2-1-port4: cannot reset (err = -110)
[ 87.609500] usb 2-1-port4: cannot reset (err = -110)
[ 88.649453] usb 2-1-port4: cannot reset (err = -110)
[ 89.689640] usb 2-1-port4: cannot reset (err = -110)
[ 89.689660] usb 2-1-port4: Cannot enable. Maybe the USB cable is bad?
[ 90.729608] usb 2-1-port4: cannot disable (err = -110)
[ 91.769498] usb 2-1-port4: cannot disable (err = -110)
I have tried several USB peripherals, all with the same result. I have used self- powered USB hubs to rule out power supply issues. Also, same result. The corresponding file in /dev/ gets created (e.g. /dev/sda in case of thumb drive). But no device I have tried has been actually functional.

Does anyone have any idea what the problem could be? What could cause the "-110" error above? Any help would be greatly appreciated.
Thanks in advance!

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Sat Apr 25, 2020 3:31 pm

Sorry not sure what is going on with your setup. I don't have anything thing set up right now, but i can see a few things you are doing different than my setup

1) I was not using a USB hub
2) I was only using a Full speed usb device (not high speed as your logs indicated above)
3) I was probably using an older kernel than you 4.14 or 4.19

Also I was using it with USBProxy, buy i don't think that should make any difference.

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Tue Apr 28, 2020 12:49 pm

Another thing I was thinking could be causing the problem. How long are the wires to MOSI, MISO and SCLK. These should be very short (especially SCLK).

metronom
Posts: 2
Joined: Sat Apr 25, 2020 10:52 am

Re: Support for MAX3421E USB host controller

Tue Apr 28, 2020 5:05 pm

Thanks for your replies!
The whole setup takes place on a small board, the wires are max 1cm long., so that shouldn't be an issue.

I just noticed, you seem to have wired up the VL- Pin (PIN 2) of the MAX3421 to 5V.
If I interpret the data sheet correctly, that pin sets the logic power level and should be between 1.4V and 3.6V. Any particular reason you set it to 5V?
Did you use a pull-up in between INT pin and GPIO25? For me, the Interrupt GPIO recieves 0 by default, which seems odd, seeing how the MAX3421 works with active low interrupts.

Thanks again!

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Tue Apr 28, 2020 5:41 pm

That is pin 2 of the pi gio header(+5V) connected to +5V pin on the sparkfun board (the mod I listed feeds this to the input to 3.3V regulator). You are correct pin2 of the MAX3421E is connected to 3.3V.

The sparkfun board has a 2.2Kohm resistor on the interrupt.



http://www.sparkfun.com/datasheets/DevT ... ld-v13.pdf
https://www.sparkfun.com/products/9947

Rivelino
Posts: 2
Joined: Sun Jul 05, 2020 9:56 am

Re: Support for MAX3421E USB host controller

Sun Jul 26, 2020 9:54 am

Hi to everyone.

@emw : Do you have a working image for pi zero w with USBProxy ?

Max2341E is working with drivers, but USBProxy throw me a lot of errors.

Anyone also try it Raspdancer ? Have anyone a working image?

Regards

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Sun Jul 26, 2020 12:48 pm

I don't have an image i can give you. but maybe i can help with errors are you getting with usbproxy?

Rivelino
Posts: 2
Joined: Sun Jul 05, 2020 9:56 am

Re: Support for MAX3421E USB host controller

Wed Jul 29, 2020 10:56 am

Hi,
I observed on compile "make" i have 3 errors from GadgetFShelpers.c and dirent.h for "readdir_r".
What i read this command is obsolete. I try it with no luck to change it to new command "readdir".
I have also error on compilation.
Can you help me with compile?

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: Support for MAX3421E USB host controller

Wed Jul 29, 2020 12:56 pm

I am working with a heavily modified version of usb proxy, so I can't check right now. but I seem to remember the readdir_r was a warning not an error. The following comments are a bit dated, but I hope they help.

There is a fork @ https://github.com/scottellis/USBProxy which replaces readdir_r and a few other minor changes.

You will also need to add "20980000.usb", to *devices[] in src/Plugins/Hosts/GadgetFS_helpers.c to recognize the pi zero w otg controller.

Have you verified the Max2421E is working. usbProxy requires a host and an otg port to work.

Return to “General discussion”