USB MSD | |
---|---|
Quick Look | |
Hardware | WF32 or Wi-Fire |
Core | USB_MSD.h |
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)
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)
onInPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l)
USB Mass Storage Device
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();
}
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() {
}
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) {}
uint16_t getDescriptorLength();
uint8_t getInterfaceCount();
bool getStringDescriptor(uint8_t idx, uint16_t maxlen);
uint32_t populateConfigurationDescriptor(uint8_t *buf);
void initDevice(USBManager *manager);
bool getDescriptor(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);
void configureEndpoints();
bool onSetupPacket(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);
bool onInPacket(uint8_t ep, uint8_t target, uint8_t *data, uint32_t l);
void onEnumerated();
github.com/chipKIT32/chipKIT-core/tree/master/pic32/cores/pic32 - The github repository for the PIC32 ChipKit Core
github.com/chipKIT32/chipKIT-core/tree/master/pic32/libraries/USB_MSD - The github folder for this USB_MSD Library
www.youtube.com/watch?v=Ifx-MyQUfDQ - YouTube Demo Video