eMMC/SD Card Example

Source: example/rt_device/emmc

Overview

This example demonstrates how to create partitions on eMMC or SD card, mount the elm (FAT) filesystem on the partitions, and perform file operations.

Supported Platforms

  • sf32lb56-lcd_a128r12n1

  • sf32lb56-lcd_n16r12n1

  • sf32lb58-lcd_n16r64n4

  • sf32lb58-lcd_a128r32n1_dsi

Usage Guide

The eMMC application creates partitions on the board’s TF card, mounts the filesystem (FAT format), and provides common file commands via the UART console.

df               - Show filesystem disk usage
mountfs          - Mount device to filesystem
mkfs             - Format disk with filesystem
mkdir            - Create a directory
pwd              - Print current working directory
cd               - Change working directory
rm               - Remove (unlink) files/directories
cat              - Concatenate files (create and write content)
mv               - Rename SOURCE to DEST
cp               - Copy SOURCE to DEST
ls               - List files and directories

Expected Results

  1. Mount success log (look for the highlighted areas in the image below)
    alt text

  2. File operations: use ls to list existing files/directories, mkdir <dir> to create a directory, cd into it, echo to create a text file and write content, cat to view file content, and pwd to check the current working directory. alt text

Read/Write Speed Test

This example provides 4 commands for testing eMMC/SD card read/write speed. Output unit is Mb/s.

Basic Commands (fixed 512-byte blocks)

Command

Usage Example

Description

fs_write

fs_write /1.txt 4096

Write 4096 blocks of 512B (2MB) to a file, testing filesystem write speed

fs_read

fs_read /1.txt 4096

Read 4096 blocks of 512B (2MB) from a file, testing filesystem read speed

Parameter num is the number of 512B blocks. Total data size = num x 512B. For example, fs_write /1.txt 2048 writes 1MB, fs_write /1.txt 4096 writes 2MB.

Unexpected Results (logs)

alt text

Failure Causes and Solutions

  1. If the log shows the following, first check whether a TF card is inserted, then verify that SD is enabled in menuconfig (refer to the menuconfig configuration section above):

rt_mmcsd_blk_device_create find [sd0] fail !!!
  1. If the log shows the following, check whether a TF card is inserted:

[E/DFS] Device (root) was not found
[E/DFS] Device (misc) was not found

If the expected output does not appear, troubleshoot from the following aspects:

  • Check whether hardware connections are correct

  • Check whether the USB connector is loose

  • Check whether the USB cable supports data transfer

  • Check whether the TF card is functional