AnsweredAssumed Answered

MQX USB Host: Cannot catch USB_DEVICE_ATTACHED event

Question asked by Gabriele Ligorio on Mar 23, 2017
Latest reply on Apr 5, 2017 by Daniel Chen

Hello,

 

I am trying to use USB Host libraries for MSD in IAR, MQX version 4.1.0, board K21F120M. I need to write in a USB mass storage device.

 

To this purpose I created a dedicated task  (see void Main_Task ( uint32_t param ), below) where I installed the driver, init the host and register the driver. Then in the infinite loop, I wait for the USB_DEVICE_ATTACHED:

My problem is that I never catch the USB_DEVICE_ATTACHED, but I always stay in USB_DEVICE_IDLE instead.

 

The callback function which should manage the events is "usb_host_mass_device_event()" and it is associated to my USB device in the DriverInfoTable (see below).

Unfortunately, this function is never called and I was not able to track the interrupt that should be calling it.

Any suggestion?

 

Thanks

Gabriele

 

Here's the code:

/* Driver Info Table */

static  USB_HOST_DRIVER_INFO DriverInfoTable[] =
{
   /* USB 2.0 hard drive */
   {

 

      {0x0C, 0x09},                 /* Vendor ID per USB-IF             */
      {0x00, 0x10},                 /* Product ID per manufacturer      */
      USB_CLASS_MASS_STORAGE,       /* Class code                       */
      USB_SUBCLASS_MASS_SCSI,       /* Sub-Class code                   */
      USB_PROTOCOL_MASS_BULK,       /* Protocol                         */
      0,                            /* Reserved                         */
      usb_host_mass_device_event    /* Application call back function   */
   },


   {
      {0x00,0x00},                  /* All-zero entry terminates        */
      {0x00,0x00},                  /*    driver info list.             */
      0,
      0,
      0,
      0,
      NULL
   }

 

};

 

 

void Main_Task ( uint32_t param )
{

    ... some init code ...

 

   _int_disable();

   _int_install_unexpected_isr();


   // Install USB Host Driver
   if (MQX_OK != _usb_host_driver_install(USBCFG_DEFAULT_HOST_CONTROLLER)) {
      printf("\n Driver installation failed");
      _task_block();
   }
   
   status = _usb_host_init(USBCFG_DEFAULT_HOST_CONTROLLER, &host_handle);

   if (status != USB_OK) {
      _int_enable();
      printf("\nUSB Host Initialization failed. STATUS: %x", status);
      fflush(stdout);
      _task_block();
   } /* Endif */

 

   status = _usb_host_driver_info_register(host_handle, DriverInfoTable);
   if (status != USB_OK) {
      _int_enable();
      printf("\nDriver Registration failed. STATUS: %x", status);
      fflush(stdout);
      _task_block();
   }

 

   _int_enable();

 

  /* Infinite loop */
   for ( ; ; ) {
      for (i = 0; i < MAX_MASS_DEVICES; i++) {
         switch ( mass_device[i].dev_state ) {
            case USB_DEVICE_IDLE:
                  break ;
            case USB_DEVICE_ATTACHED:

                  printf("Mass Storage Device attached\n");
                  fflush(stdout);

 

                 .... more code...

               

           } /* end switch */

       } /* end for */

   } /* end for */

 

} /* end Main_task */

Outcomes