<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>

電子發燒友App

硬聲App

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示
電子發燒友網>電子資料下載>電子資料>帶有RT-Thread的更好的SD庫

帶有RT-Thread的更好的SD庫

2023-06-14 | zip | 0.00 MB | 次下載 | 免費

資料介紹

描述

背景

Arduino IDE 附帶的 SD 庫很方便,但缺少 exFAT、LFN(長文件名)和非英文字符支持等功能。本文介紹了一種替代 SD 卡驅動程序(基于 RT-Thread)來解決這些問題。

RT-線程

RT-Thread是一個免費的開源(Apache 許可證 2.0)RTOS,并以 Arduino 庫的形式提供。還有另一篇文章 ( Multitasking on Arduino ) 可用于了解 RT-Thread 的基本概念。

讓我們從通過 Arduino IDE 的庫管理器安裝庫開始。(本文基于 RT-Thread 庫版本 0.4.4 。)

SD 卡驅動程序 (TL;DR)

(如果您對實現不感興趣,只想知道如何使用它,請跳過本節。)

RT-Thread 庫中的 SD 卡支持采用DFS(設備文件系統)的形式,它是 RT-Thread 架構的一部分。FAT 是 RT-Thread 支持的文件系統之一。(在 RT-Thread 庫的 0.4.4 版本中,FAT 是唯一支持的文件系統。)

FAT DFS 本??身就是基于ChaN 的 FatFs 項目的優秀作品。

標準的 RT-Thread DFS 提供以下文件系統和文件接口

