金牌会员
- 积分
- 2555
- 金钱
- 2555
- 注册时间
- 2017-12-16
- 在线时间
- 188 小时
|
10金钱
本帖最后由 sfd123 于 2023-5-27 16:32 编辑
MCU是STM32F207,使用ST的标准库;从机是一个虚拟了4个串口的设备目前,通过在函数CDC_InterfaceInit()里手动配置如下:
/* Data Interface */ if((pphost->device_prop.Itf_Desc[1.bInterfaceClass == DATA_INTERFACE_CLASS_CODE)&& \
(pphost->device_prop.Itf_Desc[1.bInterfaceSubClass == RESERVED) && \
(pphost->device_prop.Itf_Desc[1.bInterfaceProtocol == NO_CLASS_SPECIFIC_PROTOCOL_CODE))
{
/*Collect the class specific endpoint address and length*/
CDC_Machine.CDC_DataItf.ep_addr = pphost->device_prop.Ep_Desc[1][0.bEndpointAddress;
CDC_Machine.CDC_DataItf.length = pphost->device_prop.Ep_Desc[1][0.wMaxPacketSize;
if(pphost->device_prop.Ep_Desc[1][0.bEndpointAddress & 0x80)
{
CDC_Machine.CDC_DataItf.cdcInEp = (pphost->device_prop.Ep_Desc[1][0.bEndpointAddress);
}
else
{
CDC_Machine.CDC_DataItf.cdcOutEp = (pphost->device_prop.Ep_Desc[1][0.bEndpointAddress);
}
if(pphost->device_prop.Ep_Desc[1][1.bEndpointAddress & 0x80)
{
CDC_Machine.CDC_DataItf.cdcInEp = (pphost->device_prop.Ep_Desc[1][1.bEndpointAddress);
}
else
{
CDC_Machine.CDC_DataItf.cdcOutEp = (pphost->device_prop.Ep_Desc[1][1.bEndpointAddress);
}
CDC_Machine.CDC_DataItf.cdcInEp = 0x83;//手动配置
CDC_Machine.CDC_DataItf.cdcOutEp = 3;//手动配置
/*Allocate the length for host channel number out*/
CDC_Machine.CDC_DataItf.hc_num_out = USBH_Alloc_Channel(pdev, CDC_Machine.CDC_DataItf.cdcOutEp); /*Allocate the length for host channel number in*/
CDC_Machine.CDC_DataItf.hc_num_in = USBH_Alloc_Channel(pdev, CDC_Machine.CDC_DataItf.cdcInEp); /* Open channel for OUT endpoint */
USBH_Open_Channel (pdev, CDC_Machine.CDC_DataItf.hc_num_out, pphost->device_prop.address, pphost->device_prop.speed, EP_TYPE_BULK, CDC_Machine.CDC_DataItf.length); /* Open channel for IN endpoint */ USBH_Open_Channel (pdev, CDC_Machine.CDC_DataItf.hc_num_in, pphost->device_prop.address, pphost->device_prop.speed, EP_TYPE_BULK, CDC_Machine.CDC_DataItf.length); /*Initilise the Tx/Rx Params*/
CDC_InitTxRxParam(); /*Initialize the class specific request with "GET_LINE_CODING"*/
CDC_ReqState = CDC_GET_LINE_CODING_RQUEST ;
通过手动配置,可以与4个串口的任意一个正常收发通信,因为手动配置成一个,所以也只能与其中的一个通信
问题是:如何才能随时、任意与其中一个通信?我尝试改为:
/*Collect the class specific endpoint address and length*/
CDC_Machine.CDC_DataItf.ep_addr = pphost->device_prop.Ep_Desc[port[0]][0.bEndpointAddress;
CDC_Machine.CDC_DataItf.length = pphost->device_prop.Ep_Desc[port[0]][0.wMaxPacketSize;
for(i=0;i<4;i++)
{
if(pphost->device_prop.Ep_Desc[port[i]][0.bEndpointAddress & 0x80)
{
CDC_Machine.CDC_DataItf.cdcInEp[i] = (pphost->device_prop.Ep_Desc[port[i]][0.bEndpointAddress);
}
else
{
CDC_Machine.CDC_DataItf.cdcOutEp[i] = (pphost->device_prop.Ep_Desc[port[i]][0.bEndpointAddress);
}
if(pphost->device_prop.Ep_Desc[port[i]][1.bEndpointAddress & 0x80)
{
CDC_Machine.CDC_DataItf.cdcInEp[i] = (pphost->device_prop.Ep_Desc[port[i]][1.bEndpointAddress);
}
else
{
CDC_Machine.CDC_DataItf.cdcOutEp[i = (pphost->device_prop.Ep_Desc[port[i]][1.bEndpointAddress);
}
/*Allocate the length for host channel number out*/
CDC_Machine.CDC_DataItf.hc_num_out = USBH_Alloc_Channel(pdev, CDC_Machine.CDC_DataItf.cdcOutEp[i); /*Allocate the length for host channel number in*/
CDC_Machine.CDC_DataItf.hc_num_in = USBH_Alloc_Channel(pdev, CDC_Machine.CDC_DataItf.cdcInEp[i); /* Open channel for OUT endpoint */
USBH_Open_Channel (pdev, CDC_Machine.CDC_DataItf.hc_num_out, pphost->device_prop.address,pphost->device_prop.speed,EP_TYPE_BULK, CDC_Machine.CDC_DataItf.length); /* Open channel for IN endpoint */ USBH_Open_Channel (pdev, CDC_Machine.CDC_DataItf.hc_num_in, pphost->device_prop.address, pphost->device_prop.speed, EP_TYPE_BULK, CDC_Machine.CDC_DataItf.length);
}
/*Initilise the Tx/Rx Params*/
CDC_InitTxRxParam();
/*Initialize the class specific request with "GET_LINE_CODING"*/
CDC_ReqState = CDC_GET_LINE_CODING_RQUEST ;
在接收和发送函数中 通过改CDC_Machine.CDC_DataItf.hc_num_out和CDC_Machine.CDC_DataItf.hc_num_in进行收发,发现发送正常,但是接收没有数据
麻烦对USB比较清楚的达人指点一下,非常感谢!
|
|