STM32 + FatFs + SD card via SPI【二】FatFS指令操作

前言

接續著上一篇再來是介紹CLI菜單所提供的功能

CLI菜單內容

	"[Disk contorls]\n"
	" di <pd#> - Initialize disk\n"
	" dd [<pd#> <lba>] - Dump a secrtor\n"
	" ds <pd#> - Show disk status\n"
	"[Buffer controls]\n"
	" bd <ofs> - Dump working buffer\n"
	" be <ofs> [<data>] ... - Edit working buffer\n"
	" br <pd#> <lba> [<count>] - Read disk into working buffer\n"
	" bw <pd#> <lba> [<count>] - Write working buffer into disk\n"
	" bf <val> - Fill working buffer\n"
	"[File system controls]\n"
	" fi <ld#> [<mount>]- Force initialized the volume\n"
	" fs [<path>] - Show volume status\n"
	" fl [<path>] - Show a directory\n"
	" fo <mode> <file> - Open a file\n"
	" fc - Close the file\n"
	" fe <ofs> - Move fp in normal seek\n"
	" fd <len> - Read and dump the file\n"
	" fr <len> - Read the file\n"
	" fw <len> <val> - Write to the file\n"
	" fn <org.name> <new.name> - Rename an object\n"
	" fu <name> - Unlink an object\n"
	" fv - Truncate the file at current fp\n"
	" fk <name> - Create a directory\n"
	" fa <atrr> <mask> <object name> - Change attribute of an object\n"
	" ft <year> <month> <day> <hour> <min> <sec> <name> - Change timestamp of an object\n"
	" fx <src.file> <dst.file> - Copy a file\n"
	" fg <path> - Change current directory\n"
	" fq - Show current directory\n"
	" fb <name> - Set volume label\n"
	" fm <ld#> <type> <csize> - Create file system\n"
	" fz [<len>] - Change/Show R/W length for fr/fw/fx command\n"
	"[Misc commands]\n"
	" md[b|h|w] <addr> [<count>] - Dump memory\n"
	" mf <addr> <value> <count> - Fill memory\n"
	" me[b|h|w] <addr> [<value> ...] - Edit memory\n"
	" t [<year> <mon> <mday> <hour> <min> <sec>] - Set/Show RTC\n"

[Disk contorls] 磁碟操控

di <pd#> - Initialize disk

>di 0	//initialize device 0
rc=0	//response success

在做其它操作前的必要執行指令

指令di 使用disk_initialize()對SD card做初始化( 74 clocks + CMD0 +...一連串的設定)

返回值 0 為成功;除此之外的狀態如下


