> 文章列表 > USB键盘实现——设置地址(二)

USB键盘实现——设置地址(二)

USB键盘实现——设置地址(二)

文章目录

  • 设置地址
    • 仓库地址
    • 设备请求
      • 标准设备请求
      • USB 控制端点收到的数据
    • 附 STM32 枚举日志

设置地址

设置地址内容解析和 HID鼠标 一致。

仓库地址

仓库地址

设备请求

标准设备请求

typedef struct __attribute__ ((packed)){union {struct __attribute__ ((packed)) {uint8_t recipient :  5; ///< Recipient type usb_request_recipient_t.uint8_t type      :  2; ///< Request type usb_request_type_t.uint8_t direction :  1; ///< Direction type. usb_dir_t} bmRequestType_bit;uint8_t bmRequestType;};uint8_t  bRequest;uint16_t wValue;uint16_t wIndex;uint16_t wLength;
} usb_control_request_t;

USB 控制端点收到的数据

0x0 0x5 0x4 0x0 0x0 0x0 0x0 0x0
  • bmRequestType:0x00
    • 数据传输方向为 0,host->device
    • 标准请求
    • 请求的接收者为设备
  • bRequest:0x05
    • SET_ADDRESS 设置地址请求
  • wValue:0x0004(LSB)
    • 低位:0x04 设备地址低位
    • 高位:0x00 设备地址高位
  • wIndex:0x0000(LSB)
    • 低位:0x00
    • 高位:0x00
  • wLength:0x0000
    • 低位:0x00
    • 高位:0x00

这里将收到的地址 0x04 写入 STM32 的 USB 地址寄存器 USB_OTG_DCFG_DAD 即可

设置地址完成之后主机会再次获取设备描述符,这一次是真心的获取

0x80 0x6 0x0 0x1 0x0 0x0 0x12 0x0
  • wLength:0x12
    • 低位:0x12 请求返回的字节数为 0x12。
    • 高位:0x00

其它位段和设备描述符文章一致。

附 STM32 枚举日志

HID 键盘枚举日志

suspend int
bus reset int
enum done int
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x1 0x0 0x0 0x40 0x0 
dcd xfer 12
input ep int 
d->h :0x12 0x1 0x0 0x2 0x0 0x0 0x0 0x40 0xfe 0xca 0x8 0x40 0x0 0x1 0x1 0x2 0x3 0x1 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
bus reset int
output ep int 
send xfer complete event
enum done int
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x0 0x5 0x4 0x0 0x0 0x0 0x0 0x0 
dcd xfer 0
input ep int 
edpt int send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x1 0x0 0x0 0x12 0x0 
dcd xfer 12
input ep int 
d->h :0x12 0x1 0x0 0x2 0x0 0x0 0x0 0x40 0xfe 0xca 0x8 0x40 0x0 0x1 0x1 0x2 0x3 0x1 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
output ep int 
send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x2 0x0 0x0 0xff 0x0 
dcd xfer 22
input ep int 
d->h :0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32 0x9 0x4 0x0 0x0 0x1 0x3 0x1 0x1 0x0 0x9 0x21 0x11 0x1 0x0 0x1 0x22 0x41 0x0 0x7 0x5 0x81 0x3 0x8 0x0 0xa 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x3 0x3 0x9 0x4 0xff 0x0 
send xfer complete event
dcd xfer e
input ep int 
d->h :0xe 0x3 0x31 0x0 0x32 0x0 0x33 0x0 0x34 0x0 0x35 0x0 0x36 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x3 0x0 0x0 0xff 0x0 
send xfer complete event
dcd xfer 4
input ep int 
d->h :0x4 0x3 0x9 0x4 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x2 0x3 0x9 0x4 0xff 0x0 
send xfer complete event
dcd xfer 1e
input ep int 
d->h :0x1e 0x3 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 0x0 0x20 0x0 0x44 0x0 0x65 0x0 0x76 0x0 0x69 0x0 0x63 0x0 0x65 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x6 0x0 0x0 0xa 0x0 
send xfer complete event
get device qualifier
stall ep0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x1 0x0 0x0 0x12 0x0 
dcd xfer 12
input ep int 
d->h :0x12 0x1 0x0 0x2 0x0 0x0 0x0 0x40 0xfe 0xca 0x8 0x40 0x0 0x1 0x1 0x2 0x3 0x1 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x2 0x0 0x0 0x9 0x0 
send xfer complete event
dcd xfer 9
input ep int 
d->h :0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x2 0x0 0x0 0x22 0x0 
send xfer complete event
dcd xfer 22
input ep int 
d->h :0x9 0x2 0x22 0x0 0x1 0x1 0x0 0xa0 0x32 0x9 0x4 0x0 0x0 0x1 0x3 0x1 0x1 0x0 0x9 0x21 0x11 0x1 0x0 0x1 0x22 0x41 0x0 0x7 0x5 0x81 0x3 0x8 0x0 0xa 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x0 0x9 0x1 0x0 0x0 0x0 0x0 0x0 
send xfer complete event
edpt open
dcd xfer 0
input ep int 
edpt int send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x21 0xa 0x0 0x0 0x0 0x0 0x0 0x0 
dcd xfer 0
input ep int 
edpt int send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x81 0x6 0x0 0x22 0x0 0x0 0x81 0x0 
dcd xfer 40
input ep int 
d->h :0x5 0x1 0x9 0x6 0xa1 0x1 0x5 0x7 0x19 0xe0 0x29 0xe7 0x15 0x0 0x25 0x1 0x95 0x8 0x75 0x1 0x81 0x2 0x95 0x1 0x75 0x8 0x81 0x1 0x5 0x8 0x19 0x1 0x29 0x5 0x95 0x5 0x75 0x1 0x91 0x2 0x95 0x1 0x75 0x3 0x91 0x1 0x5 0x7 0x19 0x0 0x2a 0xff 0x0 0x15 0x0 0x26 0xff 0x0 0x95 0x6 0x75 0x8 0x81 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 1
input ep int 
d->h :0xc0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
output ep int 
send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x21 0x9 0x0 0x2 0x0 0x0 0x1 0x0 
dcd xfer 1
rxflvl int
output ep int 
send xfer complete event
dcd xfer 0
input ep int 
edpt int send xfer complete event
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x0 0x3 0x0 0x0 0xff 0x0 
dcd xfer 4
input ep int 
d->h :0x4 0x3 0x9 0x4 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x1 0x3 0x9 0x4 0xff 0x0 
send xfer complete event
dcd xfer 10
input ep int 
d->h :0x10 0x3 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
setup packed recvd
setup packed done
output ep int 
h->d: 0x80 0x6 0x2 0x3 0x9 0x4 0xff 0x0 
send xfer complete event
dcd xfer 1e
input ep int 
d->h :0x1e 0x3 0x74 0x0 0x79 0x0 0x75 0x0 0x73 0x0 0x74 0x0 0x6c 0x0 0x69 0x0 0x20 0x0 0x44 0x0 0x65 0x0 0x76 0x0 0x69 0x0 0x63 0x0 0x65 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 0
rxflvl int
output ep int 
send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event
dcd xfer 8
0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 
input ep int 
d->h :0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 
turn off txfe
input ep int 
edpt int send xfer complete event