2012-11-18 06:49 AM
Tried to implement custom device control over vendor specific requests.
Usb device library v1.1.0, usb otg library v2.1.0 and stm32f207 on device side, libusb 1.011, debian gnu linux on host side. For experiment i modify custom hid example - added some code toUSBD_HID_Setup() func. On host side i'm just use example from libusb package - hid-custom-irq commandline. device is recognized, handle open successfully. But something wrong - when i issue set-led on all is ok - no errors from libusb and led is on and when i issue set-led off - led is still turn on and libusb shows time-out. code on mcu:case
USB_REQ_TYPE_VENDOR:
{ switch(req->bRequest)
{ caseCUSTOM_MC_JOB:
HidCCommand=req->bRequest; USBD_CtlPrepareRx(pdev, CBuffer, req->wLength); break;
caseCUSTOM_RQ_SET_STATUS:
ctmp=(req->wValue); if(ctmp)
{ LEDOn(LED3); } else LEDOff(LED3); //GPIOC->BSRRL |= ((uint16_t)ctmp&0x0f)<<6; //GPIOC->BSRRH |= ((~ctmp)&0x0f)<<6; break;
} code on PC (unmodified example except changed vid&pid and so on)}
else if((isOn = (strcasecmp(argv[1],
''on'') == 0)) || strcasecmp(argv[1],
''off'') == 0){
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, isOn, 0, buffer, 0, 5000); if(cnt < 0){
fprintf(stderr,
''USB error: %s\n'', usb_strerror());
} } experiment a bit with wValue on pc side - it seems that if i send somethig else than 1 - got same error. anybody experience anything similar? #stm32-usb-device2012-11-19 09:49 PM
I don't see any error on your above code.
To get more clues, a) Watch USB traffic with a hardware bus analyzer or a software sniffer. Virtual USB Analyzer - Linux graphic sniffer http://vusb-analyzer.sourceforge.net b) Place a break point at LEDOff(LED3) on the firmware, to confirm this part is visited. Tsuneo2012-11-19 11:02 PM
>>a) Watch USB traffic with a hardware bus analyzer or a software sniffer.
already done - in wireshark i see setup packet with correct values, but in that case aswer came in 5 seconds saying that there's timeout. >>b) Place a break point at LEDOff(LED3) on the firmware, to confirm this part is visited.now i try to set up USART debug messages.And side question - can you point at some guide to completely custom device class (or just example) with stm32 usb device library. i've seen some examples that sort on AVR, but it's hard to convert.Device i'm trying to implement is lab stand controller. command sequences from host is about 40 bytes/command, status reports and possibly adc data stream.2012-11-20 12:19 AM
upd. in case of status request and in case of set with non-1 wValue firmware doesn't recognize request as vendor type. Other examples i've seen that sometimes they used 'if' series with req_type combined with some mask(recipient and direction) instead of 'switch' statement
2012-11-21 08:43 AM
After active googling with various requests problem finally dissolves. There was problem in example.
inserted next code just after opening devicedetach_kernel_driver_np(handle,0);
claim interface(handle,0);
and then used USB_RECIPIENT_INTERFACE instead of RECIPIENT_DEVICE in usb_control_msg();
solution was found