AnsweredAssumed Answered

LDD_USB times out with LDD_USB_TRANSFER_ERROR_BUS_TIMEOUT on first command

Question asked by Jeremy Gordon on Jan 3, 2016
Latest reply on Jan 13, 2016 by Jeremy Gordon



I'm using a custom K20DX256 based board and am trying to use the LDD_USB interface generated by processor expert to implement a simple USB host.


My device successfully generates a reset recovery event identifying as a high speed device and the device physically powers up but I'm getting stuck trying to query the device descriptor. I always get a LDD_USB_TRANSFER_ERROR_BUS_TIMEOUT.


I have tried a few different USB devices with no difference.


I'm assuming that getting past USB device reset means that the electrical level stuff is working (it's a very basic board with 30 ohm resistors in serial connecting a USB micro and the K20 DP/DN pins, with matched length on the DP/DN differential pair data traces).


Any ideas?






void USB1_OnHostResetRecovery(LDD_TUserData *UserDataPtr, LDD_USB_TBusSpeed CurrentSpeed)


  bus_speed = CurrentSpeed;

  _lwevent_set(&reset_recovery, 1);



void Task1_task(uint32_t task_init_data)


  // initialize the reset recovery event

  _lwevent_create(&reset_recovery, 0);

  _lwevent_clear(&reset_recovery, 1);


  // init and enable the USB host

  LDD_TDeviceData* pUSB1 = USB1_Init(NULL);

  if( pUSB1 == NULL ) {

  SEGGER_RTT_printf(0, "error: failed to init USB1.\n");


  _mqx_uint error;

  if( (error = USB1_Enable(pUSB1)) != ERR_OK ) {

  SEGGER_RTT_printf(0, "error: unable to enable USB1. (0x%x)\n", error);



  // wait indefinitely for the device to be plugged in

  _lwevent_wait_for(&reset_recovery, 1, TRUE, 0);


  LDD_USB_Host_TPipeHandle *defaultPipeHandle;

  LDD_USB_Host_TPipeDescr defaultPipeParams;

  memset(&defaultPipeParams, 0, sizeof(defaultPipeParams));

  // the default address

  defaultPipeParams.DevAddress = 0;

  defaultPipeParams.DevSpeed = bus_speed;

  defaultPipeParams.MaxPacketSize = 64;

  defaultPipeParams.EpDir = LDD_USB_DIR_OUT;

  // the default endpoint

  defaultPipeParams.EpNumber = 0;

  defaultPipeParams.TransferType = LDD_USB_CONTROL;

  if( (error = USB1_HostOpenPipe(pUSB1, &defaultPipeParams, &defaultPipeHandle)) != ERR_OK ) {

  SEGGER_RTT_printf(0, "error: failed to open the default endpoint on USB1 (%x).\n", error);


  LDD_USB_TSDP transferSetupData;

  transferSetupData.bmRequestType = 0x80;

  transferSetupData.bRequest = LDD_USB_REQ_GET_DESCRIPTOR;

  transferSetupData.wValue = 0x0100;

  transferSetupData.wIndex = 0x0000;

  transferSetupData.wLength = 18;

  LDD_USB_Host_TTD transferDescriptor;

  unsigned char descriptor[18];

  memset(&transferDescriptor, 0, sizeof(transferDescriptor));

  transferDescriptor.SDPPrt = &transferSetupData;

  transferDescriptor.BufferPtr = descriptor;

  transferDescriptor.BufferSize = 18;

  //transferDescriptor.CallbackFnPtr = &GetDescriptorDoneCB;

  LDD_USB_Host_TTransferHandle *transferHandle;

  if( (error = USB1_HostSendSetup(pUSB1, defaultPipeHandle, &transferDescriptor, &transferHandle)) != ERR_OK ) {

  SEGGER_RTT_printf(0, "error: failed to send the GET_DESCRIPTOR query on USB1 (%x).\n", error);


  while(1) {

  LDD_USB_TTransferState state = USB1_HostGetTransferStatus(pUSB1, transferHandle);

  if( state < LDD_USB_TRANSFER_QUEUED ) {

  SEGGER_RTT_printf(0, "error: transfer state is (%x).\n", state);