I need to read simple files off a USB drive with minimum hardware. What approach should I use?

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a potential application that would use USB drives to hold some configuration data, and I'm trying to understand the simplest approach to do this.  The application requires very little MCU processing power otherwise - any AVR 8 pins and up could handle it, or certainly any ARM Cortex M (these are the families I know best, so it will come down to one of those).  The idea is that a user plugs in a pre-configured USB drive and turns an encoder knob or presses a button to select one configuration.  That's it.

 

So I'll need to be able to talk USB and talk files.  Beyond that, I'm in unknown territory, but keeping the hardware cheap is important.

 

Thoughts?  Comments?

 

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to have some sort of FAT file system handler.  Here is some info:

 

1.2. Adding File System to Your Products Adding a file system, such as FAT, to a product can cost a company thousands of dollars. A reliable FAT stack source code costs between $4,000 and $10,000. That is not all, FAT is useless without driver for the connected media, an SD card for example. Understanding the media, porting, compiling and linking are also other complicated steps. Our own research shows that adding a file system to a product would take about 6 months or cost about $10,000!!!

 

https://www.mouser.com/datasheet/2/170/uALFAT%20Manual-1167518.pdf

 

I've used their chips in the past & they've worked well....though by now there may be some better solutions!

 

Also see this for inspiration:

http://ww1.microchip.com/downloads/en/AppNotes/Petit-Fat-File-System-00002799A.pdf

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Mar 31, 2020 - 09:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, USB drive sort of means, uh...., USB, no? Not only that, the USB device that the thumb drive connects to must be a Host. That really narrows the AVR offering.

 

I do not think that FatFs will be of any help to you. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah, this may be the wrong approach (but USB drives are so convenient!).  Maybe special hardware is a better choice.  Then it needs other special hardware to program it, but it still may be the right tradeoff.  Definitely need to keep thinking about this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
the USB device that the thumb drive connects to must be a Host. That really narrows the AVR offering.

Indeed.

 

Much more common on ARM-based chips.

 

I do not think that FatFs will be of any help to you. 

Why not?

 

For "ready to go" solutions, maybe look at:

 

https://www.hobbytronics.co.uk/usb-host

 

https://www.ftdichip.com/Products/ICs/VNC2.htm - see 'Development Modules' near the foot of the page.

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FatFs relies on the "op codes" implemented by SD cards. Do thumb drives use the same scheme?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's just at the low level device interface.

 

Plenty of examples of people using FatFs with USB MSC ...

 

https://www.google.com/search?q=fatfs+usb+mass+storage

 

EDIT

 

Right here:  https://www.avrfreaks.net/forum/combining-lufa-and-fatfs-usb-drive

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Apr 1, 2020 - 12:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


An alternative might be an SD or uSD card interfaced to your widget's mcu.  Almost trivially easy with fatfs, and need no special peripherals.  SPI is useful, but even GPIO pins can be used to bitbang.

 

Then provide one of these:

 

https://www.canadacomputers.com/product_info.php?cPath=11_171&item_id=050635

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, that SD card interface looks very promising.  Many thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I agree with he other that you might be better of using an sd card as interface.

 

if you ever want to go the USB route, then you need a USB device that can be a On The Go (OTG) host. But is not a "just simple"  thing to implement.

at least a number of years ago at my work we did a proof of concept and then it took our FW engineers a lot of effort to get things going.

 

we choose to go the SD card route in the end to safe us a lot of head aches.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got involved in the fatfs thingy about 12 years ago, when working on a new system...they suddenly laid on me that some of the data needed to be read by a PC app opening thumb drive files & "all I had to do" was create the file and write it to the thumb drive as part of the sensor reading.  They insisted it MUST use a thumb drive.

Found some of these fatfs chips that made a tough job relatively painless.  It was a $$$ system, so the cost of the fatfs chip didn't matter.  I don't think OTG was even avail at the time (or was just around the corner)

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be able to plug a USB memory stick (or any USB class device) into something it has to be able to operate USB host mode. Now there is a special, limited form of host mode called "On The Go" (OTG) which was developed so that things like cameras and mobile phones could have things like printers and memory sticks plugged into them (literally "on the go" means "USB hosting while out and about and not having access to a big cumbersome PC"). In the entire AVR range there are two models that have OTG which are the AT90USB647 and the AT90USB1287. The latter processor is the one at the heart of the AT90USBKEY - which is a demo platform for all the AT90USB models - it uses the "top of the range" 1287 so it can do "one of everything".

 

Dean did most of his LUFA development on the AT90USBKEY so naturally some of the support/demos in LUFA are for 1287 in host mode and that includes Mas Storage:

 

https://github.com/abcminiuser/lufa/tree/master/Demos/Host/ClassDriver/MassStorageHost

 

Of course mass storage is just one part of the jig saw. The raw interface to storage over USB is actually SCSI (anyone who did computers in the 70's will likely remember Small Computer Systems Interface!) so there's basically "read block N" and "write block N". To interpret a filing system on top you then need to add a filing system layer and the usual choice for FAT based storage (as most memory sticks are formatted) is FatFs as noted above in this thread. So I have seen reference to projects using LUFA MassStorageHost and FatFs in threads on Freaks where folks have combined the USB level SCSI interface from LUFA as the "disk level" interface to FatFs.

 

I thought the LUFA tree itself had an example but I can't immediately see it. But a google for "lufa msd scsi fatfs" would probably hit relevant traffic about all this.

 

PS it's not particularly easy!

 

EDIT: that google lead to this:  https://www.avrfreaks.net/forum/combining-lufa-and-fatfs-usb-drive

Last Edited: Wed. Apr 1, 2020 - 09:13 AM