Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to transmit a file into a USB device

Status
Not open for further replies.

s1rUK

Newbie level 3
Newbie level 3
Joined
Jun 1, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Milan
Activity points
1,307
Hi there,

I'm working on app that permits myself to transfer a file located in my file system into a usb device (FAT32). I have to use Bulk Transfer Only mode that means to use stream of characters only. I looked through the LibUsb library using it in my IDE I can transmit a string. To transfer a whole file I suppose I've to dodge the file system building a char sequence that permits to recognise a file in the file system and to put it into the usb device.


Suggestions?


This work under Linux w 2.6.32 kernel version
 

In the case of FAT32. You specify the LBA and write all the data and then you write the FAT32 table the locations which correspond to a particular file.
Which of these steps do you wanna dodge? What is your end application??
 

I wanna try to dodge the using of System call to copy a file from my filesystem to an external usb device. I used a test library called LibUsb to do it. Unfortunately the usb_bulk_write() command send a sequence of character, compliantly at Bulk Transfer Only mode which requires to transmit data by using streams of 0 and 1.

Follows the usb_bulk_write() definition
**broken link removed**

I'm looking how I have to build the correct sequence to send with this method.

My scope is to bypass the system call and move a file into a usb device. It's just a task to understand the BTO transmission with a usb drive.

Cheers
 

I don't think the "char* bytes" parameter in usb_bulk_write function does mean you have to send ascii data. char is the fundamental data type that is equivalent to BYTE in C. You can for sure pass binary data there.
 

Secondly, I have to enable the usb device to recognise my transmission like a file.

Sounds like if I should build a firmware :|
 

Are you using an off the shelf product or you are developing a new product ?

If it is an off the shelf product, you need to know how it expects data. On the other hand, if you are developing one, it is up to you how you want to transfer data.
 

If you are using an off the shelf product you'll have to parse the descriptor to understand what protocol it follows... since you are talking bulk transfer only i believe you are talking about MSC BOT protocol.... in that case the device will expect the host driver to follow BOT spec which means you have to use the packets with the signature "USBC" and stuff to mass storage requests i.e. you'll be writing out an entire driver on the host side...

Here is the sticky part... if you want your data to be readable only by you, you can always build your own custom protocol... no big deal but if you want it to be readable in say a PC that you plug it into.... you are gonna have to understand the file system format used in the drive and write an driver which can handle that as well... which of these are you planning to do....
 

I didn't hear a reason, why you don't want to mount the USB device as a removable disk and use standard Linux file I/O.
 

Usually, if you want to send data from a file to your device, you can just read the file as you would do normally, either in text mode or in binary mode (if all you want is data) and send the resulting bytes via LibUSB.

As said earlier, LibUSB allows you to sand anything in its unsigned char* parameter, it just says it will send the data byte per byte (hence the size parameter is in bytes)

I am actually doing a bootloader with LibUSB, and it works fine!

What LibUSB will NOT do, is have your device recognized as a standard mass storage device.

In order to have a standard mass storage device, you need to define the device as an MSD device, and attach it to the host driver corresponding to MSD.

Something to know, is that the OS can handle the MSD by itself. All you need to do is properly define the msd usb descriptors, and handle the write / read requests properly. The memory will, physically, be a storage on your device of XXX bytes. The host, when formatting the device (can be done from the standard OS user interface (eg in windows right click / format), will allocate memory for the file system index file (especially if it does not detect any file system) This should work.

Cheers!
Paul
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top