Using SD Card in Linux (uClinux)
This application note explains how to use SD Card in Linux on the Emcraft Systems STM32H7 SOM soldered onto the STM32H7-BSB Rev 4A baseboard. Support for the SD Card is enabled in the standard rootfs
project available from the Emcraft software distribution and installed on each module shipped by Emcraft.
Insert a pre-formatted card with an MS-DOS file system to the SD Card slot on the development baseboard. When you boot the uImage on the STM32H7, there should be messages similar to the ones shown below. In the below example, Linux has detected an SD Card with a single partition on it:
[ 3.010346] mmci-pl18x 52007000.mmc: Got CD GPIO
[ 3.017170] mmci-pl18x 52007000.mmc: mmc0: PL180 manf 53 rev1 at
0x52007000 irq 42,0 (pio)
[ 3.070152] mmci-pl18x 48022400.mmc: mmc1: PL180 manf 53 rev1 at
0x48022400 irq 44,0 (pio)
[ 3.112321] mmc0: new high speed SDHC card at address aaaa
[ 3.131100] mmcblk0: mmc0:aaaa SC16G 14.8 GiB
[ 3.167430] mmcblk0: p1
At this point you are ready to mount the MS-DOS file system on the SD Card. This is done as follows:
/ # mount /dev/mmcblk0p1 /mnt
Check that the file system has indeed been mounted (refer to the last line in the below output):
/ # mount
rootfs on / type rootfs (rw)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,relatime,mode=777)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
/dev/mmcblk0p1 on /mnt type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,
iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
Now you can write something to the SD Card. In the below example, we store the current date and time to a log file, although in real-life applications you will probably want to do something more meaningful:
Verify the written content by reading the log file back:
Write throughput is measured to be the following:
Read throughput is as follows:
Ok, you have validated that we can write data to the SD Card. Now you remove the card from the embedded target. Unmount the file system and then extract the card from the SD Card slot:
At this point, you can take the card to your PC or notebook and process data stored in the MS-DOS filesystem. As a final step in this application note, validate hot insertion of SD Card on the target. Insert the card back into the SD Card slot on the baseboard with Linux up and running on the STM32H7. Messages similar to the ones shown below should appear on the Linux console:
Mount the MS-DOS file system and verify the content of the previously created log file: