Littlefs_portenta_h7庫
目錄
- tortenta_h7的重要說明
- 為什麼我們需要這個Littlefs_portenta_h7庫
- ChangElog
- 先決條件
- 安裝
- 使用Arduino Library Manager
- 手動安裝
- VS代碼和平台
- 軟件包的補丁
- 1。對於Linux中的Arduino IDE,用於portenta_h7板
- 例子
- 1。 LITTLEFS_COUNTING
- 2。 littlefs_test
- 示例LittleFS_Test
- 調試終端輸出樣品
- 1。 Littlefs_countingon portenta_h7_m7
- 2。 portenta_h7_m7上的littlefs_test
- 偵錯
- 故障排除
- 問題
- 做
- 完畢
- 貢獻和感謝
- 貢獻
- 執照
- 版權
tortenta_h7的重要說明
新的portenta_h7板的LittleF當前僅進行了最多8個文件測試。從9歲及以上的文件,某種程度上奇怪地無法編寫和 /或閱讀。這可能是ArduinoCore-mbed mbed_portenta core中的錯誤。從核心v2.0.0到v2.6.1 ,觀察到相同的行為。
如果將LittleFS尺寸降低到1024KB ,則最多4個文件可以進行測試。
當心並繼續檢查更新。
為什麼我們需要這個Littlefs_portenta_h7庫
特徵
該庫只是一個簡單的LittleFS包裝器,可以使用Arduinocore-Mbed Mbed_portenta Core來促進您對MBED tortenta_h7上板載閃存的使用。
文件系統訪問使用普通POSIX API或MBED文件系統API
目前支持的董事會
- 使用arduinocore-mbed mbed_portenta core
先決條件
Arduino IDE 1.8.19+ for Arduino。-
ArduinoCore-mbed mbed_portenta core 3.4.1+用於Arduino portenta_h7板,例如portenta_h7 rev2 abx00042,等。
安裝
使用Arduino Library Manager
最好和最簡單的方法是使用Arduino Library Manager 。搜索Littlefs_portenta_h7 ,然後選擇 /安裝最新版本。您也可以使用此鏈接以獲取更詳細的說明。
手動安裝
安裝的另一種方法是:
- 導航到Littlefs_portenta_h7頁面。
- 下載最新版本的
LittleFS_Portenta_H7-main.zip 。 - 將zip文件提取到
LittleFS_Portenta_H7-main目錄 - 將整個
LittleFS_Portenta_H7-main文件夾複製到Arduino庫的目錄,例如~/Arduino/libraries/ 。
VS代碼和平台
- 安裝VS代碼
- 安裝平台
- 使用庫管理器安裝Littlefs_portenta_h7庫。在Platform.io作者的庫中搜索Littlefs_portenta_h7
- 使用示例中的Platform.ini文件包括Platform.ini文件,以確保將自動安裝所有依賴的庫。請訪問文檔以獲取項目配置文件中的其他選項和示例
軟件包的補丁
1。對於Linux中的Arduino IDE,用於portenta_h7板
要能夠在Linux(Ubuntu等)中使用Arduino IDE上傳固件到portenta_h7 ,您必須將文件portenta_post_install.sh複製到mbed_portenta目錄(〜/.arduino15/packages/packages/packages/arduino/arduino/ardware/ardware/ardware/mbed_portenta/3.4.4.1/portenta_4.1/portenta__porst_post_post)。
然後使用sudo運行以下命令
$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1
$ chmod 755 portenta_post_install.sh
$ sudo ./portenta_post_install.sh
這將創建file /etc/udev/rules.d/49-portenta_h7.rules如下:
# Portenta H7 bootloader mode UDEV rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"
假設Arduinocore-Mbed Core版本為3.4.1。現在,只能將一個文件複製到目錄中:
-
~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh
每當安裝新版本時,請記住將此文件複製到新版本目錄中。例如,新版本是x.yy.zz
該文件必須複製到目錄中:
-
~/.arduino15/packages/arduino/hardware/mbed_portenta/x.yy.zz/portenta_post_install.sh
例子
- Littlefs_counting
- Littlefs_test
示例LittleFS_Test
| #定義lfs_mbed_portenta_h7_version_min_target “ Littlefs_portenta_h7 v1.2.0 ” |
| #定義lfs_mbed_portenta_h7_version_min 1002000 |
| |
| #定義_lfs_loglevel_ 1 |
| |
| #定義force_reformat false |
| |
| #包括< littlefs_portenta_h7.h > |
| |
| Littlefs_mbed *myfs; |
| |
| uint32_t file_size_kb = 64 ; |
| |
| void readcharsfromfile ( const char *路徑) |
| { |
| 系列。打印( “ readcharsfromfile: ” );系列。打印(路徑); |
| |
| 文件 *file = fopen (路徑, “ r ” ); |
| |
| 如果(文件) |
| { |
| 系列。 println ( “ =>打開ok ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ =>打開失敗” ); |
| 返回; |
| } |
| |
| char c; |
| |
| 而( true ) |
| { |
| c = fgetc (file); |
| |
| if ( feof (file)) |
| { |
| 休息; |
| } |
| 別的 |
| 系列。打印(c); |
| } |
| |
| fclose (file); |
| } |
| |
| void readfile ( const char *路徑) |
| { |
| 系列。打印( “讀取文件: ” );系列。打印(路徑); |
| |
| 文件 *file = fopen (路徑, “ r ” ); |
| |
| 如果(文件) |
| { |
| 系列。 println ( “ =>打開ok ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ =>打開失敗” ); |
| 返回; |
| } |
| |
| char c; |
| uint32_t numread = 1 ; |
| |
| while (numread) |
| { |
| numRead = fread ((( uint8_t *)&c, sizeof (c), 1 ,file); |
| |
| 如果(numread) |
| 系列。打印(c); |
| } |
| |
| fclose (file); |
| } |
| |
| void writefile ( const char *路徑, const char *消息, size_t messagesize) |
| { |
| 系列。打印( “寫入文件: ” );系列。打印(路徑); |
| |
| 文件 *file = fopen (路徑, “ w ” ); |
| |
| 如果(文件) |
| { |
| 系列。 println ( “ =>打開ok ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ =>打開失敗” ); |
| 返回; |
| } |
| |
| if ( fwrite ((( uint8_t *)消息, 1 ,messagesize,file)) |
| { |
| 系列。 println ( “ *寫入OK ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ *寫作失敗” ); |
| } |
| |
| fclose (file); |
| } |
| |
| void appendfile ( const char *路徑, const char *消息, size_t messagesize) |
| { |
| 系列。打印( “附加文件: ” );系列。打印(路徑); |
| |
| 文件 *file = fopen (路徑, “ a ” ); |
| |
| 如果(文件) |
| { |
| 系列。 println ( “ =>打開ok ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ =>打開失敗” ); |
| 返回; |
| } |
| |
| if ( fwrite ((( uint8_t *)消息, 1 ,messagesize,file)) |
| { |
| 系列。 println ( “ *附加OK ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ *附加失敗” ); |
| } |
| |
| fclose (file); |
| } |
| |
| void deletefile ( const char *路徑) |
| { |
| 系列。打印( “刪除文件: ” );系列。打印(路徑); |
| |
| if (刪除(路徑)== 0 ) |
| { |
| 系列。 println ( “ => ok ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ =>失敗” ); |
| 返回; |
| } |
| } |
| |
| void renamefile ( const char * path1, const char * path2) |
| { |
| 系列。打印( “重命名文件: ” );系列。打印(Path1); |
| 系列。打印( “ to: ” );系列。打印(Path2); |
| |
| if ( rename (path1,path2)== 0 ) |
| { |
| 系列。 println ( “ => ok ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ =>失敗” ); |
| 返回; |
| } |
| } |
| |
| void testfileio ( const char *路徑) |
| { |
| 系列。打印( “測試文件I/O with: ” );系列。打印(路徑); |
| |
| #定義buff_size 512 |
| |
| static uint8_t buf [buff_size]; |
| |
| 文件 *file = fopen (路徑, “ w ” ); |
| |
| 如果(文件) |
| { |
| 系列。 println ( “ =>打開ok ” ); |
| } |
| 別的 |
| { |
| 系列。 println ( “ =>打開失敗” ); |
| 返回; |
| } |
| |
| size_t i; |
| 系列。 println ( “ - 寫作” ); |
| |
| uint32_t start = millis (); |
| |
| size_t結果= 0 ; |
| |
| //用file_size_kb編寫文件 |
| for (i = 0 ; i <file_size_kb * 2 ; i ++) |
| { |
| 結果= fwrite (buf,buff_size, 1 ,file); |
| |
| 如果(結果!= 1 ) |
| { |
| 系列。打印( “寫入結果= ” );系列。 println (結果); |
| 系列。打印( “寫入錯誤,i = ” );系列。 println (i); |
| |
| 休息; |
| } |
| } |
| |
| 系列。 println ( “ ” ); |
| uint32_t end = millis () - start; |
| |
| 系列。打印(I / 2 ); |
| 系列。 print ( “用(MS)寫的kbytes ” ); |
| 系列。 println (end); |
| |
| fclose (file); |
| |
| printline (); |
| |
| //////////////////////////////////////////////////////////////////////////////////////// |
| |
| file = fopen (路徑, “ r ” ); |
| |
| start = millis (); |
| end = start; |
| i = 0 ; |
| |
| 如果(文件) |
| { |
| start = millis (); |
| 系列。 println ( “ - 閱讀” ); |
| |
| 結果= 0 ; |
| |
| fseek (文件, 0 ,seek_set); |
| |
| //使用file_size_kb讀取文件 |
| for (i = 0 ; i <file_size_kb * 2 ; i ++) |
| { |
| 結果= fread (buf,buff_size, 1 ,file); |
| |
| 如果(結果!= 1 ) |
| { |
| 系列。打印( “讀取結果= ” );系列。 println (結果); |
| 系列。打印( “讀取錯誤,i = ” );系列。 println (i); |
| |
| 休息; |
| } |
| } |
| |
| 系列。 println ( “ ” ); |
| end = millis () - 開始; |
| |
| 系列。打印((i * buff_size) / 1024 ); |
| 系列。打印( “ kbytes讀(MS) ” ); |
| 系列。 println (end); |
| |
| fclose (file); |
| } |
| 別的 |
| { |
| 系列。 println ( “ - 無法打開讀取文件” ); |
| } |
| } |
| |
| void printline () |
| { |
| 系列。 println ( “ ================================================= |
| } |
| |
| void setup () |
| { |
| 系列。開始( 115200 ); |
| 而(!序列) |
| |
| 延遲( 1000 ); |
| |
| 系列。打印( “ n start littlefs_test on ” );系列。 println (board_name); |
| 系列。 println (lfs_mbed_portenta_h7_version); |
| |
| #如果定義(lfs_mbed_portenta_h7_version_min) |
| if (lfs_mbed_portenta_h7_version_int <lfs_mbed_portenta_h7_version_min) |
| { |
| 系列。打印( “警告。必須在版本相等或遲到的版本上使用此示例: ” ); |
| 系列。 println (lfs_mbed_portenta_h7_version_min_target); |
| } |
| #endif |
| |
| myfs = new Littlefs_mbed (); |
| |
| 如果(!myfs-> init ()) |
| { |
| 系列。 println ( “ Littlefs安裝失敗” ); |
| |
| 返回; |
| } |
| |
| char filename1 [] = mbed_littlefs_file_prefix “ /hello1.txt ” ; |
| char filename2 [] = mbed_littlefs_file_prefix “ /hello2.txt ” ; |
| |
| char消息[] = “ hello from ” board_name “ n ” ; |
| |
| printline (); |
| writefile (filename1,消息, sizeof (message)); |
| printline (); |
| ReadFile (filename1); |
| printline (); |
| |
| appendfile (filename1,消息, sizeof (message)); |
| printline (); |
| ReadFile (filename1); |
| printline (); |
| |
| Renamefile (filename1,filename2); |
| printline (); |
| readCharsFromFile (filename2); |
| printline (); |
| |
| deletefile (filename2); |
| printline (); |
| ReadFile (filename2); |
| printline (); |
| |
| testfileio (filename1); |
| printline (); |
| testfileio (filename2); |
| printline (); |
| deletefile (filename1); |
| printline (); |
| deletefile (filename2); |
| printline (); |
| |
| 系列。 println ( “ n測試完成” ); |
| } |
| |
| void loop () |
| { |
| } |
調試終端輸出樣品
1。 Littlefs_countingon portenta_h7_m7
以下是在MBED portenta_h7_m7上運行示例LittleFS_Counting時的示例終端輸出
1.1首次運行
Start LittleFS_Counting on PORTENTA_H7_M7
LittleFS_Portenta_H7 v1 .2.0
[LFS] Flash Size : (KB) = 2048.00
[LFS] FlashIAP Start Address: = 0x0x8080000
[LFS] LittleFS size (KB) = 1536.00
[LFS] LittleFS Mount OK
Times have been run = 1
=> Open to write OK
重置後1.2
Start LittleFS_Counting on PORTENTA_H7_M7
LittleFS_Portenta_H7 v1 .2.0
[LFS] Flash Size : (KB) = 2048.00
[LFS] FlashIAP Start Address: = 0x0x8080000
[LFS] LittleFS size (KB) = 1536.00
[LFS] LittleFS Mount OK
=> Open to read OK
Times have been run = 2
=> Open to write OK
2。 portenta_h7_m7上的littlefs_test
以下是在運行示例示例littlefs_test上的示例終端輸出
Start LittleFS_Test on PORTENTA_H7_M7
LittleFS_Portenta_H7 v1 .2.0
[LFS] Flash Size : (KB) = 2048.00
[LFS] FlashIAP Start Address: = 0x0x8080000
[LFS] LittleFS size (KB) = 1536.00
[LFS] LittleFS Mount OK
====================================================
Writing file: /littlefs/hello1.txt => Open OK
* Writing OK
====================================================
Reading file: /littlefs/hello1.txt => Open OK
Hello from PORTENTA_H7_M7
====================================================
Appending file: /littlefs/hello1.txt => Open OK
* Appending OK
====================================================
Reading file: /littlefs/hello1.txt => Open OK
Hello from PORTENTA_H7_M7
Hello from PORTENTA_H7_M7
====================================================
Renaming file: /littlefs/hello1.txt to: /littlefs/hello2.txt => OK
====================================================
readCharsFromFile: /littlefs/hello2.txt => Open OK
Hello from PORTENTA_H7_M7
Hello from PORTENTA_H7_M7
====================================================
Deleting file: /littlefs/hello2.txt => OK
====================================================
Reading file: /littlefs/hello2.txt => Open Failed
====================================================
Testing file I/O with: /littlefs/hello1.txt => Open OK
- writing
64 Kbytes written in (ms) 1077
====================================================
- reading
384 Kbytes read in (ms) 0
====================================================
Testing file I/O with: /littlefs/hello2.txt => Open OK
- writing
64 Kbytes written in (ms) 1003
====================================================
- reading
64 Kbytes read in (ms) 0
====================================================
Deleting file: /littlefs/hello1.txt => OK
====================================================
Deleting file: /littlefs/hello2.txt => OK
====================================================
偵錯
默認情況下啟用調試。
您還可以將調試級別( LFS_Loglevel )從0更改為4
# define LFS_DEBUG_OUTPUT Serial
// These define's must be placed at the beginning before #include "LittleFS_Portenta_H7.h"
// _LFS_LOGLEVEL_ from 0 to 4
# define _LFS_LOGLEVEL_ 0
故障排除
如果您遇到彙編錯誤,則通常需要安裝Arduino Board的核心版本的較新版本。
有時,只有在您使用新添加的功能時,只有將板核更新為最新版本時,庫才能正常工作。
問題
提交問題:LittleFS_Portenta_h7問題
做
- 搜索錯誤和改進。
完畢
- 使用arduinocore -mbed mbed_portenta core
- 添加版本字符串
- 添加目錄
- 將
LittleFS尺寸降低至1024KB - 修復
multiple-definitions鏈接器錯誤 - 使用
allman樣式添加ASTYLE。庫圖書館
貢獻和感謝
非常感謝大家的錯誤報告,新功能建議,測試和為該庫的開發做出貢獻。
貢獻
如果您想為這個項目做出貢獻:
- 報告錯誤和錯誤
- 要求增強
- 創建問題並提取請求
- 告訴其他人這個圖書館
執照
版權
版權(C)2021- Khoi Hoang