STM32--USB详细使用说明
if (pInformation->
pInformation->
pInformation->
if (pInformation->
if (ValBit(pInformation->
pInformation->Ctrl_Info.PacketSize = pProperty-> pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
DataStageIn();
}
else//主机向设备
{
pInformation->ControlState = OUT_DATA;
vSetEPRxStatus(EP_RX_VALID);
}
return;
}
usb_coer.c的文件里面
void DataStageIn(void)
{
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;//端点信息保存在指针变量中
uint32_t save_wLength = pEPinfo->Usb_wLength;//得到字符的长度
uint32_t ControlState = pInformation->ControlState;//得到当前的状态
uint8_t *DataBuffer;
uint32_t Length;
if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))//如果字符长度为0 且控制状态是最后输入的数据
{
if(Data_Mul_MaxPacketSize == TRUE)//如果字符的长度是数据包的整数倍
{
Send0LengthData();
ControlState = LAST_IN_DATA;
Data_Mul_MaxPacketSize = FALSE;//这一次发送0字节 状态转为最后输入阶段
}
else//字符的长度比数据包要小
{//数据已经发送完
ControlState = WAIT_STATUS_OUT;
#ifdef STM32F10X_CL
PCD_EP_Read (ENDP0, 0, 0);
#endif
#ifndef STM32F10X_CL
vSetEPTxStatus(EP_TX_STALL);//设置端点的发送状态停止
#endif
}
goto Expect_Status_Out;
}
Length = pEPinfo->PacketSize;//得到数据包大小 64字节
ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;//比较大小得到是LAST_IN_DATA还是IN_DATA 18字节<64字节 ControlState = LAST_IN_DATA
if (Length > save_wLength)
{
Length = save_wLength;
}
DataBuffer = (*pEPinfo->CopyData)(Length);//DataBuffer指向要复制数据的地址 这个地址是随Usb_wOffset变化的
#ifdef STM32F10X_CL
PCD_EP_Write (ENDP0, DataBuffer, Length);
#else
//GetEPTxAddr(ENDP0) 得到发送缓冲区相应端点的地址
//将DataBuffer中的数据复制到相应的发送缓冲区中
UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
#endif
SetEPTxCount(ENDP0, Length);//设置相应的端点要发送的字节数
pEPinfo->Usb_wLength -= Length;//等于0
pEPinfo->Usb_wOffset += Length;//偏移到18
vSetEPTxStatus(EP_TX_VALID);//使能发送端点 只要主机的IN令牌包一来 SIE就会将描述符返回给主机
USB_StatusOut();
//设置接收端点有效 这个实际上使接受也有效,
Expect_Status_Out:
pInformation->ControlState = ControlState;//保存控制状态
}
***************(4)**************
uint8_t In0_Process(void)
{
uint32_t ControlState = pInformation->ControlState;
if ((ControlState == IN_DATA) || (ControlState ==LAST_IN_DATA))//进入到这里
{
DataStageIn();//第一次取设备描述符只取一次当前的状态变为WAIT_STATUS_IN表明设备等待状态过程 主机输出0字节
ControlState = pInformation->ControlState;
}
else if (ControlState == WAIT_STATUS_IN)//设置地址状态阶段进入这个程序
{
if ((pInformation->USBbRequest == SET_ADDRESS) &&
(Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)))
{
SetDeviceAddress(pInformation->USBwValue0);//设置使用新的地址
pUser_Standard_Requests->User_SetDeviceAddress();
}
(*pProperty->Process_Status_IN)();
ControlState = STALLED;//变为这个状态
}
else
{
ControlState = STALLED;
}
pInformation->ControlState = ControlState;
return Post0_Process();
}
uint8_t Out0_Process(void)
{
uint32_t ControlState = pInformation->ControlState;
if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
{
//主机在完成传输前终止传输
ControlState = STALLED;
}
else if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
{
DataStageOut();
ControlState = pInformation->ControlState;
}
else if (ControlState == WAIT_STATUS_OUT)//进入到这个里面
{
(*pProperty->Process_Status_OUT)();//这个函数其实什么也没做
#ifndef STM32F10X_CL
ControlState = STALLED;//状态变成了终止发送和接受
#endif
}
else
{
ControlState = STALLED;
}
pInformation->ControlState = ControlState;
return Post0_Process();
}
***************(5)**************
获取设备描述符以后,主机再一次的复位设备,设备又进入初始状态。开始枚举的第二步设置地址。
void NoData_Setup0(void)
{
RESULT Result = USB_UNSUPPORT;
uint32_t RequestNo = pInformation->USBbRequest;
uint32_t ControlState;
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) //设备请求
{
else if (RequestNo == SET_ADDRESS) /设置地址
{
if ((pInformation->USBwValue0 > 127) || (pInformation->USBwValue1 != 0)
|| (pInformation->USBwIndex != 0)
|| (pInformation->Current_Configuration != 0))
{
ControlState = STALLED;
goto exit_NoData_Setup0;
}
else
{
Result = USB_SUCCESS;
STM32USB使用说 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)