發(fā)現(xiàn)只要編譯選項(xiàng)設(shè)置成沒(méi)有優(yōu)化,usb host就會(huì)出問(wèn)題
使用官方例程:Wch例子\CH32V307EVT\EVT\EXAM\USB\USBHS\HOST_KM
官方例程默認(rèn)是 -os優(yōu)化,插入一個(gè)usb設(shè)備以后,輸出:
SystemClk 222:96000000
ChipID:30500518
USB HOST KM Test
TIM3 Init OK!
USBHS Host Init
USB Port1 Dev Out.
USB Port1 Dev In.
Enum:
Get DevDesc: 12 01 10 01 00 00 00 08 a7 1e 64 00 00 02 00 01 00 01?
Set DevAddr: OK
Get CfgDesc: 09 02 22 00 01 01 00 a0 32 09 04 00 00 01 03 01 02 00 09 21 10 01 00 01 22 69 00 07 05 81 03 08 00 02?
DevType: 03
Set Cfg: OK
Root Device Is HID. Enum Hid:
Analyze CfgDesc: OK
Get Interface0 RepDesc: 06 b5 ff 09 01 a1 01 85 b5 09 02 15 00 26 ff 00 75 08 95 07 81 02 09 02 15 00 26 ff 00 75 08 95 07 91 02 c0 05 01 09 02 a1 01 85 02 09 01 a1 00 05 09 19 01 29 08 15 00 25 01 95 08 75 01 81 02 05 01 09 30 09 31 16 01 f8 26 ff 07 75 0c 95 02 81 06 09 38 15 81 25 7f 75 08 95 01 81 06 05 0c 0a 38 02 95 01 81 06 c0 c0?
Get StringDesc2: 16 03 32 00 2e 00 34 00 47 00 20 00 4d 00 6f 00 75 00 73 00 65 00?
Further Enum Result: OK
------------------------------------------------------------------------------------------------------------
如果把這個(gè)優(yōu)化選項(xiàng)改為 None -00,輸出為
SystemClk 222:96000000
ChipID:30500518
USB HOST KM Test
TIM3 Init OK!
USBHS Host Init
USB Port1 Dev Out.
USB Port1 Dev In.
Enum:
Get DevDesc: Err(20)
Get DevDesc: Err(20)
Get DevDesc: Err(20)
Get DevDesc: Err(20)
Get DevDesc: Err(20)
Get DevDesc: Err(20)
Enum Fail with Error Code:45