Skip to content

USB: USB_Host_Shield_2.0

hasu@tmk edited this page Jan 12, 2024 · 6 revisions

Address Assignment

  • Hub with parent = 0 is assigned to 0x41. port is not used.
  • Device with parent = 0 is assigned to 0x01. port is not used.
  • Hub with parent != 0 is assigned using hubCounter. port is not used.
  • Device with parent != 0 is assigned using port.

address.h:

virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0)

UsbDeviceAddress:

struct UsbDeviceAddress {
        union {

                struct {
                        uint8_t bmAddress : 3; // device address/port number
                        uint8_t bmParent : 3; // parent hub address
                        uint8_t bmHub : 1; // hub flag
                        uint8_t bmReserved : 1; // reserved, must be zero
                } __attribute__((packed));
                uint8_t devAddress;
        };
} __attribute__((packed));
    bit ____________________________ Reserved(0)
       /   _________________________ Hub flag(bmHub)
      /   /   ______________________ Parent Hub no(bmParent)
     /   /   /   /   /   ___________ Hub no or Port no(bmAddress)
    /   /   /   /   /   /   /   /
    7   6   5   4   3   2   1   0
    -----------------------------
    0   0   0   0   0   0   0   0  00   Default Address
    0   0   0   0   0   0   0   1  01   Device directly attached on Host Controller
    0   1   0   0   0   0   0   1  41   Hub 1 directly attached to Host Controller
    0   1   0   0   1   0   1   0  4A   Hub 2 on Hub 1
    0   1   0   0   1   0   1   1  4B   Hub 3 on Hub 1
    0   1   0   1   0   0   1   1  53   Hub 3 on Hub 2
    0   0   0   0   1   0   0   1  09   Device on Port 1 of Hub 1(Root Hub)
    0   0   0   0   1   0   1   0  0A   Device on Port 2 of Hub 1(Root Hub)
    0   0   0   1   0   0   0   1  11   Device on Port 1 of Hub 2
    0   0   0   1   0   0   1   0  12   Device on Port 2 of Hub 2

Error

MAX3421E error codes:

/* Host error result codes, the 4 LSB's in the HRSL register */
#define hrSUCCESS   0x00                                                                    
#define hrBUSY      0x01                                                                    
#define hrBADREQ    0x02                                                                    
#define hrUNDEF     0x03                                                                       
#define hrNAK       0x04                                                                       
#define hrSTALL     0x05                                                                       
#define hrTOGERR    0x06                                                      
#define hrWRONGPID  0x07                                                      
#define hrBADBC     0x08                                                                                   
#define hrPIDERR    0x09                                                                                   
#define hrPKTERR    0x0A                                                                                   
#define hrCRCERR    0x0B                                                         
#define hrKERR      0x0C                                                         
#define hrJERR      0x0D                                                         
#define hrTIMEOUT   0x0E                 
#define hrBABBLE    0x0F                

Line State

https://www.usbmadesimple.co.uk/ums_3.htm

State D+ D- Desc
Differential '1' high low
Differential '0' low hight
Single Ended Zero (SE0) low low
Single Ended One (SE1) high high
J State: Low-speed low hight Differential '0'
J State: Full-speed high low Differential '1'
K State: Low-speed high low Differential '1'
K State: Full-speed low hight Differential '0'
Idle State: Low-speed low hight J State, D- pull-up
Idle State: Full-speed high low J State, D+ pull-up
Resume State K State
Start of Packet (SOP) Data lines switch from idle to K state
End of Packet (EOP) SE0 for 2 bit times followed by J state for 1 bit time
Disconnect SE0 for >= 2us
Connect Idle for 2.5us
Reset SE0 for >= 2.5 us

bPwrOn2PwrGood

https://elixir.bootlin.com/linux/v5.15.4/source/drivers/usb/core/hub.h#L147

static inline unsigned hub_power_on_good_delay(struct usb_hub *hub)
{
	unsigned delay = hub->descriptor->bPwrOn2PwrGood * 2;

	if (!hub->hdev->parent)	/* root hub */
		return delay;
	else /* Wait at least 100 msec for power to become stable */
		return max(delay, 100U);
}

Clone Incompatibility

74HC125 vs 74AHC125

https://www.printed-droid.com/kb/usb-host-shield-repair/

Clone Issues

Clone this wiki locally