1.4 FAT File System Using SDSPI Media
This application shows an example of using the MPLAB Harmony File System to access and modify the contents of an SD card using the SDSPI driver and the SPI PLIB.
Description
File System Operations on the SD Card
- Application opens a file
named
FILE_TOO_LONG_NAME_EXAMPLE_123.JPGin the root directory of the SD card and reads its content into memory:- 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 image file could
be any arbitrary JPEG (image) file chosen by the user and then
renamed to
- Application creates directory
named
Dir1in the root directory - Application creates a new
file named
FILE_TOO_LONG_NAME_EXAMPLE_123.JPGinsideDir1 - Application copies the content from step 1 into this newly created file
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.
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. This content can also be downloaded using content manager by following these instructions.
Path of the application within the repository is apps/fs/sdspi_fat/firmware.
To build the application, refer to the following table and open the project using its IDE.
| Project Name | Description |
|---|---|
| pic32mk_mcj_curiosity_pro.X | MPLAB X project for PIC32MK MCJ Curiosity Pro Development Board |
| pic32mk_mcm_curiosity_pro.X | MPLAB X project for PIC32MK MCM Curiosity Pro Development Board |
| pic32mk_mca_curiosity_pro.X | MPLAB X project for PIC32MK MCA Curiosity Pro Development Board |
Setting Up the Hardware
The following table shows the target hardware for the application projects.
| Project Name | Description |
|---|---|
| pic32mk_mcj_curiosity_pro.X | PIC32MK MCJ Curiosity Pro Development Board |
| pic32mk_mcm_curiosity_pro.X | PIC32MK MCM Curiosity Pro Development Board |
| pic32mk_mca_curiosity_pro.X | PIC32MK MCA Curiosity Pro Development Board |
Setting Up PIC32MK MCJ Curiosity Pro Development Board
- To run the demo, the
following additional hardware is required:
- One microSD card
- Create a new JPEG
file in the SD card with name
FILE_TOO_LONG_NAME_EXAMPLE_123.JPG
- Connect micro USB cable to the Debug USB connector (J1) on the board to the computer
- Connect IO1 Xplained Pro Extension Kit to the EXT1 (J501) header of PIC32MK MCJ Curiosity Pro Development Board
- Insert the microSD card in the microSD card slot of the IO1 Xplained Pro Extension Kit
Setting Up PIC32MK MCM Curiosity Pro Development Board
- To run the demo, the
following additional hardware is required:
- One microSD card
- Create a new JPEG
file in the SD card with name
FILE_TOO_LONG_NAME_EXAMPLE_123.JPG
- Connect a micro USB cable to the USB DEBUG port J500
- Install microSD Click board™ onto the mikroBUS™ socket J300 of PIC32MK MCM Curiosity Pro Development Board
- Insert the microSD card in the microSD card slot of the microSD Click board
Setting Up PIC32MK MCA Curiosity Pro Development Board
- To run the demo, the
following additional hardware is required:
- One microSD card
- Create a new JPEG
file in the SD card with name
FILE_TOO_LONG_NAME_EXAMPLE_123.JPG
- Connect micro USB cable to the Debug USB connector (J1) on the board to the computer
- Connect IO1 Xplained Pro Extension Kit to the J501 header of PIC32MK MCA Curiosity Pro Development Board
- Insert the microSD card in the microSD card slot of the IO1 Xplained Pro Extension Kit
Running the Application
- Build and program the application using its IDE.
- Press Switch to start the file operations.
- The LED is turned ON if there was
no error during creating the directory and copying the file into it.
Refer to the following table for Switch and LED names:
Board Switch Name LED Name PIC32MK MCJ Curiosity Pro Development Board SW200 LED2 PIC32MK MCM Curiosity Pro Development Board SW1 LED1 PIC32MK MCA Curiosity Pro Development Board SW200 LED1 - If LED is ON, insert the SD card into the host PC.
- SD card should have the file
Dir1/FILE_TOO_LONG_NAME_EXAMPLE_123.JPGand should match the original image.
