Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
luozhenger
rt-thread
提交
9b44af94
R
rt-thread
项目概览
luozhenger
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b44af94
编写于
12月 14, 2017
作者:
lymzzyh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Components][Drivers][USB HOST]Fix core stack and msc driver
可以挂U盘了 欢迎测试鲁棒性已打通F4全系列HOST驱动(OTGFS)
上级
18d42fe0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
47 deletion
+82
-47
components/drivers/Kconfig
components/drivers/Kconfig
+7
-2
components/drivers/usb/usbhost/class/mass.c
components/drivers/usb/usbhost/class/mass.c
+23
-17
components/drivers/usb/usbhost/class/udisk.c
components/drivers/usb/usbhost/class/udisk.c
+14
-7
components/drivers/usb/usbhost/core/core.c
components/drivers/usb/usbhost/core/core.c
+36
-19
components/drivers/usb/usbhost/core/hub.c
components/drivers/usb/usbhost/core/hub.c
+2
-2
未找到文件。
components/drivers/Kconfig
浏览文件 @
9b44af94
...
...
@@ -107,9 +107,14 @@ menu "Using USB"
default n
if RT_USING_USB_HOST
config RT_USBH_
ADK
bool "Enable
connected with Android by ADK USB
"
config RT_USBH_
MSTORAGE
bool "Enable
Udisk Drivers
"
default n
if RT_USBH_MSTORAGE
config UDISK_MOUNTPOINT
string "Udisk mount dir"
default "/"
endif
endif
config RT_USING_USB_DEVICE
bool "Using USB device"
...
...
components/drivers/usb/usbhost/class/mass.c
浏览文件 @
9b44af94
...
...
@@ -59,11 +59,14 @@ static rt_err_t _pipe_check(struct uhintf* intf, upipe_t pipe)
rt_kprintf
(
"pipe status error
\n
"
);
return
-
RT_EIO
;
}
if
(
pipe
->
status
==
UPIPE_STATUS_STALL
)
{
/* clear the pipe stall status */
ret
=
rt_usbh_clear_feature
(
device
,
pipe
->
ep
.
bEndpointAddress
,
USB_FEATURE_ENDPOINT_HALT
);
if
(
ret
!=
RT_EOK
)
return
ret
;
}
/* clear the pipe stall status */
ret
=
rt_usbh_clear_feature
(
device
,
pipe
->
ep
.
bEndpointAddress
,
USB_FEATURE_ENDPOINT_HALT
);
if
(
ret
!=
RT_EOK
)
return
ret
;
rt_thread_delay
(
50
);
...
...
@@ -172,7 +175,7 @@ static rt_err_t rt_usb_bulk_only_xfer(struct uhintf* intf,
if
(
csw
.
status
!=
0
)
{
rt_kprintf
(
"csw status error:%d
\n
"
,
csw
.
status
);
//
rt_kprintf("csw status error:%d\n",csw.status);
return
-
RT_ERROR
;
}
...
...
@@ -211,16 +214,20 @@ rt_err_t rt_usbh_storage_get_max_lun(struct uhintf* intf, rt_uint8_t* max_lun)
USB_REQ_TYPE_INTERFACE
;
setup
.
bRequest
=
USBREQ_GET_MAX_LUN
;
setup
.
wValue
=
intf
->
intf_desc
->
bInterfaceNumber
;
setup
.
wIndex
=
1
;
setup
.
wLength
=
0
;
setup
.
wIndex
=
0
;
setup
.
wLength
=
1
;
/* do control transfer request */
if
(
rt_usb_hcd_setup_xfer
(
device
->
hcd
,
device
->
pipe_ep0_out
,
&
setup
,
timeout
)
!=
8
)
{
if
(
rt_usb_hcd_pipe_xfer
(
device
->
hcd
,
device
->
pipe_ep0_in
,
max_lun
,
1
,
timeout
)
!=
1
)
{
return
-
RT_EIO
;
}
return
-
RT_EIO
;
}
if
(
rt_usb_hcd_pipe_xfer
(
device
->
hcd
,
device
->
pipe_ep0_in
,
max_lun
,
1
,
timeout
)
!=
1
)
{
return
-
RT_EIO
;
}
if
(
rt_usb_hcd_pipe_xfer
(
device
->
hcd
,
device
->
pipe_ep0_out
,
RT_NULL
,
0
,
timeout
)
!=
0
)
{
return
-
RT_EIO
;
}
return
RT_EOK
;
...
...
@@ -264,7 +271,10 @@ rt_err_t rt_usbh_storage_reset(struct uhintf* intf)
{
return
-
RT_EIO
;
}
if
(
rt_usb_hcd_pipe_xfer
(
device
->
hcd
,
device
->
pipe_ep0_in
,
RT_NULL
,
0
,
timeout
)
!=
0
)
{
return
-
RT_EIO
;
}
return
RT_EOK
;
}
...
...
@@ -462,7 +472,7 @@ rt_err_t rt_usbh_storage_inquiry(struct uhintf* intf, rt_uint8_t* buffer)
cmd
.
xfer_len
=
36
;
cmd
.
dflags
=
CBWFLAGS_DIR_IN
;
cmd
.
lun
=
0
;
cmd
.
cb_len
=
12
;
cmd
.
cb_len
=
6
;
//12
cmd
.
cb
[
0
]
=
SCSI_INQUIRY_CMD
;
cmd
.
cb
[
4
]
=
36
;
...
...
@@ -614,10 +624,6 @@ static rt_err_t rt_usbh_storage_disable(void* arg)
/* free storage instance */
if
(
stor
!=
RT_NULL
)
rt_free
(
stor
);
/* free interface instance */
if
(
intf
!=
RT_NULL
)
rt_free
(
intf
);
return
RT_EOK
;
}
...
...
components/drivers/usb/usbhost/class/udisk.c
浏览文件 @
9b44af94
...
...
@@ -141,7 +141,7 @@ static rt_size_t rt_udisk_write (rt_device_t dev, rt_off_t pos, const void* buff
*
* @return the error code, RT_EOK on successfully.
*/
static
rt_err_t
rt_udisk_control
(
rt_device_t
dev
,
rt_uint8_
t
cmd
,
void
*
args
)
static
rt_err_t
rt_udisk_control
(
rt_device_t
dev
,
in
t
cmd
,
void
*
args
)
{
ustor_t
stor
;
struct
ustor_data
*
data
;
...
...
@@ -203,14 +203,21 @@ rt_err_t rt_udisk_run(struct uhintf* intf)
rt_usbh_clear_feature
(
intf
->
device
,
0
,
USB_FEATURE_ENDPOINT_HALT
);
/* reset pipe in endpoint */
ret
=
rt_usbh_clear_feature
(
intf
->
device
,
if
(
stor
->
pipe_in
->
status
==
UPIPE_STATUS_STALL
)
{
ret
=
rt_usbh_clear_feature
(
intf
->
device
,
stor
->
pipe_in
->
ep
.
bEndpointAddress
,
USB_FEATURE_ENDPOINT_HALT
);
if
(
ret
!=
RT_EOK
)
return
ret
;
if
(
ret
!=
RT_EOK
)
return
ret
;
}
/* reset pipe out endpoint */
ret
=
rt_usbh_clear_feature
(
intf
->
device
,
stor
->
pipe_out
->
ep
.
bEndpointAddress
,
USB_FEATURE_ENDPOINT_HALT
);
if
(
ret
!=
RT_EOK
)
return
ret
;
if
(
stor
->
pipe_out
->
status
==
UPIPE_STATUS_STALL
)
{
ret
=
rt_usbh_clear_feature
(
intf
->
device
,
stor
->
pipe_out
->
ep
.
bEndpointAddress
,
USB_FEATURE_ENDPOINT_HALT
);
if
(
ret
!=
RT_EOK
)
return
ret
;
}
while
((
ret
=
rt_usbh_storage_inquiry
(
intf
,
inquiry
))
!=
RT_EOK
)
{
...
...
@@ -223,7 +230,7 @@ rt_err_t rt_udisk_run(struct uhintf* intf)
}
i
=
0
;
/* wait device ready */
while
((
ret
=
rt_usbh_storage_test_unit_ready
(
intf
))
!=
RT_EOK
)
{
...
...
components/drivers/usb/usbhost/core/core.c
浏览文件 @
9b44af94
...
...
@@ -83,7 +83,7 @@ static struct uendpoint_descriptor ep0_out_desc =
USB_DESC_TYPE_ENDPOINT
,
0x00
|
USB_DIR_OUT
,
USB_EP_ATTR_CONTROL
,
0x
4
0
,
0x
0
0
,
0x00
,
};
static
struct
uendpoint_descriptor
ep0_in_desc
=
...
...
@@ -93,7 +93,7 @@ static struct uendpoint_descriptor ep0_in_desc =
USB_DESC_TYPE_ENDPOINT
,
0x00
|
USB_DIR_IN
,
USB_EP_ATTR_CONTROL
,
0x
4
0
,
0x
0
0
,
0x00
,
};
rt_err_t
rt_usbh_attatch_instance
(
uinst_t
device
)
...
...
@@ -112,7 +112,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
rt_memset
(
&
cfg_desc
,
0
,
sizeof
(
struct
uconfig_descriptor
));
dev_desc
=
&
device
->
dev_desc
;
/* alloc address 0 ep0 pipe*/
ep0_out_desc
.
wMaxPacketSize
=
8
;
ep0_in_desc
.
wMaxPacketSize
=
8
;
rt_usb_hcd_alloc_pipe
(
device
->
hcd
,
&
device
->
pipe_ep0_out
,
device
,
&
ep0_out_desc
);
rt_usb_hcd_alloc_pipe
(
device
->
hcd
,
&
device
->
pipe_ep0_in
,
device
,
&
ep0_in_desc
);
...
...
@@ -125,38 +128,43 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
rt_kprintf
(
"get device descriptor head failed
\n
"
);
return
ret
;
}
//should reset bus
/* reset bus */
rt_usbh_hub_reset_port
(
device
->
parent_hub
,
device
->
port
);
rt_thread_delay
(
2
);
rt_usbh_hub_clear_port_feature
(
device
->
parent_hub
,
i
+
1
,
PORT_FEAT_C_CONNECTION
);
/* set device address */
ret
=
rt_usbh_set_address
(
device
);
/* free address 0 ep0 pipe*/
rt_usb_hcd_free_pipe
(
device
->
hcd
,
device
->
pipe_ep0_out
);
rt_usb_hcd_free_pipe
(
device
->
hcd
,
device
->
pipe_ep0_in
);
if
(
ret
!=
RT_EOK
)
{
rt_kprintf
(
"set device address failed
\n
"
);
return
ret
;
}
/* free true address ep0 pipe*/
/* free address 0 ep0 pipe*/
rt_usb_hcd_free_pipe
(
device
->
hcd
,
device
->
pipe_ep0_out
);
rt_usb_hcd_free_pipe
(
device
->
hcd
,
device
->
pipe_ep0_in
);
/* set device max packet size */
ep0_out_desc
.
wMaxPacketSize
=
device
->
dev_desc
.
bMaxPacketSize0
;
ep0_in_desc
.
wMaxPacketSize
=
device
->
dev_desc
.
bMaxPacketSize0
;
/* alloc true address ep0 pipe*/
rt_usb_hcd_alloc_pipe
(
device
->
hcd
,
&
device
->
pipe_ep0_out
,
device
,
&
ep0_out_desc
);
rt_usb_hcd_alloc_pipe
(
device
->
hcd
,
&
device
->
pipe_ep0_in
,
device
,
&
ep0_in_desc
);
/* set device max packet size */
device
->
max_packet_size
=
device
->
dev_desc
.
bMaxPacketSize0
;
RT_DEBUG_LOG
(
1
,
(
"get device descriptor length %d
\n
"
,
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"get device descriptor length %d
\n
"
,
dev_desc
->
bLength
));
/* get full device descriptor again */
ret
=
rt_usbh_get_descriptor
(
device
,
USB_DESC_TYPE_DEVICE
,
(
void
*
)
dev_desc
,
dev_desc
->
bLength
);
ret
=
rt_usbh_get_descriptor
(
device
,
USB_DESC_TYPE_DEVICE
,
(
void
*
)
dev_desc
,
dev_desc
->
bLength
);
if
(
ret
!=
RT_EOK
)
{
rt_kprintf
(
"get full device descriptor failed
\n
"
);
return
ret
;
}
RT_DEBUG_LOG
(
1
,
(
"Vendor ID 0x%x
\n
"
,
dev_desc
->
idVendor
));
RT_DEBUG_LOG
(
1
,
(
"Product ID 0x%x
\n
"
,
dev_desc
->
idProduct
));
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"Vendor ID 0x%x
\n
"
,
dev_desc
->
idVendor
));
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"Product ID 0x%x
\n
"
,
dev_desc
->
idProduct
));
/* get configuration descriptor head */
ret
=
rt_usbh_get_descriptor
(
device
,
USB_DESC_TYPE_CONFIGURATION
,
&
cfg_desc
,
18
);
...
...
@@ -195,7 +203,7 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
return
-
RT_ERROR
;
}
RT_DEBUG_LOG
(
1
,
(
"interface class 0x%x, subclass 0x%x
\n
"
,
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"interface class 0x%x, subclass 0x%x
\n
"
,
intf_desc
->
bInterfaceClass
,
intf_desc
->
bInterfaceSubClass
));
/* alloc pipe*/
...
...
@@ -275,14 +283,17 @@ rt_err_t rt_usbh_detach_instance(uinst_t device)
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"free interface instance %d
\n
"
,
i
));
rt_usbh_class_driver_disable
(
device
->
intf
[
i
]
->
drv
,
(
void
*
)
device
->
intf
[
i
]);
rt_free
(
device
->
intf
[
i
]);
}
if
(
device
->
cfg_desc
)
rt_free
(
device
->
cfg_desc
);
rt_usb_hcd_free_pipe
(
device
->
hcd
,
device
->
pipe_ep0_out
);
rt_usb_hcd_free_pipe
(
device
->
hcd
,
device
->
pipe_ep0_in
);
for
(
l
=
device
->
pipe
.
next
;
l
!=
&
device
->
pipe
;
l
=
l
->
next
)
while
(
device
->
pipe
.
next
!=
&
device
->
pipe
)
{
l
=
device
->
pipe
.
next
;
rt_list_remove
(
l
);
rt_usb_hcd_free_pipe
(
device
->
hcd
,
rt_list_entry
(
l
,
struct
upipe
,
list
));
}
rt_memset
(
device
,
0
,
sizeof
(
struct
uinstance
));
...
...
@@ -390,7 +401,10 @@ rt_err_t rt_usbh_set_configure(uinst_t device, int config)
{
return
RT_ERROR
;
}
if
(
rt_usb_hcd_pipe_xfer
(
device
->
hcd
,
device
->
pipe_ep0_in
,
RT_NULL
,
0
,
timeout
)
!=
0
)
{
return
RT_ERROR
;
}
return
RT_EOK
;
}
...
...
@@ -555,12 +569,15 @@ int rt_usb_hcd_pipe_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, int nbytes, int
rt_size_t
remain_size
;
rt_size_t
send_size
;
remain_size
=
nbytes
;
rt_uint8_t
*
pbuffer
=
(
rt_uint8_t
*
)
buffer
;
do
{
RT_DEBUG_LOG
(
RT_DEBUG_USB
,(
"pipe transform remain size,: %d
\n
"
,
remain_size
));
send_size
=
(
remain_size
>
pipe
->
ep
.
wMaxPacketSize
)
?
pipe
->
ep
.
wMaxPacketSize
:
remain_size
;
if
(
hcd
->
ops
->
pipe_xfer
(
pipe
,
USBH_PID_DATA
,
buffer
,
send_size
,
timeout
)
==
send_size
)
if
(
hcd
->
ops
->
pipe_xfer
(
pipe
,
USBH_PID_DATA
,
p
buffer
,
send_size
,
timeout
)
==
send_size
)
{
remain_size
-=
send_size
;
pbuffer
+=
send_size
;
}
else
{
...
...
components/drivers/usb/usbhost/core/hub.c
浏览文件 @
9b44af94
...
...
@@ -25,7 +25,7 @@
#include <rtthread.h>
#include <drivers/usb_host.h>
#define USB_THREAD_STACK_SIZE
2048
#define USB_THREAD_STACK_SIZE
4096
static
struct
rt_messagequeue
*
usb_mq
;
static
struct
uclass_driver
hub_driver
;
...
...
@@ -481,7 +481,7 @@ static void rt_usbh_hub_irq(void* context)
rt_usbh_hub_port_change
(
hub
);
rt_kprintf
(
RT_DEBUG_USB
,(
"hub int xfer...
\n
"
));
RT_DEBUG_LOG
(
RT_DEBUG_USB
,(
"hub int xfer...
\n
"
));
/* parameter check */
RT_ASSERT
(
pipe
->
inst
->
hcd
!=
RT_NULL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录