Is there any API in MQX USB device stack to reset the underlaying USB Device?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Is there any API in MQX USB device stack to reset the underlaying USB Device?

2,015件の閲覧回数
siddu
Contributor I

Hi I need information  on API information to reset  underlaying USB device.

 

This API to cause the USB device to reenumeration.

 

 

Regards,

Subhashini

ラベル(1)
タグ(1)
0 件の賞賛
返信
4 返答(返信)

649件の閲覧回数
Jarpba
Contributor II

I'm interested in this also... or actually what I want is a bit different but relates to first post.

 

In my software (using mqx 3.7) k60 is connected to pc as a mass storage device to view files on sd card (READ ONLY). That's ok so far and I can read my data from usb but then I want to update that data which means I have to make Windows see the changes. The only way, it seems, would be to reinitialise the usb device connection but in my situation the device must not be disconnected physically from the pc. So the usb device reset or reinit has to be done in software but there seems to be no functions for doing that? How can I reset msd on the fly? Any advice would be welcome... :smileyhappy:

 

Currently I have managed to make the device disconnect from pc by setting usb pullup resistor value but re-enabling it won't reconnect the device. Running TestAppInit() function after that won't reconnect either (As a base for my project I have used usb msc demo project). The other way that works, is to reset the whole system after the data is updated but that isn't quite a solution.

0 件の賞賛
返信

649件の閲覧回数
Fabi
Contributor III

The host (windows) caches the FAT and file data. However, opening the file with FILE_FLAG_NO_BUFFERING  flushes the buffer and induced to re-read the data by the host. Note, this flag requires data read of 512 Bytes minimum, but USB fullspeed endpoint provides 64 Bytes only. So, closing and re-opening the stream without this flag is necessary.

Here's my sample code:

    hd = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL );
    CloseHandle( hd );

    hd = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
    if( hd != (HANDLE)-1 )
    {
      ReadFile( hd, buf, 10, &bytes, NULL );
      std::cout << bytes << " Bytes read" << std::endl;
    }
    else
      std::cout << "Error: " << GetLastError() << std::endl;

@Jarpba: PLS, Could you provide your code, especially for USB_MSC_DEVICE_READ_REQUEST to adapt SD card to MSD? I want to implement this functionality, too. But If I try read (sdcard_handle, lba_data_ptr->buff_ptr, lba_data_ptr->size); I get kerner panic and memory dump with it. TY

0 件の賞賛
返信

649件の閲覧回数
Fabi
Contributor III

Update: it suffice to open the file with CreateFile(...,FILE_FLAG_NO_BUFFERING,...). Other apps (also the same app) re-read the content of the file until the file handle is closed.


Remark: If you want to read the file in the same app, use second handle i.e..:

  hd_unbuf = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL );
  while( true )
  {
    hd = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
    if( hd != (HANDLE)-1 )
    {
      memset ( buf, 0x00, sizeof(buf) );
      //SetFilePointer ( hd, 0, 0, FILE_BEGIN );
      ReadFile( hd, buf, 10, &bytes, NULL );
      if ( bytes > 0 )
        std::cout << buf << std::endl;
      CloseHandle( hd );
      Sleep( 1000 );
    }
    else
      std::cout << "Error: " << GetLastError() << std::endl;
  }

  CloseHandle( hd_unbuf );


0 件の賞賛
返信

649件の閲覧回数
JuroV
NXP Employee
NXP Employee

Hi siddu.

 

If you deployed MQX's USB DDK device, then you cannot reset the device as you want, that command must come from host.

If you deployed MQX's USB HDK host, then you can use:

 

_usb_host_bus_control(handle, USB_ASSERT_BUS_RESET); and  _usb_host_bus_control(handle, USB_DEASSERT_BUS_RESET);

 

but, unfortunatelly, this is not supported by low-level drivers yet (although, as you see, the API is prepared)...

0 件の賞賛
返信