SDIO - List the files in SD Card
Preparation
- Ameba x 1
- SD card or MicroSD card x 1
- SD sniffer x 1 (optional)
Example
This example list all the files under the root directory of the SD card.
Open the sample code in “File” -> “Examples” -> “AmebaSdFatFs” -> “list_root_files”
Compile and upload to Ameba, then press the reset button.
Execution result screenshot:
Code reference
First, we initialize the SdFatFs:
fs.begin();Next, use readDir() to read the file list under root directory and store the data to buffer. The first argument is the absolute path of the directory to read (that is the root directory in this example), the second argument is the buffer, and the third is the size of the buffer.
fs.readDir(fs.getRootPath(), buf, sizeof(buf));The data format in the buffer is shown in below figure. Each file name is separated by ‘\0’.
Copyrights ©瑞晟微电子(苏州)有限公司 2021. All rights reserved. Terms of Use