Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
03a69276
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
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,发现更多精彩内容 >>
提交
03a69276
编写于
12月 15, 2017
作者:
lymzzyh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[BSP][STM32F4xx-HAL][USB HOST]Add USB host drivers and rename device drivers
上级
87d057f1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
326 addition
and
7 deletion
+326
-7
bsp/stm32f4xx-HAL/Kconfig
bsp/stm32f4xx-HAL/Kconfig
+19
-0
bsp/stm32f4xx-HAL/drivers/SConscript
bsp/stm32f4xx-HAL/drivers/SConscript
+3
-2
bsp/stm32f4xx-HAL/drivers/drv_usbd.c
bsp/stm32f4xx-HAL/drivers/drv_usbd.c
+2
-2
bsp/stm32f4xx-HAL/drivers/drv_usbd.h
bsp/stm32f4xx-HAL/drivers/drv_usbd.h
+3
-3
bsp/stm32f4xx-HAL/drivers/drv_usbh.c
bsp/stm32f4xx-HAL/drivers/drv_usbh.c
+279
-0
bsp/stm32f4xx-HAL/drivers/drv_usbh.h
bsp/stm32f4xx-HAL/drivers/drv_usbh.h
+20
-0
未找到文件。
bsp/stm32f4xx-HAL/Kconfig
浏览文件 @
03a69276
...
...
@@ -339,6 +339,25 @@ if RT_USING_USB_DEVICE
default 0x5750
endif
if RT_USING_USB_HOST
menu "USB Host Config"
config USBH_USING_CONTROLLABLE_POWER
bool "using a gpio control usb power"
default y
if USBH_USING_CONTROLLABLE_POWER
config USBH_POWER_PIN
int "power control pin"
default 15
config USBH_CURRENT_PIN
int "current check pin"
default 86
endif
config USBH_USING_VBUS
bool "using vbus check pin"
default n
endmenu
endif
...
...
bsp/stm32f4xx-HAL/drivers/SConscript
浏览文件 @
03a69276
...
...
@@ -26,11 +26,12 @@ if GetDepend(['RT_USING_WDT']):
src
+=
[
'drv_iwg.c'
]
if
GetDepend
([
'RT_USING_USB_DEVICE'
]):
src
+=
[
'drv_usb.c'
]
src
+=
[
'drv_usb
d
.c'
]
if
GetDepend
([
'RT_USING_RTC'
]):
src
+=
[
'drv_rtc.c'
]
if
GetDepend
([
'RT_USING_USB_HOST'
]):
src
+=
[
'drv_usbh.c'
]
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'Drivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
...
...
bsp/stm32f4xx-HAL/drivers/drv_usb.c
→
bsp/stm32f4xx-HAL/drivers/drv_usb
d
.c
浏览文件 @
03a69276
/*
* File : stm32_usb.c
* File : stm32_usb
d
.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
...
...
@@ -11,7 +11,7 @@
* Date Author Notes
* 2017-10-30 ZYH the first version
*/
#include "drv_usb.h"
#include "drv_usb
d
.h"
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
...
...
bsp/stm32f4xx-HAL/drivers/drv_usb.h
→
bsp/stm32f4xx-HAL/drivers/drv_usb
d
.h
浏览文件 @
03a69276
/*
* File : stm32_usb.h
* File : stm32_usb
d
.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
...
...
@@ -11,8 +11,8 @@
* Date Author Notes
* 2017-10-30 ZYH the first version
*/
#ifndef __STM32_USB_H__
#define __STM32_USB_H__
#ifndef __STM32_USB
D
_H__
#define __STM32_USB
D
_H__
#include <rtthread.h>
int
stm_usbd_register
(
void
);
...
...
bsp/stm32f4xx-HAL/drivers/drv_usbh.c
0 → 100644
浏览文件 @
03a69276
/*
* File : stm32_usbh.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2017-10-30 ZYH the first version
*/
#include "drv_usbh.h"
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#define OTG_FS_PORT 1
static
HCD_HandleTypeDef
_stm_hhcd_fs
;
static
struct
rt_completion
urb_completion
;
void
HAL_HCD_MspInit
(
HCD_HandleTypeDef
*
hcdHandle
)
{
GPIO_InitTypeDef
GPIO_InitStruct
;
if
(
hcdHandle
->
Instance
==
USB_OTG_FS
)
{
/**USB_OTG_FS GPIO Configuration
PA9 ------> USB_OTG_FS_VBUS
PA10 ------> USB_OTG_FS_ID
PA11 ------> USB_OTG_FS_DM
PA12 ------> USB_OTG_FS_DP
*/
__HAL_RCC_GPIOA_CLK_ENABLE
();
#ifdef USBH_USING_VBUS
GPIO_InitStruct
.
Pin
=
GPIO_PIN_9
;
GPIO_InitStruct
.
Mode
=
GPIO_MODE_INPUT
;
GPIO_InitStruct
.
Pull
=
GPIO_NOPULL
;
HAL_GPIO_Init
(
GPIOA
,
&
GPIO_InitStruct
);
#endif
GPIO_InitStruct
.
Pin
=
GPIO_PIN_12
|
GPIO_PIN_11
;
GPIO_InitStruct
.
Mode
=
GPIO_MODE_AF_PP
;
GPIO_InitStruct
.
Pull
=
GPIO_NOPULL
;
GPIO_InitStruct
.
Speed
=
GPIO_SPEED_FREQ_LOW
;
GPIO_InitStruct
.
Alternate
=
GPIO_AF10_OTG_FS
;
HAL_GPIO_Init
(
GPIOA
,
&
GPIO_InitStruct
);
/* Peripheral clock enable */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE
();
/* Peripheral interrupt init */
HAL_NVIC_SetPriority
(
OTG_FS_IRQn
,
5
,
0
);
HAL_NVIC_EnableIRQ
(
OTG_FS_IRQn
);
}
}
void
HAL_HCD_MspDeInit
(
HCD_HandleTypeDef
*
hcdHandle
)
{
if
(
hcdHandle
->
Instance
==
USB_OTG_FS
)
{
/* Peripheral clock disable */
__HAL_RCC_USB_OTG_FS_CLK_DISABLE
();
/**USB_OTG_FS GPIO Configuration
PA9 ------> USB_OTG_FS_VBUS
PA10 ------> USB_OTG_FS_ID
PA11 ------> USB_OTG_FS_DM
PA12 ------> USB_OTG_FS_DP
*/
#ifdef USBH_USING_VBUS
HAL_GPIO_DeInit
(
GPIOA
,
GPIO_PIN_9
);
#endif
HAL_GPIO_DeInit
(
GPIOA
,
GPIO_PIN_12
|
GPIO_PIN_11
);
/* Peripheral interrupt Deinit*/
HAL_NVIC_DisableIRQ
(
OTG_FS_IRQn
);
}
}
void
OTG_FS_IRQHandler
(
void
)
{
rt_interrupt_enter
();
HAL_HCD_IRQHandler
(
&
_stm_hhcd_fs
);
rt_interrupt_leave
();
}
void
HAL_HCD_SOF_Callback
(
HCD_HandleTypeDef
*
hhcd
)
//提供定时器
{
//rt_kprintf("sof callback\n");
}
static
__IO
rt_bool_t
connect_status
=
RT_FALSE
;
void
HAL_HCD_Connect_Callback
(
HCD_HandleTypeDef
*
hhcd
)
{
uhcd_t
hcd
=
(
uhcd_t
)
hhcd
->
pData
;
if
(
!
connect_status
)
{
connect_status
=
RT_TRUE
;
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"connected
\n
"
));
rt_usbh_root_hub_connect_handler
(
hcd
,
OTG_FS_PORT
,
RT_FALSE
);
}
}
void
HAL_HCD_Disconnect_Callback
(
HCD_HandleTypeDef
*
hhcd
)
{
uhcd_t
hcd
=
(
uhcd_t
)
hhcd
->
pData
;
if
(
connect_status
)
{
connect_status
=
RT_FALSE
;
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"disconnnect
\n
"
));
rt_usbh_root_hub_disconnect_handler
(
hcd
,
OTG_FS_PORT
);
}
}
void
HAL_HCD_HC_NotifyURBChange_Callback
(
HCD_HandleTypeDef
*
hhcd
,
uint8_t
chnum
,
HCD_URBStateTypeDef
urb_state
)
{
//rt_kprintf("NotifyURBChange_Callback\n");
rt_completion_done
(
&
urb_completion
);
}
static
rt_err_t
drv_reset_port
(
rt_uint8_t
port
)
{
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"reset port
\n
"
));
HAL_HCD_ResetPort
(
&
_stm_hhcd_fs
);
return
RT_EOK
;
}
static
int
drv_pipe_xfer
(
upipe_t
pipe
,
rt_uint8_t
token
,
void
*
buffer
,
int
nbytes
,
int
timeout
)
{
while
(
1
)
{
if
(
!
connect_status
)
{
return
-
1
;
}
rt_completion_init
(
&
urb_completion
);
HAL_HCD_HC_SubmitRequest
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
,
(
pipe
->
ep
.
bEndpointAddress
&
0x80
)
>>
7
,
pipe
->
ep
.
bmAttributes
,
token
,
buffer
,
nbytes
,
0
);
rt_completion_wait
(
&
urb_completion
,
timeout
);
if
(
HAL_HCD_HC_GetState
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
)
==
HC_NAK
)
{
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"nak
\n
"
));
if
(
pipe
->
ep
.
bmAttributes
==
USB_EP_ATTR_INT
)
{
rt_thread_delay
((
pipe
->
ep
.
bInterval
*
RT_TICK_PER_SECOND
/
1000
)
>
0
?
(
pipe
->
ep
.
bInterval
*
RT_TICK_PER_SECOND
/
1000
)
:
1
);
}
HAL_HCD_HC_Halt
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
);
HAL_HCD_HC_Init
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
,
pipe
->
ep
.
bEndpointAddress
,
pipe
->
inst
->
address
,
USB_OTG_SPEED_FULL
,
pipe
->
ep
.
bmAttributes
,
pipe
->
ep
.
wMaxPacketSize
);
continue
;
}
else
if
(
HAL_HCD_HC_GetState
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
)
==
HC_STALL
)
{
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"stall
\n
"
));
pipe
->
status
=
UPIPE_STATUS_STALL
;
if
(
pipe
->
callback
!=
RT_NULL
)
{
pipe
->
callback
(
pipe
);
}
return
-
1
;
}
else
if
(
HAL_HCD_HC_GetState
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
)
==
URB_ERROR
)
{
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"error
\n
"
));
pipe
->
status
=
UPIPE_STATUS_ERROR
;
if
(
pipe
->
callback
!=
RT_NULL
)
{
pipe
->
callback
(
pipe
);
}
return
-
1
;
}
else
if
(
HAL_HCD_HC_GetURBState
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
)
!=
URB_NOTREADY
&&
HAL_HCD_HC_GetURBState
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
)
!=
URB_NYET
)
{
RT_DEBUG_LOG
(
RT_DEBUG_USB
,
(
"ok
\n
"
));
pipe
->
status
=
UPIPE_STATUS_OK
;
if
(
pipe
->
callback
!=
RT_NULL
)
{
pipe
->
callback
(
pipe
);
}
return
nbytes
;
}
return
-
1
;
}
}
static
rt_uint16_t
pipe_index
=
0
;
static
rt_uint8_t
drv_get_free_pipe_index
()
{
rt_uint8_t
idx
;
for
(
idx
=
1
;
idx
<
16
;
idx
++
)
{
if
(
!
(
pipe_index
&
(
0x01
<<
idx
)))
{
pipe_index
|=
(
0x01
<<
idx
);
return
idx
;
}
}
return
0xff
;
}
static
void
drv_free_pipe_index
(
rt_uint8_t
index
)
{
pipe_index
&=
~
(
0x01
<<
index
);
}
static
rt_err_t
drv_open_pipe
(
upipe_t
pipe
)
{
pipe
->
pipe_index
=
drv_get_free_pipe_index
();
HAL_HCD_HC_Init
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
,
pipe
->
ep
.
bEndpointAddress
,
pipe
->
inst
->
address
,
USB_OTG_SPEED_FULL
,
pipe
->
ep
.
bmAttributes
,
pipe
->
ep
.
wMaxPacketSize
);
/* Set DATA0 PID token*/
if
(
_stm_hhcd_fs
.
hc
[
pipe
->
pipe_index
].
ep_is_in
)
{
_stm_hhcd_fs
.
hc
[
pipe
->
pipe_index
].
toggle_in
=
0
;
}
else
{
_stm_hhcd_fs
.
hc
[
pipe
->
pipe_index
].
toggle_out
=
0
;
}
return
RT_EOK
;
}
static
rt_err_t
drv_close_pipe
(
upipe_t
pipe
)
{
HAL_HCD_HC_Halt
(
&
_stm_hhcd_fs
,
pipe
->
pipe_index
);
drv_free_pipe_index
(
pipe
->
pipe_index
);
return
RT_EOK
;
}
struct
uhcd_ops
_uhcd_ops
=
{
drv_reset_port
,
drv_pipe_xfer
,
drv_open_pipe
,
drv_close_pipe
,
};
static
rt_err_t
_init
(
rt_device_t
device
)
{
HCD_HandleTypeDef
*
hhcd
=
(
HCD_HandleTypeDef
*
)
device
->
user_data
;
hhcd
->
Instance
=
USB_OTG_FS
;
hhcd
->
Init
.
Host_channels
=
8
;
hhcd
->
Init
.
speed
=
HCD_SPEED_FULL
;
hhcd
->
Init
.
dma_enable
=
DISABLE
;
hhcd
->
Init
.
phy_itface
=
HCD_PHY_EMBEDDED
;
hhcd
->
Init
.
Sof_enable
=
DISABLE
;
RT_ASSERT
(
HAL_HCD_Init
(
hhcd
)
==
HAL_OK
);
HAL_HCD_Start
(
hhcd
);
#ifdef USBH_USING_CONTROLLABLE_POWER
rt_pin_mode
(
USBH_POWER_PIN
,
PIN_MODE_OUTPUT
);
rt_pin_write
(
USBH_POWER_PIN
,
PIN_LOW
);
#endif
return
RT_EOK
;
}
int
stm_usbh_register
(
void
)
{
uhcd_t
uhcd
=
(
uhcd_t
)
rt_malloc
(
sizeof
(
struct
uhcd
));
RT_ASSERT
(
uhcd
!=
RT_NULL
);
rt_memset
((
void
*
)
uhcd
,
0
,
sizeof
(
struct
uhcd
));
uhcd
->
parent
.
type
=
RT_Device_Class_USBHost
;
uhcd
->
parent
.
init
=
_init
;
uhcd
->
parent
.
user_data
=
&
_stm_hhcd_fs
;
uhcd
->
ops
=
&
_uhcd_ops
;
uhcd
->
num_ports
=
1
;
_stm_hhcd_fs
.
pData
=
uhcd
;
rt_device_register
((
rt_device_t
)
uhcd
,
"usbh"
,
0
);
rt_usb_host_init
();
return
RT_EOK
;
}
INIT_DEVICE_EXPORT
(
stm_usbh_register
);
bsp/stm32f4xx-HAL/drivers/drv_usbh.h
0 → 100644
浏览文件 @
03a69276
/*
* File : stm32_usbh.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2017-12-12 ZYH the first version
*/
#ifndef __STM32_USBH_H__
#define __STM32_USBH_H__
#include <rtthread.h>
int
stm_usbh_register
(
void
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录