MQX USB Host: Cannot catch USB_DEVICE_ATTACHED event

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

MQX USB Host: Cannot catch USB_DEVICE_ATTACHED event

919 Views
gabrieleligorio
Contributor I

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 */

Labels (1)
0 Kudos
5 Replies

543 Views
gabrieleligorio
Contributor I

Hi Daniel,

thanks for your reply. I am not using the dev board.

I am using a customized board, which actually mounts a MK22FN1M0XXX12 processor.

Thanks

Gabriele

0 Kudos

543 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Gabriele:

From hardware aspect, I would suggest you double check the USB related circuit with TWR-K21F120M board.

From software aspect, if the attach event does not generate, one reason is your entries are not correct in the DriverInfo Table. This table should contain the devices supported and handled by the application

Regards

Daniel

0 Kudos

543 Views
gabrieleligorio
Contributor I

Hi Daniel,

We double-checked the HW and it turned out that it could not work as USB host, but only as USB device.

Thank you for your insightful help.

Best regards

Gabriele

0 Kudos

543 Views
danielchen
NXP TechSupport
NXP TechSupport

Welcome, thank you for your feedback.

Regards

Daniel

0 Kudos

543 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi  Gabriele :

Do you use NXP/Freescale released TWR-K21F120M board ?

Regards

Daniel

0 Kudos