搜索
bottom↓
回复: 41

stm32上移植fatfs文件系统同时管理spi_falsh和sd卡,已经实现...

  [复制链接]

出0入0汤圆

发表于 2014-3-17 16:01:59 | 显示全部楼层 |阅读模式
最近项目需要在spi_falsh里放一mp3文件和字库,但是往flash里面放这些文件比较麻烦,所以就想用sd卡把这些文件自动下载到falsh里面,我这里使用的flash型号是w25q128,16Mb空间。sd卡接口采用sdio来驱动。文件系统使用的是最新的fatfs 0.10版本。spi_falsh驱动使用的是野火的代码,自己又改良和添加了部分函数,以适合移植fatfs。注意:本工程硬件平台是野火的stm32开发板。完成了从sd卡复制文件到spi_flash.

下面贴上代码。
diskio.c

  1. #include "diskio.h"                /* FatFs lower layer API */
  2. //#include "usbdisk.h"        /* Example: USB drive control */
  3. //#include "atadrive.h"        /* Example: ATA drive control */
  4. //#include "sdcard.h"                /* Example: MMC/SDC contorl */
  5. #include "spi_flash.h"
  6. #include "sdio_sdcard.h"


  7. /* Definitions of physical drive number for each media */
  8. #define NORFLASH                0
  9. #define MMC                1
  10. #define USB                2

  11. #define BLOCK_SIZE            512 /* Block Size in Bytes */
  12. /*-----------------------------------------------------------------------*/
  13. /* Inidialize a Drive                                                    */
  14. /*-----------------------------------------------------------------------*/

  15. DSTATUS disk_initialize (
  16.         BYTE pdrv                                /* Physical drive nmuber (0..) */
  17. )
  18. {
  19.         DSTATUS res;
  20.         SD_Error  Stat;
  21.         switch (pdrv)
  22.         {
  23.                 case NORFLASH :
  24.                         SPI_FLASH_Init();
  25.                         res=RES_OK;
  26.                         break;
  27.                
  28.                 case MMC:
  29.                         Stat = SD_Init();
  30.                         if (Stat!=SD_OK )
  31.                         {
  32.                                 res=STA_NOINIT;
  33.                         }
  34.                         else
  35.                         {
  36.                                 res = RES_OK;
  37.                         }
  38. //                        break;
  39.         }       
  40.         return res;
  41. }



  42. /*-----------------------------------------------------------------------*/
  43. /* Get Disk Status                                                       */
  44. /*-----------------------------------------------------------------------*/

  45. DSTATUS disk_status (
  46.         BYTE pdrv                /* Physical drive nmuber (0..) *///ÎïÀíÇý¶¯ºÅ
  47. )
  48. {

  49.         return RES_OK;

  50. }



  51. /*-----------------------------------------------------------------------*/
  52. /* Read Sector(s)                                                        */
  53. /*-----------------------------------------------------------------------*/

  54. DRESULT disk_read (
  55.         BYTE pdrv,                /* Physical drive nmuber (0..) *///ÎïÀíÇý¶¯ºÅ
  56.         BYTE *buff,                /* Data buffer to store read data *///½«Òª¶ÁÈ¡µÄÊý¾ÝµÄ»º³åÇø
  57.         DWORD sector,        /* Sector address (LBA) *///ÉÈÇøµØÖ·
  58.         UINT count                /* Number of sectors to read (1..128) *///½«Òª¶ÁÈ¡µÄÉÈÇøÊý
  59. )
  60. {

  61.         switch (pdrv)
  62.         {
  63.                 case NORFLASH :
  64.                         // translate the arguments here
  65.                         SPI_FLASH_SectorRead(buff, sector, count);
  66.                         // translate the reslut code here
  67.                         return RES_OK;
  68.                
  69.                 case MMC:
  70.                         if (count > 1)
  71.                         {
  72.                                 SD_ReadMultiBlocks(buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
  73.                        
  74.                                                 /* Check if the Transfer is finished */
  75.                                 SD_WaitReadOperation();  //Ñ­»·²éѯdma´«ÊäÊÇ·ñ½áÊø
  76.                        
  77.                                         /* Wait until end of DMA transfer */
  78.                                 while(SD_GetStatus() != SD_TRANSFER_OK);

  79.                         }
  80.                         else
  81.                         {
  82.                                
  83.                                 SD_ReadBlock(buff, sector*BLOCK_SIZE, BLOCK_SIZE);

  84.                                                 /* Check if the Transfer is finished */
  85.                                 SD_WaitReadOperation();  //Ñ­»·²éѯdma´«ÊäÊÇ·ñ½áÊø
  86.                        
  87.                                         /* Wait until end of DMA transfer */
  88.                                 while(SD_GetStatus() != SD_TRANSFER_OK);

  89.                         }
  90.                         return RES_OK;
  91.                
  92.                
  93.         }
  94.         return RES_PARERR;

  95. }



  96. /*-----------------------------------------------------------------------*/
  97. /* Write Sector(s)                                                       */
  98. /*-----------------------------------------------------------------------*/

  99. #if _USE_WRITE
  100. DRESULT disk_write (
  101.         BYTE pdrv,                        /* Physical drive nmuber (0..) *///ÎïÀíÇý¶¯ºÅ
  102.         const BYTE *buff,        /* Data to be written *///ҪдÈëµÄÊý¾ÝµÄÖ¸Õë
  103.         DWORD sector,                /* Sector address (LBA) *///ҪдÈëµÄÉÈÇøµØÖ·
  104.         UINT count                        /* Number of sectors to write (1..128) */
  105. )
  106. {
  107.         switch (pdrv)
  108.         {
  109.                 case  NORFLASH:
  110.                         SPI_FLASH_SectorWrite(buff, sector, count);
  111.                         return RES_OK;
  112.                
  113.                 case MMC:
  114.                         if (count > 1)
  115.                         {
  116.                                 SD_WriteMultiBlocks((uint8_t *)buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
  117.                                
  118.                                         /* Check if the Transfer is finished */
  119.                                 SD_WaitWriteOperation();           //µÈ´ýdma´«Êä½áÊø
  120.                                 while(SD_GetStatus() != SD_TRANSFER_OK); //µÈ´ýsdioµ½sd¿¨´«Êä½áÊø
  121.                         }
  122.                         else
  123.                         {
  124.                                 SD_WriteBlock((uint8_t *)buff,sector*BLOCK_SIZE, BLOCK_SIZE);
  125.                                
  126.                                         /* Check if the Transfer is finished */
  127.                                                 SD_WaitWriteOperation();           //µÈ´ýdma´«Êä½áÊø
  128.                                         while(SD_GetStatus() != SD_TRANSFER_OK); //µÈ´ýsdioµ½sd¿¨´«Êä½áÊø
  129.                         }
  130.                         return RES_OK;
  131.                
  132.         }
  133.         return RES_PARERR;
  134. }
  135. #endif


  136. /*-----------------------------------------------------------------------*/
  137. /* Miscellaneous Functions                                               */
  138. /*-----------------------------------------------------------------------*/

  139. #if _USE_IOCTL
  140. DRESULT disk_ioctl (
  141.         BYTE pdrv,                /* Physical drive nmuber (0..) *///ÎïÀíÇý¶¯ºÅ
  142.         BYTE cmd,                /* Control code */
  143.         void *buff                /* Buffer to send/receive control data */
  144. )
  145. {
  146.         DRESULT sta=RES_ERROR;
  147.         DWORD nFrom,nTo;
  148.         int i;
  149.         switch (pdrv)
  150.         {
  151.                 case NORFLASH :
  152.                         switch(cmd)
  153.                         {
  154.                                  case CTRL_SYNC:
  155.                                          sta=RES_OK;
  156.                                          break;
  157.                                  
  158.                                  case GET_SECTOR_COUNT:
  159.                                          *(DWORD*)buff = 4096;
  160.                                          sta=RES_OK;
  161.                                         break;
  162.                                  
  163.                                  case GET_SECTOR_SIZE:
  164.                                          *(WORD*)buff = 4096;
  165.                                          sta=RES_OK;
  166.                                          break;
  167.                                  
  168.                                  case GET_BLOCK_SIZE:
  169.                                          *(DWORD*)buff = 65536;
  170.                                                 sta=RES_OK;
  171.                                     break;
  172.                                  
  173.                                  case CTRL_ERASE_SECTOR:
  174.                                          nFrom = *((DWORD*)buff);
  175.                                          nTo = *(((DWORD*)buff)+1);
  176.                                          for(i = nFrom;i <= nTo;i ++)
  177.                                                         SPI_FLASH_SectorErase(i);
  178.                                          sta=RES_OK;
  179.                                          break;
  180.                                                           
  181.                         }       

  182.                 case MMC:
  183.                         switch(cmd)
  184.                         {
  185.                                  case CTRL_SYNC:
  186.                                          sta=RES_OK;
  187.                                          break;
  188.                                  
  189.                                  case GET_SECTOR_COUNT:
  190. //                                         *(DWORD*)buff = 4096;
  191.                                          sta=RES_OK;
  192.                                         break;
  193.                                  
  194.                                  case GET_SECTOR_SIZE:
  195.                                          *(WORD*)buff = 512;
  196.                                          sta=RES_OK;
  197.                                          break;
  198.                                  
  199.                                  case GET_BLOCK_SIZE:
  200.                                                 sta=RES_OK;
  201.                                     break;
  202.                                  
  203.                                  case CTRL_ERASE_SECTOR:
  204.                                          sta=RES_OK;
  205.                                          break;
  206.                                                           
  207.                         }       
  208.                
  209.         }return sta;
  210. }
  211. #endif

  212. DWORD get_fattime(void)
  213. {

  214.         return 0;

  215. }
复制代码
文件系统配置ffconf.h
  1. /*---------------------------------------------------------------------------/
  2. /  FatFs - FAT file system module configuration file  R0.10a (C)ChaN, 2014
  3. /---------------------------------------------------------------------------*/

  4. #ifndef _FFCONF
  5. #define _FFCONF 29000        /* Revision ID */


  6. /*---------------------------------------------------------------------------/
  7. / Functions and Buffer Configurations
  8. /---------------------------------------------------------------------------*/

  9. #define        _FS_TINY                0        /* 0:Normal or 1:Tiny */
  10. /* When _FS_TINY is set to 1, it reduces memory consumption _MAX_SS bytes each
  11. /  file object. For file data transfer, FatFs uses the common sector buffer in
  12. /  the file system object (FATFS) instead of private sector buffer eliminated
  13. /  from the file object (FIL). */


  14. #define _FS_READONLY        0        /* 0:Read/Write or 1:Read only */
  15. /* Setting _FS_READONLY to 1 defines read only configuration. This removes
  16. /  writing functions, f_write(), f_sync(), f_unlink(), f_mkdir(), f_chmod(),
  17. /  f_rename(), f_truncate() and useless f_getfree(). */


  18. #define _FS_MINIMIZE        0        /* 0 to 3 */
  19. /* The _FS_MINIMIZE option defines minimization level to remove API functions.
  20. /
  21. /   0: All basic functions are enabled.
  22. /   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
  23. /      f_truncate() and f_rename() function are removed.
  24. /   2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
  25. /   3: f_lseek() function is removed in addition to 2. */


  26. #define        _USE_STRFUNC        1        /* 0:Disable or 1-2:Enable */
  27. /* To enable string functions, set _USE_STRFUNC to 1 or 2. */


  28. #define        _USE_MKFS                1        /* 0:Disable or 1:Enable */
  29. /* To enable f_mkfs() function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */


  30. #define        _USE_FASTSEEK        1        /* 0:Disable or 1:Enable */
  31. /* To enable fast seek feature, set _USE_FASTSEEK to 1. */


  32. #define _USE_LABEL                1        /* 0:Disable or 1:Enable */
  33. /* To enable volume label functions, set _USE_LAVEL to 1 */


  34. #define        _USE_FORWARD        0        /* 0:Disable or 1:Enable */
  35. /* To enable f_forward() function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */


  36. /*---------------------------------------------------------------------------/
  37. / Locale and Namespace Configurations
  38. /---------------------------------------------------------------------------*/

  39. #define _CODE_PAGE        936
  40. /* The _CODE_PAGE specifies the OEM code page to be used on the target system.
  41. /  Incorrect setting of the code page can cause a file open failure.
  42. /
  43. /   932  - Japanese Shift-JIS (DBCS, OEM, Windows)
  44. /   936  - Simplified Chinese GBK (DBCS, OEM, Windows)
  45. /   949  - Korean (DBCS, OEM, Windows)
  46. /   950  - Traditional Chinese Big5 (DBCS, OEM, Windows)
  47. /   1250 - Central Europe (Windows)
  48. /   1251 - Cyrillic (Windows)
  49. /   1252 - Latin 1 (Windows)
  50. /   1253 - Greek (Windows)
  51. /   1254 - Turkish (Windows)
  52. /   1255 - Hebrew (Windows)
  53. /   1256 - Arabic (Windows)
  54. /   1257 - Baltic (Windows)
  55. /   1258 - Vietnam (OEM, Windows)
  56. /   437  - U.S. (OEM)
  57. /   720  - Arabic (OEM)
  58. /   737  - Greek (OEM)
  59. /   775  - Baltic (OEM)
  60. /   850  - Multilingual Latin 1 (OEM)
  61. /   858  - Multilingual Latin 1 + Euro (OEM)
  62. /   852  - Latin 2 (OEM)
  63. /   855  - Cyrillic (OEM)
  64. /   866  - Russian (OEM)
  65. /   857  - Turkish (OEM)
  66. /   862  - Hebrew (OEM)
  67. /   874  - Thai (OEM, Windows)
  68. /   1    - ASCII (Valid for only non-LFN cfg.) */


  69. #define        _USE_LFN        0                /* 0 to 3 */
  70. #define        _MAX_LFN        255                /* Maximum LFN length to handle (12 to 255) */
  71. /* The _USE_LFN option switches the LFN feature.
  72. /
  73. /   0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
  74. /   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
  75. /   2: Enable LFN with dynamic working buffer on the STACK.
  76. /   3: Enable LFN with dynamic working buffer on the HEAP.
  77. /
  78. /  When enable LFN feature, Unicode handling functions ff_convert() and ff_wtoupper()
  79. /  function must be added to the project.
  80. /  The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When use stack for the
  81. /  working buffer, take care on stack overflow. When use heap memory for the working
  82. /  buffer, memory management functions, ff_memalloc() and ff_memfree(), must be added
  83. /  to the project. */


  84. #define        _LFN_UNICODE        0        /* 0:ANSI/OEM or 1:Unicode */
  85. /* To switch the character encoding on the FatFs API (TCHAR) to Unicode, enable LFN
  86. /  feature and set _LFN_UNICODE to 1. This option affects behavior of string I/O
  87. /  functions. */


  88. #define _STRF_ENCODE        0        /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */
  89. /* When Unicode API is enabled by _LFN_UNICODE option, this option selects the character
  90. /  encoding on the file to be read/written via string I/O functions, f_gets(), f_putc(),
  91. /  f_puts and f_printf(). This option has no effect when Unicode API is not enabled. */


  92. #define _FS_RPATH                2        /* 0 to 2 */
  93. /* The _FS_RPATH option configures relative path feature.
  94. /
  95. /   0: Disable relative path feature and remove related functions.
  96. /   1: Enable relative path. f_chdrive() and f_chdir() function are available.
  97. /   2: f_getcwd() function is available in addition to 1.
  98. /
  99. /  Note that output of the f_readdir() fnction is affected by this option. */


  100. /*---------------------------------------------------------------------------/
  101. / Drive/Volume Configurations
  102. /---------------------------------------------------------------------------*/

  103. #define _VOLUMES        8
  104. /* Number of volumes (logical drives) to be used. */


  105. #define _STR_VOLUME_ID        0        /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
  106. #define _VOLUME_STRS        "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
  107. /* When _STR_VOLUME_ID is set to 1, also pre-defined string can be used as drive number
  108. /  in the path name. _VOLUME_STRS defines the drive ID strings for each logical drives.
  109. /  Number of items must be equal to _VOLUMES. Valid characters for the drive ID strings
  110. /  are: 0-9 and A-Z. */


  111. #define        _MULTI_PARTITION        0        /* 0:Single partition, 1:Enable multiple partition */
  112. /* By default(0), each logical drive number is bound to the same physical drive number
  113. /  and only a FAT volume found on the physical drive is mounted. When it is set to 1,
  114. /  each logical drive number is bound to arbitrary drive/partition listed in VolToPart[].
  115. */


  116. #define        _MIN_SS                512
  117. #define        _MAX_SS                4096
  118. /* These options configure the sector size to be supported. (512, 1024, 2048 or 4096)
  119. /  Always set both 512 for most systems, all memory card and hard disk. But a larger
  120. /  value may be required for on-board flash memory and some type of optical media.
  121. /  When _MIN_SS != _MAX_SS, FatFs is configured to multiple sector size and
  122. /  GET_SECTOR_SIZE command must be implemented to the disk_ioctl() function. */


  123. #define        _USE_ERASE        0/* 0:Disable or 1:Enable */
  124. /* To enable sector erase feature, set _USE_ERASE to 1. Also CTRL_ERASE_SECTOR command
  125. /  should be added to the disk_ioctl() function. */


  126. #define _FS_NOFSINFO        0        /* 0 to 3 */
  127. /* If you need to know correct free space on the FAT32 volume, set bit 0 of this
  128. /  option and f_getfree() function at first time after volume mount will force
  129. /  a full FAT scan. Bit 1 controls the last allocated cluster number as bit 0.
  130. /
  131. /  bit0=0: Use free cluster count in the FSINFO if available.
  132. /  bit0=1: Do not trust free cluster count in the FSINFO.
  133. /  bit1=0: Use last allocated cluster number in the FSINFO if available.
  134. /  bit1=1: Do not trust last allocated cluster number in the FSINFO.
  135. */



  136. /*---------------------------------------------------------------------------/
  137. / System Configurations
  138. /---------------------------------------------------------------------------*/

  139. #define _WORD_ACCESS        0        /* 0 or 1 */
  140. /* The _WORD_ACCESS option is an only platform dependent option. It defines
  141. /  which access method is used to the word data on the FAT volume.
  142. /
  143. /   0: Byte-by-byte access. Always compatible with all platforms.
  144. /   1: Word access. Do not choose this unless under both the following conditions.
  145. /
  146. /  * Address misaligned memory access is always allowed for all instructions.
  147. /  * Byte order on the memory is little-endian.
  148. /
  149. /  If it is the case, _WORD_ACCESS can also be set to 1 to improve performance
  150. /  and reduce code size.
  151. */


  152. #define        _FS_LOCK        0        /* 0:Disable or >=1:Enable */
  153. /* To enable file lock control feature, set _FS_LOCK to 1 or greater.
  154. /  The value defines how many files/sub-directories can be opened simultaneously.
  155. /  This feature consumes _FS_LOCK * 12 bytes of bss area. */


  156. #define _FS_REENTRANT        0                /* 0:Disable or 1:Enable */
  157. #define _FS_TIMEOUT                1000        /* Timeout period in unit of time ticks */
  158. #define        _SYNC_t                        HANDLE        /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID and etc.. */
  159. /*#include <windows.h>*/

  160. /* A header file that defines sync object types on the O/S, such as windows.h,
  161. /  ucos_ii.h and semphr.h, should be included here when enable this option.
  162. /  The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
  163. /
  164. /   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
  165. /   1: Enable re-entrancy. Also user provided synchronization handlers,
  166. /      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
  167. /      function must be added to the project.
  168. */


  169. #endif /* _FFCONFIG */
复制代码
主函数里面是从sd卡里面复制确定名字的文件,你可以根据自己的需求改写。main.c
  1. #include "main.h"
  2. FRESULT scan_files (char* path) ;      /* Start node to be scanned (also used as work area) */

  3. u8 buffer[4096]={0};
  4. int main(void)
  5. {
  6.         FRESULT res;  

  7.         FIL fsrc,fdst;
  8.         FATFS fs_spi,fs_sd,*fs=&fs_spi;
  9.        
  10.         DWORD fre_clust, fre_sect, tot_sect;
  11.         UINT br, bw;            // File R/W count
  12.        
  13.        

  14. //        u8 buffer1[2048];
  15.        
  16.         USART1_Config();
  17. //        for(a=0;a<4096;a++)
  18. //                buffer[a]='6';
  19. //        SPI_FLASH_Init();

  20.         res=f_mount(&fs_spi,"0:",0);
  21.         res=f_mount(&fs_sd,"1:",0);       
  22.         if (res != FR_OK)
  23.         {
  24.                 printf("\r\n¹ÒÔØÎļþϵͳʧ°Ü,´íÎó´úÂë: %u",res);
  25.                 return 0;
  26.         }       
  27.        
  28. ///////¸ñʽ»¯spi_flash////////////
  29.         printf("\r\nÕýÔÚ¸ñʽ»¯´ÅÅÌ,ÇëÉÔºò...");
  30.         res=f_mkfs("0:",1,0);
  31.         if (res == FR_OK)
  32.         {
  33.                 printf("\r\n¸ñʽ»¯³É¹¦...");
  34.         }
  35.         else
  36.         {
  37.                 printf("\r\n¸ñʽ»¯Ê§°Ü...");
  38.                 printf("\r\n´íÎó´úÂë: %u\r\n",res);
  39.                 return 0;
  40.         }       
  41. //////////////////////////////////////////
  42.        
  43.         res = f_getfree("0:", &fre_clust, &fs);
  44.     if (res) printf("»ñÈ¡´ÅÅÌ¿Õ¼äʧ°Ü£¬Ê§°Ü´úÂë:%u\r\n",res);

  45.     /* Get total sectors and free sectors */
  46.     tot_sect = (fs->n_fatent - 2) * fs->csize;
  47.     fre_sect = fre_clust * fs->csize;

  48.     /* Print the free space (assuming 512 bytes/sector) */
  49.     printf("%10lu KiB total drive space.\n%10lu KiB available.\n",
  50.            tot_sect*4, fre_sect*4);
  51.        
  52. //////////´ò¿ªºÍ´´½¨Îļþ       
  53.         res = f_open (&fsrc, "1:1.mp3", FA_OPEN_EXISTING | FA_READ );
  54.         if (res == FR_OK)
  55.         {
  56.                 printf("\r\n³É¹¦´ò¿ªÎļþ1.mp3");
  57.         }
  58.         else
  59.         {
  60.                 printf("\r\n´ò¿ªÎļþʧ°Ü...");
  61.                 printf("\r\n´íÎó´úÂë: %u\r\n",res);
  62.                 return 0;
  63.         }       
  64.        
  65.         res = f_open (&fdst, "0:1.mp3", FA_CREATE_ALWAYS | FA_WRITE );
  66.         if (res == FR_OK)
  67.         {
  68.                 printf("\r\n³É¹¦´´½¨Îļþ1.mp3");
  69.         }
  70.         else
  71.         {
  72.                 printf("\r\n´´½¨Îļþʧ°Ü...");
  73.                 printf("\r\n´íÎó´úÂë: %u\r\n",res);
  74.                 return 0;
  75.         }       
  76. ///////////////////////////////////
  77.        
  78.        
  79.        
  80. /////////////////////////////////¸´ÖÆÎļþ
  81.         printf("\r\nÕýÔÚ¸´ÖÆÎļþ...");
  82.         for(;;)
  83.         {
  84.                 res = f_read(&fsrc, buffer, 4096, &br);
  85.                 if(res||br==0)break;
  86.                 res = f_write(&fdst,buffer,br,&bw);
  87.                 if(res||bw<br)break;
  88.                 printf("*");
  89.         }
  90.         printf("\r\nÎļþ¸´ÖƳɹ¦...");
  91. ///////////////////////////////////////

  92.         res = f_close(&fsrc);
  93.         res = f_close(&fdst);
  94.        
  95.          res = f_getfree("0:", &fre_clust, &fs);
  96.     if (res) printf("»ñÈ¡´ÅÅÌ¿Õ¼äʧ°Ü£¬Ê§°Ü´úÂë:%u\r\n",res);

  97.     /* Get total sectors and free sectors */
  98.     tot_sect = (fs->n_fatent - 2) * fs->csize;
  99.     fre_sect = fre_clust * fs->csize;

  100.     /* Print the free space (assuming 512 bytes/sector) */
  101.     printf("%10lu KiB total drive space.\n%10lu KiB available.\n",
  102.            tot_sect*4, fre_sect*4);
  103.        
  104.         while(1);
  105. }





  106. FRESULT scan_files (
  107.     char* path        /* Start node to be scanned (also used as work area) */
  108. )
  109. {
  110.     FRESULT res;
  111.     FILINFO fno;
  112.     DIR dir;
  113.     int i;
  114.     char *fn;   /* This function is assuming non-Unicode cfg. */
  115. #if _USE_LFN
  116.     static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
  117.     fno.lfname = lfn;
  118.     fno.lfsize = sizeof lfn;
  119. #endif


  120.     res = f_opendir(&dir, path);                       /* Open the directory */
  121.     if (res == FR_OK) {
  122.         i = strlen(path);
  123.         for (;;) {
  124.             res = f_readdir(&dir, &fno);                   /* Read a directory item */
  125.             if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
  126.             if (fno.fname[0] == '.') continue;             /* Ignore dot entry */
  127. #if _USE_LFN
  128.             fn = *fno.lfname ? fno.lfname : fno.fname;
  129. #else
  130.             fn = fno.fname;
  131. #endif
  132.             if (fno.fattrib & AM_DIR) {                    /* It is a directory */
  133.                 sprintf(&path[i], "/%s", fn);
  134.                 res = scan_files(path);
  135.                 if (res != FR_OK) break;
  136.                 path[i] = 0;
  137.             } else {                                       /* It is a file. */
  138.                 printf("%s/%s\n", path, fn);
  139.             }
  140.         }
  141.         f_closedir(&dir);
  142.     }

  143.     return res;
  144. }
复制代码






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

阿莫论坛才是最爱国的,关心国家的经济、社会的发展、担心国家被别国牵连卷入战争、知道珍惜来之不易的和平发展,知道师夷之长,关注世界的先进文化与技术,也探讨中国文化的博大精深,也懂得警惕民粹主义的祸国殃民等等等等,无不是爱国忧民的表现。(坛友:tianxian)

出0入0汤圆

 楼主| 发表于 2014-3-17 16:03:34 | 显示全部楼层
欢迎下载测试,如有bug还请告知,多谢!

出0入0汤圆

 楼主| 发表于 2014-3-17 16:27:31 | 显示全部楼层
自己顶!

出0入0汤圆

发表于 2014-3-17 16:53:45 | 显示全部楼层
有硬件的时候来测测。

出0入0汤圆

发表于 2014-3-17 19:02:58 | 显示全部楼层
这个TF卡支持大容量不?2G以上的!呵呵!

出0入0汤圆

发表于 2014-4-16 08:52:42 | 显示全部楼层
mark

                                         

出0入0汤圆

发表于 2014-4-16 10:52:00 | 显示全部楼层
顶一个,赞一下楼主;

出0入0汤圆

发表于 2014-4-16 18:10:38 | 显示全部楼层
怎么编译有这问题

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2014-4-22 11:32:06 | 显示全部楼层
已经下载,我编译没有问题,MDK的版本是4.72。

出0入0汤圆

发表于 2014-5-15 15:41:29 | 显示全部楼层
马克一下,多谢支持!

出0入0汤圆

发表于 2014-5-24 11:02:48 | 显示全部楼层
谢谢楼主分享。

出0入0汤圆

发表于 2014-6-12 16:59:32 | 显示全部楼层
正在格式化磁盘,请稍候...
格式化成功...获取磁盘空间失败,失败代码:12
         0 KiB total drive space.
         0 KiB available.
出错了,不知道什么原因,我也是用的W25Q128的Flash,MCU移植到STM32F103C8T6上面,也是用的PA4.5.6.7  IO   单独的读写扇区,测试OK

出0入0汤圆

发表于 2014-6-12 17:29:04 | 显示全部楼层
文件读写都OK,就是获取大小不行,怎么回事?

出0入0汤圆

 楼主| 发表于 2014-6-13 10:37:16 | 显示全部楼层
xiechenglin 发表于 2014-6-12 17:29
文件读写都OK,就是获取大小不行,怎么回事?

我这测试没有问题,我用的是vet6,看看是不是你的启动文件和头文件有问题。

出0入0汤圆

发表于 2014-6-13 17:13:43 | 显示全部楼层
下载测试一下,好东西

出0入0汤圆

发表于 2014-9-1 12:00:34 | 显示全部楼层
很好的东东,学习了

出0入0汤圆

发表于 2014-9-2 00:02:40 | 显示全部楼层
我也在学习FATFS

出0入0汤圆

发表于 2014-11-25 10:04:34 | 显示全部楼层
收藏了……

出0入17汤圆

发表于 2014-12-5 09:19:47 | 显示全部楼层
多谢楼主分享,正需要,下来试试看

出0入0汤圆

发表于 2014-12-5 13:18:14 | 显示全部楼层
mark

出0入0汤圆

发表于 2014-12-5 16:24:28 | 显示全部楼层
一个字 就是好

出0入0汤圆

发表于 2014-12-6 16:34:43 | 显示全部楼层
收藏                                                                     

出0入0汤圆

发表于 2014-12-6 16:35:04 | 显示全部楼层
收藏                                                                     

出0入0汤圆

发表于 2014-12-7 01:57:08 来自手机 | 显示全部楼层
好东西,赶紧收藏了

出0入0汤圆

发表于 2015-7-5 18:03:24 | 显示全部楼层
MARK         

出0入0汤圆

发表于 2015-7-5 18:04:10 | 显示全部楼层
资料不错

出0入0汤圆

发表于 2015-8-7 18:41:57 | 显示全部楼层
楼主为何我的读取文件出现FR_NO_FILESYSTEM

        res = f_mount(0,&fs);                                                 /* Mount a Logical Drive 0 */
        if (res != FR_OK)
        {
                printf("\r\n挂载文件系统失败,错误代码: %u",res);
                return;
        }       
// res = f_mkfs(0,1,4096);
        res = f_getfree("/",&fre_clust,&fls);

出0入0汤圆

发表于 2015-9-14 14:30:57 | 显示全部楼层
楼主厉害 下载来学习一下 自己弄的总是卡在check_fs

出0入0汤圆

发表于 2015-9-14 15:27:44 | 显示全部楼层
下载测试一下

出0入0汤圆

发表于 2015-9-29 09:02:45 | 显示全部楼层
mark一下,现在文件系统已经移植成功,准备看看如何来读取SD卡存储的数据。

出0入0汤圆

发表于 2015-9-29 09:40:45 | 显示全部楼层
好资料,顶~

出0入0汤圆

发表于 2015-10-16 00:13:09 | 显示全部楼层
不错,赞一个!

出0入0汤圆

发表于 2015-10-16 13:26:04 | 显示全部楼层
好东西,顶楼主

出0入0汤圆

发表于 2015-10-19 13:24:30 | 显示全部楼层
一直想搞fatfs学习下,一直没深入进去,现在好好学习下~

出0入0汤圆

发表于 2015-11-2 13:08:11 | 显示全部楼层
资料不错,十分感谢

出0入0汤圆

发表于 2016-5-31 22:51:39 | 显示全部楼层
在SPI Flash上的fatfs速度怎么样?

出0入0汤圆

发表于 2016-6-1 09:19:54 | 显示全部楼层
收藏起来,越来越喜欢这个坛子了,好东西真好

出0入0汤圆

发表于 2017-3-24 22:49:37 | 显示全部楼层
謝謝分享   

出0入0汤圆

发表于 2017-7-18 09:47:22 | 显示全部楼层
mark  stm32上移植fatfs文件系统同时管理spi_falsh和sd卡

出0入0汤圆

发表于 2017-7-23 00:48:38 | 显示全部楼层
感谢楼主的分享

出0入0汤圆

发表于 2022-6-11 00:53:53 | 显示全部楼层
小文件复制速度如何
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-16 13:19

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表