STM32_USB_CH341 icon indicating copy to clipboard operation
STM32_USB_CH341 copied to clipboard

上位机反复请求设备状态

Open imuncle opened this issue 5 years ago • 1 comments

你好,我参照你的代码实现CH341的模拟,目前已经成功枚举,串口调试软件也能成功打开串口,但打开串口之后电脑不断请求设备状态,也就是下面:

int ch341_get_status(struct usb_device *dev) 
{ 
  char *buffer; 
  int r = -ENOMEM; 
  const unsigned size = 8; 
  
   dbg("ch341_get_status()"); 
   
   buffer = kmalloc(size, GFP_KERNEL); 
  if (!buffer) 
    goto out; 
   
   r = ch341_control_in(dev, 0x95, 0x0706, 0, buffer, size); 
  /* return value ignored */ 
   r = 0; 
  
  out: kfree(buffer); 
  return r; 
 } 

我猜测是上位机让设备复位后在查询设备的复位情况。你的代码里面的处理方式是:

/*******************************************************************************
* Function Name  : Virtual_Com_Port_Data_Setup
* Description    : handle the data class specific requests
* Input          : Request Nb.
* Output         : None.
* Return         : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
static u8 vender_request;

u8 *Vender_Handle_CH341(u16 Length)
{
    u16 wValue = pInformation->USBwValues.w;
    u16 wIndex = pInformation->USBwIndexs.w;
    static u8 buf1[2]={0x30,0};
    static u8 buf2[2]={0xc3,0};
    change_byte(wValue);
    change_byte(wIndex);
   
    // 省略其他代码...

    case 0x95:
            if(wValue==0x2518)
                return buf2;
            else if(wValue==0x0706)
                return (u8 *)&ch341_state;     
    }
    return 0;
}

我按照你的代码返回值为0xee9fch341_state返回,但并没有解决问题。

希望能从你这获得帮助,谢谢!

imuncle avatar Nov 28 '19 06:11 imuncle

改行啦 不玩硬件啦

blackmiaool avatar Nov 28 '19 11:11 blackmiaool