TF Card (MicroSD)
1 TF Card Introduction
The SD card is a non-volatile memory card format introduced by Panasonic, Toshiba, and SanDisk in 1999. It is widely used in digital cameras, camcorders, game consoles, and a large number of embedded devices. The TF card (MicroSD card) is a product launched by SanDisk in 2004. While delivering the same functionality, its form factor is drastically reduced, making it the most mainstream mobile device storage card today. Our M4-R1 development board is equipped with one TF card slot for convenient data storage. This slot is connected directly via PCB traces to the RK3568 chip's SDMMC pins (including CMD, CLK, DATA0–DATA3, plus power and ground).
Tips
The SDMMC interface is the standard interface for SD cards and MMC cards. The SD card is one kind of SDMMC interface device, and the MMC card is another.

At the software level, the Linux kernel already includes a complete SDMMC controller driver and SD card protocol stack. Rockchip also provides solid mainline kernel support for its chips.
2 TF Card Board Interface

3 TF Card Usage — Command-Line Method
3.1 Device Tree Analysis
Tips
The file path below: out/kernel/src_tmp/linux-5.10/arch/arm64/boot/dts/rockchip/ requires the kernel source to be compiled first.
Base controller definition (rk3568.dtsi):
sdmmc0: dwmmc@fe2b0000 {
compatible = "rockchip,rk3568-dw-mshc", "rockchip,rk3288-dw-mshc";
reg = <0x0 0xfe2b0000 0x0 0x4000>;
interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
max-frequency = <150000000>;
clocks = <&cru HCLK_SDMMC0>, <&cru CLK_SDMMC0>,
<&cru SCLK_SDMMC0_DRV>, <&cru SCLK_SDMMC0_SAMPLE>;
clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
fifo-depth = <0x100>;
resets = <&cru SRST_SDMMC0>;
reset-names = "reset";
status = "disabled";
};The RK3568 chip defines 4 SDMMC controllers. Here we take the sdmmc0 controller used by the TF card as an example. The other controllers differ only in maximum frequency and register address:
compatible: compatibility string, specifies the driverreg: register address range (0xfe2b0000-0xfe2b3fff)interrupts: interrupt number 98, triggered on high levelmax-frequency: maximum operating frequency 150 MHzclocks: four clock sources (bus clock, interface clock, drive clock, sample clock)fifo-depth: FIFO depth 256 bytesresets: reset controlstatus: disabled by default
Pin multiplexing configuration (pin layer - rk3568-pinctrl.dtsi):
sdmmc0 {
sdmmc0_bus4: sdmmc0-bus4 {
rockchip,pins =
/* sdmmc0_d0 */
<1 RK_PD5 1 &pcfg_pull_up_drv_level_2>,
/* sdmmc0_d1 */
<1 RK_PD6 1 &pcfg_pull_up_drv_level_2>,
/* sdmmc0_d2 */
<1 RK_PD7 1 &pcfg_pull_up_drv_level_2>,
/* sdmmc0_d3 */
<2 RK_PA0 1 &pcfg_pull_up_drv_level_2>;
};
sdmmc0_clk: sdmmc0-clk {
rockchip,pins =
/* sdmmc0_clk */
<2 RK_PA2 1 &pcfg_pull_up_drv_level_2>;
};
sdmmc0_cmd: sdmmc0-cmd {
rockchip,pins =
/* sdmmc0_cmd */
<2 RK_PA1 1 &pcfg_pull_up_drv_level_2>;
};
sdmmc0_det: sdmmc0-det {
rockchip,pins =
/* sdmmc0_det */
<0 RK_PA4 1 &pcfg_pull_up>;
};
sdmmc0_pwren: sdmmc0-pwren {
rockchip,pins =
/* sdmmc0_pwren */
<0 RK_PA5 1 &pcfg_pull_none>;
};
};SDMMC0 pin groups:
sdmmc0_bus4: 4-bit data line (D0-D3)sdmmc0_d0: RK_PD5 (GPIO1_D5)sdmmc0_d1: RK_PD6 (GPIO1_D6)sdmmc0_d2: RK_PD7 (GPIO1_D7)sdmmc0_d3: RK_PA0 (GPIO2_A0)sdmmc0_clk: clock line RK_PA2 (GPIO2_A2)sdmmc0_cmd: command line RK_PA1 (GPIO2_A1)sdmmc0_det: card detect RK_PA4 (GPIO0_A4)sdmmc0_pwren: power enable RK_PA5 (GPIO0_A5)
Board-level configuration (rk3568-toybrick.dtsi):
&sdmmc0 {
max-frequency = <150000000>;
supports-sd;
bus-width = <4>;
cap-mmc-highspeed;
cap-sd-highspeed;
disable-wp;
sd-uhs-sdr104;
vmmc-supply = <&vcc3v3_sd>;
vqmmc-supply = <&vccio_sd>;
pinctrl-names = "default";
pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd &sdmmc0_det>;
status = "okay";
};supports-sd: supports SD cardbus-width = <4>: 4-bit data buscap-sd-highspeed: supports high-speed modesd-uhs-sdr104: supports UHS-I SDR104 modevmmc-supply: main power supplyvqmmc-supply: I/O voltage supplypinctrl-0: specifies the pin groups used
3.2 Application-Layer Method for Using a TF Card
When an SD card (TF card) is inserted, the system detects the insertion event (via pin polling) and sends a signal to identify the card. After successful identification, a block device is created in the system. In past development, after the kernel recognized the SD card, we had to manually use the mount command to mount the SD card to a specified path for subsequent reading, and use the umount command to unmount it after reading. Nowadays, most operating systems already support automatic mounting of TF cards and USB flash drive devices.
For application development, we do not need to care about how the hardware and kernel configure the SD card; we only need to call the file operation APIs under Linux to access the contents of the SD card.
In actual use, for this development board, you only need to insert the TF card into the TF card socket (hot-pluggable), then use the df -h command to view the total capacity, used space, free space, and mount points of all mounted disks, partitions, and storage devices on the system. By entering the corresponding mount point, we can read and operate on the contents of the TF card.
3.3 Functional Demonstration
The TF card used for testing is shown below:

Enter df -h to view the mount directory:
df -h
Enter the corresponding mount point to view the contents of the TF card.