/* File system operations */
struct dfs_filesystem_ops
{
   const char *name;
   uint32_t flags;      /* flags for file system operations */
   /* operations for file */
   const struct dfs_file_ops *fops;
   /* mount and unmount file system */
   int (*mount)    (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
   int (*unmount)  (struct dfs_filesystem *fs);
   /* make a file system */
   int (*mkfs)     (rt_device_t devid);
   int (*statfs)   (struct dfs_filesystem *fs, struct statfs *buf);
   int (*unlink)   (struct dfs_filesystem *fs, const char *pathname);
   int (*stat)     (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
   int (*rename)   (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
};
/* File operations */
struct dfs_file_ops
{
   int (*open)     (struct dfs_fd *fd);
   int (*close)    (struct dfs_fd *fd);
   int (*ioctl)    (struct dfs_fd *fd, int cmd, void *args);
   int (*read)     (struct dfs_fd *fd, void *buf, size_t count);
   int (*write)    (struct dfs_fd *fd, const void *buf, size_t count);
   int (*flush)    (struct dfs_fd *fd);
   int (*lseek)    (struct dfs_fd *fd, off_t offset);
   int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count);
   int (*poll)     (struct dfs_fd *fd, struct rt_pollreq *req);
}

一個特定的 DFS 可能會實現它們的全部或部分。當掛載DFS時,例如dfs_mount("SD", "/", "elm", 0, 0),特定的DFS會綁定到一個設備上。在這種情況下,DFS "elm" (FatFs) 綁定到設備 "SD"。

標準的 RT-Thread 設備提供以下接口:

/* operations set for device object */
struct rt_device_ops
{
   /* common device interface */
   rt_err_t  (*init)   (rt_device_t dev);
   rt_err_t  (*open)   (rt_device_t dev, rt_uint16_t oflag);
   rt_err_t  (*close)  (rt_device_t dev);
   rt_size_t (*read)   (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
   rt_size_t (*write)  (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
   rt_err_t  (*control)(rt_device_t dev, int cmd, void *args);
};

一個特定的設備可以實現它們的全部或全部(將函數指針設置為 NULL)。

在庫中,名為“SD”的設備實現了與SD卡訪問相關的功能,在MKRZERO板的情況下,它涉及到一個名為“SPI1”的低級設備。而 SPI 設備最終涉及到了 Arduino SPI 庫。

數據記錄器示例

Arduino SD 庫提供了一個名為“Datalogger”的示例。RT-Thread 庫中也提供了相同的示例,如下面的代碼部分所列。

不同之處在于,在下面的示例代碼中,采樣間隔為 1 秒,并且只執行 10 次。

您可能已經注意到上面的注釋open()功能。要打開現有文件并刪除其所有內容,只需O_APPENDO_TRUNC標志替換即可。

當使用 MKRZERO 板運行以下示例時,您可能會觀察到串行監視器的以下輸出

\ | /
- RT -     Thread Operating System
/ | \     4.0.1 build Apr 17 2019
2006 - 2019 Copyright by rt-thread team
+ Mount SD to "/"
416,347,312
finsh />436,369,335
442,375,340
449,376,338
449,375,346
429,374,341
447,369,342
449,363,338
426,363,334
419,353,327

使用 Shell 進行操作

使用 RT-Thread 庫的真正優勢在于它使您能夠使用 (FinSH) shell 命令來操作文件。

串行監視器或其他串行終端工具中,輸入ls()命令將顯示當前目錄(在本例中為“/”)中的文件列表,如下所示。

ls()
Directory /:
DATALOG.TXT         240
HI_UTF8.TXT         35
A_REAL~1.TXT        22
       0, 0x00000000 

文件名后面的數字是以字節為單位的文件大小。在上面的屏幕截圖中,“datalog.txt”的大小為 240 字節,因為我運行了該示例兩次。

輸入cat("datalog.txt")命令會顯示“datalog.txt”的內容,確認有20條記錄。

finsh />cat("datalog.txt")
464,358,333
464,368,336
480,381,354
447,364,346
443,363,340
441,365,343
463,371,345
467,374,313
447,364,345
465,369,346
416,347,312
436,369,335
442,375,340
449,376,338
449,375,346
429,374,341
447,369,342
449,363,338
426,363,334
419,353,327
       0, 0x00000000

還有copy()rm()命令。

finsh />copy("datalog.txt", "copy.txt")
       0, 0x00000000
finsh />ls()
Directory /:
COPY.TXT            240
DATALOG.TXT         240
HI_UTF8.TXT         35
A_REAL~1.TXT        22
       0, 0x00000000
finsh />rm("copy.txt")
       0, 0x00000000
finsh />ls()
Directory /:
DATALOG.TXT         240
HI_UTF8.TXT         35
A_REAL~1.TXT        22
       0, 0x00000000

要列出所有可用命令,請輸入list()。

finsh />list()
--Function List:
hello            -- say hello world
version          -- show RT-Thread version information
list             -- list available commands
list_mem         -- list memory usage information
list_thread      -- list thread
list_sem         -- list semaphore in system
list_mutex       -- list mutex in system
list_event       -- list event in system
list_mb          -- list mail box in system
list_mq          -- list message queue in system
list_memp        -- list memory pool in system
list_timer       -- list timer in system
list_dev         -- list device in system
mkfs             -- make a file system
df               -- get disk free
mkdir            -- create a directory
cd               -- change current working directory
ls               -- list directory contents
rm               -- remove files or directories
cat              -- print file content
copy             -- copy file or dir
list_sd          -- show SD information
--Variable List:
dummy            -- dummy variable for finsh
       0, 0x00000000

ExFAT、LFN 和非英文字符支持

默認情況下不啟用 ExFAT、LFN(長文件名)和非英文字符支持(以使示例更?。?。在“ rtconfig.h ”(位于 RT-Thread 庫目錄中)中打開以下配置以啟用這些功能。

#define RT_DFS_ELM_USE_EXFAT
#define RT_DFS_ELM_USE_LFN              (2)
#define RT_DFS_ELM_MAX_LFN              (255)
#define RT_DFS_ELM_CODE_PAGE            936

RT_DFS_ELM_MAX_LFN表示文件名的最大長度,可以在 12 到 255 的范圍內。

RT_DFS_ELM_CODE_PAGE默認設置為 437 用于美國,更改為 936 將啟用簡體中文支持,如下所示。

finsh />ls()
Directory /:
DATALOG.TXT         240
hi_utf8.txt         35
a_really_long_file_name.txt22
      0, 0x00000000
finsh />cat("hi_utf8.txt")
Hello, world!
世界,你好!	0, 0x00000000

下一步

  • RT-Thread Primer(即將推出)

下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數據手冊
  2. 1.06 MB  |  532次下載  |  免費
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費
  9. 5元宇宙深度解析—未來的未來-風口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費
  11. 6迪文DGUS開發指南
  12. 31.67 MB  |  194次下載  |  免費
  13. 7元宇宙底層硬件系列報告
  14. 13.42 MB  |  182次下載  |  免費
  15. 8FP5207XR-G1中文應用手冊
  16. 1.09 MB  |  178次下載  |  免費

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費
  3. 2555集成電路應用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費
  7. 4開關電源設計實例指南
  8. 未知  |  21549次下載  |  免費
  9. 5電氣工程師手冊免費下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費
  11. 6數字電路基礎pdf(下載)
  12. 未知  |  13750次下載  |  免費
  13. 7電子制作實例集錦 下載
  14. 未知  |  8113次下載  |  免費
  15. 8《LED驅動電路設計》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費
  3. 2protel99se軟件下載(可英文版轉中文版)
  4. 78.1 MB  |  537798次下載  |  免費
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費
  11. 6電路仿真軟件multisim 10.0免費下載
  12. 340992  |  191187次下載  |  免費
  13. 7十天學會AVR單片機與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費
  15. 8proe5.0野火版下載(中文版免費下載)
  16. 未知  |  138040次下載  |  免費
亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>