cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f2 libusb and custom usb request - something strange

gilrum
Associate II
Posted on November 18, 2012 at 15:49

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)

{

case

CUSTOM_MC_JOB:

HidCCommand=req->bRequest;

USBD_CtlPrepareRx(pdev,

CBuffer,

req->wLength);

break

;

case

CUSTOM_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-device

4 REPLIES 4
tsuneo
Senior
Posted on November 20, 2012 at 06:49

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.

Tsuneo

gilrum
Associate II
Posted on November 20, 2012 at 08:02

>>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.
gilrum
Associate II
Posted on November 20, 2012 at 09:19

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

gilrum
Associate II
Posted on November 21, 2012 at 17:43

After active googling with various requests problem finally dissolves. There was problem in example.

inserted next code just after opening device

detach_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

http://pl.digipedia.org/usenet/thread/14995/6944/