Read and Write a Flash drive (USB Thumb Drive)

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

Read and Write a Flash drive (USB Thumb Drive)

#1 Post by bobspencerr » 19 Mar 2012 07:48

Hi all,

Does anyone have any working code or guidance for reading and writing data to a file on a Flash Drive (USB Thumb Drive).
Is there a library I haven't seen?
I am using a pic32 with USB OTG facility but am alittle confused.

Any help appreciated.

:?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Read and Write a Flash drive (USB Thumb Drive)

#2 Post by filip » 19 Mar 2012 10:53

Hi,

Unfortunately, there is currently no USB OTG library available in the compiler at the moment, but we have in plans to include it.

Regards,
Filip.

bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

Re: Read and Write a Flash drive (USB Thumb Drive)

#3 Post by bobspencerr » 20 Mar 2012 00:51

Thanks for the reply Filip,
I will be reading a lot of documentation soon and see if I can make something myself.

Cheers.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Read and Write a Flash drive (USB Thumb Drive)

#4 Post by LGR » 04 Apr 2012 18:14

I can think of another application for USBOTG: bluetooth. The SPI bluetooth modules are pretty expensive, but the USB dongles are quite cheap. I just don't know how practical it is to develop the code. USBOTG opens the door to a number of very cheap interfaces, at least in theory. Video on a PIC32, anyone? :twisted:
If you know what you're doing, you're not learning anything.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Read and Write a Flash drive (USB Thumb Drive)

#5 Post by Dany » 31 Oct 2012 12:56

Hi, there is a flash drive library for PIC24: http://www.libstock.com/projects/view/4 ... st-library. I assume the code (except for the HW related part), can also be used for PIC32...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Read and Write a Flash drive (USB Thumb Drive)

#6 Post by LGR » 10 Jan 2013 20:58

Dany, how difficult would it be to do the reverse: make a PIC (18, 24, 32) appear to a computer as a flash drive?
If you know what you're doing, you're not learning anything.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Read and Write a Flash drive (USB Thumb Drive)

#7 Post by Dany » 11 Jan 2013 12:18

LGR wrote:Dany, how difficult would it be to do the reverse: make a PIC (18, 24, 32) appear to a computer as a flash drive?
Hi,
There is an MSD (Mass Storage device) library for P18 and P24, see http://www.libstock.com/projects/view/71/usb-oa. :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Read and Write a Flash drive (USB Thumb Drive)

#8 Post by LGR » 02 Sep 2013 17:36

Dany,

Let me be clearer on what I want to do.

Instead of using a pic to make an SD card look like a USB card, I'd like to make PIC I/O appear as a file or files on USB. For example, let's imagine that I have a file on the USB MSD device named PORTB. If the host computer reads the file, and it returns a character string (ASCII decimal representation of the port status). That makes it easy for any computer to read any status at the OS level.

To do that, I would need to be able to receive the file and path as a string, and return the file content as a string. I don't see how to do that with this library; it seems to want to treat the MSD as a series of sectors. Is there a reasonably easy way to intercept the file/path and return the file as a string, and bypass all of the FAT code?
If you know what you're doing, you're not learning anything.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Read and Write a Flash drive (USB Thumb Drive)

#9 Post by Dany » 02 Sep 2013 19:25

LGR wrote:Instead of using a pic to make an SD card look like a USB card, I'd like to make PIC I/O appear as a file or files on USB. For example, let's imagine that I have a file on the USB MSD device named PORTB. If the host computer reads the file, and it returns a character string (ASCII decimal representation of the port status). That makes it easy for any computer to read any status at the OS level.

To do that, I would need to be able to receive the file and path as a string, and return the file content as a string. I don't see how to do that with this library; it seems to want to treat the MSD as a series of sectors.
Ai. You are right. The MSD USB definitions indeed only allows the PC to read/write sectors from the PIC's (SD)MMC card. The responsibility handling the data is competely in the PC (e.g. the FAT/file processing). The PIC is only responsible for sending sectors to the PC and receiving sectors from it (accompanied with the associated MMC read/writes).
Is there a reasonably easy way to intercept the file/path and return the file as a string, and bypass all of the FAT code?
To bypass the FAT code, you can not use USB MSD, that is for sure. That also means that the PIC will not appear as an extra drive on the PC.

I think that for your application you will have to go to the CDC protocol (the PIC is seen on the PC as an extra comport, and you can communicate with the PIC via e.g. HyterTerminal), or the HID protocol (in which case you will have of course to write a PC application to communicate with the PIC).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Read and Write a Flash drive (USB Thumb Drive)

#10 Post by LGR » 02 Sep 2013 20:55

Thanks, Dany.

For reasons that I don't want to go into, I want to present the data as files. I think what I might try is use the MSD library, but map the 'drive' into RAM on a PIC32 or maybe a FRAM chip. Then I can get inside of the 'drive', and set and read the data. Do you see any reason why this can't work?
If you know what you're doing, you're not learning anything.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Read and Write a Flash drive (USB Thumb Drive)

#11 Post by Dany » 03 Sep 2013 10:28

LGR wrote:Thanks, Dany.

For reasons that I don't want to go into, I want to present the data as files. I think what I might try is use the MSD library, but map the 'drive' into RAM on a PIC32 or maybe a FRAM chip. Then I can get inside of the 'drive', and set and read the data. Do you see any reason why this can't work?
This should work, but keep in mind that the data (in RAM) must be according the FAT format (or must be at least presented/sent/received to/from the host that the latter thinks it is in FAT format).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for PIC32 General”