Skip to content

TUDelftSBT/chibios-rt-usb-msd

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mass Storage Device

This driver implements a USB mass storage device. It requires a Chibios block device (e.g mmc_spi or SDC)

Bugs & TODO:

  • Currently the Read/Write function is written and optimized for MMC_SPI but not the generic BaseBlockDevice. Achieving 200KiB/s read/write over 20MHz MMC SPI
  • Commenting and formatting.
  • Clean code from unnecessary statements
  • Replace prepare transmit and prepare receive by descent functions
  • Improve boot performance??? takes some seconds to load when plugged in
  • Device descriptor define for easy inserting in already existsing usb descriptors
  • HAL settings for IN and OUT endpoints and interface number
  • Remove daisy chaining of multiple MSDP and instead using LUN. Advantage is less endpoints used and otherwise it is just an composite device containing multiple mass storage devices...

Example usage:

USBMassStorageDriver UMSD1;

mmcObjectInit(&MMCD1);
mmcStart(&MMCD1, &mmccfg);
mmcConnect(&MMCD1);

msdObjectInit(&UMSD);
msdStart(&UMSD, &ums_cfg);

msdReady(&UMSD, &MMCD1);
msdEject(&UMSD);

...

static void usb_event(USBDriver *usbp, usbevent_t event) {
  switch (event) {
  case USB_EVENT_CONFIGURED:
    chSysLockFromIsr();

    // Endpoints initializations
    usbInitEndpointI(usbp, MASS_STORAGE_IN_EPADDR, &ms_ep_in_config);
    usbInitEndpointI(usbp, MASS_STORAGE_OUT_EPADDR, &ms_ep_out_config);

    msdConfigureHookI(usbp);
    chSysUnlockFromIsr();
    return;
    
  case USB_EVENT_SUSPEND:
    // USB Disconnect detection
    msdSuspendHookI(usbp); 
    return;
  }
  return;
}

Events:

chEvtRegisterMask(&UMSD1.evt_ejected, &listener_ejected, 2);

while(TRUE) {
  if(chEvtWaitOneTimeout(1, TIME_IMMEDIATE)) {
    /* drive is now connected */
      
    /* wait until the drive is ejected */
    chEvtWaitOne(2);
      
    /* drive is now ejected. do something */
  }

  chThdSleepMilliseconds(1000);
}

Reference

About

Chibios USB device drivers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%