Hi I need information on API information to reset underlaying USB device.
This API to cause the USB device to reenumeration.
Regards,
Subhashini
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...
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.
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
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 );
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)...