STM32 USB学习笔记

本文详细介绍了STM32 USB设备的初始化流程,包括结构体的定义、初始化函数及复位处理。重点讲解了USB_Istr()中断服务函数,解析中断类型并调用相应的处理函数,如Joystick_Reset()进行端点初始化。同时阐述了数据正确传输中断的处理,以及在数据阶段如何根据主机请求发送设备描述符。
摘要由CSDN通过智能技术生成

 

 

typedef struct _DEVICE_PROP

{

  void(*Init)(void);        /* Initialize thedevice */

  void(*Reset)(void);       /* Reset routine ofthis device */

  void(*Process_Status_IN)(void);

  void(*Process_Status_OUT)(void);

 RESULT (*Class_Data_Setup)(u8 RequestNo);

 RESULT (*Class_NoData_Setup)(u8 RequestNo);

 RESULT (*Class_Get_Interface_Setting)(u8 Interface, u8 AlternateSetting);

u8* (*GetDeviceDescriptor)(u16 Length);

  u8*(*GetConfigDescriptor)(u16 Length);

  u8*(*GetStringDescriptor)(u16 Length);

u8* RxEP_buffer;

  u8MaxPacketSize;

}DEVICE_PROP;

 

DEVICE_PROP *pProperty;

 

pProperty = &Device_Property;

 

DEVICE_PROP Device_Property =

  {

   Joystick_init,   //鼠标初始化

   Joystick_Reset,       //鼠标复位

   Joystick_Status_In,

   Joystick_Status_Out,

   Joystick_Data_Setup,

   Joystick_NoData_Setup,

   Joystick_Get_Interface_Setting,

   Joystick_GetDeviceDescriptor,

   Joystick_GetConfigDescriptor,

   Joystick_GetStringDescriptor,

   0,

   0x40 /*MAX PACKET SIZE*/

 };

 

 

 

 

 

 

 

 

 

 

typedef struct _USER_STANDARD_REQUESTS

{

  void(*User_GetConfiguration)(void);       /*Get Configuration */

  void(*User_SetConfiguration)(void);       /*Set Configuration */

  void(*User_GetInterface)(void);           /*Get Interface */

  void(*User_SetInterface)(void);           /*Set Interface */

  void(*User_GetStatus)(void);              /*Get Status */

  void(*User_ClearFeature)(void);           /*Clear Feature */

  void(*User_SetEndPointFeature)(void);     /*Set Endpoint Feature */

  void(*User_SetDeviceFeature)(void);       /*Set Device Feature */

  void(*User_SetDeviceAddress)(void);       /*Set Device Address */

}

USER_STANDARD_REQUESTS;

 

 

USER_STANDARD_REQUESTS  *pUser_Standard_Requests;

 

pUser_Standard_Requests =&User_Standard_Requests;

 

USER_STANDARD_REQUESTSUser_Standard_Requests =

  {

   Joystick_GetConfiguration,

   Joystick_SetConfiguration,

   Joystick_GetInterface,

   Joystick_SetInterface,

   Joystick_GetStatus,

   Joystick_ClearFeature,

   Joystick_SetEndPointFeature,

   Joystick_SetDeviceFeature,

   Joystick_SetDeviceAddress

 };

 

 

 

 

 

 

 

 

 

 

 

 

typedef struct _DEVICE_INFO

{

  u8USBbmRequestType;       /* bmRequestType*/

  u8USBbRequest;            /* bRequest */

 u16_u8 USBwValues;         /*wValue */

 u16_u8 USBwIndexs;         /* wIndex */

 u16_u8 USBwLengths;        /*wLength */

 

  u8ControlState;           /* of typeCONTROL_STATE */

  u8Current_Feature;

  u8Current_Configuration;   /* Selectedconfiguration  当前配置*/

  u8Current_Interface;       /* Selectedinterface of current configuration 当前接口*/

  u8Current_AlternateSetting;/* Selected Alternate Setting of current

                                    interface*/

 ENDPOINT_INFO Ctrl_Info;

}DEVICE_INFO;

 

 

DEVICE_INFO *pInformation;

pInformation = &Device_Info;

DEVICE_INFO Device_Info;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

pInformation->ControlState = 2; //

 

函数1

void USB_Init(void)

{

  pInformation = &Device_Info;

  pInformation->ControlState = 2; 

 pProperty = &Device_Property;

 pUser_Standard_Requests = &User_Standard_Requests;

 pProperty->Init();  //下步进入此函数

}

用于初始化几个结构体

函数2

void Joystick_init(void)

{

  pInformation->Current_Configuration = 0;

 PowerOn();

  _SetISTR(0);               /*clear pending interrupts */

  wInterrupt_Mask =IMR_MSK;   //将中断使能的值赋给wInterrupt_Mask

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值