dd [<pd#> <lba>] - Dump a secrtor

>dd 0 0	//Dump device 0 sector 0

指令dd 使用disk_read()讀取出指定sector的內容


ds <pd#> - Show disk status

>ds 0	//show disk 0 status

指令ds 使用disk_ioctl()讀取磁碟狀態

輸出磁碟的狀態 Driver size,Block size,CSD,CID,OCR ...



[Buffer controls]

di <pd#> - Initialize disk

>di 0	//initialize device 0
rc=0	//response success


[File system controls] 檔案系統操作

fi <ld#> [<mount>]- Force initialized the volume

>fi 0	//initialize device 0
rc=0 FR_OK    //response success

在做檔案操作前的必要執行指令

指令fi 使用f_mount()掛載磁碟,返回值對應結果如下


fs [<path>] - Show volume status

>fs 0	//show device 0 volume status

顯示此磁碟使用的File System內容

指令fs 使用f_getfree()取得volume的size及未使用空間的大小,返回值對應結果如下


fl [<path>] - Show a directory

顯示指定的資料夾檔案列表,使用的空間及剩餘的空間

>fl folderName	//show "folder" content

指令fl 使用f_opendir()打定指定的資料夾,f_readdir()取得資料夾的內容,返回值對應結果如下


不加參數時則顯示最上層的檔案及資料夾


fo <mode> <file> - Open a file

開啟檔案

<mode>:開啟的模式(參考下圖)

<file>:預開啟的檔案名

>fo 1 filename	//open file by READ mode
rc=0 FR_OK	//success

指令fl 使用f_open()開啟檔案


fc - Close the file

關閉檔案

>fo    //Close file
rc=0 FR_OK	//success

指令fc 使用f_close()關閉檔案


fe <ofs> - Move fp in normal seek

移動 read/write時的指標 延展大小

<ofs> 延展/縮減的尺寸

>fe size_value   //Close file

指令fe 使用f_lseek()移動檔案指標


fd <len> - Read and dump the file

顯示檔案內容

<len> 顯示的長度

>fd lenght   //print file content

fr <len> - Read the file

計算檔案讀取時的速度

<len> 讀取長度

>fr length   //Read file

fw <len> <val> - Write to the file

寫入檔案

<len> 寫入長度

<val> 寫入內容(ASCII十進制)

>fw length data//Write to the file

指令fw 使用f_write()來寫入檔案

注意:官方此函式有問題,只能寫入1個字元


fn <org.name> <new.name> - Rename an object

改名

<org.name> 預改名稱的檔案

<new.name> 更改後的名稱

>fn oldFile newName//rename file

指令fw 使用f_rename()來為檔案更名


fu <name> - Unlink an object

刪除檔案

<name> 被刪除的檔案

>fn filename//delete file

指令fw 使用f_unlink()來刪除檔案


fv - Truncate the file at current fp

截斷檔案大小

>fv //rename file

指令fv 使用f_truncate()


fk <name> - Create a directory

建立資料夾

<name> 資料夾名稱

>fk foldername //create folder

指令fv 使用f_mkdir()來產生新的folder


fa <atrr> <mask> <name> - Change attribute of an object

改變物件的屬性

>fa //change object attribute

指令fa 使用f_chmod()


ft <year> <month> <day> <hour> <min> <sec> <name> - Change timestamp of an object

修改檔案的時間標記

>fa //change object timestamp

指令ft 使用f_utime()


fx <src.name> <dst.name> - Copy a file

複製檔案

<src.name> 檔案來源

<dst.name> 新檔案名稱

>fx oldname newname //copy a file

fg <path> - Change current directory

切換路徑

>fg path //change path

指令ft 使用f_chdir()


fq - Show current dir path

顯示目前路徑

>fq //show current path

指令ft 使用f_getcwd()


fb <name> - Set volume label

設定Volume標籤

<name> 標籤名稱

>fb name //set volume label

指令ft 使用f_setlabel()


fm <ld#> <type> <csize> - Create file system

建立File System

<ld#> 標籤名稱

<type> 標籤名稱

<csize> 標籤名稱

>fm //show current path

指令ft 使用f_mkfs()


fz [<len>] - Change/Show R/W length for fr/fw/fx command

改變/顯示 讀/寫的長度

<len>  改變的長度

>fz length//change r/w length

t [<year> <mon> <mday> <hour> <min> <sec>] - Set/Show RTC

顯示/改變RTC時間


留言

2024

11-27SPI Flash 操作 (Read/Write/Erase)
11-19Rotary Encoder Switch 旋轉編碼開關
11-14Command Line Interface - CLI via UART
11-14【STM32】USB HID - Volume Control
11-13【STM32】USB Custom HID
11-12【STM32】USB HID Keyboard + Mouse
11-12【STM32】USB HID Keyboard
11-12【STM32】USB HID Mouse
10-15SSD1306 128x64 OLED 【五】Wokwi Animator
09-2432F429IDISCOVERY - - LTDC [3] + FMC (SDRAM) + FatFS
09-2432F429IDISCOVERY - - LTDC [2] + FMC (SDRAM)
09-20STM32 + FatFs + SD card via SPI【三】FatFS指令操作II
09-19STM32 + FatFs + SD card via SPI【二】FatFS指令操作
09-18STM32 + FatFs + SD card via SPI【一】移植FatFS
09-0232F429IDISCOVERY - - LTDC [1]
04-17SSD1306 128x64 OLED 【四】Adafruit / GFX Library
04-17Arduino - Serial Plotter繪圖儀
04-16SSD1306 128x64 OLED 【三】
04-15SSD1306 128x64 OLED 【二】 Datasheet
04-12SSD1306 128x64 OLED 【一】I2C版本
03-20【freeRTOS】vTaskDelay 與 vTaskDelayUntil 的差異
03-19【freeRTOS】API功能列表
03-18【freeRTOS】Day1
03-08MBR和Blank project的差別
03-05刪除註冊檔registry的資料
02-27DFU over Bluetooth Low Energy
02-27nRF Util - 使用手冊
02-26nRF Command Line Tools
02-20建立BootLoader settings
02-19Secure DFU packet (ZIP) build 建立含袐鑰的Zip檔
02-19Secure DFU via BLE
02-19Secure DFU via UART
02-16nRF Util 安裝
01-16nRF52840 ic升級成nRF52840 Dongle的程式

2023

11-21[ SEGGER Embedded Studio ] 新增header files
11-21[ SEGGER Embedded Studio ] 編譯nRF52840時遇到的問題
11-07Arduino Nano ESP32 - Debugging除錯模式
11-03Git快速入手 - 使用Git GUI
10-30Git快速入手 - 使用Git Bash
10-12程式碼高亮顯示 -- google-code-prettify

2022

11-30[EZ-PD] CCG6DF CCG6SF的Host SDK遇到編譯錯誤(一)

2019

05-27[ Eagle PCB ] 合板成品
05-23#CASE_001_USB_TOOL_RL78_G12
05-22[ Eagle PCB ] 初次洗板
05-21[ Eagle PCB ] Panelize 併板
05-20[ Eagle PCB ] 建立自己的Library及元件
05-20[ Eagle PCB ] 添加library及元件
05-20[ Eagle PCB ] Introduce

2018

04-25[ TCP test Tool ] 好用的TCP Server/Client工具
01-16RZ/A1H -[0]- Renesas RZ/A1H YR0K77210S009BE BSP環境架設

2017

12-11EZ USB Suit使用JLink online debug FX3
10-20RL78 -[12]- CS+_CACX_Lab5_LowPower mode
10-16RL78 -[11]- CS+_CACX_Lab4_ADC_溫度感測
10-13RL78 -[10]- CS+_CACX_Lab4_ADC_內部參考電壓
10-13RL78 -[9]- CS+_Lab3_I2C + MPU6050
10-13RL78 -[8]- CS+_Lab2_Uart transmit
10-12RL78 -[7]- Renesas Flash Programmer 獨立燒錄軟體
10-12RL78 -[6]- CS+_雜記
10-12RL78 -[5]- CS+_tracking variables on debug mode
10-12RL78 -[4]- CS+_顯示ROM與RAM的使用size
10-12RL78 -[3]- CS+_Lab1_Led blinking
10-12RL78 -[2]- CS+專案建立
10-12RL78 -[1]- 開發環境介紹
10-06ESP-01 -[0]- 硬體設置
10-06LinkIt 7688 program Renesas RL78/G12 by 1-wire
10-06LinkIt Smart 7688 -[3]- Build the firmware from source codes
10-06LinkIt Smart 7688 -[2]- 使用UART進入bootloader / kernel console
10-06LinkIt Smart 7688 -[1]- 使用SSH連接kernel console
10-06LinkIt Smart 7688 -[0]- 初次使用
07-14LinkIt Smart 7688 -[9]- Using MRAA SPI in Python
07-13LinkIt Smart 7688 -[8]- Using MRAA UART in Python
07-12LinkIt Smart 7688 -[7]- Using MRAA I2C in Python
07-12LinkIt Smart 7688 -[6]- Using MRAA PWM in Python
07-12LinkIt Smart 7688 -[5]- Using MRAA GPIO in Python
07-10LinkIt Smart 7688 -[4]- 雜記
06-29輕乳酪蛋糕 Cotton Cheesecake
06-26VirtualBox 的 Ubuntu與Windows 共用資料夾

2015

04-29偵測USB PnP