PIC32MX470 Curiosity USB Mass Storage Host Demo to write a file to a USB Flash drive Introduction This application demonstrates the use of the USB 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. The PIC32MX470 Curiosity Development Board contains PIC32MX470F512H MCU with Full-Speed USB module that enables you to implement USB functionality through the micro-AB USB connector. Required Tools and Applications Microchip Tools and Applications You will need the following Microchip development tools to run USB MSD Host demo PIC32MX470 Curiosity Development Board (DM320103), available from Microchip Direct Download and install latest version of MPLAB® X Integrated Development Environment (IDE) Download and install the latest version of MPLAB® XC32 Compiler Optionally Download and install the latest version of MPLAB® Harmony Integrated Software Framework. Note: Using MPLAB® Harmony Integrated Software Framework you will be able to extend the functionality of this project by adding new modules, software frameworks and libraries to your project. Building the Application Download the msd_basic demo project to your local PC. To build this project, you must open (in MPLAB X, File->Open Project) the msd_basic.X project (from <path-of-project-in-your-pc>/msd_basic/firmware) in MPLAB X IDE, as shown below. Select configuration for PIC32MX470 Curiosity board from the drop-down list as shown below. The other configurations will not work under standalone mode. However, if you want to work with this project for other configurations listed, you can migrate this project into a Harmony project, and then build for other configurations. Please follow the instructions provided in Migrating from standalone Harmony project to standard Harmony project The ‘pic32mx470_curiosity’ configuration sets up MPLAB X IDE to build and run the demonstration application on the PIC32MX470 Curiosity Development Board, with the PIC32MX470F512H microcontroller. The USB Stack will be configured for Interrupt mode operation and the USB Driver will be configured for Dynamic operation mode. Clean and Build the project Check the Build log, at the bottom of the MPLAB X IDE Note: Often times a project won't compile if you are on a Windows machine due to a limitation in the path length. Windows OS has a max path length of 260 characters, so file paths are sometimes truncated when attempting to compile which leads to files not being found by the compiler. Try putting the project in the topmost directory, usually "C: /". For more information please see MSDN article from Microsoft. Configuring the Hardware Power the PIC32MX470 Curiosity Development Board from a Host PC through a Type-A male to mini-B USB cable connected to Mini-B port (J3). The cable is not included with the kit. Ensure that a jumper is placed in J8 header (between 4 & 3) to select supply from debug USB connector. Place a jumper in the J13 header to use the Curiosity board in host mode. In host mode, the board acts like a computer. A USB peripheral (such as a mouse, keyboard, or pen drive) can be plugged into the curiosity board through micro-B port (J12). Plug in a USB peripheral with a micro-A USB connector, or use a micro USB OTG to USB adapter. Running the Demo 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 in MPLAB X IDE and select the PIC32MX470 Curiosity project configuration. 2. Build the code and program the device by clicking on the program button as shown below. 3. With the code running, Plug in a OTG pen drive that has micro-A USB connector to micro-B port (J12), or use a micro USB OTG to USB adapter (or micro USB OTG cable) for pen drive that connects with Type-A port. 4. The demonstration application enumerate the pen drive, it creates new text file (file.txt), writes the text (Hello World”) and closes the file. 5. 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. 6. LED2 illuminates once the file is written to the pen drive. LED1 illuminates in case of error. 7. Remove the pen drive. Verify the text file by connecting the pen drive to host PC.
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project