/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name : usb_core.c
* Author : MCD Application Team
* Version : V1.0
* Date : 10/08/2007
* Description : Standard protocol processing (USB v2.0)
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define ValBit(VAR,Place) (VAR & (1 << Place))
#define SetBit(VAR,Place) (VAR |= (1 << Place))
#define ClrBit(VAR,Place) (VAR &= ((1 << Place) ^ 255))
#define Send0LengthData() { _SetEPTxCount(ENDP0, 0); \
vSetEPTxStatus(EP_TX_VALID); \
}
#define vSetEPRxStatus(st) (SaveRState = st)
#define vSetEPTxStatus(st) (SaveTState = st)
#define USB_StatusIn() Send0LengthData()
#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
#define StatusInfo1 StatusInfo.bw.bb0
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u16_u8 StatusInfo;
/* Private function prototypes -----------------------------------------------*/
static void DataStageOut(void);
static void DataStageIn(void);
static void NoData_Setup0(void);
static void Data_Setup0(void);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : Standard_GetConfiguration.
* Description : Return the current configuration variable address.
* Input : Length - How many bytes are needed.
* Output : None.
* Return : Return 1 , if the request is invalid when "Length" is 0.
* Return "Buffer" if the "Length" is not 0.
*******************************************************************************/
u8 *Standard_GetConfiguration(u16 Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength =
sizeof(pInformation->Current_Configuration);
return 0;
}
pUser_Standard_Requests->User_GetConfiguration();
return (u8 *)&pInformation->Current_Configuration;
}
/*******************************************************************************
* Function Name : Standard_SetConfiguration.
* Description : This routine is called to set the configuration value
* Then each class should configure device themself.
* Input : None.
* Output : None.
* Return : Return USB_SUCCESS, if the request is performed.
* Return USB_UNSUPPORT, if the request is invalid.
*******************************************************************************/
RESULT Standard_SetConfiguration(void)
{
if ((pInformation->USBwValue0 <=
Device_Table.Total_Configuration) && (pInformation->USBwValue1 == 0)
&& (pInformation->USBwIndex == 0)) /*call Back usb spec 2.0*/
{
pInformation->Current_Configuration = pInformation->USBwValue0;
pUser_Standard_Requests->User_SetConfiguration();
return USB_SUCCESS;
}
else
{
return USB_UNSUPPORT;
}
}
/*******************************************************************************
* Function Name : Standard_GetInterface.
* Description : Return the Alternate Setting of the current interface.
* Input : Length - How many bytes are needed.
* Output : None.
* Return : Return 0, if the request is invalid when "Length" is 0.
* Return "Buffer" if the "Length" is not 0.
*******************************************************************************/
u8 *Standard_GetInterface(u16 Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength =
sizeof(pInformation->Current_AlternateSetting);
return 0;
}
pUser_Standard_Requests->User_GetInterface();
return (u8 *)&pInformation->Current_AlternateSetting;
}
/*******************************************************************************
* Function Name : Standard_SetInterface.
* Description : This routine is called to set the interface.
* Then each class should configure the interface them self.
* Input : None.
* Output : None.
* Return : - Return USB_SUCCESS, if the request is performed.
* - Return USB_UNSUPPORT, if the request is invalid.
*******************************************************************************/
RESULT Standard_SetInterface(void)
{
RESULT Re;
/*Test if the specified Interface and Alternate Setting are supported by
the application Firmware*/
Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, pInformation->USBwValue0);
if (pInformation->Current_Configuration != 0)
{
if ((Re != USB_SUCCESS) || (pInformation->USBwIndex1 != 0)
|| (pInformation->USBwValue1 != 0))
{
return USB_UNSUPPORT;
}
else if (Re == USB_SUCCESS)
{
pUser_Standard_Requests->User_SetInterface();
pInformation->Current_Interface = pInformation->USBwIndex0;
pInformation->Current_AlternateSetting = pInformation->USBwValue0;
return USB_SUCCESS;
}
}
return USB_UNSUPPORT;
}
/*******************************************************************************
* Function Name : Standard_GetStatus.
* Description : Copy the device request data to "StatusInfo buffer".
* Input : - Length - How many bytes are needed.
* Output : None.
* Return : Return 0, if the request is at end of data block,
* or is invalid when "Length" is 0.
*******************************************************************************/
u8 *Standard_GetStatus(u16 Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength = 2;
return 0;
}
StatusInfo.w = 0;
/* Reset Status Information */
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
{
/*Get Device Status */
u8 Feature = pInformation->Current_Feature;
/* Remote Wakeup enabled */
if (ValBit(Feature, 5))
{
SetBit(StatusInfo0, 1);
}
/* Self-powered */
if (ValBit(Feature, 6))
{
SetBit(StatusInfo0, 0);
}
else /* Bus-powered */
{
ClrBit(StatusInfo0, 0);
}
}
/*Interface Status*/
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
{
return (u8 *)&StatusInfo;
}
/*Get EndPoint Status*/
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
{
u8 Related_Endpoint;
u8 wIndex0 = pInformation->USBwIndex0;
Related_Endpoint = (wIndex0 & 0x0f);
if (ValBit(wIndex0, 7))
{
/* IN endpoint */
if (_GetTxStallStatus(Related_Endpoint))
{
SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
}
}
else
{
/* OUT endpoint */
if (_GetRxStallStatus(Related_Endpoint))
{
SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
}
}
}
else
{
return NULL;
没有合适的资源?快使用搜索试试~ 我知道了~
USBLib.rar_STM32 U盘_STM32 usb cdc_stm32 pci9052_stm32 USB传输_单片机
共452个文件
o:109个
d:99个
c:59个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 17 浏览量
2022-07-14
00:45:52
上传
评论
收藏 2.24MB RAR 举报
温馨提示
stm32单片机的usb程序包,包括,U盘,数据传输,五纬杆操纵等
资源推荐
资源详情
资源评论
收起资源包目录
USBLib.rar_STM32 U盘_STM32 usb cdc_stm32 pci9052_stm32 USB传输_单片机 (452个子文件)
MassStorage.axf 229KB
AudioSpeaker.axf 212KB
VirtualCOMPort.axf 210KB
DFU.axf 204KB
JoyStickMouse.axf 166KB
JoyStickMouse_Opt.Bak 4KB
MassStorage_Uv2.Bak 4KB
AudioSpeaker_Uv2.Bak 4KB
VirtualCOMPort_Uv2.Bak 4KB
DFU_Uv2.Bak 4KB
MassStorage_Opt.Bak 4KB
JoyStickMouse_Uv2.Bak 4KB
AudioSpeaker_Opt.Bak 3KB
DFU_Opt.Bak 3KB
VirtualCOMPort_Opt.Bak 3KB
MassStorage_sct.Bak 479B
usb_core.c 29KB
usb_regs.c 28KB
msd.c 27KB
stm32f10x_it.c 23KB
stm32f10x_it.c 22KB
stm32f10x_it.c 22KB
stm32f10x_it.c 22KB
stm32f10x_it.c 22KB
usb_prop.c 22KB
spi_flash.c 18KB
usb_prop.c 12KB
usb_prop.c 12KB
hw_config.c 12KB
usb_prop.c 12KB
usb_desc.c 11KB
usb_scsi.c 11KB
usb_prop.c 10KB
usb_bot.c 10KB
hw_config.c 9KB
hw_config.c 9KB
hw_config.c 9KB
hw_config.c 9KB
usb_desc.c 8KB
usb_desc.c 7KB
usb_desc.c 7KB
usb_pwr.c 7KB
usb_pwr.c 7KB
usb_pwr.c 7KB
stm32f10x_vector.c 7KB
stm32f10x_vector.c 7KB
stm32f10x_vector.c 7KB
stm32f10x_vector.c 7KB
stm32f10x_vector.c 7KB
usb_pwr.c 7KB
usb_pwr.c 7KB
usb_int.c 6KB
memory.c 6KB
usb_istr.c 6KB
usb_istr.c 5KB
usb_istr.c 5KB
usb_istr.c 5KB
usb_istr.c 5KB
usb_desc.c 5KB
main.c 4KB
main.c 3KB
usb_mem.c 3KB
stm32f10x_vector.c 3KB
stm32f10x_vector.c 3KB
stm32f10x_vector.c 3KB
stm32f10x_vector.c 3KB
stm32f10x_vector.c 3KB
main.c 3KB
scsi_data.c 3KB
usb_init.c 3KB
main.c 3KB
main.c 3KB
usb_endp.c 3KB
usb_endp.c 3KB
usb_endp.c 2KB
usb_prop.d 1KB
stm32f10x_it.d 1KB
stm32f10x_it.d 1KB
usb_prop.d 1KB
hw_config.d 1KB
hw_config.d 1KB
stm32f10x_it.d 1KB
stm32f10x_it.d 1KB
memory.d 1KB
hw_config.d 1KB
usb_pwr.d 1KB
usb_pwr.d 1KB
usb_pwr.d 1KB
usb_pwr.d 1KB
main.d 1KB
main.d 1KB
hw_config.d 1KB
usb_pwr.d 1KB
main.d 1KB
main.d 1KB
main.d 1KB
stm32f10x_it.d 835B
hw_config.d 815B
stm32f10x_lib.d 793B
stm32f10x_lib.d 791B
共 452 条
- 1
- 2
- 3
- 4
- 5
资源评论
四散
- 粉丝: 49
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功