how to issue a device reset using usb stack?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to issue a device reset using usb stack?

1,719 Views
banxian
Contributor I

hello, I am porting a usb exploit applications from macosx to an imxrt1011 kit.

the code is copied from usb_host_hid_generic with some change (hid to dfu, and add some more wait states).

I found after a DFU_CLRSTATUS command, device is disconnect but doesnot reconnect after one second. (timeout error on suspend)

QQ图片20200104100803.png

in PC's usb stack, it looks like this:

QQ图片20200104101350.png

so I guess I need to force a soft reset after an dfu clear status control message (like IOUSBDeviceInterface->ResetDevice  under osx or libusb_reset_device under linux).

I tried call

            if (USB_HostDeinit(&g_HostHandle) != kStatus_USB_Success) {
                usb_echo("host deinit error\r\n");
            }

            status = USB_HostInit(CONTROLLER_ID, &g_HostHandle, USB_HostEvent);
            if (status != kStatus_USB_Success) {
                usb_echo("host init error\r\n");
            }

in one of my step but it just cause a hardfault.on USB_HostDeinit.

a single USB_HostInit call doesn't fix suspend timeout error, too.

is there any examples to do a device reset in host side?

I know dfu protocol have a DFU_DETACH command to do a detach-attach sequence in device side, but I do not want send extra packet to device because it may change device's heap, which have side effect in exploit.

I am using mcuxprsso sdk 2.6.0, in usb_examples, each host sample is one way state machine which lacks re plugin support.

0 Kudos
3 Replies

1,539 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Banxian:

Please refer to below API, USB_HostRemoveDevice.  it is similar to yours. ,but not sure if it will meet your requirements


/*!
* @brief Removes the attached device.
*
* This function removes the attached device.
* This function should not be used all the time.
*
* @param[in] hostHandle The host handle.
* @param[in] deviceHandle Removing device handle.
*
* @retval kStatus_USB_Success Remove successfully.
* @retval kStatus_USB_InvalidHandle The hostHandle or deviceHandle is a NULL pointer.
* @retval kStatus_USB_InvalidParameter The deviceHandle instance don't belong to hostHandle instance.
*/
extern usb_status_t USB_HostRemoveDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle);

Regards

Daniel

0 Kudos

1,541 Views
banxian
Contributor I

infact I tried USB_HostRemoveDevice before I post this thread, but it takes no help.

            if (USB_HostRemoveDevice(&g_HostHandle, g_HostDfuGeneric.deviceHandle) != kStatus_USB_Success) {
                usb_echo("remove device error\r\n");
            }

0 Kudos

1,249 Views
bulubuch
Contributor I

Hello dear banxian,

g_HostHandle and g_HostDfuGeneric.deviceHandle are already pointers. remove & ands it should be fine.
Regards

0 Kudos