Set up the files

… visits
Parent Previous Next

Choose the files before compiling. The PC will see these fixed names and sizes each time the device starts.

MSC tab defining three fixed files: DEVICE.TXT at 128 bytes, STATUS.CSV at 128 bytes, and writable SETTINGS.BIN at 64 bytes.

Each virtual file has a name, fixed length and write setting. This picture uses DEVICE.TXT; for the worked example below, use DEMO.TXT at 64 bytes with writing enabled, as shown in the table.

  1. Select the exact device and Mass Storage Class (MSC). Set the board's clock and registers as described in Choose the PIC and set its clock.
  2. In MSC, enter a drive label of 1–11 characters. Letters, digits, spaces, underscores and hyphens are accepted.
  3. Select the file count. Give each file a unique name, its fixed length in bytes, and its writable setting.
  4. Enable the serial-number descriptor. Enter 12–126 uppercase hexadecimal characters: 0–9 and A–F. Give each physical unit a unique last 12 characters. For a single test board, 000000000123 is a valid example.
  5. Keep MSC's 64-byte IN and OUT buffers and disable ping-pong. The tool checks these requirements.
  6. Save the configuration and copy the generated Integration listing. Keep its device-specific clock setup, configuration fuses and, if selected, ISR setup. Add your file handlers to its main loop.

The minimum 12-character serial is a requirement of the USB Mass Storage Bulk-Only Transport specification, sections 4.1.1 and 4.1.2. It lets the host distinguish devices sharing a VID/PID. It is an identifier, not a password.

Set up the three example files

Use the following setup for the three-file walkthrough:

Tool slot

Filename

Length

Writable

Firmware index

Contents in this example

1

DEMO.TXT

64 bytes

Yes

0

Text in RAM

2

STATUS.CSV

128 bytes

No

1

A measurement snapshot in RAM

3

SETTINGS.BIN

64 bytes

Yes

2

Binary settings in RAM

All files appear in the drive's root directory; folders are not supported. Names use the 8.3 format: up to eight characters before the dot and up to three after it. Use letters, digits, underscore or hyphen. Names are case-insensitive and normalized to uppercase. Avoid Windows reserved names such as CON and COM1. The tool converts STATUS.CSV to the padded descriptor text "STATUS CSV"; you do not type that padding in the filename field.

Check the generated settings

The generated definitions for this layout include:

$define USB_MSC_ENABLE 1

$define USB_MSC_FILES 3

$define USB_MSC_NAME_1 "DEMO    TXT"

$define USB_MSC_SIZE_1 64

$define USB_MSC_WRITE_1 1

$define USB_MSC_NAME_2 "STATUS  CSV"

$define USB_MSC_SIZE_2 128

$define USB_MSC_WRITE_2 0

$define USB_MSC_NAME_3 "SETTINGSBIN"

$define USB_MSC_SIZE_3 64

$define USB_MSC_WRITE_3 1

These are an excerpt, not a replacement for the complete generated header. Do not define them twice. Each file length is 1–1,041,408 bytes, subject to the combined limit of 2034 sectors for all files. File length is separate from USB packet size and RAM allocation. For example, a 100 KiB file can be read from external storage in small pieces without a 100 KiB RAM array. The tool rounds each file's allocation up to 512-byte sectors and checks the volume limit.

See also

Created with the Personal Edition of HelpNDoc: Modernize your help files with HelpNDoc's WinHelp HLP to CHM conversion tool