HOME
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
Shop
  • English
  • 简体中文
HOME
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
Shop
  • English
  • 简体中文
  • GM-3568JHF

    • 1. Introduction

      • GM-3568JHF Introduction
    • 2. Quick Start

      • 01 Environment Construction
      • 02 Compilation Instructions
      • 03 Burning Guide
      • 04 Debugging Tools
      • 05 Software Update
      • 06 View information
      • 07 Test Command
      • 08 Application Compilation
      • 09 Source code acquisition
    • 3. Peripherals and Interfaces

      • USB
      • Display and touch
      • Ethernet
      • WIFI
      • Bluetooth
      • TF-Card
      • Audio
      • Serial Port
      • CAN
      • RTC
    • 4. Application Development

      • 01 UART read and write case
      • 02 Key detection case
      • 03 LED light flashing case
      • 04 MIPI screen detection case
      • 05 Read USB device information example
      • 06 FAN Detection Case
      • 07 FPGA FSPI Communication Case
      • 08 FPGA DMA read and write case
      • 09 GPS debugging case
      • 10 Ethernet Test Cases
      • 11 RS485 reading and writing examples
      • 12 FPGA IIC read and write examples
      • 13 PN532 NFC card reader case
      • 14 TF card reading and writing case
    • 5. QT Development

      • 01 ARM64 cross compiler environment construction
      • 02 QT program added automatic startup service
    • 6. Others

      • 01 Modification of the root directory file system
      • 02 System auto-start service

14 TF card reading and writing case

1 Case Introduction

This case mainly demonstrates how to mount a TF card to the Linux file system, and perform read and write operations and file management on the TF card.

2 Mount TF card

root@linaro-alip:/# fdisk -l
···
Disk /dev/mmcblk1: 29.72 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 23000000-0000-4C4A-8000-699000005ABB

Check the partition information of the TF card. mmcblk1p1 is a partition of the TF card device and can be mounted to the Linux system.

root@linaro-alip:/# lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
mmcblk1      179:0    0  7.4G  0 disk 
└─mmcblk1p1  179:1    0  7.4G  0 part

Create a mount point and mount the device:

sudo mkdir /mnt/tfcard                   
sudo mount /dev/mmcblk1p1 /mnt/tfcard

Check the mount result, it has been successfully mounted

root@linaro-alip:/# df -h
………
/dev/mmcblk1p1  7.5G   16K  7.5G   1% /mnt/tfcard

3 Case operation process

After successfully mounting the TF card, you can read, write and manage files on the TF card according to the following operation process.

Open the terminal and copy the executable program smdt_TF in the bin directory of this case (05-Development Materials\Software Development Materials\linux_demo\smdt_TF_demo\bin) to the development board file system (the source code can be viewed in the src path).

#Modify the display level of Linux kernel logs. The kernel log level is set to show only emergency or higher-priority messages.
echo 1 4 1 7 > /proc/sys/kernel/printk

Execute the following command in the terminal to switch to the directory where the smdt_TF executable program is located

#切换到 smdt_TF 可执行程序所在目录
cd ‘the file's directory’

#查看 smdt_TF 是否在该目录下
ls

If the executable file smdt_TF is in the current directory, modify the permissions of the executable file

#修改文件权限
chmod 777 smdt_TF

#查询是否修改成功
ls -ld smdt_TF

After confirming that the file modification permission is successful, execute ./smdt_TF -h to view the help information of the program.

root@linaro-alip:/# ./TF -h
Usage:
  -w "<text>" <file>  Write <text> to <file>
  -r <file>         Read and print the content of <file>
  -d <file>         Delete the specified <file>
  -ls              List all files and directories in the TF card
  -h                Show this help message

Write to TF card

root@linaro-alip:/# ./TF -w "HELLO SMDT" test.txt
Data written to /mnt/tfcard/test.txt

Check the files in the TF card and you can see that test.txt has been created.

root@linaro-alip:/# ./TF  -ls
Files and directories in /mnt/tfcard:
System Volume Information
test.txt

Read and write files, consistent with the information written

root@linaro-alip:/# ./TF -r test.txt
Read from file: HELLO SMDT

Delete the file and check the mounted directory to see that the file has been deleted.

root@linaro-alip:/# ./TF -d test.txt
File /mnt/tfcard/test.txt deleted successfully.
root@linaro-alip:/# ./TF -ls
Files and directories in /mnt/tfcard:
System Volume Information

Finally, you can uninstall the device

umount /mnt/TF_Card
Edit this page on GitHub
Last Updated:
Contributors: zwhuang
Prev
13 PN532 NFC card reader case