0

Introduction

On a USB device I am developing, I want to offer a USB Mass Storage endpoint for configuration updates.

The device is connected internally via a USB pin header, and to update the configuration, a user would only have to copy a file onto the "fake" flash drive, so no additional software would be required. This makes the solution portable between all kinds of operating systems and improves user experience.

Using LUFA, I have managed to implement a USB device with a Mass Storage endpoint that supports enough basic SCSI commands to be recognised as a storage device by Windows.

But, now that I'm trying to fully implement the SCSI Reduced Block Command set, I realise that there might be an issue. The MCU I'm using, an Atmega32u4, only has 2.5KB of SRAM. Part of that is taken up by global variables and buffers for the primary functionality, so I'd like to use only 1KB of that for the SCSI storage capabilities.

Problem Description

TL;DR from above: I only have about 1KB available for a storage buffer to implement the most basic USB Mass Storage functionality on an MCU.

From my knowledge, to properly function as a block device, a mass storage device needs to be formatted. I don't know what the leanest commonly (Windows and Linux) supported file system is. My assumption is FAT32, but in any case it needs to store all of the info associated with a partition and one file on it in addition to the file itself. Additionally, SCSI seems to work on a 512 byte block size, so the whole "flash drive" would be written to with just two block writes, which sounds like it would cause trouble.

My question(s) now is/are:

Is it possible to make/emulate a fully functioning USB Flash Disk with just 1KB of storage? What would prevent me from doing this? How much overhead space would an empty partition need? Could I maybe even implement this without partitioning the device by using a non-SCSI USB mode?

2
  • I am confused here. You are going to implement a Mass Storage device, yet you don't have any idea of what the device memory structure and minimum capacity should be. Then how do you plan to implement the design? BTW, before FAT32, there were perfect mass-storage devices with FAT16 and even FAT12. Commented Jul 27, 2017 at 22:49
  • Ah right, I wasn't aware that FAT16 still existed. The Mass Storage was supposed to purely be a portable interface for updating the configuration. The maximum capacity is 1KB, the minimum is probably 512B because that's how large one sector is. Not sure what you mean by structure. All of these things could be entirely simulated for all I care.
    – iFreilicht
    Commented Jul 28, 2017 at 9:32

1 Answer 1

2

You need a MBR 512 bytes, FAT table, backup FAT table, 1st sector of the partition is the root directory, and then storage. Each one requires 512 bytes. FAT16 FAT table can hold 256 clusters/sectors so if you need more than that you will need more sectors in the FAT table.

 1 MBR
 2 FAT
 3 Backup FAT
 4 Root directory partition 1
 5 512 bytes storage
 6 512 bytes storage

So a Minimum of 6 sectors using FAT16, and a couple more for FAT32.

If you emulated the FAT table and backup FAT you could probably get away with around 20 bytes each. (You would just report the rest of the FAT as all zeros.) The other sectors would be hard to reduce.

I highly recommend at least 10k or 20 sectors so you have some wiggle room in case your file gets bigger over time.

7
  • What about FAT12? Commented Jul 27, 2017 at 22:49
  • @AliChen The FAT12 file system has the same overhead. Its just you can fit more clusters per sector in the 2 FAT tables. Which is irrelevant since he only needs 2 clusters of actual storage. Even with 100 cluster on FAT32 is 400 bytes, and you still have 112 bytes left. 100 clusters is 50k, way more than needed.
    – cybernard
    Commented Jul 27, 2017 at 22:51
  • +1 for valuable info, thanks. I think the OP should embed some tiny 8-pin EEPROM with SPI for bigger storage capacity, and problem will be solved. Commented Jul 27, 2017 at 23:11
  • 1
    You don't need a MBR; most flash drives don't have a partition table by default. Microsoft calls this a "super floppy". (If you create one, Windows will not mount past the first partition either.)
    – Bob
    Commented Jul 27, 2017 at 23:35
  • @Bob If you make it a logic device install of a physical device that is correct. Since there is no MBR you could never have a partition table.
    – cybernard
    Commented Jul 27, 2017 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .