1.7 MSD Basic Example (msd_basic)

This application demonstrates the ability of the MPLAB Harmony USB Host Stack to support MSD Host Class Driver . It demonstrates the feature with an application to read / write a file to a USB Flash drive.

Description

This application demonstrates the use of the MSD Host Class Driver to write a file to a USB Flash drive. The application uses the USB Host_layer , MSD class driver and the MPLAB Harmony File System Framework to enumerate a USB Flash drive and to write a file to it.

Downloading and building the application

To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.

Path of the application within the repository is usb_apps_host/apps/msd_basic.

Following table gives the details of project configurations, target device used, hardware and its IDE. Open the project using the respective IDE and build it.

Project NameIDETarget DeviceHardware / Configuration
pic32mk_gp_db.XMPLABXPIC32MK1024GPE100PIC32MK General Purpose (GP) Development Board
pic32mk_gp_db_freertos.XMPLABXPIC32MK1024GPE100PIC32MK General Purpose (GP) Development Board
pic32mx470_curiosity.XMPLABXPIC32MX470F512HPIC32MX Curiosity Development Board
pic32mx470_curiosity_freertos.XMPLABXPIC32MX470F512HPIC32MX Curiosity Development Board
pic32mz_das_sk.XMPLABXPIC32MZ2064DAS169PIC32MZ Embedded Graphics with Stacked DRAM (DA) Starter Kit
pic32mz_ef_curiosity_2.XMPLABXPIC32MZ2048EFM144Curiosity PIC32MZ EF 2.0 Development Board
pic32mz_ef_sk.XMPLABXPIC32MZ2048EFH144PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit
pic32mz_ef_sk_freertos.XMPLABXPIC32MZ2048EFH144PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit
pic32mz_w1_curiosity.XMPLABXPIC32MZ1025W104132Curiosity PIC32MZ W1 Development Board
sam_9x60_ek.XMPLABXSAM9X60SAM9X60-EK Evaluation Board
sam_9x60_ek_freertos.XMPLABXSAM9X60SAM9X60-EK Evaluation Board
sam_9x60_curiosity.XMPLABXSAM9X60SAM9X60 Curiosity Development Board
sam_9x60_curiosity_freertos.XMPLABXSAM9X60SAM9X60 Curiosity Development Board
sam_9x75_eb.XMPLABXSAM9X75SAM9X75-DDR3-EB Evaluation Board
sam_a5d2_xult.XMPLABXATSAMA5D27CSAMA5D2 Xplained Ultra Board
sam_a5d2_xult_freertos.XMPLABXATSAMA5D27CSAMA5D2 Xplained Ultra Board
sam_a5d27_som1_ek.XMPLABXATSAMA5D27CSAMA5D27 SOM1 Kit1
sam_a5d27_som1_ek_freertos.XMPLABXATSAMA5D27CSAMA5D27 SOM1 Kit1
sam_a5d27_wlsom1_ek1.XMPLABXATSAMA5D27CATSAMA5D27 WLSOM1 EK1
sam_a5d27_wlsom1_ek1_freertos.XMPLABXATSAMA5D27CATSAMA5D27 WLSOM1 EK1
sam_a7g5_ek.XMPLABXSAMA7G54SAMA7G5 EK Board
sam_d21_xpro.XMPLABXATSAMD21J18ASAMD21 Xplained Pro Board
sam_e54_xpro.XMPLABXATSAME54P20ASAME54 Xplained Pro Board
sam_e70_xult.XMPLABXATSAME70Q21BSAME70 Xplained Ultra Board
sam_e70_xult_freertos.XMPLABXATSAME70Q21BSAME70 Xplained Ultra Board
sam_g55_xpro.XMPLABXATSAMG55J19SAMG55 Xplained Pro Board
sam_g55_xpro_freertos.XMPLABXATSAMG55J19SAMG55 Xplained Pro Board
sam_l21_xpro.XMPLABXATSAML21J18BSAML21 Xplained Pro Board
sam_v71_xult_freertos.XMPLABXATSAMV71Q21BSAMV71 Xplained Ultra board
pic32cz_ca80_curiosity_ultra.XMPLABXPIC32CZ8110CA80208PIC32CZ Curiosity Development Board
pic32cz_ca80_curiosity_ultra_freertos.XMPLABXPIC32CZ8110CA80208PIC32CZ Curiosity Development Board
pic32ck_gc01_curiosity_ultra.XMPLABXPIC32CK2051GC01144PIC32CK GC Curiosity Ultra Development Board
pic32ck_gc01_curiosity_ultra_freertos.XMPLABXPIC32CK2051GC01144PIC32CK GC Curiosity Ultra Development Board
pic32cm_le00_curiosity_pro.XMPLABXPIC32CM5164LE00100PIC32CM Lx Curiosity Pro Board
pic32cx_sg41_curiosity_ultra.XMPLABXPIC32CX1025SG41128PIC32CX SG41 Curiosity Ultra Evaluation Board
sam_a5d29_curiosity.XMPLABXATSAMA5D29SAMA5D29 Curiosity Development Board
sam_9x75_curiosity.XMPLABXSAM9X75D2GSAM9X75-Curiosity Development Board
sam_a7d65_curiosity.XMPLABXSAMA7D65 SAMA7D65 Curiosity Development Board
wbz653_curiosity.XMPLABXWBZ653WBZ653 Curiosity Board

Configuring the Hardware

PIC32CZ CA80 Curiosity Development Board
  • Connect the USB device to the micro-B connector (J102) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED1 indicates the file write is complete.
PIC32CX SG41 Curiosity Ultra Evaluation Board
  • Connect the USB device to the micro-B connector (J200) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED1 indicates the file write is complete.
PIC32CK GC Curiosity Ultra Development Board
  • An external power supply (6.5V to 14V) must be connected through the J200 connector.
  • Connect the USB device to the Type-C connector (J202).
  • LED1 indicates the file write is complete
Curiosity Pro PIC32CM LE00 Development Board
  • Powered the board by connecting an host to "DEBUG USB" (J300) connector.
  • Connect the USB device to the USB Host "TARGET USB" (J200) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED1 indicates the file write is complete.
Curiosity PIC32MZ EF 2.0 Development Board
  • Connect the USB device to the "TARGET USB" connector (J201) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED1 indicates the file write is complete.
Curiosity PIC32MX470 Development Board
  • Install a jumper in the J13 header to drive the VBUS line in Host mode.
  • Connect the USB device to the USB micro-AB connector J12 using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED1 indicates the file write is complete.
PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit
  • Connect the USB device to the Type-A connector J5, which is located on the top side of the starter kit.
  • LED1 indicates the file write is complete.
PIC32MK General Purpose (GP) Development Board
  • Connect the USB device to the Type-A connector J5, which is located on the top side of the starter kit.
  • LED1 indicates the file write is complete.
PIC32MZ Embedded Graphics with Stacked DRAM (DA) Starter Kit
  • Connect the USB device to the Type-A connector J7, which is located on the top side of the starter kit.
  • LED1 indicates the file write is complete.
SAM D21 Xplained Pro Board
  • The jumper titled "PA03 SELECT" must be shorted between PA03 and USB_ID (positions 2 and 3).
  • Connect the USB device to the "TARGET USB" connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED0 indicates the file write is complete.

    Note: Note: An unexpected behavior may be observed if the attached USB device draws an excess amount of current from the board and the Vdd voltage drops below 2.7 volts. The demo has the wait states (NVM_CTRLB <RWS[3:0]>) value set to '1'.

SAM E54 Xplained Pro Board
  • Connect the USB device to the "TARGET USB" connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED0 indicates the file write is complete.
SAM E70 Xplained Ultra Board
  • Jumper J203 must be shorted between PB08 and LED2 (positions 1 and 2).
  • Connect the USB device to the "TARGET USB" connector (J200) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED3 indicates the file write is complete.
SAMG55 Xplained Pro Board
  • Chip Erase Jumper must be open.
  • Connect the USB device to the "TARGET USB" connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED0 indicates the file write is complete.
SAML21 Xplained Pro Board
  • Connect the USB device to the "TARGET USB" connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED0 indicates the file write is complete.
SAMV71 Xplained Ultra Board
  • Jumper titled "USB VBUS" must be shorted between PC09 and LED1 (positions 1 and 2)
  • Connect the USB device to the "TARGET USB" connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • LED0 indicates the file write is complete.
Curiosity PIC32MZ W1 Development Board
  • Jumper J205 must be shorted.
  • Connect the USB device to the "TARGET USB" connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
  • The LED D204 indicates the file write is complete.
  • J205 must be shorted for the Device Functionality
  • Jumper on the pin J211 must be placed between pin 1 and pin 2

SAM9X60-EK Evaluation Board
  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)

    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SDMMC connector J4 on the board.
    • Reset the board by pressing the Push Button SW3.
  • Jumpers J20, J21, and J13 must be open.

  • Jumper J2 and J3 must be shorted.

  • Connect the USB Micro-B port J22 on board to the computer using a micro USB cable (to enable debug com port).

  • Connect the USB Micro-B Connector (J7) on the board to the computer using a micro USB cable to power up the board.

  • Connect the USB device to the Type-A connector (J8).

  • LED D1 indicates the file write is complete.

SAM9X60-Curiosity Board
  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)

    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SDMMC0 connector J3 on the board.
    • Reset the board by pressing the Push Button RESET.
  • Jumper J4 must be shorted.

  • Connect the USB Micro-B Connector (J1) on the board to the computer using a micro USB cable.

  • Connect the USB device to the Type-A connector (J10).

  • LED D1 on the board indicates the file write is complete.

SAM9X75-DDR3-EB Evaluation Board
  • Powered the board with an external power supply (or use the micro AB connector).

  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)

    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SDMMC connector (SDMMC0) on the board.
    • Reset the board by pressing the Push Button RESET, then START.
  • Connect an USB to serial cable to DBGU0 (to enable debug com port).

  • Connect the USB device to the Type-A connector or to the micro AB with a specific dongle (in these case the need to be powered by the external power supply).

  • LED near VDDCORE inscription on the board indicates the file write is complete.

SAMA5D2 Xplained Ultra Board
  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)
    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SDMMC1 slot on the board.
    • Reset the board by pressing the Push Button BP3.
  • Connect the EDBG USB Micro-B port J14 on the board to the computer using a micro USB cable.
  • Connect the USB device to the USB Type-A connector "A5-USB-B" (J13).
  • RGB LED turning to Green indicates the file write is complete.
SAMA5D27 SOM1 Kit1
  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)
    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SDMMC0 slot (J12) on the board.
    • Reset the board by pressing the Push Button PB1.
  • Connect the Debug USB port (J10) on the board to the computer using a micro USB cable.
  • Connect the USB device to the USB-B Type-C connector (J19) on the board.
  • RGB LED turning to Green indicates the file write is complete.

ATSAMA5D27-WLSOM1 Evaluation Kit
  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)
    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SD Card Connector (J4) on the board.
    • Reset the board by pressing the Reset Button (nRST)
  • Connect the USB-A MicroAB connector (J10) on the board to the computer using a micro USB cable.
  • Press the "START_SOM" button to activate board start-up.
  • Connect the USB device to the USB Type-A connector (J11) on the board.
  • RGB LED turning to Green indicates the file write is complete.

SAMA7G5-EK Evaluation Kit
  • Powered the board with an external power supply (J1).
  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)
    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SD Card Connector (J4) on the board.
    • Reset the board by pressing the Reset Button (nRST)
  • Press the "nSTART" button to activate board start-up.
  • Connect the USB device to the USB Host Type-A connector (J9) on the board. Alternatively, the USB Device could be connected to the Type-C connector (J8) or micro A/B connector (J7).
  • RGB LED turning to Green indicates the file write is complete.
SAMA5D29 Curiosity Development Board
  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)
    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the μSD-CARD connector J6 on the board.(This connector is present on the bottom face of the board)
    • Reset the board by pressing the Push Button RESET.
  • Press the "START" button to activate board start-up.
  • Connect the USB device to the USB_B Type-A connector (J11) on the board.
  • RGB LED (D5) turning to Green indicates the file write is complete.

SAM9X75-Curiosity Development Board

  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)
    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the μSD-CARD connector (J14) on the board.(This connector is present on the bottom face of the board)
    • Reset the board by pressing the Push Button RESET.
  • Press the "START" button to activate board start-up.
  • Connect the USB device to the USB_B Type-A connector (J15) or USB_C Type-A connector (J16) on the board.
  • RGB LED (LD1) turning to Green indicates the file write is complete.

SAMA7D65 Curiosity Development Board

  • Setup the SD card (Note: exFAT formatted SD Cards are not supported)
    • Download harmony MPU bootstrap loader from this location.
    • Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
    • Insert the SD card into the SD-CARD connector (J10) on the board.
    • Reset the board by pressing the Push Button RESET.
  • Press the "START" button to activate board start-up.
  • Connect the USB device to the USB_B Type-A connector (J23) or USB_C Type-A connector (J24) on the board.
  • RGB LED turning to Green indicates the file write is complete.

WBZ653 Curiosity Board
  • Connect a Type-C cable between the DBG USB (J100) port on the board and the PC to power up the board.
  • The Jumper J102 must be shorted between 5V and VBUS.
  • The Jumper J104 must be connected between VBUSON and EN (Positions 2 and 3).
  • Connect the USB device to the USB Type-C connector TARGET USB (J103). A USB Type-C to Type-A Female adapter is required to connect the USB device to the board (This adapter is not included in the kit).
  • The RGB_LED (D800) turning Green indicates the file write is complete.

Running the Application

This application demonstrates the use of the MSD Host Class Driver to write a file to USB Flash drive. The application uses the USB Host_layer, MSD class driver and the MPLAB Harmony File System Framework to enumerate a USB Flash drive and to write a file to it.

  1. Open the project with appropriate IDE. Compile the project and program the target device.
  2. With the code running, attach a USB Flash drive to the Host connector on the desired starter kit.
  3. The demonstration application will then create a file named file.txt. It will then write the text "Hello World" to this file, and then close the file.
  4. The LED on the selected hardware will indicate the status of the operation. Refer to the Configuring the Hardware instruction for details.
  5. The USB Flash drive can then be attached to a USB Host personal computer to verify the demonstration application operation.
  6. Steps 3 through 6 can be repeated.
  7. If the USB Flash drive already contains a file with the name file.txt, the demonstration application will append the text "Hello World" to the end of the file contents.