OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3831|回复: 1

USB枚举阶段的代码疑惑

[复制链接]

1

主题

3

帖子

0

精华

新手入门

积分
27
金钱
27
注册时间
2015-3-11
在线时间
0 小时
发表于 2015-3-28 17:51:32 | 显示全部楼层 |阅读模式
5金钱


USB枚举阶段的代码疑惑
学习ALIENTEK MINISTM32 实验34 USB读卡器实验时遇到一个问题.
Data_Setup0()函数中有这么几句话:
if (ValBit(pInformation->USBbmRequestType, 7))
{
/* Device ==> Host */
__IO uint32_t wLength = pInformation->USBwLength; //★注意这里.
/* Restrict the data length to be the one host asks for */
if (pInformation->Ctrl_Info.Usb_wLength > wLength)
{
pInformation->Ctrl_Info.Usb_wLength = wLength;
}
else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength)
{
if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize)
{
Data_Mul_MaxPacketSize = FALSE;
}
else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0)
{
Data_Mul_MaxPacketSize = TRUE;
}
}   
pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
DataStageIn();
}
上面的pInformation是结构体DEVICE_INFO的指针,但是可以看到,该结构体中没有USBwLength变量.
typedef struct _DEVICE_INFO
{
  uint8_t USBbmRequestType;       /* bmRequestType */
  uint8_t USBbRequest;            /* bRequest */
  uint16_t_uint8_t USBwValues;         /* wValue */
  uint16_t_uint8_t USBwIndexs;         /* wIndex */
  uint16_t_uint8_t USBwLengths;        /* wLength */
  uint8_t ControlState;           /* of type CONTROL_STATE */
  uint8_t Current_Feature;
  uint8_t Current_Configuration;   /* Selected configuration */
  uint8_t Current_Interface;       /* Selected interface of current configuration */
  uint8_t Current_AlternateSetting;/* Selected Alternate Setting of current
                                     interface*/
  ENDPOINT_INFO Ctrl_Info;
}DEVICE_INFO;
编译运行,都没事,我看STM32_USB-FS-Device_Lib_V4.0.0库中的代码也是这样的,这是为什么呢?



最佳答案

查看完整内容[请看2#楼]

哦。找到原因了。 uint16_t_uint8_t是共用体 typedef union {     uint16_t w;     struct BW     {          unit8_t bb1;          unit8_t bb0;      }bw; } 定义了uint16_t_uint8_t USBwLengths;后,  ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

3

帖子

0

精华

新手入门

积分
27
金钱
27
注册时间
2015-3-11
在线时间
0 小时
 楼主| 发表于 2015-3-28 17:51:33 | 显示全部楼层
哦。找到原因了。
uint16_t_uint8_t是共用体
typedef union
{
    uint16_t w;
    struct BW
    {
         unit8_t bb1;
         unit8_t bb0;
     }bw;
}
定义了uint16_t_uint8_t USBwLengths;后, 在usb_core.h中有如下宏定义
#define USBwLength USBwLengths.w
看代码太马虎了,不好意思。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-24 11:04

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表