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