4

So working on an embedded system I have a USB drive that is used to charge the device as well as reading some data.

Using usbd_core.c I can check the status,

  • when there's nothing connected the status is 4 (USBD_STATE_SUSPENDED).
  • As soon as I connect something the status changes to 1 (USBD_STATE_DEFAULT).
  • But when I disconnect it the status doesn't change, it continues to be 1 (USBD_STATE_DEFAULT).

Is it supposed to be like this or I am missing something?

I have also tried USBD_Stop() and USBD_Start() to see if it makes any difference but still the status doesn't change when I disconnect it.

Any ideas?

Trygve Laugstøl
  • 7,440
  • 2
  • 36
  • 40
  • "usbd_core.c" from where? The file is by no means universal or standard, and the same filename may be used in more than one implementation. – Clifford Jun 18 '15 at 09:32

1 Answers1

1

The USB specification defines six USB device states:

  • Attached: the device is attached to the USB but is not powered by the USB.

  • Powered: the device is attached to the USB and has been powered but has not yet received any reset request.

  • Default: the device is attached to the USB. It is powered and reset, but no unique address has been assigned to it.

  • Address: the device is attached to the USB, it is powered and reset and has had a unique address assigned to it.

  • Configured: the device is already in address state and configured. It is not in suspend state.

  • Suspended: the device is attached and configured, but has not detected any activity on the bus for at least 3 ms.

As you can see suspended requires an attached and configured device, however also note that all of these states require an attached device and cannot apparently be used to imply a physically detached device.

Disconnection is a low-level event from the USB controller - your API may provide a callback for such events.

Clifford
  • 88,407
  • 13
  • 85
  • 165