Microchip® Advanced Software Framework

Quick Start Guide for USB Host Mass-Storage Module (UHI MSC)

This is the quick start guide for the USB Host Mass-Storage Module (UHI MSC) with step-by-step instructions on how to configure and use the modules in a selection of use cases.

The use cases highlights several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic Use Case

In this basic use case, the "USB Host MSC (Single Class support)" module is used.

The "USB Host MSC (Multiple Classes support)" module usage is described in Advanced Use Cases.

This example do a simple physical memory access, but a file system module can be added to decode the USB memory file system, see FatFS examples.

Setup Steps

As a USB host, it follows common USB host setup steps. Refer to USB Host Basic Setup.

Usage Steps

Example Code

Content of conf_usb_host.h:

#define USB_HOST_UHI UHI_MSC
#define UHI_MSC_CHANGE(dev, b_plug) my_callback_msc_change(dev, b_plug)
extern bool my_callback_msc_change(uhc_device_t* dev, bool b_plug);
#include "uhi_msc_mem.h" // At the end of conf_usb_host.h file

Add to application C-file:

static bool my_flag_autorize_msc_check = false;
bool my_callback_msc_change(uhc_device_t* dev, bool b_plug)
{
if (b_plug) {
my_flag_autorize_msc_check = true;
} else {
my_flag_autorize_msc_check = false;
}
}
void my_task(void)
{
if (!my_flag_autorize_msc_check) {
return;
}
my_flag_autorize_msc_check = false;
// Check all new USB disks plugged
for (uint8_t lun=0; lun < uhi_msc_mem_get_lun(); lun++) {
// Wait the end of USB disk install
while (CTRL_BUSY == uhi_msc_mem_test_unit_ready(lun));
if (CTRL_GOOD != uhi_msc_mem_test_unit_ready(lun)) {
// Removal disk not present or fail
continue;
}
// Read capacity
uint32_t max_lba;
uhi_msc_mem_read_capacity(lun, &max_lba);
}
}

Workflow

  1. Ensure that conf_usb_host.h is available and contains the following configuration, which is the USB host MSC configuration:
    #define USB_HOST_UHI UHI_MSC
    Note
    It defines the list of UHI supported by USB host.
    #define UHI_MSC_CHANGE(dev, b_plug) my_callback_msc_change(dev, b_plug)
    extern bool my_callback_msc_change(uhc_device_t* dev, bool b_plug);
    Note
    This callback is called when a USB device MSC is plugged or unplugged.
  2. The access of the USB memories is allowed through functions described in API Overview.

Advanced Use Cases

For more advanced use of the UHI MSC module, see the following: