1.3 FAT File System Using SD Card Media

This application shows an example of using the MPLAB Harmony File System to access and modify the contents of a SD card using the SDSPI driver and the SPI PLIB.

Description

File System Operations on the SD Card:

  • The application opens a file named FILE_TOO_LONG_NAME_EXAMPLE_123.JPG on the SD card
  • Reads the content of the file and creates a directory named Dir1
  • Inside the directory, writes the copied content into another file Dir1/FILE_TOO_LONG_NAME_EXAMPLE_123.JPG

The image file could be any arbitrary JPEG (image) file chosen by the user and then renamed to FILE_TOO_LONG_NAME_EXAMPLE_123.JPG. The reason for choosing a JPEG file for test purposes is that the duplicate file, Dir1/FILE_TOO_LONG_NAME_EXAMPLE_123.JPG created by the demonstration could be easily verified for correctness.

If the new file inside Dir1 opens for viewing on the computer and matches to original image, the test is deemed to have passed. Otherwise, if the file does not open (i.e., is corrupted), the test will be considered to have failed.

Note: Since the application creates a directory named Dir1, it is important that a folder with the same name does not exist on the SD card. If a directory named Dir1 is already present on the SD card, the application will fail.

File System Layer Uses:

SDSPI Driver to communicate to SD Card over SPI interface.

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.

Path of the application within the repository is apps/fs/sdspi_fat.

To build the application, refer to the following table and open the project using its IDE.

Project NameDescription
pic32wm_bw1_curiosity.XMPLAB X project for PIC32WM-BW1 Curiosity board

Setting Up the Hardware

The following table shows the target hardware for the application projects.

Project NameDescription
pic32wm_bw1_curiosity.XPIC32WM-BW1 Curiosity board

Setting Up PIC32WM-BW1 Curiosity board

  • To run the demo, the following additional hardware are required:
  • Connect the click board onto the click board socket on the curiosity board
  • Copy a JPEG file in the SD Card with name FILE_TOO_LONG_NAME_EXAMPLE_123.JPG
  • Insert microSD card on the click board
  • Connect the USB port on the board to the computer using a USB Type-C cable

Running the Application

  1. Build and program the application using its IDE.
  2. Press the switch to start the application.
  3. The LED is turned ON if there was no error during creating the directory and copying the file into it.
  4. If LED is ON, insert the SD Card on to the host PC.
  5. SD Card should have the file Dir1/FILE_TOO_LONG_NAME_EXAMPLE_123.JPG and should match the original image.
Refer to the following table for the Switch and LED names:
BoardSwitch NameLED Name
PIC32WM-BW1 Curiosity boardSW2Green LED