Beaglebone Black (BBB) is a nice embedded platform suitable for rapid design of low volume embedded devices.
It has plenty of possibilities, however compared to for example PocketBeagle, it lacks USB on the expansion headers.
My goal is to design an embedded device, which will contain an LTE modem module (such as SIM7600 or simillar with USB interface) or to use a mini-PCIe connector to extend existing design. A lot of mini-PCIe modules don't use actually PCIe, but just power and USB routed to the connector to standard places.
To accomplish my goal, I have basically two possibilities:
As you can see - I have chosen number two.
For the purpose, I have bought USB Host Shield for Arduino with MAX3421, removed both level shifters on the board with hot air, closed ALL solderable bridges except 5V and 3.3V close to writing "VBUS PWR". Then I have connected the board to my BBB in following way:
Next, I have compiled the max3421-hcd.c kernel module as a .ko dynamically loadable module, edited accordingly the device tree and I got this setup working at 8MHz of SPI clock giving me approximately 50-300kbps LTE speed with a Huawei E3372 USB LTE stick.
You have multiple options when building MAX3421 kernel module:
You can read tutorial from Derek Molloy (http://derekmolloy.ie/writing-a-linux-kernel-module-part-1-introduction/) where this is explained in detail, but in several steps:
sudo apt-get install linux-headers-$(uname -r)
obj-m+=max3421-hcd.o
all:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean
make
insmod max3421-hcd.ko
TL;DR version is:
arch/arm/boot/dts
and open file am335x-boneblack.dts
am335x-boneblack.dts
file:
&am33xx_pinmux {
spi0_pins: pinmux_spi0_pins {
pinctrl-single,pins = <
0x150 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_sclk.spi0_sclk */
0x154 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_d0.spi0_d0 */
0x158 (PIN_OUTPUT_PULLUP | MUX_MODE0) /* spi0_d1.spi0_d1 */
0x15c (PIN_OUTPUT_PULLUP | MUX_MODE0) /* spi0_cs0.spi0_cs0 */
0x040 0x37 /* P9_15, pull up, gpio mode 7 */
>;
};
};
/* enable SPIs */
&spi0 {
/*
SPI0 pins:
MOSI - P9.21
MISO - P9.18
SCK - P9.22
CS0 - P9.17
INT - P9.15 - GPIO48 -> GPIO1.16
*/
pinctrl-0 = <&spi0_pins>;
pinctrl-names = "default";
status = "okay";
/*
Maxim Integrated SPI-based USB 2.0 host controller MAX3421E
Required properties:
- compatible: Should be "maxim,max3421"
- spi-max-frequency: maximum frequency for this device must not exceed 26 MHz.
- reg: chip select number to which this device is connected.
- maxim,vbus-en-pin: <GPOUTx ACTIVE_LEVEL>
GPOUTx is the number (1-8) of the GPOUT pin of MAX3421E to drive Vbus.
ACTIVE_LEVEL is 0 or 1.
- interrupts: the interrupt line description for the interrupt controller.
The driver configures MAX3421E for active low level triggered interrupts,
configure your interrupt line accordingly.
*/
/*
from linux/irq.h
IRQ_TYPE_NONE = 0x00000000,
IRQ_TYPE_EDGE_RISING = 0x00000001,
IRQ_TYPE_EDGE_FALLING = 0x00000002,
IRQ_TYPE_EDGE_BOTH = (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING),
IRQ_TYPE_LEVEL_HIGH = 0x00000004,
IRQ_TYPE_LEVEL_LOW = 0x00000008,
IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH),
IRQ_TYPE_SENSE_MASK = 0x0000000f,
IRQ_TYPE_DEFAULT = IRQ_TYPE_SENSE_MASK,
*/
max3421@0 {
compatible = "maxim,max3421";
reg = <0>; /* using chip select / slave select 0 */
maxim,vbus-en-pin = <3 0>; /* GPOUT 3 on MAX3421 used to drive active low - PMOS 5V switch can be added */
spi-max-frequency = <8000000>; /* maximum is 26MHz here for MAX3421! */
interrupt-parent = <&gpio1>; /* taken from am33xx.dtsi, GPIO1 */
interrupts = <16 8>; /* GPIOx_16, LOW LEVEL interrupt, not edge, use pull-up! */
/* Connect INT signal to P9.15, GPIO48 a.k.a. GPIO1_16 ! */
};
};
sudo apt-get install -y gcc-arm-none-eabi
)CROSS_COMPILE=arm-none-eabi- ARCH=arm make dtbs
arch/arm/boot/dts/am335x-boneblack.dtb
uEnv.txt
file under /boot/uEnv.txt
to contain only these valid lines:uname_r=4.19.94-ti-r42
dtb=am335x-boneblack.dtb
enable_uboot_overlays=0
cmdline=coherent_pool=1M net.ifnames=0 lpj=1990656 rng_core.default_quality=100 quiet
am335x-boneblack.dtb
in /boot/dtbs/4.19.94-ti-r42/am335x-boneblack.dtb
/boot/dtbs/4.19.94-ti-r42/
to some "OLD" folder or delete theminsmod max3421-hcd.ko
in the folder where the .ko file is located[ 95.651274] max3421_hcd: loading out-of-tree module taints kernel.
[ 95.659255] max3421-hcd spi0.0: BUILD:Jul 1 2021 16:05:46
[ 95.672123] max3421-hcd spi0.0: property 'maxim,vbus-en-pin' value is <3 0>
[ 95.672446] max3421-hcd spi0.0: MAX3421 USB Host-Controller Driver
[ 95.672469] max3421-hcd spi0.0: new USB bus registered, assigned bus number 2
dDevice= 4.19
1
[ 95.672839] usb usb2: Product: MAX3421 USB Host-Controller Driver
[ 95.672846] usb usb2: Manufacturer: Linux 4.19.94-ti-r42 max3421
[ 95.672853] usb usb2: SerialNumber: spi0.0
[ 95.680083] hub 2-0:1.0: USB hub found
[ 95.680206] hub 2-0:1.0: 1 port detected
[ 95.685626] max3421-hcd spi0.0: rev 0x13, SPI clk 8000000Hz, bpw 8, irq 67
[ 96.013414] usb 2-1: new full-speed USB device number 2 using max3421-hcd
[ 96.171407] usb 2-1: not running at top speed; connect to a high speed hub
Device= 6.54
[ 96.184366] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 96.184374] usb 2-1: Product: USB2.1 Hub
[ 96.184381] usb 2-1: Manufacturer: GenesysLogic
[ 96.195397] hub 2-1:1.0: USB hub found
[ 96.199318] hub 2-1:1.0: 4 ports detected
[ 96.549357] usb 2-1.4: new full-speed USB device number 3 using max3421-hcd
cdDevice= 6.00
=3
[ 96.706757] usb 2-1.4: Product: FT232R USB UART
[ 96.706764] usb 2-1.4: Manufacturer: FTDI
[ 96.706771] usb 2-1.4: SerialNumber: A50285BI
[ 96.955632] usbcore: registered new interface driver usbserial_generic
[ 96.961402] usbserial: USB Serial support registered for generic
[ 97.070310] usbcore: registered new interface driver ftdi_sio
ce
[ 97.076451] ftdi_sio 2-1.4:1.0: FTDI USB Serial Device converter detected
[ 97.085606] usb 2-1.4: Detected FT232RL
B0
#
lsusb
shows:debian@beaglebone:~/max3421$ lsusb
Bus 002 Device 003: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 002 Device 002: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
/dev
, I can see:debian@beaglebone:~/max3421$ ls /dev | grep USB
ttyUSB0
debian@beaglebone:~/max3421$ sudo rmmod max3421_hcd
[ 295.115297] BUG: scheduling while atomic: rmmod/1107/0x00000002
[ 295.121461] Preemption disabled at:
<execution HANGS>