11 TF Card
1 TF Card Introduction
SD card is a non-volatile memory card format launched 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 (Micro SD card) was a product launched by SanDisk in 2004. While achieving the same functionality, its volume was significantly reduced, making it the most mainstream mobile device storage card currently. Our M4-R1 development board is equipped with a TF card slot for convenient data storage.
This card slot is directly connected to the SDMMC pins of the RK3568 chip through PCB traces (including CMD, CLK, DATA0-DATA3 as well as power and ground).
Tips
The SDMMC interface is the standard interface for SD cards and MMC cards. SD card is one type of SDMMC interface, and MMC card is another type of SDMMC interface.

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

3 TF Card Usage - Command Line Method
3.1 Device Tree Parsing
Tips
The file path below: out/kernel/src_tmp/linux-5.10/arch/arm64/boot/dts/rockchip/ requires compiling the source code first.
Basic 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 use the sdmmc0 controller used by the TF card as an example for explanation. The only differences between other controllers are the maximum frequency and register addresses:
compatible: Compatibility string, specifies the driverreg: Register address range (0xfe2b0000-0xfe2b3fff)interrupts: Interrupt number 98, high-level triggermax-frequency: Maximum working frequency 150MHzclocks: 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 group:
sdmmc0_bus4: 4-bit data lines (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 detection 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 cardsbus-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 group used
3.2 Method of Using TF Card at Application Layer
When an SD card (TF card) is inserted, the system detects the insertion event (through 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 identified the SD card, we needed to manually use the mount command to mount the SD card to a specified path for subsequent reading. After reading was completed, we needed to use the umount command to unmount. Now most operating systems already support automatic mounting of TF cards and USB drives.
For application development, we don't need to care about how the hardware and kernel configure the SD card. We can simply call Linux file operation APIs to access the contents of the SD card.
In actual use, for this development board, we only need to insert the TF card into the TF card slot (supports hot-swapping), and then use the df -h command to view all mounted disks on the system, including partition, total capacity of storage devices, used space, remaining space, and mount points. We can enter the corresponding mount point to read and operate the TF card contents.
3.3 Specific Function Demonstration
The TF card used for testing is as follows:

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

