SD card memory to USB stick

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

HI.

I would like change USB Device Example to function with SD card instead virtual memory.

I can't reach progress. If I start my project I will get an error "invalid USB descriptor" in Windows 10.

Any help ?

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

I don't really understand what you mean. Are you planning to attach a micro (presumably running FatFs) to an SD/MMC so that when it's plugged into a PC it enumerates as if it were an MSD class USB device?

 

Sure it's do able but given that almost all PCs can natively read SD/MMC these days anyway what would be the point?

 

BTW a post in ASF tells us nothing about what kind of micro you are talking about. Clearly an AT90USB family member or something similar would be far more suited to this task than an attiny5 (say) !

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

I have device with SD card and I can't remove this card from device. The device has USB. So, I want use my device as USB stick... when I connect my device to PC, it will behave as USB mass storage.

 

There is one tutorial about USB Device in Atmel Studio, but with internal memory of microcontroller and I want use SD card.

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

Still not nearly enough detail. For example I have a Sony compact camera that uses both SD/MMC and also has a USB interface. It just so happens that in that case the firmware of the camera maps the contents of the SD/MMC through so it looks like an MSD via USB - so you can read the card's contents from the PC. But this is reliant on what Sony already programmed the camera to do.

 

Once again you haven't even said what model of AVR you are talking about. If it is a mega-USB chip then you would probably choose to use LUFA and Dean has examples of using that with FatFs to do pretty much what you are talking about here. So is the micro you plan to program a mega-USB series chip or not ? Or is it an Xmega? Or is it an AVR32-UC3? Or is it a SAM Cortex chip?

Last Edited: Wed. Aug 16, 2017 - 03:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is SAME70Q21 on SAM E70 Xplained Evaluation Kit.

It just so happens that in that case the firmware of the camera maps the contents of the SD/MMC through so it looks like an MSD via USB - so you can read the card's contents from the PC.

It is normal function of USB Device mass storage...Do you know ASF and Atmel Studio ?? You can look there and you will understand my problem.

Example is mapped to virtual memory and I need SD card. What is incomprehensible on that ?

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

MSD just implements a SCSI interface to the disk - basically things like "read sector N" so you need to map those requests to reading sectors on the SD. The "PC end" will then treat this thing like a "normal disk" and will start by asking for sector 0 which will tell it enough (perhaps after a partition table indirection) to know the format (FAT32 etc) of the storage array.

 

If you don't already understand about MSD and SCSI and so on (and perhaps a bit about FAT and how to read SD sectors) this is going be a VERY complex project.

 

Some googling hits:

 

https://en.wikipedia.org/wiki/US...

http://www.shakthimaan.com/downl...

Last Edited: Wed. Aug 16, 2017 - 04:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that you are absolutely out...I don't start at very begining, but with ASF, Atmel Studio and example for USB device with internal memory (virtual memory behaves as USB stick). If you don't have Atmel Studio, you can't help me.

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

jackxl wrote:
I think that you are absolutely out...I don't start at very begining

I think you missed (or misunderstood) clawson's point.

 

The point is that if you don't have a solid understanding of how MSD, SCSI, FAT, etc, work, then having ASF, Atmel Studio, etc is not going to get you very far.

 

They are just tools for writing code - you still need to understand the principles of MSD, SCSI, FAT, etc to know what code to write!

 

If you don't have Atmel Studio, you can't help me.

Nonsense.

 

The principles of MSD, SCSI, FAT, etc are totally independent of what tools - even what language - you use.

 

 

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

I know, but there are examples and libraries and I am sure that I have to only right configure something without creating all code from begining.

I set all in folder config and LUN_2 = ENABLE instead LUN_0, initialized SD card, mount SD card and start udc_start().

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

jackxl wrote:
have to only right configure something without creating all code from begining.
If you really believe that you have completely underestimated the things you are dealing with here. (which was my point above).

 

As I say (and Andy corroborated) the fact is that to do an MSD solution you need to understand SCSI and to interface to SD/MMC you need to understand about SPI and things like SD/MMC power on and init sequences.

 

it's not just a question of connecting a couple of modules from ASF and suddenly you have a complete solution. This is a very complex project and you will need a deep understanding of the procedures and protocols to even know what modules you are going to need in the solution let alone how you might expect them to interact.

 

I'd start by getting the SD/MMC stuff working first. You only need "low level" for this (unless the micro app needs to "see" the files too) so you just need a disk_init() and a disk_read_sector() (and perhaps a write too?) but just getting things to the point where you can simply read sector N from any SD/MMC will be a challenge in itself.

 

As I mentioned above the usual solution is FaFs. I think that's what Atmel have used within ASF but for clarity it might be worth studying it outside the ASF environment.

 

Oh and "Atmel Start" is potentially a "better" solution than ASF though I think there is maybe some suggestion that "ASF 4" is the same as Start ?

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

I started with SD card and Fat and it works, USB not.

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

I solved it :D haha. It was only about settings as I thought. Problem with merge example USB Device and SD_MMC caused this

/* Enable ICache and DCache */
#define CONF_BOARD_ENABLE_CACHE

So:

1) Merge example SD_MMC_EXAMPLE and USB_DEVICE_EXAMPLE (virtual memory is mapped instead SD card) from ASF

2) Remove #define CONF_BOARD_ENABLE_CACHE

3) Set LUN_0 to DISABLED and LUN_2 to ENABLED

4) Remove VIRTUAL_MEMORY_ENABLED from Symbols in project settings