135 lines
3.3 KiB
C
135 lines
3.3 KiB
C
#include "usb_bsp.h"
|
||
#include "delay.h"
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
|
||
//ALIENTEK STM32开发板
|
||
//USB-BSP 代码
|
||
//正点原子@ALIENTEK
|
||
//技术论坛:www.openedv.com
|
||
//创建日期:2016/1/21
|
||
//版本:V1.0
|
||
//版权所有,盗版必究。
|
||
//Copyright(C) 广州市星翼电子科技有限公司 2009-2019
|
||
//All rights reserved
|
||
//*******************************************************************************
|
||
//修改信息
|
||
//无
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
|
||
//USB OTG 底层IO初始化
|
||
//pdev:USB OTG内核结构体指针
|
||
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);
|
||
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS, ENABLE) ;
|
||
|
||
GPIO_PinAFConfig(GPIOB,GPIO_PinSource14,GPIO_AF_OTG2_FS) ;
|
||
GPIO_PinAFConfig(GPIOB,GPIO_PinSource15,GPIO_AF_OTG2_FS) ;
|
||
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||
}
|
||
|
||
//USB OTG 中断设置,开启USB FS中断
|
||
//pdev:USB OTG内核结构体指针
|
||
void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
|
||
{
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
|
||
#ifdef USE_USB_OTG_HS
|
||
NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
|
||
#else
|
||
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
|
||
#endif
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
|
||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
|
||
NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_OUT_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
|
||
NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_IN_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
#endif
|
||
}
|
||
|
||
//USB OTG 中断设置,开启USB FS中断
|
||
//pdev:USB OTG内核结构体指针
|
||
void USB_OTG_BSP_DisableInterrupt(void)
|
||
{
|
||
}
|
||
//USB OTG 端口供电设置(本例程未用到)
|
||
//pdev:USB OTG内核结构体指针
|
||
//state:0,断电;1,上电
|
||
void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev, uint8_t state)
|
||
{
|
||
}
|
||
//USB_OTG 端口供电IO配置(本例程未用到)
|
||
//pdev:USB OTG内核结构体指针
|
||
void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev)
|
||
{
|
||
}
|
||
//USB_OTG us级延时函数
|
||
//本例程采用SYSTEM文件夹的delay.c里面的delay_us函数实现
|
||
//官方例程采用的是定时器2来实现的.
|
||
//usec:要延时的us数.
|
||
void USB_OTG_BSP_uDelay (const uint32_t usec)
|
||
{
|
||
uint32_t count = 0;
|
||
const uint32_t utime = (14 * usec);
|
||
do
|
||
{
|
||
if ( ++count > utime )
|
||
{
|
||
return ;
|
||
}
|
||
}
|
||
while (1);
|
||
}
|
||
//USB_OTG ms级延时函数
|
||
//本例程采用SYSTEM文件夹的delay.c里面的delay_ms函数实现
|
||
//官方例程采用的是定时器2来实现的.
|
||
//msec:要延时的ms数.
|
||
void USB_OTG_BSP_mDelay (const uint32_t msec)
|
||
{
|
||
USB_OTG_BSP_uDelay(msec * 1000);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|