chipKIT® Development Platform

Inspired by Arduino™

Last edit: 2021-03-21 22:34 by Majenko

USB MSD

USB MSD
Quick Look
Hardware WF32 or Wi-Fire
Core USB_MSD.h
  1. Detailed Introduction

  2. Introductory Programs

    1. Analog to File

    2. MSDtest

  3. Full library usage

    1. USB_MSD

      1. Constructor

        1. USB_MSD(DFSVOL &dv, const char *mfg = NULL, const char *model = NULL) : _volume(&dv), _mfg(mfg), _model(model)

        2. USB_MSD(DFSVOL *dv, const char *mfg = NULL, const char *model = NULL) : _volume(dv), _mfg(mfg), _model(model)

      2. Public Functions

        1. getDescriptorLength()

        2. getInterfaceCount()

        3. getStringDescriptor(uint8_t idx, uint16_t maxlen)

        4. populateConfigurationDescriptor(uint8_t *buf)

        5. initDevice(USBManager *manager)

        6. getDescriptor(uint8_t ep, uint8_t target, uint8_t id, uint8_t maxlen)

        7. getReportDescriptor(uint8_t ep, uint8_t target, uint8_t id, uint8_t maxlen)

        8. configureEndpoints()

        9. onSetupPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l)

        10. onOutPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l)

        11. onInPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l)

        12. onEnumerated()

  4. External Links

Detailed Introduction

USB Mass Storage Device

Introductory Programs

Analog to File

Stores all the analog input values into a text file in the ramdisk, which you can then access from your PC. Because the PC caches everything and doesn't know the file has changed it never shows any updated values, but on linux you can mount the device, cat the file, then unmount it again and you get the changes.

#include <DFATFS.h>
#include <RAMVOL.h>
#include <USB_MSD.h>


const uint32_t diskSectors = RAMVOL::CMINSECTORS;
const uint32_t sectorSize = RAMVOL::CBSECTOR;

uint8_t ramVolBuff[diskSectors * sectorSize];
RAMVOL ramVol(ramVolBuff, diskSectors);
DFILE dataFile;

USBFS usbDevice;
USBManager USB(usbDevice, 0x04d8, 0x0f5d);
USB_MSD ramdisk(ramVol);

void setup() {
   
    ramVol.disk_initialize();
    DFATFS::fsmkfs(ramVol);
    USB.addDevice(ramdisk);
    USB.begin();
    DFATFS::fsmount(ramVol, DFATFS::szFatFsVols[0], 0);
}

void loop() {
    delay(100);
    dataFile.fsopen("data.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    for (int i = 0; i < 12; i++) {
        dataFile.printf("%2d: %4d\r\n", i, analogRead(i));
    } 
    dataFile.fssync();
    dataFile.fsclose();
}

MSDtest

Implements a basic Mass Storage Device on a chipKIT.

#include <DFATFS.h>
#include <RAMVOL.h>
#include <USB_MSD.h>


const uint32_t diskSectors = RAMVOL::CMINSECTORS;
const uint32_t sectorSize = RAMVOL::CBSECTOR;

uint8_t ramVolBuff[diskSectors * sectorSize];
RAMVOL ramVol(ramVolBuff, diskSectors);

USBManager USB(usbDevice, 0x04d8, 0x0f5d);
USB_MSD ramdisk(ramVol);

void setup() {
    ramVol.disk_initialize();
    DFATFS::fsmkfs(ramVol);
    USB.addDevice(ramdisk);
    USB.begin();
}

void loop() {
}

Full library usage

USB_MSD

Constructor


USB_MSD(DFSVOL &dv, const char *mfg = NULL, const char *model = NULL) : _volume(&dv), _mfg(mfg), _model(model)

USB_MSD(DFSVOL &dv, const char *mfg = NULL, const char *model = NULL) : _volume(&dv), _mfg(mfg), _model(model) {}        

USB_MSD(DFSVOL *dv, const char *mfg = NULL, const char *model = NULL) : _volume(dv), _mfg(mfg), _model(model)

USB_MSD(DFSVOL *dv, const char *mfg = NULL, const char *model = NULL) : _volume(dv), _mfg(mfg), _model(model) {}

Public Functions


getDescriptorLength()

uint16_t getDescriptorLength();

getInterfaceCount()

uint8_t getInterfaceCount();

getStringDescriptor(uint8_t idx, uint16_t maxlen)

bool getStringDescriptor(uint8_t idx, uint16_t maxlen);

populateConfigurationDescriptor(uint8_t *buf)

uint32_t populateConfigurationDescriptor(uint8_t *buf);

initDevice(USBManager *manager)

void initDevice(USBManager *manager);

getDescriptor(uint8_t ep, uint8_t target, uint8_t id, uint8_t maxlen)

bool getDescriptor(uint8_t ep, uint8_t target, uint8_t id, uint8_t maxlen);

getReportDescriptor(uint8_t ep, uint8_t target, uint8_t id, uint8_t maxlen)

bool getReportDescriptor(uint8_t ep, uint8_t target, uint8_t id, uint8_t maxlen);

configureEndpoints()

void configureEndpoints();

onSetupPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l)

bool onSetupPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l);

onOutPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l)

bool onOutPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l);

onInPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l)

bool onInPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l);

onEnumerated()

void onEnumerated();

External Links