Преглед изворни кода

1.冗余文件整理理;

libo пре 2 година
родитељ
комит
f26e231b77
37 измењених фајлова са 0 додато и 43632 уклоњено
  1. 0 288
      Middlewares/Third_Party/FatFs/src/00history.txt
  2. 0 21
      Middlewares/Third_Party/FatFs/src/00readme.txt
  3. 0 141
      Middlewares/Third_Party/FatFs/src/diskio.c
  4. 0 80
      Middlewares/Third_Party/FatFs/src/diskio.h
  5. 0 6140
      Middlewares/Third_Party/FatFs/src/ff.c
  6. 0 361
      Middlewares/Third_Party/FatFs/src/ff.h
  7. 0 122
      Middlewares/Third_Party/FatFs/src/ff_gen_drv.c
  8. 0 80
      Middlewares/Third_Party/FatFs/src/ff_gen_drv.h
  9. 0 341
      Middlewares/Third_Party/FatFs/src/ffconf_template.h
  10. 0 38
      Middlewares/Third_Party/FatFs/src/integer.h
  11. 0 3870
      Middlewares/Third_Party/FatFs/src/option/cc932.c
  12. 0 11045
      Middlewares/Third_Party/FatFs/src/option/cc936.c
  13. 0 8674
      Middlewares/Third_Party/FatFs/src/option/cc949.c
  14. 0 6900
      Middlewares/Third_Party/FatFs/src/option/cc950.c
  15. 0 388
      Middlewares/Third_Party/FatFs/src/option/ccsbcs.c
  16. 0 177
      Middlewares/Third_Party/FatFs/src/option/syscall.c
  17. 0 17
      Middlewares/Third_Party/FatFs/src/option/unicode.c
  18. 0 221
      Middlewares/Third_Party/FatFs/src/st_readme.txt
  19. 0 445
      func/func_fatfs.c
  20. 0 80
      func/func_fatfs.h
  21. 0 689
      func/func_fatfs_record.c
  22. 0 80
      func/func_fatfs_record.h
  23. 0 143
      func/func_sdmmc_sdcard.c
  24. 0 52
      func/func_sdmmc_sdcard.h
  25. 0 59
      mid_fatfs/fatfs.c
  26. 0 49
      mid_fatfs/fatfs.h
  27. 0 273
      mid_fatfs/ffconf.h
  28. 0 170
      mid_fatfs/sdcard_diskio.c
  29. 0 46
      mid_fatfs/sdcard_diskio.h
  30. 0 239
      mid_fatfs/w25qxx_diskio.c
  31. 0 46
      mid_fatfs/w25qxx_diskio.h
  32. 0 969
      obj/obj_sdmmc_sdcard.c
  33. 0 356
      obj/obj_sdmmc_sdcard.h
  34. 0 545
      obj/obj_spi_sd_stm32.c
  35. 0 53
      obj/obj_spi_sd_stm32.h
  36. 0 319
      sys/sys_malloc.c
  37. 0 115
      sys/sys_malloc.h

+ 0 - 288
Middlewares/Third_Party/FatFs/src/00history.txt

@@ -1,288 +0,0 @@
-----------------------------------------------------------------------------
-  Revision history of FatFs module
-----------------------------------------------------------------------------
-
-R0.00 (February 26, 2006)
-
-  Prototype.
-
-
-
-R0.01 (April 29, 2006)
-
-  The first release.
-
-
-
-R0.02 (June 01, 2006)
-
-  Added FAT12 support.
-  Removed unbuffered mode.
-  Fixed a problem on small (<32M) partition.
-
-
-
-R0.02a (June 10, 2006)
-
-  Added a configuration option (_FS_MINIMUM).
-
-
-
-R0.03 (September 22, 2006)
-
-  Added f_rename().
-  Changed option _FS_MINIMUM to _FS_MINIMIZE.
-
-
-
-R0.03a (December 11, 2006)
-
-  Improved cluster scan algorithm to write files fast.
-  Fixed f_mkdir() creates incorrect directory on FAT32.
-
-
-
-R0.04 (February 04, 2007)
-
-  Added f_mkfs().
-  Supported multiple drive system.
-  Changed some interfaces for multiple drive system.
-  Changed f_mountdrv() to f_mount().
-
-
-
-R0.04a (April 01, 2007)
-
-  Supported multiple partitions on a physical drive.
-  Added a capability of extending file size to f_lseek().
-  Added minimization level 3.
-  Fixed an endian sensitive code in f_mkfs().
-
-
-
-R0.04b (May 05, 2007)
-
-  Added a configuration option _USE_NTFLAG.
-  Added FSINFO support.
-  Fixed DBCS name can result FR_INVALID_NAME.
-  Fixed short seek (<= csize) collapses the file object.
-
-
-
-R0.05 (August 25, 2007)
-
-  Changed arguments of f_read(), f_write() and f_mkfs().
-  Fixed f_mkfs() on FAT32 creates incorrect FSINFO.
-  Fixed f_mkdir() on FAT32 creates incorrect directory.
-
-
-
-R0.05a (February 03, 2008)
-
-  Added f_truncate() and f_utime().
-  Fixed off by one error at FAT sub-type determination.
-  Fixed btr in f_read() can be mistruncated.
-  Fixed cached sector is not flushed when create and close without write.
-
-
-
-R0.06 (April 01, 2008)
-
-  Added fputc(), fputs(), fprintf() and fgets().
-  Improved performance of f_lseek() on moving to the same or following cluster.
-
-
-
-R0.07 (April 01, 2009)
-
-  Merged Tiny-FatFs as a configuration option. (_FS_TINY)
-  Added long file name feature. (_USE_LFN)
-  Added multiple code page feature. (_CODE_PAGE)
-  Added re-entrancy for multitask operation. (_FS_REENTRANT)
-  Added auto cluster size selection to f_mkfs().
-  Added rewind option to f_readdir().
-  Changed result code of critical errors.
-  Renamed string functions to avoid name collision.
-
-
-
-R0.07a (April 14, 2009)
-
-  Septemberarated out OS dependent code on reentrant cfg.
-  Added multiple sector size feature.
-
-
-
-R0.07c (June 21, 2009)
-
-  Fixed f_unlink() can return FR_OK on error.
-  Fixed wrong cache control in f_lseek().
-  Added relative path feature.
-  Added f_chdir() and f_chdrive().
-  Added proper case conversion to extended character.
-
-
-
-R0.07e (November 03, 2009)
-
-  Septemberarated out configuration options from ff.h to ffconf.h.
-  Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH.
-  Fixed name matching error on the 13 character boundary.
-  Added a configuration option, _LFN_UNICODE.
-  Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
-
-
-
-R0.08 (May 15, 2010)
-
-  Added a memory configuration option. (_USE_LFN = 3)
-  Added file lock feature. (_FS_SHARE)
-  Added fast seek feature. (_USE_FASTSEEK)
-  Changed some types on the API, XCHAR->TCHAR.
-  Changed .fname in the FILINFO structure on Unicode cfg.
-  String functions support UTF-8 encoding files on Unicode cfg.
-
-
-
-R0.08a (August 16, 2010)
-
-  Added f_getcwd(). (_FS_RPATH = 2)
-  Added sector erase feature. (_USE_ERASE)
-  Moved file lock semaphore table from fs object to the bss.
-  Fixed f_mkfs() creates wrong FAT32 volume.
-
-
-
-R0.08b (January 15, 2011)
-
-  Fast seek feature is also applied to f_read() and f_write().
-  f_lseek() reports required table size on creating CLMP.
-  Extended format syntax of f_printf().
-  Ignores duplicated directory separators in given path name.
-
-
-
-R0.09 (September 06, 2011)
-
-  f_mkfs() supports multiple partition to complete the multiple partition feature.
-  Added f_fdisk().
-
-
-
-R0.09a (August 27, 2012)
-
-  Changed f_open() and f_opendir() reject null object pointer to avoid crash.
-  Changed option name _FS_SHARE to _FS_LOCK.
-  Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
-
-
-
-R0.09b (January 24, 2013)
-
-  Added f_setlabel() and f_getlabel().
-
-
-
-R0.10 (October 02, 2013)
-
-  Added selection of character encoding on the file. (_STRF_ENCODE)
-  Added f_closedir().
-  Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
-  Added forced mount feature with changes of f_mount().
-  Improved behavior of volume auto detection.
-  Improved write throughput of f_puts() and f_printf().
-  Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
-  Fixed f_write() can be truncated when the file size is close to 4GB.
-  Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect value on error.
-
-
-
-R0.10a (January 15, 2014)
-
-  Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
-  Added a configuration option of minimum sector size. (_MIN_SS)
-  2nd argument of f_rename() can have a drive number and it will be ignored.
-  Fixed f_mount() with forced mount fails when drive number is >= 1. (appeared at R0.10)
-  Fixed f_close() invalidates the file object without volume lock.
-  Fixed f_closedir() returns but the volume lock is left acquired. (appeared at R0.10)
-  Fixed creation of an entry with LFN fails on too many SFN collisions. (appeared at R0.07)
-
-
-
-R0.10b (May 19, 2014)
-
-  Fixed a hard error in the disk I/O layer can collapse the directory entry.
-  Fixed LFN entry is not deleted when delete/rename an object with lossy converted SFN. (appeared at R0.07)
-
-
-
-R0.10c (November 09, 2014)
-
-  Added a configuration option for the platforms without RTC. (_FS_NORTC)
-  Changed option name _USE_ERASE to _USE_TRIM.
-  Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b)
-  Fixed a potential problem of FAT access that can appear on disk error.
-  Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
-
-
-
-R0.11 (February 09, 2015)
-
-  Added f_findfirst(), f_findnext() and f_findclose(). (_USE_FIND)
-  Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c)
-  Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
-
-
-
-R0.11a (September 05, 2015)
-
-  Fixed wrong media change can lead a deadlock at thread-safe configuration.
-  Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
-  Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
-  Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
-  Fixed errors in the case conversion teble of Unicode (cc*.c).
-
-
-
-R0.12 (April 12, 2016)
-
-  Added support for exFAT file system. (_FS_EXFAT)
-  Added f_expand(). (_USE_EXPAND)
-  Changed some members in FINFO structure and behavior of f_readdir().
-  Added an option _USE_CHMOD.
-  Removed an option _WORD_ACCESS.
-  Fixed errors in the case conversion table of Unicode (cc*.c).
-
-
-
-R0.12a (July 10, 2016)
-
-  Added support for creating exFAT volume with some changes of f_mkfs().
-  Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed.
-  f_forward() is available regardless of _FS_TINY.
-  Fixed f_mkfs() creates wrong volume. (appeared at R0.12)
-  Fixed wrong memory read in create_name(). (appeared at R0.12)
-  Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
-
-
-
-R0.12b (September 04, 2016)
-
-  Made f_rename() be able to rename objects with the same name but case.
-  Fixed an error in the case conversion teble of code page 866. (ff.c)
-  Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12)
-  Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)
-  Fixed f_mkfs() creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12)
-  Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)
-  Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)
-  Fixed some internal errors in f_expand() and f_lseek(). (appeared at R0.12)
-
-
-
-R0.12c (March 04, 2017)
-
-  Improved write throughput at the fragmented file on the exFAT volume.
-  Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN.
-  Fixed successive f_getfree() can return wrong count on the FAT12/16 volume. (appeared at R0.12)
-  Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c)
-

+ 0 - 21
Middlewares/Third_Party/FatFs/src/00readme.txt

@@ -1,21 +0,0 @@
-FatFs Module Source Files R0.12c
-
-
-FILES
-
-  00readme.txt   This file.
-  00history.txt  Revision history.
-  ff.c           FatFs module.
-  ffconf.h       Configuration file of FatFs module.
-  ff.h           Common include file for FatFs and application module.
-  diskio.h       Common include file for FatFs and disk I/O module.
-  diskio.c       An example of glue function to attach existing disk I/O module to FatFs.
-  integer.h      Integer type definitions for FatFs.
-  option         Optional external modules.
-
-
-  Low level disk I/O module is not included in this archive because the FatFs
-  module is only a generic file system layer and it does not depend on any specific
-  storage device. You have to provide a low level disk I/O module written to
-  control the storage device that attached to the target system.
-

+ 0 - 141
Middlewares/Third_Party/FatFs/src/diskio.c

@@ -1,141 +0,0 @@
-/*-----------------------------------------------------------------------*/
-/* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2017        */
-/*                                                                       */
-/*   Portions COPYRIGHT 2017 STMicroelectronics                          */
-/*   Portions Copyright (C) 2017, ChaN, all right reserved               */
-/*-----------------------------------------------------------------------*/
-/* If a working storage control module is available, it should be        */
-/* attached to the FatFs via a glue function rather than modifying it.   */
-/* This is an example of glue functions to attach various existing      */
-/* storage control modules to the FatFs module with a defined API.       */
-/*-----------------------------------------------------------------------*/
-
-/* Includes ------------------------------------------------------------------*/
-#include "diskio.h"
-#include "ff_gen_drv.h"
-
-#if defined ( __GNUC__ )
-#ifndef __weak
-#define __weak __attribute__((weak))
-#endif
-#endif
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-extern Disk_drvTypeDef  disk;
-
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/**
-  * @brief  Gets Disk Status
-  * @param  pdrv: Physical drive number (0..)
-  * @retval DSTATUS: Operation status
-  */
-DSTATUS disk_status (
-	BYTE pdrv		/* Physical drive number to identify the drive */
-)
-{
-  DSTATUS stat;
-
-  stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
-  return stat;
-}
-
-/**
-  * @brief  Initializes a Drive
-  * @param  pdrv: Physical drive number (0..)
-  * @retval DSTATUS: Operation status
-  */
-DSTATUS disk_initialize (
-	BYTE pdrv				/* Physical drive nmuber to identify the drive */
-)
-{
-  DSTATUS stat = RES_OK;
-
-  if(disk.is_initialized[pdrv] == 0)
-  {
-    disk.is_initialized[pdrv] = 1;
-    stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
-  }
-  return stat;
-}
-
-/**
-  * @brief  Reads Sector(s)
-  * @param  pdrv: Physical drive number (0..)
-  * @param  *buff: Data buffer to store read data
-  * @param  sector: Sector address (LBA)
-  * @param  count: Number of sectors to read (1..128)
-  * @retval DRESULT: Operation result
-  */
-DRESULT disk_read (
-	BYTE pdrv,		/* Physical drive nmuber to identify the drive */
-	BYTE *buff,		/* Data buffer to store read data */
-	DWORD sector,	        /* Sector address in LBA */
-	UINT count		/* Number of sectors to read */
-)
-{
-  DRESULT res;
-
-  res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
-  return res;
-}
-
-/**
-  * @brief  Writes Sector(s)
-  * @param  pdrv: Physical drive number (0..)
-  * @param  *buff: Data to be written
-  * @param  sector: Sector address (LBA)
-  * @param  count: Number of sectors to write (1..128)
-  * @retval DRESULT: Operation result
-  */
-#if _USE_WRITE == 1
-DRESULT disk_write (
-	BYTE pdrv,		/* Physical drive nmuber to identify the drive */
-	const BYTE *buff,	/* Data to be written */
-	DWORD sector,		/* Sector address in LBA */
-	UINT count        	/* Number of sectors to write */
-)
-{
-  DRESULT res;
-
-  res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
-  return res;
-}
-#endif /* _USE_WRITE == 1 */
-
-/**
-  * @brief  I/O control operation
-  * @param  pdrv: Physical drive number (0..)
-  * @param  cmd: Control code
-  * @param  *buff: Buffer to send/receive control data
-  * @retval DRESULT: Operation result
-  */
-#if _USE_IOCTL == 1
-DRESULT disk_ioctl (
-	BYTE pdrv,		/* Physical drive nmuber (0..) */
-	BYTE cmd,		/* Control code */
-	void *buff		/* Buffer to send/receive control data */
-)
-{
-  DRESULT res;
-
-  res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
-  return res;
-}
-#endif /* _USE_IOCTL == 1 */
-
-/**
-  * @brief  Gets Time from RTC
-  * @param  None
-  * @retval Time in DWORD
-  */
-__weak DWORD get_fattime (void)
-{
-  return 0;
-}
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-

+ 0 - 80
Middlewares/Third_Party/FatFs/src/diskio.h

@@ -1,80 +0,0 @@
-/*-----------------------------------------------------------------------/
-/  Low level disk interface modlue include file   (C)ChaN, 2014          /
-/-----------------------------------------------------------------------*/
-
-#ifndef _DISKIO_DEFINED
-#define _DISKIO_DEFINED
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define _USE_WRITE	1	/* 1: Enable disk_write function */
-#define _USE_IOCTL	1	/* 1: Enable disk_ioctl function */
-
-#include "integer.h"
-
-
-/* Status of Disk Functions */
-typedef BYTE	DSTATUS;
-
-/* Results of Disk Functions */
-typedef enum {
-	RES_OK = 0,		/* 0: Successful */
-	RES_ERROR,		/* 1: R/W Error */
-	RES_WRPRT,		/* 2: Write Protected */
-	RES_NOTRDY,		/* 3: Not Ready */
-	RES_PARERR		/* 4: Invalid Parameter */
-} DRESULT;
-
-
-/*---------------------------------------*/
-/* Prototypes for disk control functions */
-
-
-DSTATUS disk_initialize (BYTE pdrv);
-DSTATUS disk_status (BYTE pdrv);
-DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
-DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
-DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
-DWORD get_fattime (void);
-
-/* Disk Status Bits (DSTATUS) */
-
-#define STA_NOINIT		0x01	/* Drive not initialized */
-#define STA_NODISK		0x02	/* No medium in the drive */
-#define STA_PROTECT		0x04	/* Write protected */
-
-
-/* Command code for disk_ioctrl fucntion */
-
-/* Generic command (Used by FatFs) */
-#define CTRL_SYNC		0	/* Complete pending write process (needed at _FS_READONLY == 0) */
-#define GET_SECTOR_COUNT	1	/* Get media size (needed at _USE_MKFS == 1) */
-#define GET_SECTOR_SIZE		2	/* Get sector size (needed at _MAX_SS != _MIN_SS) */
-#define GET_BLOCK_SIZE		3	/* Get erase block size (needed at _USE_MKFS == 1) */
-#define CTRL_TRIM		4	/* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
-
-/* Generic command (Not used by FatFs) */
-#define CTRL_POWER			5	/* Get/Set power status */
-#define CTRL_LOCK			6	/* Lock/Unlock media removal */
-#define CTRL_EJECT			7	/* Eject media */
-#define CTRL_FORMAT			8	/* Create physical format on the media */
-
-/* MMC/SDC specific ioctl command */
-#define MMC_GET_TYPE		10	/* Get card type */
-#define MMC_GET_CSD			11	/* Get CSD */
-#define MMC_GET_CID			12	/* Get CID */
-#define MMC_GET_OCR			13	/* Get OCR */
-#define MMC_GET_SDSTAT		14	/* Get SD status */
-
-/* ATA/CF specific ioctl command */
-#define ATA_GET_REV			20	/* Get F/W revision */
-#define ATA_GET_MODEL		21	/* Get model name */
-#define ATA_GET_SN			22	/* Get serial number */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

Разлика између датотеке није приказан због своје велике величине
+ 0 - 6140
Middlewares/Third_Party/FatFs/src/ff.c


+ 0 - 361
Middlewares/Third_Party/FatFs/src/ff.h

@@ -1,361 +0,0 @@
-/*----------------------------------------------------------------------------/
-/  FatFs - Generic FAT file system module  R0.12c                             /
-/-----------------------------------------------------------------------------/
-/
-/ Copyright (C) 2017, ChaN, all right reserved.
-/
-/ FatFs module is an open source software. Redistribution and use of FatFs in
-/ source and binary forms, with or without modification, are permitted provided
-/ that the following condition is met:
-
-/ 1. Redistributions of source code must retain the above copyright notice,
-/    this condition and the following disclaimer.
-/
-/ This software is provided by the copyright holder and contributors "AS IS"
-/ and any warranties related to this software are DISCLAIMED.
-/ The copyright owner or contributors be NOT LIABLE for any damages caused
-/ by use of this software.
-/----------------------------------------------------------------------------*/
-
-
-#ifndef _FATFS
-#define _FATFS	68300	/* Revision ID */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "integer.h"	/* Basic integer types */
-#include "ffconf.h"		/* FatFs configuration options */
-
-#if _FATFS != _FFCONF
-#error Wrong configuration file (ffconf.h).
-#endif
-
-
-
-/* Definitions of volume management */
-
-#if _MULTI_PARTITION		/* Multiple partition configuration */
-typedef struct {
-	BYTE pd;	/* Physical drive number */
-	BYTE pt;	/* Partition: 0:Auto detect, 1-4:Forced partition) */
-} PARTITION;
-extern PARTITION VolToPart[];	/* Volume - Partition resolution table */
-#endif
-
-
-
-/* Type of path name strings on FatFs API */
-
-#if _LFN_UNICODE			/* Unicode (UTF-16) string */
-#if _USE_LFN == 0
-#error _LFN_UNICODE must be 0 at non-LFN cfg.
-#endif
-#ifndef _INC_TCHAR
-typedef WCHAR TCHAR;
-#define _T(x) L ## x
-#define _TEXT(x) L ## x
-#endif
-#else						/* ANSI/OEM string */
-#ifndef _INC_TCHAR
-typedef char TCHAR;
-#define _T(x) x
-#define _TEXT(x) x
-#endif
-#endif
-
-
-
-/* Type of file size variables */
-
-#if _FS_EXFAT
-#if _USE_LFN == 0
-#error LFN must be enabled when enable exFAT
-#endif
-typedef QWORD FSIZE_t;
-#else
-typedef DWORD FSIZE_t;
-#endif
-
-
-
-/* File system object structure (FATFS) */
-
-typedef struct {
-	BYTE	fs_type;		/* File system type (0:N/A) */
-	BYTE	drv;			/* Physical drive number */
-	BYTE	n_fats;			/* Number of FATs (1 or 2) */
-	BYTE	wflag;			/* win[] flag (b0:dirty) */
-	BYTE	fsi_flag;		/* FSINFO flags (b7:disabled, b0:dirty) */
-	WORD	id;				/* File system mount ID */
-	WORD	n_rootdir;		/* Number of root directory entries (FAT12/16) */
-	WORD	csize;			/* Cluster size [sectors] */
-#if _MAX_SS != _MIN_SS
-	WORD	ssize;			/* Sector size (512, 1024, 2048 or 4096) */
-#endif
-#if _USE_LFN != 0
-	WCHAR*	lfnbuf;			/* LFN working buffer */
-#endif
-#if _FS_EXFAT
-	BYTE*	dirbuf;			/* Directory entry block scratchpad buffer */
-#endif
-#if _FS_REENTRANT
-	_SYNC_t	sobj;			/* Identifier of sync object */
-#endif
-#if !_FS_READONLY
-	DWORD	last_clst;		/* Last allocated cluster */
-	DWORD	free_clst;		/* Number of free clusters */
-#endif
-#if _FS_RPATH != 0
-	DWORD	cdir;			/* Current directory start cluster (0:root) */
-#if _FS_EXFAT
-	DWORD	cdc_scl;		/* Containing directory start cluster (invalid when cdir is 0) */
-	DWORD	cdc_size;		/* b31-b8:Size of containing directory, b7-b0: Chain status */
-	DWORD	cdc_ofs;		/* Offset in the containing directory (invalid when cdir is 0) */
-#endif
-#endif
-	DWORD	n_fatent;		/* Number of FAT entries (number of clusters + 2) */
-	DWORD	fsize;			/* Size of an FAT [sectors] */
-	DWORD	volbase;		/* Volume base sector */
-	DWORD	fatbase;		/* FAT base sector */
-	DWORD	dirbase;		/* Root directory base sector/cluster */
-	DWORD	database;		/* Data base sector */
-	DWORD	winsect;		/* Current sector appearing in the win[] */
-	BYTE	win[_MAX_SS];	/* Disk access window for Directory, FAT (and file data at tiny cfg) */
-} FATFS;
-
-
-
-/* Object ID and allocation information (_FDID) */
-
-typedef struct {
-	FATFS*	fs;			/* Pointer to the owner file system object */
-	WORD	id;			/* Owner file system mount ID */
-	BYTE	attr;		/* Object attribute */
-	BYTE	stat;		/* Object chain status (b1-0: =0:not contiguous, =2:contiguous (no data on FAT), =3:flagmented in this session, b2:sub-directory stretched) */
-	DWORD	sclust;		/* Object start cluster (0:no cluster or root directory) */
-	FSIZE_t	objsize;	/* Object size (valid when sclust != 0) */
-#if _FS_EXFAT
-	DWORD	n_cont;		/* Size of first fragment, clusters - 1 (valid when stat == 3) */
-	DWORD	n_frag;		/* Size of last fragment needs to be written (valid when not zero) */
-	DWORD	c_scl;		/* Containing directory start cluster (valid when sclust != 0) */
-	DWORD	c_size;		/* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
-	DWORD	c_ofs;		/* Offset in the containing directory (valid when sclust != 0 and non-directory object) */
-#endif
-#if _FS_LOCK != 0
-	UINT	lockid;		/* File lock ID origin from 1 (index of file semaphore table Files[]) */
-#endif
-} _FDID;
-
-
-
-/* File object structure (FIL) */
-
-typedef struct {
-	_FDID	obj;			/* Object identifier (must be the 1st member to detect invalid object pointer) */
-	BYTE	flag;			/* File status flags */
-	BYTE	err;			/* Abort flag (error code) */
-	FSIZE_t	fptr;			/* File read/write pointer (Zeroed on file open) */
-	DWORD	clust;			/* Current cluster of fpter (invalid when fptr is 0) */
-	DWORD	sect;			/* Sector number appearing in buf[] (0:invalid) */
-#if !_FS_READONLY
-	DWORD	dir_sect;		/* Sector number containing the directory entry */
-	BYTE*	dir_ptr;		/* Pointer to the directory entry in the win[] */
-#endif
-#if _USE_FASTSEEK
-	DWORD*	cltbl;			/* Pointer to the cluster link map table (nulled on open, set by application) */
-#endif
-#if !_FS_TINY
-	BYTE	buf[_MAX_SS];	/* File private data read/write window */
-#endif
-} FIL;
-
-
-
-/* Directory object structure (DIR) */
-
-typedef struct {
-	_FDID	obj;			/* Object identifier */
-	DWORD	dptr;			/* Current read/write offset */
-	DWORD	clust;			/* Current cluster */
-	DWORD	sect;			/* Current sector (0:Read operation has terminated) */
-	BYTE*	dir;			/* Pointer to the directory item in the win[] */
-	BYTE	fn[12];			/* SFN (in/out) {body[8],ext[3],status[1]} */
-#if _USE_LFN != 0
-	DWORD	blk_ofs;		/* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
-#endif
-#if _USE_FIND
-	const TCHAR* pat;		/* Pointer to the name matching pattern */
-#endif
-} DIR;
-
-
-
-/* File information structure (FILINFO) */
-
-typedef struct {
-	FSIZE_t	fsize;			/* File size */
-	WORD	fdate;			/* Modified date */
-	WORD	ftime;			/* Modified time */
-	BYTE	fattrib;		/* File attribute */
-#if _USE_LFN != 0
-	TCHAR	altname[13];			/* Alternative file name */
-	TCHAR	fname[_MAX_LFN + 1];	/* Primary file name */
-#else
-	TCHAR	fname[13];		/* File name */
-#endif
-} FILINFO;
-
-
-
-/* File function return code (FRESULT) */
-
-typedef enum {
-	FR_OK = 0,				/* (0) Succeeded */
-	FR_DISK_ERR,			/* (1) A hard error occurred in the low level disk I/O layer */
-	FR_INT_ERR,				/* (2) Assertion failed */
-	FR_NOT_READY,			/* (3) The physical drive cannot work */
-	FR_NO_FILE,				/* (4) Could not find the file */
-	FR_NO_PATH,				/* (5) Could not find the path */
-	FR_INVALID_NAME,		/* (6) The path name format is invalid */
-	FR_DENIED,				/* (7) Access denied due to prohibited access or directory full */
-	FR_EXIST,				/* (8) Access denied due to prohibited access */
-	FR_INVALID_OBJECT,		/* (9) The file/directory object is invalid */
-	FR_WRITE_PROTECTED,		/* (10) The physical drive is write protected */
-	FR_INVALID_DRIVE,		/* (11) The logical drive number is invalid */
-	FR_NOT_ENABLED,			/* (12) The volume has no work area */
-	FR_NO_FILESYSTEM,		/* (13) There is no valid FAT volume */
-	FR_MKFS_ABORTED,		/* (14) The f_mkfs() aborted due to any problem */
-	FR_TIMEOUT,				/* (15) Could not get a grant to access the volume within defined period */
-	FR_LOCKED,				/* (16) The operation is rejected according to the file sharing policy */
-	FR_NOT_ENOUGH_CORE,		/* (17) LFN working buffer could not be allocated */
-	FR_TOO_MANY_OPEN_FILES,	/* (18) Number of open files > _FS_LOCK */
-	FR_INVALID_PARAMETER	/* (19) Given parameter is invalid */
-} FRESULT;
-
-
-
-/*--------------------------------------------------------------*/
-/* FatFs module application interface                           */
-
-FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode);				/* Open or create a file */
-FRESULT f_close (FIL* fp);											/* Close an open file object */
-FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br);			/* Read data from the file */
-FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw);	/* Write data to the file */
-FRESULT f_lseek (FIL* fp, FSIZE_t ofs);								/* Move file pointer of the file object */
-FRESULT f_truncate (FIL* fp);										/* Truncate the file */
-FRESULT f_sync (FIL* fp);											/* Flush cached data of the writing file */
-FRESULT f_opendir (DIR* dp, const TCHAR* path);						/* Open a directory */
-FRESULT f_closedir (DIR* dp);										/* Close an open directory */
-FRESULT f_readdir (DIR* dp, FILINFO* fno);							/* Read a directory item */
-FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);	/* Find first file */
-FRESULT f_findnext (DIR* dp, FILINFO* fno);							/* Find next file */
-FRESULT f_mkdir (const TCHAR* path);								/* Create a sub directory */
-FRESULT f_unlink (const TCHAR* path);								/* Delete an existing file or directory */
-FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new);	/* Rename/Move a file or directory */
-FRESULT f_stat (const TCHAR* path, FILINFO* fno);					/* Get file status */
-FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask);			/* Change attribute of a file/dir */
-FRESULT f_utime (const TCHAR* path, const FILINFO* fno);			/* Change timestamp of a file/dir */
-FRESULT f_chdir (const TCHAR* path);								/* Change current directory */
-FRESULT f_chdrive (const TCHAR* path);								/* Change current drive */
-FRESULT f_getcwd (TCHAR* buff, UINT len);							/* Get current directory */
-FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs);	/* Get number of free clusters on the drive */
-FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn);	/* Get volume label */
-FRESULT f_setlabel (const TCHAR* label);							/* Set volume label */
-FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);	/* Forward data to the stream */
-FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt);					/* Allocate a contiguous block to the file */
-FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);			/* Mount/Unmount a logical drive */
-FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len);	/* Create a FAT volume */
-FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work);			/* Divide a physical drive into some partitions */
-int f_putc (TCHAR c, FIL* fp);										/* Put a character to the file */
-int f_puts (const TCHAR* str, FIL* cp);								/* Put a string to the file */
-int f_printf (FIL* fp, const TCHAR* str, ...);						/* Put a formatted string to the file */
-TCHAR* f_gets (TCHAR* buff, int len, FIL* fp);						/* Get a string from the file */
-
-#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
-#define f_error(fp) ((fp)->err)
-#define f_tell(fp) ((fp)->fptr)
-#define f_size(fp) ((fp)->obj.objsize)
-#define f_rewind(fp) f_lseek((fp), 0)
-#define f_rewinddir(dp) f_readdir((dp), 0)
-#define f_rmdir(path) f_unlink(path)
-
-#ifndef EOF
-#define EOF (-1)
-#endif
-
-
-
-
-/*--------------------------------------------------------------*/
-/* Additional user defined functions                            */
-
-/* RTC function */
-#if !_FS_READONLY && !_FS_NORTC
-DWORD get_fattime (void);
-#endif
-
-/* Unicode support functions */
-#if _USE_LFN != 0						/* Unicode - OEM code conversion */
-WCHAR ff_convert (WCHAR chr, UINT dir);	/* OEM-Unicode bidirectional conversion */
-WCHAR ff_wtoupper (WCHAR chr);			/* Unicode upper-case conversion */
-#if _USE_LFN == 3						/* Memory functions */
-void* ff_memalloc (UINT msize);			/* Allocate memory block */
-void ff_memfree (void* mblock);			/* Free memory block */
-#endif
-#endif
-
-/* Sync functions */
-#if _FS_REENTRANT
-int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj);	/* Create a sync object */
-int ff_req_grant (_SYNC_t sobj);				/* Lock sync object */
-void ff_rel_grant (_SYNC_t sobj);				/* Unlock sync object */
-int ff_del_syncobj (_SYNC_t sobj);				/* Delete a sync object */
-#endif
-
-
-
-
-/*--------------------------------------------------------------*/
-/* Flags and offset address                                     */
-
-
-/* File access mode and open method flags (3rd argument of f_open) */
-#define	FA_READ				0x01
-#define	FA_WRITE			0x02
-#define	FA_OPEN_EXISTING	0x00
-#define	FA_CREATE_NEW		0x04
-#define	FA_CREATE_ALWAYS	0x08
-#define	FA_OPEN_ALWAYS		0x10
-#define	FA_OPEN_APPEND		0x30
-
-/* Fast seek controls (2nd argument of f_lseek) */
-#define CREATE_LINKMAP	((FSIZE_t)0 - 1)
-
-/* Format options (2nd argument of f_mkfs) */
-#define FM_FAT		0x01
-#define FM_FAT32	0x02
-#define FM_EXFAT	0x04
-#define FM_ANY		0x07
-#define FM_SFD		0x08
-
-/* Filesystem type (FATFS.fs_type) */
-#define FS_FAT12	1
-#define FS_FAT16	2
-#define FS_FAT32	3
-#define FS_EXFAT	4
-
-/* File attribute bits for directory entry (FILINFO.fattrib) */
-#define	AM_RDO	0x01	/* Read only */
-#define	AM_HID	0x02	/* Hidden */
-#define	AM_SYS	0x04	/* System */
-#define AM_DIR	0x10	/* Directory */
-#define AM_ARC	0x20	/* Archive */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _FATFS */

+ 0 - 122
Middlewares/Third_Party/FatFs/src/ff_gen_drv.c

@@ -1,122 +0,0 @@
-/**
-  ******************************************************************************
-  * @file    ff_gen_drv.c
-  * @author  MCD Application Team
-  * @brief   FatFs generic low level driver.
-  *****************************************************************************
-  * @attention
-  *
-  * Copyright (c) 2017 STMicroelectronics. All rights reserved.
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                       opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-**/
-/* Includes ------------------------------------------------------------------*/
-#include "ff_gen_drv.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-Disk_drvTypeDef disk = {{0},{0},{0},0};
-
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/**
-  * @brief  Links a compatible diskio driver/lun id and increments the number of active
-  *         linked drivers.
-  * @note   The number of linked drivers (volumes) is up to 10 due to FatFs limits.
-  * @param  drv: pointer to the disk IO Driver structure
-  * @param  path: pointer to the logical drive path
-  * @param  lun : only used for USB Key Disk to add multi-lun management
-            else the parameter must be equal to 0
-  * @retval Returns 0 in case of success, otherwise 1.
-  */
-uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun)
-{
-  uint8_t ret = 1;
-  uint8_t DiskNum = 0;
-
-  if(disk.nbr < _VOLUMES)
-  {
-    disk.is_initialized[disk.nbr] = 0;
-    disk.drv[disk.nbr] = drv;
-    disk.lun[disk.nbr] = lun;
-    DiskNum = disk.nbr++;
-    path[0] = DiskNum + '0';
-    path[1] = ':';
-    path[2] = '/';
-    path[3] = 0;
-    ret = 0;
-  }
-
-  return ret;
-}
-
-/**
-  * @brief  Links a compatible diskio driver and increments the number of active
-  *         linked drivers.
-  * @note   The number of linked drivers (volumes) is up to 10 due to FatFs limits
-  * @param  drv: pointer to the disk IO Driver structure
-  * @param  path: pointer to the logical drive path
-  * @retval Returns 0 in case of success, otherwise 1.
-  */
-uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path)
-{
-  return FATFS_LinkDriverEx(drv, path, 0);
-}
-
-/**
-  * @brief  Unlinks a diskio driver and decrements the number of active linked
-  *         drivers.
-  * @param  path: pointer to the logical drive path
-  * @param  lun : not used
-  * @retval Returns 0 in case of success, otherwise 1.
-  */
-uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
-{
-  uint8_t DiskNum = 0;
-  uint8_t ret = 1;
-
-  if(disk.nbr >= 1)
-  {
-    DiskNum = path[0] - '0';
-    if(disk.drv[DiskNum] != 0)
-    {
-      disk.drv[DiskNum] = 0;
-      disk.lun[DiskNum] = 0;
-      disk.nbr--;
-      ret = 0;
-    }
-  }
-
-  return ret;
-}
-
-/**
-  * @brief  Unlinks a diskio driver and decrements the number of active linked
-  *         drivers.
-  * @param  path: pointer to the logical drive path
-  * @retval Returns 0 in case of success, otherwise 1.
-  */
-uint8_t FATFS_UnLinkDriver(char *path)
-{
-  return FATFS_UnLinkDriverEx(path, 0);
-}
-
-/**
-  * @brief  Gets number of linked drivers to the FatFs module.
-  * @param  None
-  * @retval Number of attached drivers.
-  */
-uint8_t FATFS_GetAttachedDriversNbr(void)
-{
-  return disk.nbr;
-}
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-

+ 0 - 80
Middlewares/Third_Party/FatFs/src/ff_gen_drv.h

@@ -1,80 +0,0 @@
-/**
-  ******************************************************************************
-  * @file    ff_gen_drv.h
-  * @author  MCD Application Team
-  * @brief   Header for ff_gen_drv.c module.
-  *****************************************************************************
-  * @attention
-  *
-  * Copyright (c) 2017 STMicroelectronics. All rights reserved.
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                       opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-**/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __FF_GEN_DRV_H
-#define __FF_GEN_DRV_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include "diskio.h"
-#include "ff.h"
-#include "stdint.h"
-
-
-/* Exported types ------------------------------------------------------------*/
-
-/**
-  * @brief  Disk IO Driver structure definition
-  */
-typedef struct
-{
-  DSTATUS (*disk_initialize) (BYTE);                     /*!< Initialize Disk Drive                     */
-  DSTATUS (*disk_status)     (BYTE);                     /*!< Get Disk Status                           */
-  DRESULT (*disk_read)       (BYTE, BYTE*, DWORD, UINT);       /*!< Read Sector(s)                            */
-#if _USE_WRITE == 1
-  DRESULT (*disk_write)      (BYTE, const BYTE*, DWORD, UINT); /*!< Write Sector(s) when _USE_WRITE = 0       */
-#endif /* _USE_WRITE == 1 */
-#if _USE_IOCTL == 1
-  DRESULT (*disk_ioctl)      (BYTE, BYTE, void*);              /*!< I/O control operation when _USE_IOCTL = 1 */
-#endif /* _USE_IOCTL == 1 */
-
-}Diskio_drvTypeDef;
-
-/**
-  * @brief  Global Disk IO Drivers structure definition
-  */
-typedef struct
-{
-  uint8_t                 is_initialized[_VOLUMES];
-  const Diskio_drvTypeDef *drv[_VOLUMES];
-  uint8_t                 lun[_VOLUMES];
-  volatile uint8_t        nbr;
-
-}Disk_drvTypeDef;
-
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path);
-uint8_t FATFS_UnLinkDriver(char *path);
-uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, BYTE lun);
-uint8_t FATFS_UnLinkDriverEx(char *path, BYTE lun);
-uint8_t FATFS_GetAttachedDriversNbr(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __FF_GEN_DRV_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-

+ 0 - 341
Middlewares/Third_Party/FatFs/src/ffconf_template.h

@@ -1,341 +0,0 @@
-/*----------------------------------------------------------------------------/
-/  FatFs - Generic FAT file system module  R0.12c                             /
-/-----------------------------------------------------------------------------/
-/
-/ Copyright (C) 2017, ChaN, all right reserved.
-/ Portions Copyright (C) STMicroelectronics, all right reserved.
-/
-/ FatFs module is an open source software. Redistribution and use of FatFs in
-/ source and binary forms, with or without modification, are permitted provided
-/ that the following condition is met:
-
-/ 1. Redistributions of source code must retain the above copyright notice,
-/    this condition and the following disclaimer.
-/
-/ This software is provided by the copyright holder and contributors "AS IS"
-/ and any warranties related to this software are DISCLAIMED.
-/ The copyright owner or contributors be NOT LIABLE for any damages caused
-/ by use of this software.
-/----------------------------------------------------------------------------*/
-
-
-/*---------------------------------------------------------------------------/
-/  FatFs - FAT file system module configuration file
-/---------------------------------------------------------------------------*/
-
-#define _FFCONF 68300	/* Revision ID */
-
-/*---------------------------------------------------------------------------/
-/ Function Configurations
-/---------------------------------------------------------------------------*/
-
-#define _FS_READONLY	0
-/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
-/  Read-only configuration removes writing API functions, f_write(), f_sync(),
-/  f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
-/  and optional writing functions as well. */
-
-
-#define _FS_MINIMIZE	0
-/* This option defines minimization level to remove some basic API functions.
-/
-/   0: All basic functions are enabled.
-/   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
-/      are removed.
-/   2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
-/   3: f_lseek() function is removed in addition to 2. */
-
-
-#define	_USE_STRFUNC	0
-/* This option switches string functions, f_gets(), f_putc(), f_puts() and
-/  f_printf().
-/
-/  0: Disable string functions.
-/  1: Enable without LF-CRLF conversion.
-/  2: Enable with LF-CRLF conversion. */
-
-
-#define _USE_FIND		0
-/* This option switches filtered directory read functions, f_findfirst() and
-/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
-
-
-#define	_USE_MKFS		1
-/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
-
-
-#define	_USE_FASTSEEK	1
-/* This option switches fast seek function. (0:Disable or 1:Enable) */
-
-
-#define	_USE_EXPAND		0
-/* This option switches f_expand function. (0:Disable or 1:Enable) */
-
-
-#define _USE_CHMOD		0
-/* This option switches attribute manipulation functions, f_chmod() and f_utime().
-/  (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */
-
-
-#define _USE_LABEL		0
-/* This option switches volume label functions, f_getlabel() and f_setlabel().
-/  (0:Disable or 1:Enable) */
-
-
-#define	_USE_FORWARD	0
-/* This option switches f_forward() function. (0:Disable or 1:Enable) */
-
-
-/*---------------------------------------------------------------------------/
-/ Locale and Namespace Configurations
-/---------------------------------------------------------------------------*/
-
-#define _CODE_PAGE	850
-/* This option specifies the OEM code page to be used on the target system.
-/  Incorrect setting of the code page can cause a file open failure.
-/
-/   1   - ASCII (No extended character. Non-LFN cfg. only)
-/   437 - U.S.
-/   720 - Arabic
-/   737 - Greek
-/   771 - KBL
-/   775 - Baltic
-/   850 - Latin 1
-/   852 - Latin 2
-/   855 - Cyrillic
-/   857 - Turkish
-/   860 - Portuguese
-/   861 - Icelandic
-/   862 - Hebrew
-/   863 - Canadian French
-/   864 - Arabic
-/   865 - Nordic
-/   866 - Russian
-/   869 - Greek 2
-/   932 - Japanese (DBCS)
-/   936 - Simplified Chinese (DBCS)
-/   949 - Korean (DBCS)
-/   950 - Traditional Chinese (DBCS)
-*/
-
-
-#define	_USE_LFN	3
-#define	_MAX_LFN	255
-/* The _USE_LFN switches the support of long file name (LFN).
-/
-/   0: Disable support of LFN. _MAX_LFN has no effect.
-/   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
-/   2: Enable LFN with dynamic working buffer on the STACK.
-/   3: Enable LFN with dynamic working buffer on the HEAP.
-/
-/  To enable the LFN, Unicode handling functions (option/unicode.c) must be added
-/  to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and
-/  additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255.
-/  It should be set 255 to support full featured LFN operations.
-/  When use stack for the working buffer, take care on stack overflow. When use heap
-/  memory for the working buffer, memory management functions, ff_memalloc() and
-/  ff_memfree(), must be added to the project. */
-
-
-#define	_LFN_UNICODE	0
-/* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16)
-/  To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1.
-/  This option also affects behavior of string I/O functions. */
-
-
-#define _STRF_ENCODE	3
-/* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to
-/  be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
-/
-/  0: ANSI/OEM
-/  1: UTF-16LE
-/  2: UTF-16BE
-/  3: UTF-8
-/
-/  This option has no effect when _LFN_UNICODE == 0. */
-
-
-#define _FS_RPATH	0
-/* This option configures support of relative path.
-/
-/   0: Disable relative path and remove related functions.
-/   1: Enable relative path. f_chdir() and f_chdrive() are available.
-/   2: f_getcwd() function is available in addition to 1.
-*/
-
-
-/*---------------------------------------------------------------------------/
-/ Drive/Volume Configurations
-/---------------------------------------------------------------------------*/
-
-#define _VOLUMES	2
-/* Number of volumes (logical drives) to be used. */
-
-
-#define _STR_VOLUME_ID	0
-#define _VOLUME_STRS	"RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
-/* _STR_VOLUME_ID switches string support of volume ID.
-/  When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
-/  number in the path name. _VOLUME_STRS defines the drive ID strings for each
-/  logical drives. Number of items must be equal to _VOLUMES. Valid characters for
-/  the drive ID strings are: A-Z and 0-9. */
-
-
-#define	_MULTI_PARTITION	0
-/* This option switches support of multi-partition on a physical drive.
-/  By default (0), each logical drive number is bound to the same physical drive
-/  number and only an FAT volume found on the physical drive will be mounted.
-/  When multi-partition is enabled (1), each logical drive number can be bound to
-/  arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
-/  funciton will be available. */
-
-
-#define	_MIN_SS		512
-#define	_MAX_SS		512
-/* These options configure the range of sector size to be supported. (512, 1024,
-/  2048 or 4096) Always set both 512 for most systems, all type of memory cards and
-/  harddisk. But a larger value may be required for on-board flash memory and some
-/  type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
-/  to variable sector size and GET_SECTOR_SIZE command must be implemented to the
-/  disk_ioctl() function. */
-
-
-#define	_USE_TRIM	0
-/* This option switches support of ATA-TRIM. (0:Disable or 1:Enable)
-/  To enable Trim function, also CTRL_TRIM command should be implemented to the
-/  disk_ioctl() function. */
-
-
-#define _FS_NOFSINFO	0
-/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
-/  option, and f_getfree() function at first time after volume mount will force
-/  a full FAT scan. Bit 1 controls the use of last allocated cluster number.
-/
-/  bit0=0: Use free cluster count in the FSINFO if available.
-/  bit0=1: Do not trust free cluster count in the FSINFO.
-/  bit1=0: Use last allocated cluster number in the FSINFO if available.
-/  bit1=1: Do not trust last allocated cluster number in the FSINFO.
-*/
-
-
-
-/*---------------------------------------------------------------------------/
-/ System Configurations
-/---------------------------------------------------------------------------*/
-
-#define	_FS_TINY	0
-/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
-/  At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes.
-/  Instead of private sector buffer eliminated from the file object, common sector
-/  buffer in the file system object (FATFS) is used for the file data transfer. */
-
-
-#define _FS_EXFAT	0
-/* This option switches support of exFAT file system. (0:Disable or 1:Enable)
-/  When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1)
-/  Note that enabling exFAT discards C89 compatibility. */
-
-
-#define _FS_NORTC	0
-#define _NORTC_MON	1
-#define _NORTC_MDAY	1
-#define _NORTC_YEAR	2016
-/* The option _FS_NORTC switches timestamp functiton. If the system does not have
-/  any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable
-/  the timestamp function. All objects modified by FatFs will have a fixed timestamp
-/  defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time.
-/  To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be
-/  added to the project to get current time form real-time clock. _NORTC_MON,
-/  _NORTC_MDAY and _NORTC_YEAR have no effect.
-/  These options have no effect at read-only configuration (_FS_READONLY = 1). */
-
-
-#define	_FS_LOCK	2
-/* The option _FS_LOCK switches file lock function to control duplicated file open
-/  and illegal operation to open objects. This option must be 0 when _FS_READONLY
-/  is 1.
-/
-/  0:  Disable file lock function. To avoid volume corruption, application program
-/      should avoid illegal open, remove and rename to the open objects.
-/  >0: Enable file lock function. The value defines how many files/sub-directories
-/      can be opened simultaneously under file lock control. Note that the file
-/      lock control is independent of re-entrancy. */
-
-#define _FS_REENTRANT	0
-#define _USE_MUTEX	0
-/* Use CMSIS-OS mutexes as _SYNC_t object instead of Semaphores */
-
-#if _FS_REENTRANT
-
-#include "cmsis_os.h"
-#define _FS_TIMEOUT		1000
-
-#if _USE_MUTEX
-
-#if (osCMSIS < 0x20000U)
-#define _SYNC_t         osMutexId
-#else
-#define _SYNC_t         osMutexId_t
-#endif
-
-#else
-#if (osCMSIS < 0x20000U)
-#define _SYNC_t         osSemaphoreId
-#else
-#define	_SYNC_t         osSemaphoreId_t
-#endif
-
-#endif
-#endif //_FS_REENTRANT
-/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
-/  module itself. Note that regardless of this option, file access to different
-/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
-/  and f_fdisk() function, are always not re-entrant. Only file/directory access
-/  to the same volume is under control of this function.
-/
-/   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
-/   1: Enable re-entrancy. Also user provided synchronization handlers,
-/      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
-/      function, must be added to the project. Samples are available in
-/      option/syscall.c.
-/
-/  The _FS_TIMEOUT defines timeout period in unit of time tick.
-/  The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
-/  SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
-/  included somewhere in the scope of ff.h. */
-
-/* #include <windows.h>	// O/S definitions  */
-
-#if _USE_LFN == 3
-
-#if !defined(ff_malloc) || !defined(ff_free)
-#include <stdlib.h>
-#endif
-
-#if !defined(ff_malloc)
-#define ff_malloc malloc
-#endif
-
-#if !defined(ff_free)
-#define ff_free free
-#endif
-
-/* by default the system malloc/free are used, but when the FreeRTOS is enabled
-/ the macros pvPortMalloc()/vportFree() to be used thus uncomment the code below
-/
-*/
-/*
-#if !defined(ff_malloc) || !defined(ff_free)
-#include "cmsis_os.h"
-#endif
-
-#if !defined(ff_malloc)
-#define ff_malloc pvPortMalloc
-#endif
-
-#if !defined(ff_free)
-#define ff_free vPortFree
-#endif
-*/
-#endif
-/*--- End of configuration options ---*/

+ 0 - 38
Middlewares/Third_Party/FatFs/src/integer.h

@@ -1,38 +0,0 @@
-/*-------------------------------------------*/
-/* Integer type definitions for FatFs module */
-/*-------------------------------------------*/
-
-#ifndef _FF_INTEGER
-#define _FF_INTEGER
-
-#ifdef _WIN32	/* FatFs development platform */
-
-#include <windows.h>
-#include <tchar.h>
-typedef unsigned __int64 QWORD;
-
-
-#else			/* Embedded platform */
-
-/* These types MUST be 16-bit or 32-bit */
-typedef int				INT;
-typedef unsigned int	UINT;
-
-/* This type MUST be 8-bit */
-typedef unsigned char	BYTE;
-
-/* These types MUST be 16-bit */
-typedef short			SHORT;
-typedef unsigned short	WORD;
-typedef unsigned short	WCHAR;
-
-/* These types MUST be 32-bit */
-typedef long			LONG;
-typedef unsigned long	DWORD;
-
-/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
-typedef unsigned long long QWORD;
-
-#endif
-
-#endif

Разлика између датотеке није приказан због своје велике величине
+ 0 - 3870
Middlewares/Third_Party/FatFs/src/option/cc932.c


Разлика између датотеке није приказан због своје велике величине
+ 0 - 11045
Middlewares/Third_Party/FatFs/src/option/cc936.c


Разлика између датотеке није приказан због своје велике величине
+ 0 - 8674
Middlewares/Third_Party/FatFs/src/option/cc949.c


Разлика између датотеке није приказан због своје велике величине
+ 0 - 6900
Middlewares/Third_Party/FatFs/src/option/cc950.c


Разлика између датотеке није приказан због своје велике величине
+ 0 - 388
Middlewares/Third_Party/FatFs/src/option/ccsbcs.c


+ 0 - 177
Middlewares/Third_Party/FatFs/src/option/syscall.c

@@ -1,177 +0,0 @@
-/*------------------------------------------------------------------------*/
-/* Sample code of OS dependent controls for FatFs                         */
-/* (C)ChaN, 2014                                                          */
-/*   Portions COPYRIGHT 2017 STMicroelectronics                           */
-/*   Portions Copyright (C) 2014, ChaN, all right reserved                */
-/*------------------------------------------------------------------------*/
-
-/**
-  ******************************************************************************
-  * @attention
-  *
-  * Copyright (c) 2017 STMicroelectronics. All rights reserved.
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                       opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-**/
-
-
-
-#include "../ff.h"
-
-
-#if _FS_REENTRANT
-/*------------------------------------------------------------------------*/
-/* Create a Synchronization Object                                        */
-/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to create a new
-/  synchronization object, such as semaphore and mutex. When a 0 is returned,
-/  the f_mount() function fails with FR_INT_ERR.
-*/
-
-int ff_cre_syncobj (	/* 1:Function succeeded, 0:Could not create the sync object */
-	BYTE vol,			/* Corresponding volume (logical drive number) */
-	_SYNC_t *sobj		/* Pointer to return the created sync object */
-)
-{
-
-    int ret;
-#if _USE_MUTEX
-
-#if (osCMSIS < 0x20000U)
-    osMutexDef(MTX);
-    *sobj = osMutexCreate(osMutex(MTX));
-#else
-    *sobj = osMutexNew(NULL);
-#endif
-
-#else
-
-#if (osCMSIS < 0x20000U)
-    osSemaphoreDef(SEM);
-    *sobj = osSemaphoreCreate(osSemaphore(SEM), 1);
-#else
-    *sobj = osSemaphoreNew(1, 1, NULL);
-#endif
-
-#endif
-    ret = (*sobj != NULL);
-
-    return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Delete a Synchronization Object                                        */
-/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to delete a synchronization
-/  object that created with ff_cre_syncobj() function. When a 0 is returned,
-/  the f_mount() function fails with FR_INT_ERR.
-*/
-
-int ff_del_syncobj (	/* 1:Function succeeded, 0:Could not delete due to any error */
-	_SYNC_t sobj		/* Sync object tied to the logical drive to be deleted */
-)
-{
-#if _USE_MUTEX
-    osMutexDelete (sobj);
-#else
-    osSemaphoreDelete (sobj);
-#endif
-    return 1;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Request Grant to Access the Volume                                     */
-/*------------------------------------------------------------------------*/
-/* This function is called on entering file functions to lock the volume.
-/  When a 0 is returned, the file function fails with FR_TIMEOUT.
-*/
-
-int ff_req_grant (	/* 1:Got a grant to access the volume, 0:Could not get a grant */
-	_SYNC_t sobj	/* Sync object to wait */
-)
-{
-  int ret = 0;
-#if (osCMSIS < 0x20000U)
-
-#if _USE_MUTEX
-  if(osMutexWait(sobj, _FS_TIMEOUT) == osOK)
-#else
-  if(osSemaphoreWait(sobj, _FS_TIMEOUT) == osOK)
-#endif
-
-#else
-
-#if _USE_MUTEX
-   if(osMutexAcquire(sobj, _FS_TIMEOUT) == osOK)
-#else
-   if(osSemaphoreAcquire(sobj, _FS_TIMEOUT) == osOK)
-#endif
-
-#endif
-  {
-    ret = 1;
-  }
-
-  return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Release Grant to Access the Volume                                     */
-/*------------------------------------------------------------------------*/
-/* This function is called on leaving file functions to unlock the volume.
-*/
-
-void ff_rel_grant (
-	_SYNC_t sobj	/* Sync object to be signaled */
-)
-{
-#if _USE_MUTEX
-  osMutexRelease(sobj);
-#else
-  osSemaphoreRelease(sobj);
-#endif
-}
-
-#endif
-
-
-
-
-#if _USE_LFN == 3	/* LFN with a working buffer on the heap */
-/*------------------------------------------------------------------------*/
-/* Allocate a memory block                                                */
-/*------------------------------------------------------------------------*/
-/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
-*/
-
-void* ff_memalloc (	/* Returns pointer to the allocated memory block */
-	UINT msize		/* Number of bytes to allocate */
-)
-{
-	return ff_malloc(msize);	/* Allocate a new memory block with POSIX API */
-}
-
-
-/*------------------------------------------------------------------------*/
-/* Free a memory block                                                    */
-/*------------------------------------------------------------------------*/
-
-void ff_memfree (
-	void* mblock	/* Pointer to the memory block to free */
-)
-{
-	ff_free(mblock);	/* Discard the memory block with POSIX API */
-}
-
-#endif

+ 0 - 17
Middlewares/Third_Party/FatFs/src/option/unicode.c

@@ -1,17 +0,0 @@
-#include "../ff.h"
-
-#if _USE_LFN != 0
-
-#if   _CODE_PAGE == 932	/* Japanese Shift_JIS */
-#include "cc932.c"
-#elif _CODE_PAGE == 936	/* Simplified Chinese GBK */
-#include "cc936.c"
-#elif _CODE_PAGE == 949	/* Korean */
-#include "cc949.c"
-#elif _CODE_PAGE == 950	/* Traditional Chinese Big5 */
-#include "cc950.c"
-#else					/* Single Byte Character-Set */
-#include "ccsbcs.c"
-#endif
-
-#endif

+ 0 - 221
Middlewares/Third_Party/FatFs/src/st_readme.txt

@@ -1,221 +0,0 @@
-  @verbatim
-  ******************************************************************************
-  * @file    st_readme.txt
-  * @author  MCD Application Team
-  * @brief   This file lists the main modification done by STMicroelectronics on
-  *          FatFs for integration with STM32Cube solution.
-  *          For more details on FatFs implementation on STM32Cube, please refer
-  *          to UM1721 "Developing Applications on STM32Cube with FatFs"
-  ******************************************************************************
-  * @attention
-  *
-  * Copyright (c) 2017 STMicroelectronics. All rights reserved.
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                       opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-  @endverbatim
-
-### V2.1.4/18-10-2019 ###
-============================
-+ Fix wrong usage of the "memcpy" in the SD_Write() function
-  - drivers/sd_diskio_dma_template_bspv1.c
-  - drivers/sd_diskio_dma_template_bspv2.c
-  - drivers/sd_diskio_dma_rtos_template_bspv1.c
-  - drivers/sd_diskio_dma_rtos_template_bspv2.c
-
-+ correct the usage of the "_USE_MUTEX" config flag
-  - syscall.c
-
-### V2.1.3/26-07-2019 ###
-============================
-+ add new BSPv2 templates:
-  - drivers/sd_diskio_dma_rtos_template_bspv2.c
-  - drivers/sd_diskio_dma_template_bspv2.c
-  - drivers/sd_diskio_template_bspv2.c
-  - drivers/sdram_diskio_template_bspv2.c
-
-+ rename old template to "xxxx_diskio_template_bspv1.c":
-  - drivers/sd_diskio_dma_rtos_template_bspv1.c
-  - drivers/sd_diskio_dma_template_bspv1.c
-  - drivers/sd_diskio_template_bspv1.c
-  - drivers/sdram_diskio_template_bspv1.c
-
-+ Add CMSIS-OSv2 support in templates, syscall.c and ff_conf_template.h
-  - syscall.c
-  - ff_conf_template.h
-  - drivers/sd_diskio_dma_rtos_template_bspv2.c
-
-+ support usage of "osMutex" alongside "osSemaphore" as _SYNC_t type in fatfs
-  - syscall.c
-  - ff_conf_template.h
-
-
-### V2.1.2/29-03-2019 ###
-============================
-+ add st_license.txt in the root directory
-+ src/drivers/xxx_diskio_template.[c/h], src/ff_gen_drv.[c/h], src/option/syscall.c: update the license terms to BSD-3-Clause
-
-### V2.1.1/25-01-2019 ###
-============================
-+ sd_diskio_dma_rtos_template.c
-  - Fix memory leak in the SD_Initialize()
-  - Disable the ENABLE_SD_DMA_CACHE_MAINTENANCE flag by default to fix a build error for CM4
-  - include correct diskio header file
-
-+ sd_diskio_dma_template.c
-  - Correct the SD_read() function when enabling the ENABLE_SCRATCH_BUFFER flag
-
-+ sd_diskio_dma_rtos_template.c sd_diskio_dma_template.c
-  - fix potential overflow when using SysTick.
-
-
-### V2.1.0/21-09-2018 ###
-============================
-+ ff.c
-  - back-port a fix from 0.13, to correct an issue when using multi-threading
-    access in the same device due to a missing semaphore lock when calling
-    disk_status() API.
-
-+ sd_diskio_dma_rtos_template.c
-  - Add support to CMSIS-RTOS V2 API
-
-+ sd_diskio_dma_rtos_template.c sd_diskio_dma_template.c
-  - Add a compile flag "ENABLE_SCRATCH_BUFFER" to avoid misaligned access
-    caused buffer alignment constraint in some DMA versions.
-  - Add BSP_SD_ErrorCallback() and BSP_SD_AbortCallback() template functions.
-
-### V2.0.2/17-November-2017 ###
-============================
-+ sdram_diskio_template.c  sram_diskio_template.c
-   Fix wrong buffer size in the (SRAM/SDRAM)DISK_read(), (SRAM/SDRAM)DISK_write()
-
-+ sd_diskio_template.c
-  - define a generic 'SD_TIMEOUT' based on the BSP drivers defines. This fixes
-    a build issue when using this driver with the Adafruit shield.
-
-+ sd_diskio_dma_rtos_template.c
-  - add a check via  osKernelRunning(), to avoid runtime errors due to
-    osMessageXXX calls that needs the "osKernelStart()" call done first.
-
-+ sd_diskio_dma_template.c, sd_diskio_dma_rtos_template.c
-  - fix wrong address alignment when calling SCB_InvalidateDCache_by_Addr() and
-    SCB_CleanDCache_by_Addr(), the address has to be 32-Byte and not
-    32-bit aligned.
-
-  - fix BSP_SD_ReadCpltCallback() and BSP_SD_WriteCpltCallback() prototypes by
-    adding 'void' as argument to avoid IAR compiler errors
-
-
-+ sd_diskio_template.c sd_diskio_dma_template.c, sd_diskio_dma_rtos_template.c
-  - add the  flag "DISABLE_SD_INIT" to give the user the choice to initialize the SD
-    either in the application or in the FatFs diskio driver.
-
-+ all xxx_diskio_template.c
-  - fix GET_BLOCK_SIZE ioctl call; the return value is in unit of sectors.
-
-
-### V2.0.1/10-July-2017 ###
-============================
-+ sd_diskio_dma_template.c, sd_diskio_dma_rtos_template.c
-  - add the  flag "ENABLE_SD_DMA_CACHE_MAINTENANCE", to enable cache maintenance  at each read write operation.
-    This is useful for STM32F7/STM32H7 based platforms when using a cachable memory region.
-  - add timeout checks in SD_Read() and SD_Write() to give the control back to the application to decide in case of errors.
-
-+ ff_gen_drv.c: fix a wrong check that causes an out of bound array access.
-
-
-### V2.0.0/07-March-2017 ###
-============================
-  + Upgrade to use FatFS R0.12c. The R0.12c breaks the API compatibility with R0.11b.
-  - f_mkfs() API has a new signature.
-  - The _CODE_PAGE got new values.
-  - For more details check the files (doc/updates.txt) and the following urls:
-       http://elm-chan.org/fsw/ff/en/mkfs.html
-       http://elm-chan.org/fsw/ff/en/config.html
-
-  + Add USB, RAMDISK and uSD template drivers under src/drivers.
-    - The diskio drivers aren't part of fatfs anymore, they are just templates instead.
-    - User has to copy the suitable template .c/.h file under the project, rename them by
-      removing the "_template" suffix then link them into the final application.
-    - The diskio driver .c/.h files have to be edited according to the used platform.
-
-  + Define the macros "ff_malloc" and "ff_free" in the ff_conf_template.h and use
-    them in the syscall.c instead of direct calls to stdlib malloc and free functions.
-  + Define the "__weak" attribute in diskio.c for the GNU GCC compiler
-
-
-### V1.4.0/09-September-2016 ###
-================================
-  + Upgrade to use FatFs R0.12b.
-  + ff_conf.h: remove the use of define "_USE_BUFF_WO_ALIGNMENT".
-
-
-### V1.3.0/08-May-2015 ###
-==========================
-  + Upgrade to use FatFs R0.11.
-  + Add new APIs FATFS_LinkDriverEx() and FATFS_UnLinkDriverEx() to manage USB Key Disk having
-     multi-lun capability. These APIs are equivalent to FATFS_LinkDriver() and FATFS_UnLinkDriver()
-     with "lun" parameter set to 0.
-  + ff_conf.h: add new define "_USE_BUFF_WO_ALIGNMENT".
-     This option is available only for usbh diskio interface and allow to disable
-     the management of the unaligned buffer.
-     When STM32 USB OTG HS or FS IP is used with internal DMA enabled, this define
-     must be set to 0 to align data into 32bits through an internal scratch buffer
-     before being processed by the DMA . Otherwise (DMA not used), this define must
-     be set to 1 to avoid Data alignment and improve the performance.
-     Please note that if _USE_BUFF_WO_ALIGNMENT is set to 1 and an unaligned 32bits
-     buffer is forwarded to the FatFs Write/Read functions, an error will be returned.
-     (0: default value or 1: unaligned buffer return an error).
-
-
-  + Important note:
-      For application code based on previous FatFs version; when moving to R0.11
-      the changes that need to be done is to update ffconf.h file, taking
-      ffconf_template.h file as reference.
-
-
-### V1.2.1/20-November-2014 ###
-===============================
-  + Disk I/O drivers; change count argument type from BYTE to UINT
-
-  + Important note:
-      For application code based on previous FatFs version; when moving to R0.10b
-      the only change that need to be done is to update ffconf.h file, taking
-      ffconf_template.h file as reference.
-
-
-### V1.2.0/04-November-2014 ###
-===============================
-  + Upgrade to use FatFs R0.10b.
-  + diskio.c: update disk_read() and disk_write() argument's type.
-
-  + Important note:
-      For application code based on previous FatFs version; when moving to R0.10b
-      the only change that need to be done is to update ffconf.h file, taking
-      ffconf_template.h file as reference.
-
-
-### V1.1.1/12-September-2014 ###
-================================
-  + ff_gen_drv.c: Update the Disk_drvTypeDef disk variable initialization to avoid
-    warnings detected with Atollic TrueSTUDIO Complier.
-
-
-### V1.1.0/22-April-2014 ###
-============================
-  + Update sd_diskio to use SD BSP in polling mode instead of DMA mode (the scratch
-    buffer needed for DMA alignment is removed as well).
-  + diskio.c and ff_gen_drv.c/.h: update to prevent multiple initialization.
-
-
-### V1.0.0/18-February-2014 ###
-===============================
-   + First R0.10 customized version for STM32Cube solution.
-
-
- * <h3><center>&copy; COPYRIGHT STMicroelectronics</center></h3>
- */

+ 0 - 445
func/func_fatfs.c

@@ -1,445 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
-  ******************************************************************************
-  * @file           : main.c
-  * @brief          : Main program body
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                        opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-  */
-/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
-#include "main.h"
-
-#if USE_FATFS_RECORD
-
-#include "dev_spi_sdcard.h"
-#include "func_spi_w25qxx.h"
-#include "func_fatfs.h"
-#include "func_fatfs_record.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-
-/* USER CODE END Includes */
-
-/* Private typedef -----------------------------------------------------------*/
-
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-
-/* USER CODE END PD */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-
-/* USER CODE END PM */
-
-/* Private variables ---------------------------------------------------------*/
-
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-
-/* Private function prototypes -----------------------------------------------*/
-
-/* USER CODE BEGIN PFP */
-
-FATFS fileSystem;
-FIL 	testFile;
-uint8_t testBuffer[16] = "SD write success";
-
-
-char 		fatfs_buf[4*1024];
-
-#if  USE_SPI_SD
-const char FATFS_Path[4] = "0:/"; 					//挂载SD卡 
-#else
-const char FATFS_Path[4] ;//= "1:/"; 					//挂载FLASH.
-#endif
-char readnrf,reafsd;
-
-/* USER CODE END PFP */
-
-
-void 	func_fatfs_Get_Capacity(void);
-/* Private user code ---------------------------------------------------------*/
-/* USER CODE BEGIN 0 */
-
-/* USER CODE END 0 */
-/**
-  * @brief  The application entry point.
-  * @retval int
-  */
-int func_fatfs_init(void)
-{
-	FRESULT res;
-	 
-	uint8_t format_disk = 0;
-
-  /* Initialize all configured peripherals */
-	
-  FATFS_Init();
-
-	//res = f_mkfs ( FATFS_Path, FM_ANY, 0, fatfs_buf, sizeof(fatfs_buf));
-  /* USER CODE BEGIN 2 */
-	res = f_mount(&fileSystem, (const TCHAR*)FATFS_Path, 1);
-	
-  if(res != FR_OK)
-  {
-			func_record_fatfs_set_OK(false);
-	}
-	if(res == FR_NO_FILESYSTEM)//FLASH磁盘,FAT文件系统错误,重新格式化FLASH
-	{
-//		
-		while(res != FR_OK)
-		{
-			if(format_disk)
-			{
-				func_w25q_erase_ship();
-				format_disk = 0;
-			}
-			
-			if(format_disk)
-			{
-				res = f_mkfs (FATFS_Path, FM_ANY, 0, fatfs_buf, sizeof(fatfs_buf));
-				format_disk = 0;
-			}
-			
-			res = f_mount(&fileSystem, (const TCHAR*)FATFS_Path, 1);
-		};
-		
-	}	
-  /* USER CODE END 2 */
-
-  /* Infinite loop */
-  /* USER CODE BEGIN WHILE */
- 
-  /* USER CODE END 3 */
-	return res;
-}
-
-/**
-  * @brief  The application entry point.
-  * @retval int
-  */
-int func_fatfs_main(void)
-{
-  /* USER CODE BEGIN 1 */
-	
-	//func_fatfs_Get_Capacity();
-
-  /* USER CODE END 1 */
-	
-	return 0;
- 
-}
-
-
-typedef struct fatfs_st
-{
-	DWORD 		TotalSpace;	
-	DWORD 		AvailableSize;
-	DWORD 		UsedSize;
-}fatfs_st;
-
-fatfs_st fatfs_run_st;
-
-void func_fatfs_Capacity(void)
-{
-		FATFS *hFatfs = &fileSystem;
-	
-		fatfs_run_st.TotalSpace=((hFatfs->n_fatent - 2) * hFatfs->ssize *hFatfs->csize)/1024;
-		fatfs_run_st.AvailableSize=(hFatfs->free_clst*hFatfs->ssize*hFatfs->csize)/1024;
-		fatfs_run_st.UsedSize=fatfs_run_st.TotalSpace-fatfs_run_st.AvailableSize;  
-} 
-
-uint32_t func_fatfs_get_free(void)
-{
-	return (fileSystem.free_clst*fileSystem.ssize*fileSystem.csize)/1024;
-}
-
-
-void func_fatfs_Get_Capacity(void)
-{
-//	FRESULT result;
-//	FATFS FS;
-	FATFS *fs;
-	DWORD fre_clust;	
-
-	FRESULT res;
-	
-	res = f_getfree(FATFS_Path, &fre_clust, &fs);  /* 根目录 */
-	if ( res == FR_OK ) 
-	{
-		fatfs_run_st.TotalSpace=(fs->n_fatent - 2);
-		fatfs_run_st.AvailableSize=fre_clust;
-		fatfs_run_st.UsedSize=fatfs_run_st.TotalSpace-fatfs_run_st.AvailableSize;              
-		/* Print free space in unit of MB (assuming 512 bytes/sector) */
-//		printf("\r\n%d MB total drive space.\r\n""%d MB available.\r\n""%d MB  used.\r\n",TotalSpace, AvailableSize,UsedSize);
-	}
-	else 
-	{
-//		printf("Get SDCard Capacity Failed (%d)\r\n", result);
-	}	
-	return;
-} 
-
-void func_fatfs_Get_Capacity_Sample(void)
-{
-//	FRESULT result;
-//	FATFS FS;
-	FATFS *fs;
-	DWORD fre_clust;	
-
-	FRESULT res;
-	
-	res = f_getfree(FATFS_Path, &fre_clust, &fs);  /* 根目录 */
-	if ( res == FR_OK ) 
-	{
-		fatfs_run_st.TotalSpace=(uint16_t)(((fs->n_fatent - 2) * fs->csize ) / 2 /1024);
-		fatfs_run_st.AvailableSize=(uint16_t)((fre_clust * fs->csize) / 2 /1024);
-		fatfs_run_st.UsedSize=fatfs_run_st.TotalSpace-fatfs_run_st.AvailableSize;              
-		/* Print free space in unit of MB (assuming 512 bytes/sector) */
-//		printf("\r\n%d MB total drive space.\r\n""%d MB available.\r\n""%d MB  used.\r\n",TotalSpace, AvailableSize,UsedSize);
-	}
-	else 
-	{
-//		printf("Get SDCard Capacity Failed (%d)\r\n", result);
-	}	
-	return;
-} 
-
-FIL file;													/* 文件对象 */
-/* FatFs多项功能测试 */
-FRESULT func_fatfs_miscellaneous(void)
-{
-	FRESULT f_res;                    /* 文件操作结果 */
-	UINT fnum;            					  /* 文件成功读写数量 */
-
-	DIR dir;
-  FATFS *pfs;
-  DWORD fre_clust, fre_sect, tot_sect;
-  
-  printf("\n*************** 设备信息获取 ***************\r\n");
-  /* 获取设备信息和空簇大小 */
-  f_res = f_getfree((TCHAR const*)FATFS_Path, &fre_clust, &pfs);
-
-  /* 计算得到总的扇区个数和空扇区个数 */
-  tot_sect = (pfs->n_fatent - 2) * pfs->csize;
-  fre_sect = fre_clust * pfs->csize;
-
-  /* 打印信息(4096 字节/扇区) */
-  printf("》设备总空间:%10lu KB。\n》可用空间:  %10lu KB。\n", tot_sect *4, fre_sect *4);
-  
-  printf("\n******** 文件定位和格式化写入功能测试 ********\r\n");
-  f_res = f_open(&file, "FatFs读写测试文件.txt",
-                            FA_OPEN_EXISTING|FA_WRITE|FA_READ );
-	if ( f_res == FR_OK )
-	{
-    /*  文件定位 */
-    f_res = f_lseek(&file,f_size(&file)-1);
-    if (f_res == FR_OK)
-    {
-      /* 格式化写入,参数格式类似printf函数 */
-      f_printf(&file,"\n在原来文件新添加一行内容\n");
-      f_printf(&file,"》设备总空间:%10lu KB。\n》可用空间:  %10lu KB。\n", tot_sect *4, fre_sect *4);
-      /*  文件定位到文件起始位置 */
-      f_res = f_lseek(&file,0);
-      /* 读取文件所有内容到缓存区 */
-      f_res = f_read(&file,fatfs_buf,f_size(&file),&fnum);
-      if(f_res == FR_OK)
-      {
-        printf("》文件内容:\n%s\n",fatfs_buf);
-      }
-    }
-    f_close(&file);    
-    
-    printf("\n********** 目录创建和重命名功能测试 **********\r\n");
-    /* 尝试打开目录 */
-    f_res=f_opendir(&dir,"TestDir");
-    if(f_res!=FR_OK)
-    {
-      /* 打开目录失败,就创建目录 */
-      f_res=f_mkdir("TestDir");
-    }
-    else
-    {
-      /* 如果目录已经存在,关闭它 */
-      f_res=f_closedir(&dir);
-      /* 删除文件 */
-      f_unlink("TestDir/testdir.txt");
-    }
-    if(f_res==FR_OK)
-    {
-      /* 重命名并移动文件 */
-      f_res=f_rename("FatFs读写测试文件.txt","TestDir/testdir.txt");      
-    } 
-	}
-  else
-  {
-    printf("!! 打开文件失败:%d\n",f_res);
-    printf("!! 或许需要再次运行“FatFs移植与读写测试”工程\n");
-  }
-  return f_res;
-}
-
-
-/**
-  * 文件信息获取
-  */
-FRESULT func_fatfs_file_check(void)
-{ 
-	FRESULT f_res;                    /* 文件操作结果 */	
-  static FILINFO finfo;
-  /* 获取文件信息 */
-  f_res=f_stat("TestDir/testdir.txt",&finfo);
-  if(f_res==FR_OK)
-  {
-    printf("“testdir.txt”文件信息:\n");
-    printf("》文件大小: %ld(字节)\n", finfo.fsize);
-    printf("》时间戳: %u/%02u/%02u, %02u:%02u\n",
-           (finfo.fdate >> 9) + 1980, finfo.fdate >> 5 & 15, finfo.fdate & 31,finfo.ftime >> 11, finfo.ftime >> 5 & 63);
-    printf("》属性: %c%c%c%c%c\n\n",
-           (finfo.fattrib & AM_DIR) ? 'D' : '-',      // 是一个目录
-           (finfo.fattrib & AM_RDO) ? 'R' : '-',      // 只读文件
-           (finfo.fattrib & AM_HID) ? 'H' : '-',      // 隐藏文件
-           (finfo.fattrib & AM_SYS) ? 'S' : '-',      // 系统文件
-           (finfo.fattrib & AM_ARC) ? 'A' : '-');     // 档案文件
-  }
-  return f_res;
-}
-
-/**
-  * @brief  scan_files 递归扫描FatFs内的文件
-  * @param  path:初始扫描路径
-  * @retval result:文件系统的返回值
-  */
-FRESULT func_fatfs_scan_files (char* path) 
-{ 
-  FRESULT res; 		//部分在递归过程被修改的变量,不用全局变量	
-  FILINFO fno; 
-	DIR 		dir;	
-  int i;            
-  char *fn;        // 文件名	
-	
-#if _USE_LFN 
-  /* 长文件名支持 */
-  /* 简体中文需要2个字节保存一个“字”*/
-  static char lfn[_MAX_LFN*2 + 1]; 	
-  fno.fname = lfn; 
-  fno.fsize = sizeof(lfn); 
-#endif 
-  //打开目录
-  res = f_opendir(&dir, path); 
-  if (res == FR_OK) 
-	{ 
-    i = strlen(path); 
-    for (;;) 
-		{ 
-      //读取目录下的内容,再读会自动读下一个文件
-      res = f_readdir(&dir, &fno); 								
-      //为空时表示所有项目读取完毕,跳出
-      if (res != FR_OK || fno.fname[0] == 0) break; 	
-#if _USE_LFN 
-      fn = *fno.lfname ? fno.lfname : fno.fname; 
-#else 
-      fn = fno.fname; 
-#endif 
-      //点表示当前目录,跳过			
-      if (*fn == '.') continue; 	
-      //目录,递归读取      
-      if (fno.fattrib & AM_DIR)         
-			{ 			
-        //合成完整目录名        
-        sprintf(&path[i], "/%s", fn); 		
-        //递归遍历         
-        res = func_fatfs_scan_files(path);	
-        path[i] = 0;         
-        //打开失败,跳出循环        
-        if (res != FR_OK) 
-					break;			
-      } 
-			else 
-			{ 
-				printf("%s/%s\n", path, fn);								//输出文件名	
-        /* 可以在这里提取特定格式的文件路径 */        
-      }//else
-    } //for
-  } 
-  return res; 
-}
-
-
-/*------------------------------------------------------
- 读取指定目录下所有的文件
- 说明:
-  f_readdir    按顺序读取目录内文件,
- 重复调用此函数可读取目录内所有文件;
----------------------------------------------------------*/
-void func_fatfs_ReadDirTest(char*path)
-{
-// FRESULT res; /* FatFs 函数通用结果代码 */
-		DIR 		dir;	
-	  FILINFO fno; 
-#if _USE_LFN//如果使能支持长文件名 先对下面两项初始化
-    fileinfo.lfsize=_MAX_LFN * 2 + 1;//
-    fileinfo.lfname=(TCHAR*)FileName;//
-#endif
-    if(f_opendir(&dir,(const char*)path) == FR_OK)/* 打开文件夹目录成功,目录信息已经在dir结构体中保存 */
-    {
-        while(f_readdir(&dir, &fno) == FR_OK)  /* 读文件信息到文件状态结构体中 */
-        {
-            if(!fno.fname[0]) break; /* 如果文件名为‘\0',说明读取完成结束 */
-            printf("%s/",path);//打印路径
-#if _USE_LFN
-            printf("文件名:%s\r\n",fileinfo.lfname );//打印信息到串口
-#else
-            printf("文件名:%s\r\n", fno.fname);//
-#endif
-        }
-    }
-}
-
-
-char*  pstr = 0;
-char*  pidx = 0;
-void func_record_fatfs_str(void)
-{
-	char  str_name[] ="20221112.TXT" ;
-
-	while(1)
-	{
-		pstr =  strstr(str_name,FILE_START);
-		
-		pidx =  strstr(str_name,FILE_END);
-		UNUSED(pstr);
-		UNUSED(pidx);
-	}
-}
-
-#if 0
-static int qsort_cmp(const void *a,const void *b)
-{
-    return strcmp(( char * ) a, (const char* )b);
-}
-#define MAX_FILE_COUNT 20
-char fileList[MAX_FILE_COUNT][30];//保存文件名
-void func_fatfs_dir_qsort(uint32_t fcount)
-{
-	qsort(fileList, fcount, sizeof(fileList[0]), qsort_cmp);
-}
-#endif
-
-#endif //--------------------------USE_FATFS_RECORD------------------------------
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 80
func/func_fatfs.h

@@ -1,80 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
-  ******************************************************************************
-  * @file           : main.h
-  * @brief          : Header for main.c file.
-  *                   This file contains the common defines of the application.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                        opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-  */
-/* USER CODE END Header */
-
-
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef FUNC_FATFS_H
-#define FUNC_FATFS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f7xx_hal.h"
-#include "fatfs.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-
-/* USER CODE END Includes */
-
-/* Exported types ------------------------------------------------------------*/
-/* USER CODE BEGIN ET */
-
-/* USER CODE END ET */
-
-/* Exported constants --------------------------------------------------------*/
-/* USER CODE BEGIN EC */
-
-/* USER CODE END EC */
-
-/* Exported macro ------------------------------------------------------------*/
-/* USER CODE BEGIN EM */
-
-/* USER CODE END EM */
-
-
-
-/* Exported functions prototypes ---------------------------------------------*/
-/* USER CODE BEGIN EFP */
-int func_fatfs_init(void);
-int func_fatfs_main(void);
-
-FRESULT func_fatfs_miscellaneous(void);			//FatFs多项功能测试
-FRESULT func_fatfs_file_check(void);				//文件信息获取
-FRESULT func_fatfs_scan_files (char* path); //递归扫描FatFs内的文件
-void func_fatfs_Get_Capacity(void);
-uint32_t func_fatfs_get_free(void);
-/* USER CODE END EFP */
-
-/* Private defines -----------------------------------------------------------*/
-/* USER CODE BEGIN Private defines */
-
-/* USER CODE END Private defines */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* FUNC_FATFS_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 689
func/func_fatfs_record.c

@@ -1,689 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
-  ******************************************************************************
-  * @file           : main.c
-  * @brief          : Main program body
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                        opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-  */
-/* USER CODE END Header */
-#include "main.h"
-
-#if USE_FATFS_RECORD==1
-/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include "func_fatfs.h"
-#include "dev_spi_sdcard.h"
-#include "func_spi_w25qxx.h"
-#include "func_fatfs_record.h"
-#include "func_queue_record.h"
-#include "Data_deal.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-
-/* USER CODE END Includes */
-
-/* Private typedef -----------------------------------------------------------*/
-#define MAX_FILE_COUNT  20
-#define NUM_FILE_SET	 	10
-
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-
-/* USER CODE END PD */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-
-/* USER CODE END PM */
-
-/* Private variables ---------------------------------------------------------*/
-
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-const char FILE_START[] = "20";
-const char FILE_END[] = ".TXT";
-const char FILE_FOLD[] = "JLRECORD";
-
-
-
-/* Private function prototypes -----------------------------------------------*/
-
-
-
-typedef struct fs_record_struct
-{
-	int8_t    fs_stat;
-	const char *fold;   			//操作路径
-	int8_t *	path[32];   			//操作路径
-	int8_t 		name_new[32];			//最新的文件名
-	int8_t 		name_send[32];			//最老的文件名
-	
-	FIL 			opt_file;					//当前操作的文件
-	FATFS 		fs;	
-	DIR 			dir;							//操作的文件名
-	uint32_t  opt_len;
-	uint32_t  items_num;
-	
-	int8_t 		read_buf[512];	
-	uint32_t 	read_len;
-	
-	int8_t 		write_buf[512];		
-	uint32_t  write_len;
-	
-	uint32_t 	 file_num;
-	int8_t 		 file_list[MAX_FILE_COUNT][32];//保存文件名
-	
-	int8_t     link_ok;
-
-	uint32_t 	 free_size;
-
-}fs_record_OBJ;
-
-
-fs_record_OBJ fs_record_obj = {
-	.fs_stat = true,
-	.fold 		= FILE_FOLD,
-	.items_num= 0,
-	.file_num = 0,
-	.link_ok  = false,
-};
-
-//add boly 20221020
-//uint8_t  data_buf[16*1024] = {0};
-//end boly
-void 	func_record_Get_Capacity(void);
-void func_record_files_update(char * path);
-void func_record_dir_qsort(size_t fcount);
-
-extern SDateTime m_datetime;
-/* Private user code ---------------------------------------------------------*/
-
-uint8_t func_record_fatfs_isOK(void)
-{
-		
-		return fs_record_obj.fs_stat;
-}
-
-uint8_t func_record_fatfs_set_OK(uint8_t stat)
-{
-		fs_record_obj.fs_stat = stat;
-		return fs_record_obj.fs_stat;
-}
-
-void func_record_mk_fileName(char *buf)
-{
-		//fs_record_obj.path[12] = 0;		
-#if 0	
-		sprintf(buf,"%s/%04d%02d%02d.TXT",fs_record_obj.fold,
-																			m_datetime.year%100 + 2000,
-																			m_datetime.month%100,
-																			m_datetime.day%100
-																			);
-#elif 0
-		sprintf(buf,"%s/%04d%02d%02d.TXT",fs_record_obj.fold,
-																			m_datetime.day%100 + 2000,
-																			m_datetime.hour%100,
-																			m_datetime.min%100	
-																			);
-#else	
-			sprintf(buf,"%s/%04d%02d%02d.TXT",fs_record_obj.fold,
-																			m_datetime.hour%100 + 2000,
-																			m_datetime.min%100,
-																			m_datetime.sec%100	
-																			);
-	
-#endif	
-
-		return;
-}
-/**
-  * @brief  指定长度len,buf内容写入文件
-  * @retval int
-  */
-uint32_t func_record_write(uint8_t *buf ,uint32_t len)
-{
-		
-	FRESULT res;
-	UINT 		write_len = 0;
-
-	//根据日期生成文件名,用于文件写入
-	func_record_mk_fileName((char *)fs_record_obj.name_new);
-	
-	//打开当前存在的文件;
-	res = f_open(&fs_record_obj.opt_file,(char *)fs_record_obj.name_new , FA_WRITE| FA_OPEN_EXISTING);
-	if(FR_OK != res)
-	{
-		//检查文件个数是否超限
-		func_record_files_update((char *)fs_record_obj.fold);
-		
-		if(FR_NO_FILE == res)
-		{			
-			//创建文件并写入
-			res = f_open(&fs_record_obj.opt_file, (char*)fs_record_obj.name_new, FA_WRITE| FA_CREATE_NEW);
-			if(FR_OK != res)
-			{
-				fs_record_obj.fs_stat = false;
-				return 0;
-			}			
-		}		
-		else
-		{
-			return 0;
-		}
-	}
-	//将当前发送文件更新为当前写入文件
-	strcpy((char *)fs_record_obj.name_send,(char *)fs_record_obj.name_new);
-	
-	fs_record_obj.opt_len = f_size(&fs_record_obj.opt_file);
-	
-	//操作指针移动到文件末尾
-	res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len);
-	
-	taskENTER_CRITICAL();    /* 临界保护开启 */
-	res = f_write(&fs_record_obj.opt_file, buf, len, &write_len);	
-	res = f_close(&fs_record_obj.opt_file);		//关闭文件	
-	taskEXIT_CRITICAL();    /* 临界保护关闭 */
-	
- 	return write_len;
-}
-
-void func_record_get_NameSend(void)
-{
-	//发送文件是否存在
-	if(strlen((char*)fs_record_obj.name_send) > 0)
-	{
-		return;
-	}
-
-	
-	//检查文件个数是否超限
-	func_record_files_update((char *)fs_record_obj.fold);
-}
-
-/**
-  * @brief  The application entry point.
-  * @retval int
-  */
-uint32_t func_record_read(uint8_t *buf, uint32_t len)
-{
-	FRESULT res;
-	
-	//uint32_t 		file_len = 0;
-	uint32_t 		read_len = 0;
-	
-	func_record_get_NameSend();
-	
-	if(strlen((char *)fs_record_obj.name_send) <= 0)
-	{
-		return 0;
-	}
-	
-	res = f_open(&fs_record_obj.opt_file, (char*)fs_record_obj.name_send, FA_READ | FA_OPEN_EXISTING);
-	if(FR_OK != res)
-	{	
-		return 0;
-	}		
-	
-	fs_record_obj.opt_len = f_size(&fs_record_obj.opt_file);
-	
-	//如果文件小于数据长度,则删除文件
-	if(fs_record_obj.opt_len < len)
-	{
-			res = f_close(&fs_record_obj.opt_file);
-		
-			taskENTER_CRITICAL();    /* 临界保护开启 */
-			res = f_unlink((char*)fs_record_obj.name_send);
-			taskEXIT_CRITICAL();    /* 临界保护关闭 */
-		
-			if(res == FR_OK)
-			{
-				memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
-			}
-			return 0;
-	};
-	res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
-	
-	res = f_read(&fs_record_obj.opt_file, buf, len, &read_len);
-	
-	res = f_close(&fs_record_obj.opt_file);
-	
-		
-	return read_len;
-}
-
-uint32_t func_record_remove(uint8_t *buf, uint32_t len)
-{
-	FRESULT res;
-
-	uint32_t 		read_len = 0;
-	
-	func_record_get_NameSend();
-	
-	if(strlen((char *)fs_record_obj.name_send) <= 0)
-	{
-		return 0;
-	}
-	
-	res = f_open(&fs_record_obj.opt_file, (char*)fs_record_obj.name_send, FA_WRITE| FA_READ| FA_OPEN_EXISTING);
-	if(FR_OK != res)
-	{	
-		memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
-		return 0;
-	}		
-	
-	fs_record_obj.opt_len = f_size(&fs_record_obj.opt_file);
-	
-	//如果文件小于数据长度,则删除文件
-	if(fs_record_obj.opt_len < len)
-	{
-			res = f_close(&fs_record_obj.opt_file);
-			taskENTER_CRITICAL();    /* 临界保护开启 */
-			res = f_unlink((char*)fs_record_obj.name_send);
-			taskEXIT_CRITICAL();    /* 临界保护关闭 */
-			if(res == FR_OK)
-			{
-				memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
-			}
-			return 0;
-	};
-	res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);	
-	res = f_read(&fs_record_obj.opt_file, buf, len, &read_len);
-	
-	res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);	
-	
-	taskENTER_CRITICAL();    /* 临界保护开启 */
-	res = f_truncate(&fs_record_obj.opt_file ); 		//截断后面的文件
-	res = f_close(&fs_record_obj.opt_file);	
-	taskEXIT_CRITICAL();    /* 临界保护关闭 */	
-		
-	return read_len;
-}
-
-uint32_t func_record_delete(uint8_t *buf,uint32_t len)
-{
-	FRESULT res;
-	//uint32_t file_len = 0;
-	
-	if(strlen((char *)fs_record_obj.name_send) <= 0)
-	{
-		return 0;
-	}
-	//打开文件
-	res = f_open(&fs_record_obj.opt_file, (char*)fs_record_obj.name_send, FA_WRITE | FA_OPEN_EXISTING );
-	
-	if ( res != FR_OK ) 
-	{
-		if(res == FR_NO_FILE )
-		{
-			memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
-			memset((char*)fs_record_obj.name_new,  0x00,sizeof(fs_record_obj.name_new));
-		}
-		return res;
-	}
-	
-	fs_record_obj.opt_len = f_size(&fs_record_obj.opt_file);
-	//如果文件小于数据长度,则删除文件
-	if(fs_record_obj.opt_len <= len)
-	{
-		res = f_close(&fs_record_obj.opt_file);
-		taskENTER_CRITICAL();    /* 临界保护开启 */
-		res = f_unlink((char*)fs_record_obj.name_send);
-		taskEXIT_CRITICAL();    /* 临界保护关闭 */
-		if(res == FR_OK)
-		{
-			memset((char*)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
-		}
-		return 0;			
-	};
-	
-	res = f_lseek(&fs_record_obj.opt_file, fs_record_obj.opt_len - len);
-	taskENTER_CRITICAL();    /* 临界保护开启 */
-	res = f_truncate(&fs_record_obj.opt_file ); 		//截断后面的文件
-	taskEXIT_CRITICAL();    /* 临界保护关闭 */	
-	res = f_close(&fs_record_obj.opt_file);	
-	
-	return res;
-}
-
-
-
-/**
-  * 文件信息获取
-  */
-FRESULT func_record_file_check(void)
-{ 
-	FRESULT f_res;                    /* 文件操作结果 */	
-  static FILINFO finfo;
-  /* 获取文件信息 */
-  f_res=f_stat("TestDir/testdir.txt",&finfo);
-  if(f_res==FR_OK)
-  {
-    printf("“testdir.txt”文件信息:\n");
-    printf("》文件大小: %ld(字节)\n", finfo.fsize);
-    printf("》时间戳: %u/%02u/%02u, %02u:%02u\n",
-           (finfo.fdate >> 9) + 1980, finfo.fdate >> 5 & 15, finfo.fdate & 31,finfo.ftime >> 11, finfo.ftime >> 5 & 63);
-    printf("》属性: %c%c%c%c%c\n\n",
-           (finfo.fattrib & AM_DIR) ? 'D' : '-',      // 是一个目录
-           (finfo.fattrib & AM_RDO) ? 'R' : '-',      // 只读文件
-           (finfo.fattrib & AM_HID) ? 'H' : '-',      // 隐藏文件
-           (finfo.fattrib & AM_SYS) ? 'S' : '-',      // 系统文件
-           (finfo.fattrib & AM_ARC) ? 'A' : '-');     // 档案文件
-  }
-  return f_res;
-}
-
-/**
-  * @brief  scan_files 递归扫描FatFs内的文件
-  * @param  path:初始扫描路径
-  * @retval result:文件系统的返回值
-  */
-FRESULT func_record_scan_files (char* path) 
-{ 
-  FRESULT res; 		//部分在递归过程被修改的变量,不用全局变量	
-  FILINFO fno; 
-	DIR 		dir;	
-  int i;            
-  char *fn;        // 文件名	
-	
-#if _USE_LFN 
-  /* 长文件名支持 */
-  /* 简体中文需要2个字节保存一个“字”*/
-  static char lfn[_MAX_LFN*2 + 1]; 	
-  fno.fname = lfn; 
-  fno.fsize = sizeof(lfn); 
-#endif 
-  //打开目录
-  res = f_opendir(&dir, path); 
-  if (res == FR_OK) 
-	{ 
-    i = strlen(path); 
-    for (;;) 
-		{ 
-      //读取目录下的内容,再读会自动读下一个文件
-      res = f_readdir(&dir, &fno); 								
-      //为空时表示所有项目读取完毕,跳出
-      if (res != FR_OK || fno.fname[0] == 0) break; 	
-#if _USE_LFN 
-      fn = *fno.lfname ? fno.lfname : fno.fname; 
-#else 
-      fn = fno.fname; 
-#endif 
-      //点表示当前目录,跳过			
-      if (*fn == '.') continue; 	
-      //目录,递归读取      
-      if (fno.fattrib & AM_DIR)         
-			{ 			
-        //合成完整目录名        
-        sprintf(&path[i], "/%s", fn); 		
-        //递归遍历         
-        res = func_record_scan_files(path);	
-        path[i] = 0;         
-        //打开失败,跳出循环        
-        if (res != FR_OK) 
-					break; 
-      } 
-			else 
-			{ 
-				printf("%s/%s\n", path, fn);								//输出文件名	
-        /* 可以在这里提取特定格式的文件路径 */        
-      }//else
-    } //for
-  } 
-	
-	
-  return res; 
-}
-
-
-/*------------------------------------------------------
- 读取指定目录下所有的文件
- 说明:
-  f_readdir    按顺序读取目录内文件,
- 重复调用此函数可读取目录内所有文件;
----------------------------------------------------------*/
-void func_record_files_update(char * path)
-{		
-		char file_name[32] = {0};
-	  FRESULT res; 		//部分在递归过程被修改的变量,不用全局变量		
-	  FILINFO fno = {0}; 
-		fs_record_obj.items_num = 0;
-		fs_record_obj.file_num = 0;				
-		memset((void *)fs_record_obj.file_list, 0x00,sizeof(fs_record_obj.file_list));		
-		memset((void *)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
-		
-		//获取fatfs文件系统
-		fs_record_obj.free_size = func_fatfs_get_free();
-		
-#if _USE_LFN//如果使能支持长文件名 先对下面两项初始化
-    fileinfo.lfsize=_MAX_LFN * 2 + 1;//
-    fileinfo.lfname=(TCHAR*)FileName;//
-#endif
-    if(f_opendir(&fs_record_obj.dir,(const char*)path) != FR_OK)/* 打开文件夹目录成功,目录信息已经在dir结构体中保存 */
-    {
-			res = f_mkdir((const char*)path);
-			if(res == FR_OK)
-			{
-				fs_record_obj.fs_stat = true;
-				return;
-			}
-			else
-			{				
-				return;
-			}
-		}		
-		
-		fs_record_obj.fs_stat = true;
-		
-		//打开日志路径正常,获取路文件夹内的文件列表
-		while(f_readdir(&fs_record_obj.dir, &fno) == FR_OK)  	//读文件信息到文件状态结构体中
-		{		
-				fs_record_obj.items_num++;
-				//判定的顺序不能变			
-				if(!fno.fname[0]) break; 													//如果文件名为‘\0',说明读取完成结束
-
-				if (fno.fattrib & AM_DIR)	continue; 						  //表示目录,跳过	
-			
-				if (fno.fname[0] == '.') continue; 								//点表示当前目录,跳过				
-
-						
-				if( (fs_record_obj.file_num < MAX_FILE_COUNT)
-					&&(strstr(fno.fname,FILE_START) == fno.fname)
-				  &&((strstr(fno.fname,FILE_END) != 0))
-				)
-				{
-						sprintf((char *)fs_record_obj.file_list[fs_record_obj.file_num], "%s/%s", fs_record_obj.fold,fno.fname);//将文件名存入列表中
-						fs_record_obj.file_num ++;	
-				}
-				else
-				{	
-					/* 如果目录已经存在,关闭它 */
-					res = f_closedir(&fs_record_obj.dir);	
-					
-					sprintf((char *)file_name,"%s/%s",fs_record_obj.fold, fno.fname);								//输出文件名	
-					taskENTER_CRITICAL();    /* 临界保护开启 */
-					res = f_unlink(file_name);
-					taskEXIT_CRITICAL();    /* 临界保护关闭 */
-					if(FR_OK != res)
-					{
-											
-						fs_record_obj.fs_stat = false;
-						return;
-					}
-				}
-    }
-		
-		/* 如果目录已经存在,关闭它 */
-		res = f_closedir(&fs_record_obj.dir);
-		
-		if(fs_record_obj.file_num > 0)
-		{			
-		}
-		else
-		{
-			memset((void *)fs_record_obj.name_send, 0x00,sizeof(fs_record_obj.name_send));
-			return;
-		}
-   
-		//按文件名最小到大排序;
-		if(fs_record_obj.file_num > 1)
-		{
-			func_record_dir_qsort(fs_record_obj.file_num);
-		}
-				
-		//获取最新的文件;
-		uint8_t max_idx = fs_record_obj.file_num - 1;
-		sprintf((char *)fs_record_obj.name_send,"%s", fs_record_obj.file_list[max_idx]);			
-		
-		//如果文件个数超限,
-		if((fs_record_obj.file_num > NUM_FILE_SET)
-			||(fs_record_obj.free_size < 500))
-		{			
-			//删除日期最早的文件
-			sprintf((char *)file_name,"%s",  fs_record_obj.file_list[0]);		
-			
-			taskENTER_CRITICAL();    /* 临界保护开启 */
-			res = f_unlink(file_name);
-			taskEXIT_CRITICAL();    /* 临界保护关闭 */
-			
-			if(FR_OK != res)
-			{
-				fs_record_obj.fs_stat = false;
-				return;
-			}									
-		}		
-			
-		UNUSED(res);		
-		return;
-}
-
-
-
-int qsort_cmp(const void *a,const void *b)
-{
-    return strcmp(( char * ) a, (const char* )b);
-}
-//(void * /*base*/, size_t /*nmemb*/, size_t /*size*/, int (* /*compar*/)(const void *, const void *)) __attribute__((__nonnull__(1,4)));
-void func_record_dir_qsort(size_t fcount)
-{
-	qsort((void *)fs_record_obj.file_list, fcount, sizeof(fs_record_obj.file_list[0]), qsort_cmp);
-}
-
-
-void func_record_init(void)
-{
-	
-	memset(fs_record_obj.file_list, 0x00,sizeof(fs_record_obj.file_list));		//清空文件列表
-	fs_record_obj.file_num = 0;
-	fs_record_obj.fs_stat = true;
-	func_record_files_update((char *)fs_record_obj.fold);
-}
-
-
-void func_record_fs_test(void)
-{	
-	
-	record_test_obj.cnts++;
-	sprintf(record_test_obj.buf,"XX%08xXX",record_test_obj.cnts);
-	switch(record_test_obj.test_flag)
-	{
-		case 0:
-		{
-			func_record_write((uint8_t *)record_test_obj.buf ,strlen(record_test_obj.buf));
-		}break;
-		case 1:
-		{
-			func_record_read((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
-			func_record_delete((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
-			func_record_read((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
-		}break;
-		default:
-		{
-			func_record_read((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
-		}break;
-		
-	}
-	
-}
-
-
-char*  pstr = 0;
-char*  pidx = 0;
-void func_record_str(void)
-{
-	char  str_name[] ="20221112.TXT" ;
-
-	while(1)
-	{
-		pstr =  strstr(str_name,FILE_START);
-		
-		pidx =  strstr(str_name,FILE_END);
-		UNUSED(pstr);
-		UNUSED(pidx);
-	}
-}
-char path_buf[512] = {0};
-void func_record_fatfs_main(void const *argument)
-{
-	//func_record_str();
-
-	
-	//add boly 20221014  SD卡 FATFS组件初始化	
-#if USE_SPI_SD	
-  SDCARD_GPIO_Init();
-  SDCARD_SPI_Init();
-#endif
-	
-#if USE_SPI_FLASH	
-  func_w25q_init();
-	func_w25q_test();
-#endif
-		
-	
-	
-#if USE_FATFS_RECORD	
-	taskENTER_CRITICAL();	
-	func_fatfs_init();
-	func_fatfs_main();
-	taskEXIT_CRITICAL();
-	
-	func_record_queue_init();
-	func_record_queue_update();
-	
-	//while(1)
-	{
-		osDelay(1000);
-	};	
-	//end boly
-#endif
-
-	osDelay(1000);//
-	func_record_init();
-	while(1)
-	{
-		strcpy(path_buf,fs_record_obj.fold);
-		//func_fatfs_scan_files(path_buf);
-		//func_record_fs_test();
-		func_record_queue_test();
-		func_record_work();
-		osDelay(1000);
-	}
-}
-#endif //---------------------------USE_FATFS_RECORD----------------------------
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 80
func/func_fatfs_record.h

@@ -1,80 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
-  ******************************************************************************
-  * @file           : main.h
-  * @brief          : Header for main.c file.
-  *                   This file contains the common defines of the application.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                        opensource.org/licenses/BSD-3-Clause
-  *
-  ******************************************************************************
-  */
-/* USER CODE END Header */
-#if USE_FATFS_RECORDD
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef FUNC_RECORD_H
-#define FUNC_RECORD_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f7xx_hal.h"
-#include "fatfs.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-
-/* USER CODE END Includes */
-
-/* Exported types ------------------------------------------------------------*/
-/* USER CODE BEGIN ET */
-
-/* USER CODE END ET */
-
-/* Exported constants --------------------------------------------------------*/
-/* USER CODE BEGIN EC */
-
-/* USER CODE END EC */
-
-/* Exported macro ------------------------------------------------------------*/
-/* USER CODE BEGIN EM */
-
-/* USER CODE END EM */
-
-
-
-/* Exported functions prototypes ---------------------------------------------*/
-void func_record_init(void);														//记录文件初始化
-void func_record_fatfs_main(void const *argument);			//文件操作主函数
-void func_record_test(void);
-	
-
-uint32_t func_record_write(uint8_t *buf ,uint32_t len);
-uint32_t func_record_read(uint8_t *buf ,uint32_t len);
-uint32_t func_record_delete(uint8_t *buf,uint32_t len);
-uint8_t func_record_fatfs_set_OK(uint8_t stat);
-uint8_t func_record_fatfs_isOK(void);
-
-
-
-/* Private defines -----------------------------------------------------------*/
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* FUNC_RECORD_H */
-
-#endif //-------------------USE_FATFS_RECORDD-----------------------//
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 143
func/func_sdmmc_sdcard.c

@@ -1,143 +0,0 @@
-#ifdef USE_SDIO_SD
-/*
-#include "sys.h"
-
-#include "usart.h" 
-#include "led.h"
-#include "key.h"
-#include "ltdc.h"
-#include "lcd.h"
-#include "sdram.h"
-#include "usmart.h"
-#include "pcf8574.h"
-#include "mpu.h"
-
-*/
-#include "sys_delay.h"
-#include "sys_malloc.h"
-#include "obj_sdmmc_sdcard.h"
-/************************************************
- ALIENTEK 阿波罗STM32H7开发板 实验40
- SD卡实验-HAL库函数版
- 技术支持:www.openedv.com
- 淘宝店铺:http://eboard.taobao.com 
- 关注微信公众平台微信号:"正点原子",免费获取STM32资料。
- 广州市星翼电子科技有限公司  
- 作者:正点原子 @ALIENTEK
-************************************************/
-
-//通过串口打印SD卡相关信息
-void show_sdcard_info(void)
-{
-	switch(SDCardInfo.CardType)
-	{
-		case STD_CAPACITY_SD_CARD_V1_1:printf("Card Type:SDSC V1.1\r\n");break;
-		case STD_CAPACITY_SD_CARD_V2_0:printf("Card Type:SDSC V2.0\r\n");break;
-		case HIGH_CAPACITY_SD_CARD:printf("Card Type:SDHC V2.0\r\n");break;
-		case MULTIMEDIA_CARD:printf("Card Type:MMC Card\r\n");break;
-	}	
-  	printf("Card ManufacturerID:%d\r\n",SDCardInfo.SD_cid.ManufacturerID);	//制造商ID
- 	printf("Card RCA:%d\r\n",SDCardInfo.RCA);								//卡相对地址
-	printf("Card Capacity:%d MB\r\n",(u32)(SDCardInfo.CardCapacity>>20));	//显示容量
- 	printf("Card BlockSize:%d\r\n\r\n",SDCardInfo.CardBlockSize);			//显示块大小
-}
-//测试SD卡的读取
-//从secaddr地址开始,读取seccnt个扇区的数据
-//secaddr:扇区地址
-//seccnt:扇区数
-void sd_test_read(u32 secaddr,u32 seccnt)
-{
-	u32 i;
-	u8 *buf;
-	u8 sta=0;
-	buf=mymalloc(SRAMIN,seccnt*512);	//申请内存,从SDRAM申请内存
-	sta=SD_ReadDisk(buf,secaddr,seccnt);//读取secaddr扇区开始的内容
-	if(sta==0)			
-	{	 
-		printf("SECTOR %d DATA:\r\n",secaddr);
-		for(i=0;i<seccnt*512;i++)printf("%x ",buf[i]);//打印secaddr开始的扇区数据    	   
-		printf("\r\nDATA ENDED\r\n"); 
-	}else printf("err:%d\r\n",sta);
-	myfree(SRAMIN,buf);	//释放内存	   
-}
-
-//测试SD卡的写入(慎用,最好写全是0XFF的扇区,否则可能损坏SD卡.)
-//从secaddr地址开始,写入seccnt个扇区的数据
-//secaddr:扇区地址
-//seccnt:扇区数
-void sd_test_write(u32 secaddr,u32 seccnt)
-{
-	u32 i;
-	u8 *buf;
-	u8 sta=0;
-	buf=mymalloc(SRAMIN,seccnt*512);	//从SDRAM申请内存
-	for(i=0;i<seccnt*512;i++) 			//初始化写入的数据,是3的倍数.
-	{
-		buf[i]=i*3;
-	}
-	sta=SD_WriteDisk(buf,secaddr,seccnt);//从secaddr扇区开始写入seccnt个扇区内容
-	if(sta==0)							
-	{	 
-		printf("Write over!\r\n"); 
-	}else printf("err:%d\r\n",sta);
-	myfree(SRAMIN,buf);					//释放内存	   
-}
-int func_sd_card_main(void)
-{
-//    u8 key;		 
-	u32 sd_size;
-	u8 t=0;	
-	u8 *buf;
-/*	
-	Cache_Enable();                			//打开L1-Cache
-	//HAL_Init();				        		//初始化HAL库
-	delay_init(400);						//延时初始化
-	uart_init(115200);						//串口初始化
-	usmart_dev.init(200); 		    		//初始化USMART	
-	LED_Init();								//初始化LED
-	KEY_Init();								//初始化按键
-	SDRAM_Init();                   		//初始化SDRAM
-	LCD_Init();								//初始化LCD
-	*/
-    my_mem_init(SRAMIN);            		//初始化内部内存池
-    //my_mem_init(SRAMEX);            		//初始化外部SDRAM内存池
-
- 
- 	while(SD_Init())//检测不到SD卡
-	{
-
-		sys_delay_ms(500);			
-
-		sys_delay_ms(500);
-
-	}
-	show_sdcard_info();	//打印SD卡相关信息
-									    
-	//检测SD卡成功 											    
-
-    while(1)
-    {
-
-
-			buf=mymalloc(0,512);		//申请内存
-			if(SD_ReadDisk(buf,0,1)==0)	//读取0扇区的内容
-			{	
-				printf("SECTOR 0 DATA:\r\n");
-				for(sd_size=0;sd_size<512;sd_size++)
-					printf("%x ",buf[sd_size]);//打印0扇区数据    	   
-				printf("\r\nDATA ENDED\r\n");
-
-			}
-			myfree(0,buf);//释放内存	   
-  
-		t++;
-		sys_delay_ms(10);
-		if(t==20)
-		{
-			t=0;
-		}
-	}    
-}
-
-#endif //--------------USE_SDIO_SD-------------------------
-

+ 0 - 52
func/func_sdmmc_sdcard.h

@@ -1,52 +0,0 @@
-/**
-  ******************************************************************************
-  * @file    Templates/Inc/main.h 
-  * @author  MCD Application Team
-  * @version V1.0.0
-  * @date    21-April-2017
-  * @brief   Header for main.c module
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */
-  
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __MAIN_H
-#define __MAIN_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32h7xx_hal.h"
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-
-#endif /* __MAIN_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 59
mid_fatfs/fatfs.c

@@ -1,59 +0,0 @@
-/**
-  ******************************************************************************
-  * @file   fatfs.c
-  * @brief  Code for fatfs applications
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2022 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
-  *
-  ******************************************************************************
-  */
-
-#include "fatfs.h"
-
-uint8_t retUSER;    /* Return value for USER */
-char USERPath[4];   /* USER logical drive path */
-FATFS USERFatFS;    /* File system object for USER logical drive */
-FIL USERFile;       /* File object for USER */
-
-/* USER CODE BEGIN Variables */
-
-/* USER CODE END Variables */
-
-void FATFS_Init(void)
-{
-  /*## FatFS: Link the USER driver ###########################*/
-#if  USE_SPI_FLASH>0   //SPI FLASH W25QXX¹¦ÄÜ
-	retUSER =  FATFS_LinkDriverEx(&W25Q_Driver, USERPath, 1);	
-#elif USE_SPI_SD>0   //SPI FLASH W25QXX¹¦ÄÜ
-	retUSER =  FATFS_LinkDriverEx(&sdcard_Driver, USERPath, 1);
-#endif
-  /* USER CODE BEGIN Init */
-  /* additional user code for init */     
-  /* USER CODE END Init */
-}
-
-/**
-  * @brief  Gets Time from RTC
-  * @param  None
-  * @retval Time in DWORD
-  */
-DWORD get_fattime(void)
-{
-  /* USER CODE BEGIN get_fattime */
-  return 0;
-  /* USER CODE END get_fattime */
-}
-
-/* USER CODE BEGIN Application */
-     
-/* USER CODE END Application */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 49
mid_fatfs/fatfs.h

@@ -1,49 +0,0 @@
-/**
-  ******************************************************************************
-  * @file   fatfs.h
-  * @brief  Header for fatfs applications
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2022 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
-  *
-  ******************************************************************************
-  */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __fatfs_H
-#define __fatfs_H
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#include "ff.h"
-#include "ff_gen_drv.h"
-#include "w25qxx_diskio.h" /* defines W25Q_Driver as external */
-#include "sdcard_diskio.h" /* defines USER_Driver as external */
-/* USER CODE BEGIN Includes */
-
-/* USER CODE END Includes */
-
-extern uint8_t retUSER; /* Return value for USER */
-extern char USERPath[4]; /* USER logical drive path */
-extern FATFS USERFatFS; /* File system object for USER logical drive */
-extern FIL USERFile; /* File object for USER */
-
-void FATFS_Init(void);
-
-/* USER CODE BEGIN Prototypes */
-
-/* USER CODE END Prototypes */
-#ifdef __cplusplus
-}
-#endif
-#endif /*__fatfs_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 273
mid_fatfs/ffconf.h

@@ -1,273 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
-  ******************************************************************************
-  *  FatFs - Generic FAT file system module  R0.12c (C)ChaN, 2017
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
-  *
-  ******************************************************************************
-  */
-/* USER CODE END Header */
-
-#ifndef _FFCONF
-#define _FFCONF 68300	/* Revision ID */
-
-/*-----------------------------------------------------------------------------/
-/ Additional user header to be used
-/-----------------------------------------------------------------------------*/
-#include "main.h"
-#include "stm32f7xx_hal.h"
-
-#include "cmsis_os.h" /* _FS_REENTRANT set to 1 and CMSIS API chosen */
-/* Handle for USB Host */
-#define hUSB_Host hUsbHostFS
-
-/*-----------------------------------------------------------------------------/
-/ Function Configurations
-/-----------------------------------------------------------------------------*/
-
-#define _FS_READONLY         0      /* 0:Read/Write or 1:Read only */
-/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
-/  Read-only configuration removes writing API functions, f_write(), f_sync(),
-/  f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
-/  and optional writing functions as well. */
-
-#define _FS_MINIMIZE         0      /* 0 to 3 */
-/* This option defines minimization level to remove some basic API functions.
-/
-/   0: All basic functions are enabled.
-/   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
-/      are removed.
-/   2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
-/   3: f_lseek() function is removed in addition to 2. */
-
-#define _USE_STRFUNC         2      /* 0:Disable or 1-2:Enable */
-/* This option switches string functions, f_gets(), f_putc(), f_puts() and
-/  f_printf().
-/
-/  0: Disable string functions.
-/  1: Enable without LF-CRLF conversion.
-/  2: Enable with LF-CRLF conversion. */
-
-#define _USE_FIND            0
-/* This option switches filtered directory read functions, f_findfirst() and
-/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
-
-#define _USE_MKFS            1
-/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
-
-#define _USE_FASTSEEK        1
-/* This option switches fast seek feature. (0:Disable or 1:Enable) */
-
-#define	_USE_EXPAND		0
-/* This option switches f_expand function. (0:Disable or 1:Enable) */
-
-#define _USE_CHMOD		0
-/* This option switches attribute manipulation functions, f_chmod() and f_utime().
-/  (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */
-
-#define _USE_LABEL           0
-/* This option switches volume label functions, f_getlabel() and f_setlabel().
-/  (0:Disable or 1:Enable) */
-
-#define _USE_FORWARD         0
-/* This option switches f_forward() function. (0:Disable or 1:Enable) */
-
-/*-----------------------------------------------------------------------------/
-/ Locale and Namespace Configurations
-/-----------------------------------------------------------------------------*/
-
-#define _CODE_PAGE         936
-/* This option specifies the OEM code page to be used on the target system.
-/  Incorrect setting of the code page can cause a file open failure.
-/
-/   1   - ASCII (No extended character. Non-LFN cfg. only)
-/   437 - U.S.
-/   720 - Arabic
-/   737 - Greek
-/   771 - KBL
-/   775 - Baltic
-/   850 - Latin 1
-/   852 - Latin 2
-/   855 - Cyrillic
-/   857 - Turkish
-/   860 - Portuguese
-/   861 - Icelandic
-/   862 - Hebrew
-/   863 - Canadian French
-/   864 - Arabic
-/   865 - Nordic
-/   866 - Russian
-/   869 - Greek 2
-/   932 - Japanese (DBCS)
-/   936 - Simplified Chinese (DBCS)
-/   949 - Korean (DBCS)
-/   950 - Traditional Chinese (DBCS)
-*/
-
-#define _USE_LFN     0    /* 0 to 3 */
-#define _MAX_LFN     64  /* Maximum LFN length to handle (12 to 255) */
-/* The _USE_LFN switches the support of long file name (LFN).
-/
-/   0: Disable support of LFN. _MAX_LFN has no effect.
-/   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
-/   2: Enable LFN with dynamic working buffer on the STACK.
-/   3: Enable LFN with dynamic working buffer on the HEAP.
-/
-/  To enable the LFN, Unicode handling functions (option/unicode.c) must be added
-/  to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and
-/  additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255.
-/  It should be set 255 to support full featured LFN operations.
-/  When use stack for the working buffer, take care on stack overflow. When use heap
-/  memory for the working buffer, memory management functions, ff_memalloc() and
-/  ff_memfree(), must be added to the project. */
-
-#define _LFN_UNICODE    0 /* 0:ANSI/OEM or 1:Unicode */
-/* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16)
-/  To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1.
-/  This option also affects behavior of string I/O functions. */
-
-#define _STRF_ENCODE    3
-/* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to
-/  be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
-/
-/  0: ANSI/OEM
-/  1: UTF-16LE
-/  2: UTF-16BE
-/  3: UTF-8
-/
-/  This option has no effect when _LFN_UNICODE == 0. */
-
-#define _FS_RPATH       1 /* 0 to 2 */
-/* This option configures support of relative path.
-/
-/   0: Disable relative path and remove related functions.
-/   1: Enable relative path. f_chdir() and f_chdrive() are available.
-/   2: f_getcwd() function is available in addition to 1.
-*/
-
-/*---------------------------------------------------------------------------/
-/ Drive/Volume Configurations
-/----------------------------------------------------------------------------*/
-
-#define _VOLUMES    2
-/* Number of volumes (logical drives) to be used. */
-
-/* USER CODE BEGIN Volumes */
-#define _STR_VOLUME_ID          0	/* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
-#define _VOLUME_STRS            "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
-/* _STR_VOLUME_ID switches string support of volume ID.
-/  When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
-/  number in the path name. _VOLUME_STRS defines the drive ID strings for each
-/  logical drives. Number of items must be equal to _VOLUMES. Valid characters for
-/  the drive ID strings are: A-Z and 0-9. */
-/* USER CODE END Volumes */
-
-#define _MULTI_PARTITION     0 /* 0:Single partition, 1:Multiple partition */
-/* This option switches support of multi-partition on a physical drive.
-/  By default (0), each logical drive number is bound to the same physical drive
-/  number and only an FAT volume found on the physical drive will be mounted.
-/  When multi-partition is enabled (1), each logical drive number can be bound to
-/  arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
-/  function will be available. */
-#define _MIN_SS    512  /* 512, 1024, 2048 or 4096 */
-#define _MAX_SS    4096  /* 512, 1024, 2048 or 4096 */
-/* These options configure the range of sector size to be supported. (512, 1024,
-/  2048 or 4096) Always set both 512 for most systems, all type of memory cards and
-/  harddisk. But a larger value may be required for on-board flash memory and some
-/  type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
-/  to variable sector size and GET_SECTOR_SIZE command must be implemented to the
-/  disk_ioctl() function. */
-
-#define	_USE_TRIM      0
-/* This option switches support of ATA-TRIM. (0:Disable or 1:Enable)
-/  To enable Trim function, also CTRL_TRIM command should be implemented to the
-/  disk_ioctl() function. */
-
-#define _FS_NOFSINFO    0 /* 0,1,2 or 3 */
-/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
-/  option, and f_getfree() function at first time after volume mount will force
-/  a full FAT scan. Bit 1 controls the use of last allocated cluster number.
-/
-/  bit0=0: Use free cluster count in the FSINFO if available.
-/  bit0=1: Do not trust free cluster count in the FSINFO.
-/  bit1=0: Use last allocated cluster number in the FSINFO if available.
-/  bit1=1: Do not trust last allocated cluster number in the FSINFO.
-*/
-
-/*---------------------------------------------------------------------------/
-/ System Configurations
-/----------------------------------------------------------------------------*/
-
-#define _FS_TINY    0      /* 0:Normal or 1:Tiny */
-/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
-/  At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes.
-/  Instead of private sector buffer eliminated from the file object, common sector
-/  buffer in the file system object (FATFS) is used for the file data transfer. */
-
-#define _FS_EXFAT	0
-/* This option switches support of exFAT file system. (0:Disable or 1:Enable)
-/  When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1)
-/  Note that enabling exFAT discards C89 compatibility. */
-
-#define _FS_NORTC	0
-#define _NORTC_MON	6
-#define _NORTC_MDAY	4
-#define _NORTC_YEAR	2015
-/* The option _FS_NORTC switches timestamp functiton. If the system does not have
-/  any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable
-/  the timestamp function. All objects modified by FatFs will have a fixed timestamp
-/  defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time.
-/  To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be
-/  added to the project to get current time form real-time clock. _NORTC_MON,
-/  _NORTC_MDAY and _NORTC_YEAR have no effect.
-/  These options have no effect at read-only configuration (_FS_READONLY = 1). */
-
-#define _FS_LOCK    2     /* 0:Disable or >=1:Enable */
-/* The option _FS_LOCK switches file lock function to control duplicated file open
-/  and illegal operation to open objects. This option must be 0 when _FS_READONLY
-/  is 1.
-/
-/  0:  Disable file lock function. To avoid volume corruption, application program
-/      should avoid illegal open, remove and rename to the open objects.
-/  >0: Enable file lock function. The value defines how many files/sub-directories
-/      can be opened simultaneously under file lock control. Note that the file
-/      lock control is independent of re-entrancy. */
-
-#define _FS_REENTRANT    1  /* 0:Disable or 1:Enable */
-
-#define _USE_MUTEX       0 /* 0:Disable or 1:Enable */
-#define _FS_TIMEOUT      1000 /* Timeout period in unit of time ticks */
-#define _SYNC_t          osSemaphoreId
-/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
-/  module itself. Note that regardless of this option, file access to different
-/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
-/  and f_fdisk() function, are always not re-entrant. Only file/directory access
-/  to the same volume is under control of this function.
-/
-/   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
-/   1: Enable re-entrancy. Also user provided synchronization handlers,
-/      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
-/      function, must be added to the project. Samples are available in
-/      option/syscall.c.
-/
-/  The _FS_TIMEOUT defines timeout period in unit of time tick.
-/  The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
-/  SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
-/  included somewhere in the scope of ff.h. */
-
-/* define the ff_malloc ff_free macros as FreeRTOS pvPortMalloc and vPortFree macros */
-#if !defined(ff_malloc) && !defined(ff_free)
-#define ff_malloc  pvPortMalloc
-#define ff_free  vPortFree
-#endif
-
-#endif /* _FFCONF */

+ 0 - 170
mid_fatfs/sdcard_diskio.c

@@ -1,170 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
-  * @file    user_diskio.c
-  * @brief   This file includes a diskio driver skeleton to be completed by the user.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
-  *
-  ******************************************************************************
-  */
- /* USER CODE END Header */
-
-#ifdef USE_OBSOLETE_USER_CODE_SECTION_0
-/*
- * Warning: the user section 0 is no more in use (starting from CubeMx version 4.16.0)
- * To be suppressed in the future.
- * Kept to ensure backward compatibility with previous CubeMx versions when
- * migrating projects.
- * User code previously added there should be copied in the new user sections before
- * the section contents can be deleted.
- */
-/* USER CODE BEGIN 0 */
-/* USER CODE END 0 */
-#endif
-
-/* USER CODE BEGIN DECL */
-
-/* Includes ------------------------------------------------------------------*/
-#include <string.h>
-#include "ff_gen_drv.h"
-#include "obj_spi_sd_stm32.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* Private variables ---------------------------------------------------------*/
-/* Disk status */
-static volatile DSTATUS Stat = STA_NOINIT;
-
-/* USER CODE END DECL */
-
-/* Private function prototypes -----------------------------------------------*/
-DSTATUS sdcard_initialize (BYTE pdrv);
-DSTATUS sdcard_status (BYTE pdrv);
-DRESULT sdcard_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
-#if _USE_WRITE == 1
-  DRESULT sdcard_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
-#endif /* _USE_WRITE == 1 */
-#if _USE_IOCTL == 1
-  DRESULT sdcard_ioctl (BYTE pdrv, BYTE cmd, void *buff);
-#endif /* _USE_IOCTL == 1 */
-
-Diskio_drvTypeDef  sdcard_Driver =
-{
-  sdcard_initialize,
-  sdcard_status,
-  sdcard_read,
-#if  _USE_WRITE
-  sdcard_write,
-#endif  /* _USE_WRITE == 1 */
-#if  _USE_IOCTL == 1
-  sdcard_ioctl,
-#endif /* _USE_IOCTL == 1 */
-};
-
-/* Private functions ---------------------------------------------------------*/
-
-/**
-  * @brief  Initializes a Drive
-  * @param  pdrv: Physical drive number (0..)
-  * @retval DSTATUS: Operation status
-  */
-DSTATUS sdcard_initialize (
-	BYTE pdrv           /* Physical drive nmuber to identify the drive */
-)
-{
-  /* USER CODE BEGIN INIT */
-    Stat = SD_disk_initialize(pdrv);
-    return Stat;
-  /* USER CODE END INIT */
-}
-
-/**
-  * @brief  Gets Disk Status
-  * @param  pdrv: Physical drive number (0..)
-  * @retval DSTATUS: Operation status
-  */
-DSTATUS sdcard_status (
-	BYTE pdrv       /* Physical drive number to identify the drive */
-)
-{
-  /* USER CODE BEGIN STATUS */
-    Stat = SD_disk_status(pdrv);
-    return Stat;
-  /* USER CODE END STATUS */
-}
-
-/**
-  * @brief  Reads Sector(s)
-  * @param  pdrv: Physical drive number (0..)
-  * @param  *buff: Data buffer to store read data
-  * @param  sector: Sector address (LBA)
-  * @param  count: Number of sectors to read (1..128)
-  * @retval DRESULT: Operation result
-  */
-DRESULT sdcard_read (
-	BYTE pdrv,      /* Physical drive nmuber to identify the drive */
-	BYTE *buff,     /* Data buffer to store read data */
-	DWORD sector,   /* Sector address in LBA */
-	UINT count      /* Number of sectors to read */
-)
-{
-  /* USER CODE BEGIN READ */
-    return SD_disk_read(pdrv, buff, sector, count);
-  /* USER CODE END READ */
-}
-
-/**
-  * @brief  Writes Sector(s)
-  * @param  pdrv: Physical drive number (0..)
-  * @param  *buff: Data to be written
-  * @param  sector: Sector address (LBA)
-  * @param  count: Number of sectors to write (1..128)
-  * @retval DRESULT: Operation result
-  */
-#if _USE_WRITE == 1
-DRESULT sdcard_write (
-	BYTE pdrv,          /* Physical drive nmuber to identify the drive */
-	const BYTE *buff,   /* Data to be written */
-	DWORD sector,       /* Sector address in LBA */
-	UINT count          /* Number of sectors to write */
-)
-{
-  /* USER CODE BEGIN WRITE */
-  /* USER CODE HERE */
-    return SD_disk_write(pdrv, buff, sector, count);
-  /* USER CODE END WRITE */
-}
-#endif /* _USE_WRITE == 1 */
-
-/**
-  * @brief  I/O control operation
-  * @param  pdrv: Physical drive number (0..)
-  * @param  cmd: Control code
-  * @param  *buff: Buffer to send/receive control data
-  * @retval DRESULT: Operation result
-  */
-#if _USE_IOCTL == 1
-DRESULT sdcard_ioctl (
-	BYTE pdrv,      /* Physical drive nmuber (0..) */
-	BYTE cmd,       /* Control code */
-	void *buff      /* Buffer to send/receive control data */
-)
-{
-  /* USER CODE BEGIN IOCTL */
-    DRESULT res = SD_disk_ioctl(pdrv, cmd, buff);
-    return res;
-  /* USER CODE END IOCTL */
-}
-#endif /* _USE_IOCTL == 1 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 46
mid_fatfs/sdcard_diskio.h

@@ -1,46 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
-  * @file    user_diskio.h
-  * @brief   This file contains the common defines and functions prototypes for  
-  *          the user_diskio driver.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
-  *
-  ******************************************************************************
-  */
- /* USER CODE END Header */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef SDCARD_DISKIO_H
-#define SDCARD_DISKIO_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* USER CODE BEGIN 0 */
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-extern Diskio_drvTypeDef  sdcard_Driver;
-
-/* USER CODE END 0 */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //--------------------SDCARD_DISKIO_H--------------------------//
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 239
mid_fatfs/w25qxx_diskio.c

@@ -1,239 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
-  * @file    user_diskio.c
-  * @brief   This file includes a diskio driver skeleton to be completed by the user.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
-  *
-  ******************************************************************************
-  */
- /* USER CODE END Header */
-
-#ifdef USE_OBSOLETE_W25Q_CODE_SECTION_0
-/*
- * Warning: the user section 0 is no more in use (starting from CubeMx version 4.16.0)
- * To be suppressed in the future.
- * Kept to ensure backward compatibility with previous CubeMx versions when
- * migrating projects.
- * User code previously added there should be copied in the new user sections before
- * the section contents can be deleted.
- */
-/* USER CODE BEGIN 0 */
-/* USER CODE END 0 */
-#endif
-
-/* USER CODE BEGIN DECL */
-
-/* Includes ------------------------------------------------------------------*/
-#include <string.h>
-#include "ff_gen_drv.h"
-#include "obj_spi_sd_stm32.h"
-#include "obj_spi_w25qxx.h"
-#include "obj_hal_w25qxx.h"
-#include "obj_soft_w25qxx.h"
-#include "func_spi_w25qxx.h"
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-#define SD_CARD	 	0  		//SD卡,卷标为0
-#define EX_FLASH 	1			//外部spi flash,卷标为1
-#define EX_NAND  	2			//外部nand flash,卷标为2
-
-//对于W25Q128
-//#define FLASH_SECTOR_SIZE 	512	
-//#define FLASH_SECTOR_COUNT 	1024*16*2	//W25Q256,前25M字节给FATFS占用	
-//#define FLASH_BLOCK_SIZE   	8     		//每个BLOCK有8个扇区		
-/* Private variables ---------------------------------------------------------*/
-/* Disk status */
-static volatile DSTATUS Stat = STA_NOINIT;
-
-/* USER CODE END DECL */
-
-/* Private function prototypes -----------------------------------------------*/
-DSTATUS W25Q_initialize (BYTE pdrv);
-DSTATUS W25Q_status (BYTE pdrv);
-DRESULT W25Q_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
-#if _USE_WRITE == 1
-  DRESULT W25Q_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
-#endif /* _USE_WRITE == 1 */
-#if _USE_IOCTL == 1
-  DRESULT W25Q_ioctl (BYTE pdrv, BYTE cmd, void *buff);
-#endif /* _USE_IOCTL == 1 */
-
-Diskio_drvTypeDef  W25Q_Driver =
-{
-  W25Q_initialize,
-  W25Q_status,
-  W25Q_read,
-#if  _USE_WRITE
-  W25Q_write,
-#endif  /* _USE_WRITE == 1 */
-#if  _USE_IOCTL == 1
-  W25Q_ioctl,
-#endif /* _USE_IOCTL == 1 */
-};
-
-/* Private functions ---------------------------------------------------------*/
-
-/**
-  * @brief  Initializes a Drive
-  * @param  pdrv: Physical drive number (0..)
-  * @retval DSTATUS: Operation status
-  */
-DSTATUS W25Q_initialize (
-	BYTE pdrv           /* Physical drive nmuber to identify the drive */
-)
-{
-  /* USER CODE BEGIN INIT */
-	uint8_t res=0;	 
-
-	func_w25q_init();  //W25QXX初始化	
-	
-	if(res)
-	{
-		return  STA_NOINIT;
-	}
-	else 
-	{
-		return 0; //初始化成功 
-	}
-	
-  /* USER CODE END INIT */
-}
-
-/**
-  * @brief  Gets Disk Status
-  * @param  pdrv: Physical drive number (0..)
-  * @retval DSTATUS: Operation status
-  */
-DSTATUS W25Q_status (
-	BYTE pdrv       /* Physical drive number to identify the drive */
-)
-{
-  /* USER CODE BEGIN STATUS */
-
-	uint8_t res=0;	    
-
-	if(res)
-	{
-		return  STA_NOINIT;
-	}
-	else 
-	{
-		return 0; 
-	}
-
-  /* USER CODE END STATUS */
-}
-//uint8_t data_buf[3][0x1000]  = {0};
-/**
-  * @brief  Reads Sector(s)
-  * @param  pdrv: Physical drive number (0..)
-  * @param  *buff: Data buffer to store read data
-  * @param  sector: Sector address (LBA)
-  * @param  count: Number of sectors to read (1..128)
-  * @retval DRESULT: Operation result
-  */
-DRESULT W25Q_read (
-	BYTE pdrv,      /* Physical drive nmuber to identify the drive */
-	BYTE *buff,     /* Data buffer to store read data */
-	DWORD sector,   /* Sector address in LBA */
-	UINT count      /* Number of sectors to read */
-)
-{
-
-		uint8_t res=0; 
-    if (!count)return RES_PARERR;//count不能等于0,否则返回参数错误		 	 
-
-		W25QXX_Read(buff, sector * SPI_FLASH_SECTOR_SIZE,  count * SPI_FLASH_SECTOR_SIZE);
-
-   //处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值
-    if(res==0x00)return RES_OK;	 
-    else return RES_ERROR;	 
-
-}
-
-
-/**
-  * @brief  Writes Sector(s)
-  * @param  pdrv: Physical drive number (0..)
-  * @param  *buff: Data to be written
-  * @param  sector: Sector address (LBA)
-  * @param  count: Number of sectors to write (1..128)
-  * @retval DRESULT: Operation result
-  */
-#if _USE_WRITE == 1
-DRESULT W25Q_write (
-	BYTE pdrv,          /* Physical drive nmuber to identify the drive */
-	const BYTE *buff,   /* Data to be written */
-	DWORD sector,       /* Sector address in LBA */
-	UINT count          /* Number of sectors to write */
-)
-{
-  /* USER CODE BEGIN WRITE */
-  /* USER CODE HERE */
-
-	uint8_t res=0;  
-	
-  if (!count)return RES_PARERR;//count不能等于0,否则返回参数错误		 	
-	
-	W25QXX_Write((uint8_t*)buff, sector * SPI_FLASH_SECTOR_SIZE,  count * SPI_FLASH_SECTOR_SIZE);
-
-	//处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值
-	if(res == 0x00)
-	{
-		return RES_OK;	
-	} 
-	else 
-	{
-		return RES_ERROR;
-	}	
-
-  /* USER CODE END WRITE */
-}
-#endif /* _USE_WRITE == 1 */
-
-/**
-  * @brief  I/O control operation
-  * @param  pdrv: Physical drive number (0..)
-  * @param  cmd: Control code
-  * @param  *buff: Buffer to send/receive control data
-  * @retval DRESULT: Operation result
-  */
-#if _USE_IOCTL == 1
-DRESULT W25Q_ioctl (
-	BYTE pdrv,      /* Physical drive nmuber (0..) */
-	BYTE cmd,       /* Control code */
-	void *buff      /* Buffer to send/receive control data */
-)
-{
-  /* USER CODE BEGIN IOCTL */
-	uint8_t res=RES_OK;  		
-
-	res = func_w25q_disk_ioctl(pdrv, cmd, buff);
-
-	//处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值
-	if(res == 0x00)
-	{
-		return RES_OK;	
-	} 
-	else 
-	{
-		return RES_ERROR;
-	}	
-		
-  /* USER CODE END IOCTL */
-}
-
-#endif /* _USE_IOCTL == 1 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 46
mid_fatfs/w25qxx_diskio.h

@@ -1,46 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
-  * @file    user_diskio.h
-  * @brief   This file contains the common defines and functions prototypes for  
-  *          the user_diskio driver.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
-  * All rights reserved.</center></h2>
-  *
-  * This software component is licensed by ST under Ultimate Liberty license
-  * SLA0044, the "License"; You may not use this file except in compliance with
-  * the License. You may obtain a copy of the License at:
-  *                             www.st.com/SLA0044
-  *
-  ******************************************************************************
-  */
- /* USER CODE END Header */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef W25Q_DISKIO_H
-#define W25Q_DISKIO_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* USER CODE BEGIN 0 */
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-extern Diskio_drvTypeDef  W25Q_Driver;
-
-/* USER CODE END 0 */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* W25Q_DISKIO_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 969
obj/obj_sdmmc_sdcard.c

@@ -1,969 +0,0 @@
-#ifdef USE_SDIO_SD
-#include "obj_sdmmc_sdcard.h"
-#include "string.h"  
-#include "usart.h"	 
-//////////////////////////////////////////////////////////////////////////////////	 
-//本程序只供学习使用,未经作者许可,不得用于其它任何用途
-//ALIENTEK STM32H7开发板
-//SDMMC 驱动代码	(仅提供查询模式驱动代码)
-//正点原子@ALIENTEK
-//技术论坛:www.openedv.com
-//创建日期:2018/7/31
-//版本:V1.0
-//版权所有,盗版必究。
-//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
-//All rights reserved		 
-//********************************************************************************
-//升级说明
-//无
-////////////////////////////////////////////////////////////////////////////////// 	 
-static u8 CardType=STD_CAPACITY_SD_CARD_V1_1;			//SD卡类型(默认为1.x卡)
-static u32 CSD_Tab[4],CID_Tab[4],RCA=0;					//SD卡CSD,CID以及相对地址(RCA)数据
-SD_CardInfo SDCardInfo;									//SD卡信息
-
-//SD_ReadDisk/SD_WriteDisk函数专用buf,当这两个函数的数据缓存区地址不是4字节对齐的时候,
-//需要用到该数组,确保数据缓存区地址是4字节对齐的.
-__align(4) u8 SDMMC_DATA_BUFFER[512];						  
- 
-
-//初始化SD卡
-//返回值:错误代码;(0,无错误)
-SD_Error SD_Init(void)
-{
-	SD_Error errorstatus=SD_OK;	  
-	u8 clkdiv=0;
-	//SDMMC1 IO口初始化   	 
-    GPIO_InitTypeDef GPIO_Initure;
-
-    __HAL_RCC_SDMMC1_CLK_ENABLE();  //使能SDMMC1时钟
-    __HAL_RCC_GPIOC_CLK_ENABLE();   //使能GPIOC时钟
-    __HAL_RCC_GPIOD_CLK_ENABLE();   //使能GPIOD时钟
-/*    
-    //PC8,9,10,11,12
-    GPIO_Initure.Pin=GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
-    GPIO_Initure.Mode=GPIO_MODE_AF_PP;      //推挽复用
-    GPIO_Initure.Pull=GPIO_NOPULL;          //无上下拉
-    GPIO_Initure.Speed=GPIO_SPEED_FREQ_VERY_HIGH;     //高速
-    GPIO_Initure.Alternate=GPIO_AF12_SDIO; //复用为SDIO
-    HAL_GPIO_Init(GPIOC,&GPIO_Initure);     //初始化
-    
-    //PD2
-    GPIO_Initure.Pin=GPIO_PIN_2;            
-    HAL_GPIO_Init(GPIOD,&GPIO_Initure);     //初始化
-*/
-
-		 
-		//SDIO_DAT0 							PB14
-		//RMII_TXD1&SDIO_CLK  		PB13
-		//SDIO_CMD 								PB15
-		//RMII_TXD0&SDIO_CD/DAT3 	PB12
-
-    GPIO_Initure.Pin=GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
-    GPIO_Initure.Mode=GPIO_MODE_AF_PP;      //推挽复用
-    GPIO_Initure.Pull=GPIO_NOPULL;          //无上下拉
-    GPIO_Initure.Speed=GPIO_SPEED_FREQ_VERY_HIGH;     //高速
-    GPIO_Initure.Alternate=GPIO_AF12_SDIO; //复用为SDIO
-    HAL_GPIO_Init(GPIOC,&GPIO_Initure);     //初始化
-    
-    //SDIO-nCD	 	PD8   
-    GPIO_Initure.Pin=GPIO_PIN_8;            
-    HAL_GPIO_Init(GPIOD,&GPIO_Initure);     //初始化
-		
- 	//SDMMC外设寄存器设置为默认值 			   
-	SDMMC1->POWER=0x00000000;
-	SDMMC1->CLKCR=0x00000000;
-	SDMMC1->ARG=0x00000000;
-	SDMMC1->CMD=0x00000000;
-	SDMMC1->DTIMER=0x00000000;
-	SDMMC1->DLEN=0x00000000;
-	SDMMC1->DCTRL=0x00000000;
-	SDMMC1->ICR=0X1FE00FFF;
-	SDMMC1->MASK=0x00000000;	  
-
-    HAL_NVIC_SetPriority(SDMMC1_IRQn,2,0);  //配置SDMMC1中断,抢占优先级2,子优先级0
-    HAL_NVIC_EnableIRQ(SDMMC1_IRQn);        //使能SDMMC1中断
-    
-   	errorstatus=SD_PowerON();			//SD卡上电
- 	if(errorstatus==SD_OK)errorstatus=SD_InitializeCards();			//初始化SD卡														  
-  	if(errorstatus==SD_OK)errorstatus=SD_GetCardInfo(&SDCardInfo);	//获取卡信息
- 	if(errorstatus==SD_OK)errorstatus=SD_SelectDeselect((u32)(SDCardInfo.RCA<<16));//选中SD卡   
-   	if(errorstatus==SD_OK)errorstatus=SD_EnableWideBusOperation(1);	//4位宽度,如果是MMC卡,则不能用4位模式 
-  	if((errorstatus==SD_OK)||(MULTIMEDIA_CARD==CardType))
-	{  		    
-		if(SDCardInfo.CardType==STD_CAPACITY_SD_CARD_V1_1||SDCardInfo.CardType==STD_CAPACITY_SD_CARD_V2_0)
-		{
-			clkdiv=SDMMC_TRANSFER_CLK_DIV+2;	//V1.1/V2.0卡,设置最高48/4=12Mhz
-		}else clkdiv=SDMMC_TRANSFER_CLK_DIV;	//SDHC等其他卡,设置最高48/2=24Mhz
-		SDMMC_Clock_Set(clkdiv);	//设置时钟频率,SDMMC时钟计算公式:SDMMC_CK时钟=SDMMCCLK/[clkdiv+2];其中,SDMMCCLK固定为48Mhz 
-  	}
-	return errorstatus;		 
-}
-//SDMMC时钟初始化设置
-//clkdiv:时钟分频系数
-//CK时钟=sdmmc_ker_ck/[2*clkdiv];(sdmmc_ker_ck钟固定为400Mhz)
-void SDMMC_Clock_Set(u16 clkdiv)
-{
-	u32 tmpreg=SDMMC1->CLKCR; 
-  	tmpreg&=0XFFFFFC00; 
- 	tmpreg|=clkdiv;   
-	SDMMC1->CLKCR=tmpreg;
-} 
-//SDMMC发送命令函数
-//cmdindex:命令索引,低六位有效
-//waitrsp:期待的相应.00/10,无响应;01,短响应;11,长响应
-//arg:参数
-void SDMMC_Send_Cmd(u8 cmdindex,u8 waitrsp,u32 arg)
-{			
-	u32 tmpreg=0;
-	SDMMC1->ARG=arg;  
-	tmpreg|=cmdindex&0X3F;	//设置新的index			 
-	tmpreg|=(u32)waitrsp<<8;//设置新的wait rsp 
-	tmpreg|=0<<10;			//无等待
-  	tmpreg|=1<<12;			//命令通道状态机使能
-	SDMMC1->CMD=tmpreg;
-}
-//SDMMC发送数据配置函数
-//datatimeout:超时时间设置
-//datalen:传输数据长度,低25位有效,必须为块大小的整数倍
-//blksize:块大小.实际大小为:2^blksize字节
-//dir:数据传输方向:0,控制器到卡;1,卡到控制器;
-void SDMMC_Send_Data_Cfg(u32 datatimeout,u32 datalen,u8 blksize,u8 dir)
-{
-	u32 tmpreg;
-	SDMMC1->DTIMER=datatimeout;
-  	SDMMC1->DLEN=datalen&0X1FFFFFF;	//低25位有效
-	tmpreg=SDMMC1->DCTRL; 
-	tmpreg&=0xFFFFFF00;		//清除之前的设置.
-	tmpreg|=blksize<<4;		//设置块大小
-	tmpreg|=0<<2;			//块数据传输
-	tmpreg|=(dir&0X01)<<1;	//方向控制
-	tmpreg|=1<<0;			//数据传输使能,DPSM状态机
-	SDMMC1->DCTRL=tmpreg;		
-}  
-
-//卡上电
-//查询所有SDMMC接口上的卡设备,并查询其电压和配置时钟
-//返回值:错误代码;(0,无错误)
-SD_Error SD_PowerON(void)
-{
- 	u8 i=0;
-	u32 tempreg=0;
-	SD_Error errorstatus=SD_OK;
-	u32 response=0,count=0,validvoltage=0;
-	u32 SDType=SD_STD_CAPACITY;
-	//配置CLKCR寄存器  
-	tempreg|=0<<12;				//PWRSAV=0,非省电模式 
-	tempreg|=0<<14;				//WIDBUS[1:0]=0,1位数据宽度
-	tempreg|=0<<16;				//NEGEDGE=0,SDMMCCK下降沿更改命令和数据
-	tempreg|=0<<17;				//HWFC_EN=0,关闭硬件流控制    
-	SDMMC1->CLKCR=tempreg; 
-	SDMMC_Clock_Set(SDMMC_INIT_CLK_DIV);//设置时钟频率(初始化的时候,不能超过400Khz)			 
- 	SDMMC1->POWER=0X03;			//上电状态,开启卡时钟     
-   	for(i=0;i<74;i++)
-	{
-		SDMMC_Send_Cmd(SD_CMD_GO_IDLE_STATE,0,0);//发送CMD0进入IDLE STAGE模式命令.												  
-		errorstatus=CmdError();
-		if(errorstatus==SD_OK)break;
- 	}
- 	if(errorstatus)return errorstatus;//返回错误状态
-	SDMMC_Send_Cmd(SD_SDMMC_SEND_IF_COND,1,SD_CHECK_PATTERN);//发送CMD8,短响应,检查SD卡接口特性.
- 														//arg[11:8]:01,支持电压范围,2.7~3.6V
-														//arg[7:0]:默认0XAA
-														//返回响应7
-  	errorstatus=CmdResp7Error();						//等待R7响应
- 	if(errorstatus==SD_OK) 								//R7响应正常
-	{
-		CardType=STD_CAPACITY_SD_CARD_V2_0;				//SD 2.0卡
-		SDType=SD_HIGH_CAPACITY;			   			//高容量卡
-	}
-	SDMMC_Send_Cmd(SD_CMD_APP_CMD,1,0);					//发送CMD55,短响应	 
-	errorstatus=CmdResp1Error(SD_CMD_APP_CMD); 		 	//等待R1响应   
-	if(errorstatus==SD_OK)//SD2.0/SD 1.1,否则为MMC卡
-	{																  
-		//SD卡,发送ACMD41 SD_APP_OP_COND,参数为:0x80100000 
-		while((!validvoltage)&&(count<SD_MAX_VOLT_TRIAL))
-		{	   										   
-			SDMMC_Send_Cmd(SD_CMD_APP_CMD,1,0);				//发送CMD55,短响应	 
-			errorstatus=CmdResp1Error(SD_CMD_APP_CMD); 	 	//等待R1响应   
- 			if(errorstatus!=SD_OK)return errorstatus;   	//响应错误
-			SDMMC_Send_Cmd(SD_CMD_SD_APP_OP_COND,1,SD_VOLTAGE_WINDOW_SD|SDType);//发送ACMD41,短响应	 
-			errorstatus=CmdResp3Error(); 					//等待R3响应   
- 			if(errorstatus!=SD_OK)return errorstatus;   	//响应错误  
-			response=SDMMC1->RESP1;;			   				//得到响应
-			validvoltage=(((response>>31)==1)?1:0);			//判断SD卡上电是否完成
-			count++;
-		}
-		if(count>=SD_MAX_VOLT_TRIAL)
-		{
-			errorstatus=SD_INVALID_VOLTRANGE;
-			return errorstatus;
-		}	 
-		if(response&=SD_HIGH_CAPACITY)
-		{
-			CardType=HIGH_CAPACITY_SD_CARD;
-		}
- 	}else//MMC卡
-	{
-		//MMC卡,发送CMD1 SDMMC_SEND_OP_COND,参数为:0x80FF8000 
-		while((!validvoltage)&&(count<SD_MAX_VOLT_TRIAL))
-		{	   										   				   
-			SDMMC_Send_Cmd(SD_CMD_SEND_OP_COND,1,SD_VOLTAGE_WINDOW_MMC);//发送CMD1,短响应	 
-			errorstatus=CmdResp3Error(); 					//等待R3响应   
- 			if(errorstatus!=SD_OK)return errorstatus;   	//响应错误  
-			response=SDMMC1->RESP1;;			   				//得到响应
-			validvoltage=(((response>>31)==1)?1:0);
-			count++;
-		}
-		if(count>=SD_MAX_VOLT_TRIAL)
-		{
-			errorstatus=SD_INVALID_VOLTRANGE;
-			return errorstatus;
-		}	 			    
-		CardType=MULTIMEDIA_CARD;	  
-  	}  
-  	return(errorstatus);		
-}
-//SD卡 Power OFF
-//返回值:错误代码;(0,无错误)
-SD_Error SD_PowerOFF(void)
-{
-  	SDMMC1->POWER&=~(3<<0);//SDMMC电源关闭,时钟停止	
-	return SD_OK;		  
-}   
-//初始化所有的卡,并让卡进入就绪状态
-//返回值:错误代码
-SD_Error SD_InitializeCards(void)
-{
- 	SD_Error errorstatus=SD_OK;
-	u16 rca = 0x01;
- 	if((SDMMC1->POWER&0X03)==0)return SD_REQUEST_NOT_APPLICABLE;//检查电源状态,确保为上电状态
- 	if(SECURE_DIGITAL_IO_CARD!=CardType)				//非SECURE_DIGITAL_IO_CARD
-	{
-		SDMMC_Send_Cmd(SD_CMD_ALL_SEND_CID,3,0);		//发送CMD2,取得CID,长响应	 
-		errorstatus=CmdResp2Error(); 					//等待R2响应   
-		if(errorstatus!=SD_OK)return errorstatus;   	//响应错误		    
- 		CID_Tab[0]=SDMMC1->RESP1;
-		CID_Tab[1]=SDMMC1->RESP2;
-		CID_Tab[2]=SDMMC1->RESP3;
-		CID_Tab[3]=SDMMC1->RESP4;
-	}
-	if((STD_CAPACITY_SD_CARD_V1_1==CardType)||(STD_CAPACITY_SD_CARD_V2_0==CardType)||(SECURE_DIGITAL_IO_COMBO_CARD==CardType)||(HIGH_CAPACITY_SD_CARD==CardType))//判断卡类型
-	{
-		SDMMC_Send_Cmd(SD_CMD_SET_REL_ADDR,1,0);			//发送CMD3,短响应 
-		errorstatus=CmdResp6Error(SD_CMD_SET_REL_ADDR,&rca);//等待R6响应 
-		if(errorstatus!=SD_OK)return errorstatus;   	//响应错误		    
-	}   
-    if (MULTIMEDIA_CARD==CardType)
-    {
- 		SDMMC_Send_Cmd(SD_CMD_SET_REL_ADDR,1,(u32)(rca<<16));//发送CMD3,短响应 	   
-		errorstatus=CmdResp2Error(); 					//等待R2响应   
-		if(errorstatus!=SD_OK)return errorstatus;   	//响应错误	 
-    }
-	if (SECURE_DIGITAL_IO_CARD!=CardType)			//非SECURE_DIGITAL_IO_CARD
-	{
-		RCA = rca;
-		SDMMC_Send_Cmd(SD_CMD_SEND_CSD,3,(u32)(rca<<16));//发送CMD9+卡RCA,取得CSD,长响应 	   
-		errorstatus=CmdResp2Error(); 					//等待R2响应   
-		if(errorstatus!=SD_OK)return errorstatus;   	//响应错误		    
-  		CSD_Tab[0]=SDMMC1->RESP1;
-		CSD_Tab[1]=SDMMC1->RESP2;
-		CSD_Tab[2]=SDMMC1->RESP3;						
-		CSD_Tab[3]=SDMMC1->RESP4;					    
-	}
-	return SD_OK;//卡初始化成功
-} 
-//得到卡信息
-//cardinfo:卡信息存储区
-//返回值:错误状态
-SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
-{
- 	SD_Error errorstatus=SD_OK;
-	u8 tmp=0;	   
-	cardinfo->CardType=(u8)CardType; 				//卡类型
-	cardinfo->RCA=(u16)RCA;							//卡RCA值
-	tmp=(u8)((CSD_Tab[0]&0xFF000000)>>24);
-	cardinfo->SD_csd.CSDStruct=(tmp&0xC0)>>6;		//CSD结构
-	cardinfo->SD_csd.SysSpecVersion=(tmp&0x3C)>>2;	//2.0协议还没定义这部分(为保留),应该是后续协议定义的
-	cardinfo->SD_csd.Reserved1=tmp&0x03;			//2个保留位  
-	tmp=(u8)((CSD_Tab[0]&0x00FF0000)>>16);			//第1个字节
-	cardinfo->SD_csd.TAAC=tmp;				   		//数据读时间1
-	tmp=(u8)((CSD_Tab[0]&0x0000FF00)>>8);	  		//第2个字节
-	cardinfo->SD_csd.NSAC=tmp;		  				//数据读时间2
-	tmp=(u8)(CSD_Tab[0]&0x000000FF);				//第3个字节
-	cardinfo->SD_csd.MaxBusClkFrec=tmp;		  		//传输速度	   
-	tmp=(u8)((CSD_Tab[1]&0xFF000000)>>24);			//第4个字节
-	cardinfo->SD_csd.CardComdClasses=tmp<<4;    	//卡指令类高四位
-	tmp=(u8)((CSD_Tab[1]&0x00FF0000)>>16);	 		//第5个字节
-	cardinfo->SD_csd.CardComdClasses|=(tmp&0xF0)>>4;//卡指令类低四位
-	cardinfo->SD_csd.RdBlockLen=tmp&0x0F;	    	//最大读取数据长度
-	tmp=(u8)((CSD_Tab[1]&0x0000FF00)>>8);			//第6个字节
-	cardinfo->SD_csd.PartBlockRead=(tmp&0x80)>>7;	//允许分块读
-	cardinfo->SD_csd.WrBlockMisalign=(tmp&0x40)>>6;	//写块错位
-	cardinfo->SD_csd.RdBlockMisalign=(tmp&0x20)>>5;	//读块错位
-	cardinfo->SD_csd.DSRImpl=(tmp&0x10)>>4;
-	cardinfo->SD_csd.Reserved2=0; 					//保留
- 	if((CardType==STD_CAPACITY_SD_CARD_V1_1)||(CardType==STD_CAPACITY_SD_CARD_V2_0)||(MULTIMEDIA_CARD==CardType))//标准1.1/2.0卡/MMC卡
-	{
-		cardinfo->SD_csd.DeviceSize=(tmp&0x03)<<10;	//C_SIZE(12位)
-	 	tmp=(u8)(CSD_Tab[1]&0x000000FF); 			//第7个字节	
-		cardinfo->SD_csd.DeviceSize|=(tmp)<<2;
- 		tmp=(u8)((CSD_Tab[2]&0xFF000000)>>24);		//第8个字节	
-		cardinfo->SD_csd.DeviceSize|=(tmp&0xC0)>>6;
- 		cardinfo->SD_csd.MaxRdCurrentVDDMin=(tmp&0x38)>>3;
-		cardinfo->SD_csd.MaxRdCurrentVDDMax=(tmp&0x07);
- 		tmp=(u8)((CSD_Tab[2]&0x00FF0000)>>16);		//第9个字节	
-		cardinfo->SD_csd.MaxWrCurrentVDDMin=(tmp&0xE0)>>5;
-		cardinfo->SD_csd.MaxWrCurrentVDDMax=(tmp&0x1C)>>2;
-		cardinfo->SD_csd.DeviceSizeMul=(tmp&0x03)<<1;//C_SIZE_MULT
- 		tmp=(u8)((CSD_Tab[2]&0x0000FF00)>>8);	  	//第10个字节	
-		cardinfo->SD_csd.DeviceSizeMul|=(tmp&0x80)>>7;
- 		cardinfo->CardCapacity=(cardinfo->SD_csd.DeviceSize+1);//计算卡容量
-		cardinfo->CardCapacity*=(1<<(cardinfo->SD_csd.DeviceSizeMul+2));
-		cardinfo->CardBlockSize=1<<(cardinfo->SD_csd.RdBlockLen);//块大小
-		cardinfo->CardCapacity*=cardinfo->CardBlockSize;
-	}else if(CardType==HIGH_CAPACITY_SD_CARD)	//高容量卡
-	{
- 		tmp=(u8)(CSD_Tab[1]&0x000000FF); 		//第7个字节	
-		cardinfo->SD_csd.DeviceSize=(tmp&0x3F)<<16;//C_SIZE
- 		tmp=(u8)((CSD_Tab[2]&0xFF000000)>>24); 	//第8个字节	
- 		cardinfo->SD_csd.DeviceSize|=(tmp<<8);
- 		tmp=(u8)((CSD_Tab[2]&0x00FF0000)>>16);	//第9个字节	
- 		cardinfo->SD_csd.DeviceSize|=(tmp);
- 		tmp=(u8)((CSD_Tab[2]&0x0000FF00)>>8); 	//第10个字节	
- 		cardinfo->CardCapacity=(long long)(cardinfo->SD_csd.DeviceSize+1)*512*1024;//计算卡容量
-		cardinfo->CardBlockSize=512; 			//块大小固定为512字节
-	}	  
-	cardinfo->SD_csd.EraseGrSize=(tmp&0x40)>>6;
-	cardinfo->SD_csd.EraseGrMul=(tmp&0x3F)<<1;	   
-	tmp=(u8)(CSD_Tab[2]&0x000000FF);			//第11个字节	
-	cardinfo->SD_csd.EraseGrMul|=(tmp&0x80)>>7;
-	cardinfo->SD_csd.WrProtectGrSize=(tmp&0x7F);
- 	tmp=(u8)((CSD_Tab[3]&0xFF000000)>>24);		//第12个字节	
-	cardinfo->SD_csd.WrProtectGrEnable=(tmp&0x80)>>7;
-	cardinfo->SD_csd.ManDeflECC=(tmp&0x60)>>5;
-	cardinfo->SD_csd.WrSpeedFact=(tmp&0x1C)>>2;
-	cardinfo->SD_csd.MaxWrBlockLen=(tmp&0x03)<<2;	 
-	tmp=(u8)((CSD_Tab[3]&0x00FF0000)>>16);		//第13个字节
-	cardinfo->SD_csd.MaxWrBlockLen|=(tmp&0xC0)>>6;
-	cardinfo->SD_csd.WriteBlockPaPartial=(tmp&0x20)>>5;
-	cardinfo->SD_csd.Reserved3=0;
-	cardinfo->SD_csd.ContentProtectAppli=(tmp&0x01);  
-	tmp=(u8)((CSD_Tab[3]&0x0000FF00)>>8);		//第14个字节
-	cardinfo->SD_csd.FileFormatGrouop=(tmp&0x80)>>7;
-	cardinfo->SD_csd.CopyFlag=(tmp&0x40)>>6;
-	cardinfo->SD_csd.PermWrProtect=(tmp&0x20)>>5;
-	cardinfo->SD_csd.TempWrProtect=(tmp&0x10)>>4;
-	cardinfo->SD_csd.FileFormat=(tmp&0x0C)>>2;
-	cardinfo->SD_csd.ECC=(tmp&0x03);  
-	tmp=(u8)(CSD_Tab[3]&0x000000FF);			//第15个字节
-	cardinfo->SD_csd.CSD_CRC=(tmp&0xFE)>>1;
-	cardinfo->SD_csd.Reserved4=1;		 
-	tmp=(u8)((CID_Tab[0]&0xFF000000)>>24);		//第0个字节
-	cardinfo->SD_cid.ManufacturerID=tmp;		    
-	tmp=(u8)((CID_Tab[0]&0x00FF0000)>>16);		//第1个字节
-	cardinfo->SD_cid.OEM_AppliID=tmp<<8;	  
-	tmp=(u8)((CID_Tab[0]&0x000000FF00)>>8);		//第2个字节
-	cardinfo->SD_cid.OEM_AppliID|=tmp;	    
-	tmp=(u8)(CID_Tab[0]&0x000000FF);			//第3个字节	
-	cardinfo->SD_cid.ProdName1=tmp<<24;				  
-	tmp=(u8)((CID_Tab[1]&0xFF000000)>>24); 		//第4个字节
-	cardinfo->SD_cid.ProdName1|=tmp<<16;	  
-	tmp=(u8)((CID_Tab[1]&0x00FF0000)>>16);	   	//第5个字节
-	cardinfo->SD_cid.ProdName1|=tmp<<8;		 
-	tmp=(u8)((CID_Tab[1]&0x0000FF00)>>8);		//第6个字节
-	cardinfo->SD_cid.ProdName1|=tmp;		   
-	tmp=(u8)(CID_Tab[1]&0x000000FF);	  		//第7个字节
-	cardinfo->SD_cid.ProdName2=tmp;			  
-	tmp=(u8)((CID_Tab[2]&0xFF000000)>>24); 		//第8个字节
-	cardinfo->SD_cid.ProdRev=tmp;		 
-	tmp=(u8)((CID_Tab[2]&0x00FF0000)>>16);		//第9个字节
-	cardinfo->SD_cid.ProdSN=tmp<<24;	   
-	tmp=(u8)((CID_Tab[2]&0x0000FF00)>>8); 		//第10个字节
-	cardinfo->SD_cid.ProdSN|=tmp<<16;	   
-	tmp=(u8)(CID_Tab[2]&0x000000FF);   			//第11个字节
-	cardinfo->SD_cid.ProdSN|=tmp<<8;		   
-	tmp=(u8)((CID_Tab[3]&0xFF000000)>>24); 		//第12个字节
-	cardinfo->SD_cid.ProdSN|=tmp;			     
-	tmp=(u8)((CID_Tab[3]&0x00FF0000)>>16);	 	//第13个字节
-	cardinfo->SD_cid.Reserved1|=(tmp&0xF0)>>4;
-	cardinfo->SD_cid.ManufactDate=(tmp&0x0F)<<8;    
-	tmp=(u8)((CID_Tab[3]&0x0000FF00)>>8);		//第14个字节
-	cardinfo->SD_cid.ManufactDate|=tmp;		 	  
-	tmp=(u8)(CID_Tab[3]&0x000000FF);			//第15个字节
-	cardinfo->SD_cid.CID_CRC=(tmp&0xFE)>>1;
-	cardinfo->SD_cid.Reserved2=1;	 
-	return errorstatus;
-}
-//设置SDMMC总线宽度(MMC卡不支持4bit模式)
-//wmode:位宽模式.0,1位数据宽度;1,4位数据宽度;2,8位数据宽度
-//返回值:SD卡错误状态
-SD_Error SD_EnableWideBusOperation(u32 wmode)
-{
-  	SD_Error errorstatus=SD_OK;
-	u16 clkcr=0;
-  	if(MULTIMEDIA_CARD==CardType)return SD_UNSUPPORTED_FEATURE;//MMC卡不支持
- 	else if((STD_CAPACITY_SD_CARD_V1_1==CardType)||(STD_CAPACITY_SD_CARD_V2_0==CardType)||(HIGH_CAPACITY_SD_CARD==CardType))
-	{
-		if(wmode>=2)return SD_UNSUPPORTED_FEATURE;//不支持8位模式
- 		else   
-		{
-			errorstatus=SDEnWideBus(wmode);
- 			if(SD_OK==errorstatus)
-			{
-				clkcr=SDMMC1->CLKCR;	//读取CLKCR的值
-				clkcr&=~(3<<14);		//清除之前的位宽设置    
-				clkcr|=(u32)wmode<<14;	//1位/4位总线宽度 
-				clkcr|=0<<17;			//不开启硬件流控制
-				SDMMC1->CLKCR=clkcr;	//重新设置CLKCR值 
-			}
-		}  
-	} 
-	return errorstatus; 
-} 
-//选卡
-//发送CMD7,选择相对地址(rca)为addr的卡,取消其他卡.如果为0,则都不选择.
-//addr:卡的RCA地址
-SD_Error SD_SelectDeselect(u32 addr)
-{
- 	SDMMC_Send_Cmd(SD_CMD_SEL_DESEL_CARD,1,addr);	//发送CMD7,选择卡,短响应	 	   
-   	return CmdResp1Error(SD_CMD_SEL_DESEL_CARD);	  
-}  
-//SD卡读取单个/多个块 
-//buf:读数据缓存区
-//addr:读取地址
-//blksize:块大小
-//nblks:要读取的块数,1,表示读取单个块
-//返回值:错误状态 
-SD_Error SD_ReadBlocks(u8 *buf,long long addr,u16 blksize,u32 nblks)
-{
-  	SD_Error errorstatus=SD_OK; 
-   	u32 count=0;
-	u32 timeout=SDMMC_DATATIMEOUT;  
-	u32 *tempbuff=(u32*)buf;	//转换为u32指针 
-    SDMMC1->DCTRL=0x0;			//数据控制寄存器清零(关DMA)   
-	if(CardType==HIGH_CAPACITY_SD_CARD)//大容量卡
-	{
-		blksize=512;
-		addr>>=9;
-	}     
-	SDMMC_Send_Cmd(SD_CMD_SET_BLOCKLEN,1,blksize);			//发送CMD16+设置数据长度为blksize,短响应 	   
-	errorstatus=CmdResp1Error(SD_CMD_SET_BLOCKLEN);			//等待R1响应   
-	if(errorstatus!=SD_OK)
-    {
-        printf("SDMMC_Send_Cmd=%d\r\n",errorstatus);
-        return errorstatus;   			//响应错误
-    }
-	SDMMC_Send_Data_Cfg(SD_DATATIMEOUT,nblks*blksize,9,1);	//nblks*blksize,块大小恒为512,卡到控制器	 
-	SDMMC1->CMD|=1<<6;										//CMDTRANS=1,产生一个数据传输命令
-	if(nblks>1)												//多块读  
-	{									    
-		SDMMC_Send_Cmd(SD_CMD_READ_MULT_BLOCK,1,addr);		//发送CMD18+从addr地址出读取数据,短响应 	   
-		errorstatus=CmdResp1Error(SD_CMD_READ_MULT_BLOCK);	//等待R1响应   
-		if(errorstatus!=SD_OK)
-		{	
-			printf("SD_CMD_READ_MULT_BLOCK Error\r\n");
-			return errorstatus;   		//响应错误	 
-		}
-	}else													//单块读
-	{ 
-		SDMMC_Send_Cmd(SD_CMD_READ_SINGLE_BLOCK,1,addr);		//发送CMD17+从addr地址出读取数据,短响应 	   
-		errorstatus=CmdResp1Error(SD_CMD_READ_SINGLE_BLOCK);//等待R1响应   
-		if(errorstatus!=SD_OK)return errorstatus;   		//响应错误	 
-	} 
-	INTX_DISABLE();//关闭总中断(POLLING模式,严禁中断打断SDMMC读写操作!!!)
-	while(!(SDMMC1->STA&((1<<5)|(1<<1)|(1<<3)|(1<<8))))//无上溢/CRC/超时/完成(标志)
-	{
-		if(SDMMC1->STA&(1<<15))						//接收区半满,表示至少存了8个字
-		{
-			for(count=0;count<8;count++)			//循环读取数据
-			{
-				*(tempbuff+count)=SDMMC1->FIFO;
-			}
-			tempbuff+=8;	 
-			timeout=0X7FFFFF; 	//读数据溢出时间
-		}else 	//处理超时
-		{
-			if(timeout==0)return SD_DATA_TIMEOUT;
-			timeout--;
-		}
-	} 
-	SDMMC1->CMD&=~(1<<6);		//CMDTRANS=0,结束数据传输
-	INTX_ENABLE();				//开启总中断
-	if(SDMMC1->STA&(1<<3))		//数据超时错误
-	{										   
-		SDMMC1->ICR|=1<<3; 		//清错误标志
-		return SD_DATA_TIMEOUT;
-	}else if(SDMMC1->STA&(1<<1))//数据块CRC错误
-	{
-		SDMMC1->ICR|=1<<1; 		//清错误标志
-		if(nblks>1)				//针对可能出现的CRC错误,如果是多块读取,必须发送结束传输命令!
-		{
-			SDMMC_Send_Cmd(SD_CMD_STOP_TRANSMISSION,1,0);		//发送CMD12+结束传输 	   
-			errorstatus=CmdResp1Error(SD_CMD_STOP_TRANSMISSION);//等待R1响应   
-		}				
-		return SD_DATA_CRC_FAIL;		   
-	}else if(SDMMC1->STA&(1<<5))//接收fifo上溢错误
-	{
-		SDMMC1->ICR|=1<<5; 		//清错误标志
-		return SD_RX_OVERRUN;		 
-	}  
-	if((SDMMC1->STA&(1<<8))&&(nblks>1))//多块接收结束,发送结束指令
-	{
-		if((STD_CAPACITY_SD_CARD_V1_1==CardType)||(STD_CAPACITY_SD_CARD_V2_0==CardType)||(HIGH_CAPACITY_SD_CARD==CardType))
-		{
-			SDMMC_Send_Cmd(SD_CMD_STOP_TRANSMISSION,1,0);		//发送CMD12+结束传输 	   
-			errorstatus=CmdResp1Error(SD_CMD_STOP_TRANSMISSION);//等待R1响应   
-			if(errorstatus!=SD_OK)return errorstatus;	 
-		}
-	}
-	SDMMC1->ICR=0X1FE00FFF;	 		//清除所有标记 
-	return errorstatus;
-}	
- 		    																  
-//SD卡写单个/多个块 
-//buf:数据缓存区
-//addr:写地址
-//blksize:块大小
-//nblks:要读取的块数,1,表示读取单个块
-//返回值:错误状态												   
-SD_Error SD_WriteBlocks(u8 *buf,long long addr,u16 blksize,u32 nblks)
-{
-	SD_Error errorstatus = SD_OK;
-	u8  cardstate=0;
-	u32 timeout=0,bytestransferred=0;
-	u32 cardstatus=0,count=0,restwords=0;
-	u32 tlen=nblks*blksize;						//总长度(字节)
-	u32*tempbuff=(u32*)buf;								 
- 	if(buf==NULL)return SD_INVALID_PARAMETER;	//参数错误   
-  	SDMMC1->DCTRL=0x0;							//数据控制寄存器清零(关DMA)    
- 	if(CardType==HIGH_CAPACITY_SD_CARD)			//大容量卡
-	{
-		blksize=512;
-		addr>>=9;
-	}     
-	SDMMC_Send_Cmd(SD_CMD_SET_BLOCKLEN,1,blksize);			//发送CMD16+设置数据长度为blksize,短响应 	   
-	errorstatus=CmdResp1Error(SD_CMD_SET_BLOCKLEN);			//等待R1响应   
-	if(errorstatus!=SD_OK)return errorstatus;   			//响应错误  
-	if(nblks>1)												//多块写
-	{									     
-		if(nblks*blksize>SD_MAX_DATA_LENGTH)return SD_INVALID_PARAMETER;   
-     	if((STD_CAPACITY_SD_CARD_V1_1==CardType)||(STD_CAPACITY_SD_CARD_V2_0==CardType)||(HIGH_CAPACITY_SD_CARD==CardType))
-    	{
-			//提高性能
-	 	   	SDMMC_Send_Cmd(SD_CMD_APP_CMD,1,(u32)RCA<<16);	//发送ACMD55,短响应 	   
-			errorstatus=CmdResp1Error(SD_CMD_APP_CMD);		//等待R1响应   		   
-			if(errorstatus!=SD_OK)return errorstatus;				    
-	 	   	SDMMC_Send_Cmd(SD_CMD_SET_BLOCK_COUNT,1,nblks);	//发送CMD23,设置块数量,短响应 	   
-			errorstatus=CmdResp1Error(SD_CMD_SET_BLOCK_COUNT);//等待R1响应   		   
-			if(errorstatus!=SD_OK)return errorstatus;				    
-		} 
-		SDMMC_Send_Cmd(SD_CMD_WRITE_MULT_BLOCK,1,addr);		//发送CMD25,多块写指令,短响应 	   
-		errorstatus=CmdResp1Error(SD_CMD_WRITE_MULT_BLOCK);	//等待R1响应    
-	}else													//单块写		
-	{ 
-		SDMMC_Send_Cmd(SD_CMD_SEND_STATUS,1,(u32)RCA<<16);	//发送CMD13,查询卡的状态,短响应 	   
-		errorstatus=CmdResp1Error(SD_CMD_SEND_STATUS);		//等待R1响应   		   
-		if(errorstatus!=SD_OK)return errorstatus;
-		cardstatus=SDMMC1->RESP1;													  
-		timeout=SD_DATATIMEOUT;
-		while(((cardstatus&0x00000100)==0)&&(timeout>0)) 	//检查READY_FOR_DATA位是否置位
-		{
-			timeout--;
-			SDMMC_Send_Cmd(SD_CMD_SEND_STATUS,1,(u32)RCA<<16);//发送CMD13,查询卡的状态,短响应 	   
-			errorstatus=CmdResp1Error(SD_CMD_SEND_STATUS);	//等待R1响应   		   
-			if(errorstatus!=SD_OK)return errorstatus;				    
-			cardstatus=SDMMC1->RESP1;													  
-		}
-		if(timeout==0)return SD_ERROR;  
-		SDMMC_Send_Cmd(SD_CMD_WRITE_SINGLE_BLOCK,1,addr);	//发送CMD24,写单块指令,短响应 	   
-		errorstatus=CmdResp1Error(SD_CMD_WRITE_SINGLE_BLOCK);//等待R1响应   	
-	}	   
-	if(errorstatus!=SD_OK)return errorstatus;   	   
- 	SDMMC_Send_Data_Cfg(SD_DATATIMEOUT,nblks*blksize,9,0);	//blksize,块大小恒为512字节,控制器到卡	  
-	SDMMC1->CMD|=1<<6;										//CMDTRANS=1,产生一个数据传输命令
-	timeout=SDMMC_DATATIMEOUT; 
-	INTX_DISABLE();//关闭总中断(POLLING模式,严禁中断打断SDMMC读写操作!!!)
-	while(!(SDMMC1->STA&((1<<4)|(1<<1)|(1<<8)|(1<<3))))//下溢/CRC/数据结束/超时
-	{
-		if(SDMMC1->STA&(1<<14))							//发送区半空,表示至少存了8字(32字节)
-		{	  
-			if((tlen-bytestransferred)<SD_HALFFIFOBYTES)//不够32字节了
-			{
-				restwords=((tlen-bytestransferred)%4==0)?((tlen-bytestransferred)/4):((tlen-bytestransferred)/4+1);
-				for(count=0;count<restwords;count++,tempbuff++,bytestransferred+=4)
-				{
-					SDMMC1->FIFO=*tempbuff;
-				}
-			}else 										//发送区半空,可以发送至少8字(32字节)数据
-			{
-				for(count=0;count<SD_HALFFIFO;count++)
-				{
-					SDMMC1->FIFO=*(tempbuff+count);
-				}
-				tempbuff+=SD_HALFFIFO;
-				bytestransferred+=SD_HALFFIFOBYTES;
-			}
-			timeout=0X3FFFFFFF;		//写数据溢出时间
-		}else
-		{
-			if(timeout==0)return SD_DATA_TIMEOUT; 
-			timeout--;
-		}
-	} 
-	SDMMC1->CMD&=~(1<<6);			//CMDTRANS=0,结束数据传输
-	INTX_ENABLE();					//开启总中断
-	if(SDMMC1->STA&(1<<3))			//数据超时错误
-	{										   
-		SDMMC1->ICR|=1<<3; 			//清错误标志
-		return SD_DATA_TIMEOUT;
-	}else if(SDMMC1->STA&(1<<1))	//数据块CRC错误
-	{
-		SDMMC1->ICR|=1<<1; 			//清错误标志
-		if(nblks>1)					//针对可能出现的CRC错误,如果是多块读取,必须发送结束传输命令!
-		{
-			SDMMC_Send_Cmd(SD_CMD_STOP_TRANSMISSION,1,0);		//发送CMD12+结束传输 	   
-			errorstatus=CmdResp1Error(SD_CMD_STOP_TRANSMISSION);//等待R1响应   
-		}	
-		return SD_DATA_CRC_FAIL;		   
-	}else if(SDMMC1->STA&(1<<4)) 	//接收fifo下溢错误
-	{
-		SDMMC1->ICR|=1<<4; 			//清错误标志
-		return SD_TX_UNDERRUN;		 
-	}
-	if((SDMMC1->STA&(1<<8))&&(nblks>1))//多块发送结束,发送结束指令
-	{
-		if((STD_CAPACITY_SD_CARD_V1_1==CardType)||(STD_CAPACITY_SD_CARD_V2_0==CardType)||(HIGH_CAPACITY_SD_CARD==CardType))
-		{
-			SDMMC_Send_Cmd(SD_CMD_STOP_TRANSMISSION,1,0);		//发送CMD12+结束传输 	   
-			errorstatus=CmdResp1Error(SD_CMD_STOP_TRANSMISSION);//等待R1响应   
-			if(errorstatus!=SD_OK)return errorstatus;	 
-		}
-	}
-	SDMMC1->ICR=0X1FE00FFF;		//清除所有标记	  
- 	errorstatus=IsCardProgramming(&cardstate);
- 	while((errorstatus==SD_OK)&&((cardstate==SD_CARD_PROGRAMMING)||(cardstate==SD_CARD_RECEIVING)))
-	{
-		errorstatus=IsCardProgramming(&cardstate);
-	}   
-	return errorstatus;
-}  
-//检查CMD0的执行状态
-//返回值:sd卡错误码
-SD_Error CmdError(void)
-{
-	SD_Error errorstatus = SD_OK;
-	u32 timeout=SDMMC_CMD0TIMEOUT;	   
-	while(timeout--)
-	{
-		if(SDMMC1->STA&(1<<7))break;//命令已发送(无需响应)	 
-	}	    
-	if(timeout==0)return SD_CMD_RSP_TIMEOUT;  
-	SDMMC1->ICR=0X1FE00FFF;			//清除标记
-	return errorstatus;
-}	 
-//检查R7响应的错误状态
-//返回值:sd卡错误码
-SD_Error CmdResp7Error(void)
-{
-	SD_Error errorstatus=SD_OK;
-	u32 status;
-	u32 timeout=SDMMC_CMD0TIMEOUT;
- 	while(timeout--)
-	{
-		status=SDMMC1->STA;
-		if(status&((1<<0)|(1<<2)|(1<<6)))break;//CRC错误/命令响应超时/已经收到响应(CRC校验成功)	
-	}
- 	if((timeout==0)||(status&(1<<2)))	//响应超时
-	{																				    
-		errorstatus=SD_CMD_RSP_TIMEOUT;	//当前卡不是2.0兼容卡,或者不支持设定的电压范围
-		SDMMC1->ICR|=1<<2;				//清除命令响应超时标志
-		return errorstatus;
-	}	 
-	if(status&1<<6)						//成功接收到响应
-	{								   
-		errorstatus=SD_OK;
-		SDMMC1->ICR|=1<<6;				//清除响应标志
- 	}
-	return errorstatus;
-}	   
-//检查R1响应的错误状态
-//cmd:当前命令
-//返回值:sd卡错误码
-SD_Error CmdResp1Error(u8 cmd)
-{	  
-   	u32 status; 
-	while(1)
-	{
-		status=SDMMC1->STA;
-		if(status&((1<<0)|(1<<2)|(1<<6)))break;//CRC错误/命令响应超时/已经收到响应(CRC校验成功)
-	} 
-	if(status&(1<<2))					//响应超时
-	{																				    
- 		SDMMC1->ICR=1<<2;				//清除命令响应超时标志
-		SDMMC1->ICR=0X1FE00FFF;				//清除标记
-		return SD_CMD_RSP_TIMEOUT;
-	}	
- 	if(status&(1<<0))					//CRC错误
-	{																				    
- 		SDMMC1->ICR=1<<0;				//清除标志
-		return SD_CMD_CRC_FAIL;
-	}		
-	if(SDMMC1->RESPCMD!=cmd)return SD_ILLEGAL_CMD;//命令不匹配 
-  	SDMMC1->ICR=0X1FE00FFF;				//清除标记
-	return (SD_Error)(SDMMC1->RESP1&SD_OCR_ERRORBITS);//返回卡响应
-}
-//检查R3响应的错误状态
-//返回值:错误状态
-SD_Error CmdResp3Error(void)
-{
-	u32 status;						 
- 	while(1)
-	{
-		status=SDMMC1->STA;
-		if(status&((1<<0)|(1<<2)|(1<<6)))break;//CRC错误/命令响应超时/已经收到响应(CRC校验成功)	
-	}
- 	if(status&(1<<2))					//响应超时
-	{											 
-		SDMMC1->ICR|=1<<2;				//清除命令响应超时标志
-		return SD_CMD_RSP_TIMEOUT;
-	}	 
-   	SDMMC1->ICR=0X1FE00FFF;				//清除标记
- 	return SD_OK;								  
-}
-//检查R2响应的错误状态
-//返回值:错误状态
-SD_Error CmdResp2Error(void)
-{
-	SD_Error errorstatus=SD_OK;
-	u32 status;
-	u32 timeout=SDMMC_CMD0TIMEOUT;
- 	while(timeout--)
-	{
-		status=SDMMC1->STA;
-		if(status&((1<<0)|(1<<2)|(1<<6)))break;//CRC错误/命令响应超时/已经收到响应(CRC校验成功)	
-	}
-  	if((timeout==0)||(status&(1<<2)))	//响应超时
-	{																				    
-		errorstatus=SD_CMD_RSP_TIMEOUT; 
-		SDMMC1->ICR|=1<<2;				//清除命令响应超时标志
-		return errorstatus;
-	}	 
-	if(status&1<<0)						//CRC错误
-	{								   
-		errorstatus=SD_CMD_CRC_FAIL;
-		SDMMC1->ICR|=1<<0;				//清除响应标志
- 	}
-	SDMMC1->ICR=0X1FE00FFF;				//清除标记
- 	return errorstatus;								    		 
-} 
-//检查R6响应的错误状态
-//cmd:之前发送的命令
-//prca:卡返回的RCA地址
-//返回值:错误状态
-SD_Error CmdResp6Error(u8 cmd,u16*prca)
-{
-	SD_Error errorstatus=SD_OK;
-	u32 status;					    
-	u32 rspr1;
- 	while(1)
-	{
-		status=SDMMC1->STA;
-		if(status&((1<<0)|(1<<2)|(1<<6)))break;//CRC错误/命令响应超时/已经收到响应(CRC校验成功)	
-	}
-	if(status&(1<<2))					//响应超时
-	{																				    
- 		SDMMC1->ICR|=1<<2;				//清除命令响应超时标志
-		return SD_CMD_RSP_TIMEOUT;
-	}	 	 
-	if(status&1<<0)						//CRC错误
-	{								   
-		SDMMC1->ICR|=1<<0;				//清除响应标志
- 		return SD_CMD_CRC_FAIL;
-	}
-	if(SDMMC1->RESPCMD!=cmd)			//判断是否响应cmd命令
-	{
- 		return SD_ILLEGAL_CMD; 		
-	}	    
-	SDMMC1->ICR=0X1FE00FFF;				//清除所有标记
-	rspr1=SDMMC1->RESP1;				//得到响应 	 
-	if(SD_ALLZERO==(rspr1&(SD_R6_GENERAL_UNKNOWN_ERROR|SD_R6_ILLEGAL_CMD|SD_R6_COM_CRC_FAILED)))
-	{
-		*prca=(u16)(rspr1>>16);			//右移16位得到,rca
-		return errorstatus;
-	}
-   	if(rspr1&SD_R6_GENERAL_UNKNOWN_ERROR)return SD_GENERAL_UNKNOWN_ERROR;
-   	if(rspr1&SD_R6_ILLEGAL_CMD)return SD_ILLEGAL_CMD;
-   	if(rspr1&SD_R6_COM_CRC_FAILED)return SD_COM_CRC_FAILED;
-	return errorstatus;
-}
-
-//SDMMC使能宽总线模式
-//enx:0,不使能;1,使能;
-//返回值:错误状态
-SD_Error SDEnWideBus(u8 enx)
-{
-	SD_Error errorstatus = SD_OK;
- 	u32 scr[2]={0,0};
-	u8 arg=0X00;
-	if(enx)arg=0X02;
-	else arg=0X00;
- 	if(SDMMC1->RESP1&SD_CARD_LOCKED)return SD_LOCK_UNLOCK_FAILED;//SD卡处于LOCKED状态		    
- 	errorstatus=FindSCR(RCA,scr);						//得到SCR寄存器数据
- 	if(errorstatus!=SD_OK)return errorstatus;
-	if((scr[1]&SD_WIDE_BUS_SUPPORT)!=SD_ALLZERO)		//支持宽总线
-	{
-	 	SDMMC_Send_Cmd(SD_CMD_APP_CMD,1,(u32)RCA<<16);	//发送CMD55+RCA,短响应											  
-	 	errorstatus=CmdResp1Error(SD_CMD_APP_CMD);
-	 	if(errorstatus!=SD_OK)return errorstatus; 
-	 	SDMMC_Send_Cmd(SD_CMD_APP_SD_SET_BUSWIDTH,1,arg);//发送ACMD6,短响应,参数:10,4位;00,1位.											  
-		errorstatus=CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH);
-		return errorstatus;
-	}else return SD_REQUEST_NOT_APPLICABLE;				//不支持宽总线设置 	 
-}												   
-//检查卡是否正在执行写操作
-//pstatus:当前状态.
-//返回值:错误代码
-SD_Error IsCardProgramming(u8 *pstatus)
-{
- 	vu32 respR1 = 0, status = 0; 
-  	SDMMC_Send_Cmd(SD_CMD_SEND_STATUS,1,(u32)RCA<<16);		//发送CMD13 	   
-  	status=SDMMC1->STA;
-	while(!(status&((1<<0)|(1<<6)|(1<<2))))status=SDMMC1->STA;//等待操作完成
-   	if(status&(1<<0))			//CRC检测失败
-	{
-		SDMMC1->ICR|=1<<0;		//清除错误标记
-		return SD_CMD_CRC_FAIL;
-	}
-   	if(status&(1<<2))			//命令超时 
-	{
-		SDMMC1->ICR|=1<<2;		//清除错误标记
-		return SD_CMD_RSP_TIMEOUT;
-	}
- 	if(SDMMC1->RESPCMD!=SD_CMD_SEND_STATUS)return SD_ILLEGAL_CMD;
-	SDMMC1->ICR=0X1FE00FFF;		//清除所有标记
-	respR1=SDMMC1->RESP1;
-	*pstatus=(u8)((respR1>>9)&0x0000000F);
-	return SD_OK;
-}
-//读取当前卡状态
-//pcardstatus:卡状态
-//返回值:错误代码
-SD_Error SD_SendStatus(uint32_t *pcardstatus)
-{
-	SD_Error errorstatus = SD_OK;
-	if(pcardstatus==NULL)
-	{
-		errorstatus=SD_INVALID_PARAMETER;
-		return errorstatus;
-	}
- 	SDMMC_Send_Cmd(SD_CMD_SEND_STATUS,1,RCA<<16);	//发送CMD13,短响应		 
-	errorstatus=CmdResp1Error(SD_CMD_SEND_STATUS);	//查询响应状态 
-	if(errorstatus!=SD_OK)return errorstatus;
-	*pcardstatus=SDMMC1->RESP1;//读取响应值
-	return errorstatus;
-} 
-//返回SD卡的状态
-//返回值:SD卡状态
-SDCardState SD_GetState(void)
-{
-	u32 resp1=0;
-	if(SD_SendStatus(&resp1)!=SD_OK)return SD_CARD_ERROR;
-	else return (SDCardState)((resp1>>9) & 0x0F);
-}
-//查找SD卡的SCR寄存器值
-//rca:卡相对地址
-//pscr:数据缓存区(存储SCR内容)
-//返回值:错误状态		   
-SD_Error FindSCR(u16 rca,u32 *pscr)
-{  
-	SD_Error errorstatus = SD_OK;
-	u32 tempscr[2]={0,0};  
- 	SDMMC_Send_Cmd(SD_CMD_SET_BLOCKLEN,1,8);			//发送CMD16,短响应,设置Block Size为8字节											  
- 	errorstatus=CmdResp1Error(SD_CMD_SET_BLOCKLEN);
- 	if(errorstatus!=SD_OK)return errorstatus;	    
-  	SDMMC_Send_Cmd(SD_CMD_APP_CMD,1,(u32)rca<<16);	//发送CMD55,短响应 									  
- 	errorstatus=CmdResp1Error(SD_CMD_APP_CMD);
- 	if(errorstatus!=SD_OK)return errorstatus;
-	SDMMC_Send_Data_Cfg(SD_DATATIMEOUT,8,3,1);		//8个字节长度,block为8字节,SD卡到SDMMC.
-   	SDMMC_Send_Cmd(SD_CMD_SD_APP_SEND_SCR,1,0);		//发送ACMD51,短响应,参数为0											  
- 	errorstatus=CmdResp1Error(SD_CMD_SD_APP_SEND_SCR);
- 	if(errorstatus!=SD_OK)return errorstatus;							   
- 	while(!(SDMMC1->STA&(SDMMC_STA_RXOVERR|SDMMC_STA_DCRCFAIL|SDMMC_STA_DTIMEOUT|SDMMC_STA_DBCKEND|SDMMC_STA_DATAEND)))
-	{ 
-		if(!(SDMMC1->STA&(1<<19)))		//接收FIFO数据可用
-		{
-			tempscr[0]=SDMMC1->FIFO;	//读取FIFO内容 
-			tempscr[1]=SDMMC1->FIFO;	//读取FIFO内容 
-			break;
-		}
-	}
- 	if(SDMMC1->STA&(1<<3))		//接收数据超时
-	{										 
- 		SDMMC1->ICR|=1<<3;		//清除标记
-		return SD_DATA_TIMEOUT;
-	}else if(SDMMC1->STA&(1<<1))//已发送/接收的数据块CRC校验错误
-	{
- 		SDMMC1->ICR|=1<<1;		//清除标记
-		return SD_DATA_CRC_FAIL;   
-	}else if(SDMMC1->STA&(1<<5))//接收FIFO溢出
-	{
- 		SDMMC1->ICR|=1<<5;		//清除标记
-		return SD_RX_OVERRUN;   	   
-	} 
-   	SDMMC1->ICR=0X1FE00FFF;		//清除标记	 
-	//把数据顺序按8位为单位倒过来.   	
-	*(pscr+1)=((tempscr[0]&SD_0TO7BITS)<<24)|((tempscr[0]&SD_8TO15BITS)<<8)|((tempscr[0]&SD_16TO23BITS)>>8)|((tempscr[0]&SD_24TO31BITS)>>24);
-	*(pscr)=((tempscr[1]&SD_0TO7BITS)<<24)|((tempscr[1]&SD_8TO15BITS)<<8)|((tempscr[1]&SD_16TO23BITS)>>8)|((tempscr[1]&SD_24TO31BITS)>>24);
- 	return errorstatus;
-}  
-//读SD卡
-//buf:读数据缓存区
-//sector:扇区地址
-//cnt:扇区个数	
-//返回值:错误状态;0,正常;其他,错误代码;				  				 
-u8 SD_ReadDisk(u8*buf,u32 sector,u32 cnt)
-{
-	u8 sta=SD_OK;
-	long long lsector=sector;
-	u32 n;
-	if(CardType!=STD_CAPACITY_SD_CARD_V1_1)lsector<<=9;
-	if((u32)buf%4!=0)
-	{
-	 	for(n=0;n<cnt;n++)
-		{
-		 	sta=SD_ReadBlocks(SDMMC_DATA_BUFFER,lsector+512*n,512,1);//单个sector的读操作
-			memcpy(buf,SDMMC_DATA_BUFFER,512);
-			buf+=512;
-		} 
-	}else sta=SD_ReadBlocks(buf,lsector,512,cnt);	//单个/多个sector   
-	return sta;
-}
-//写SD卡
-//buf:写数据缓存区
-//sector:扇区地址
-//cnt:扇区个数	
-//返回值:错误状态;0,正常;其他,错误代码;	
-u8 SD_WriteDisk(u8*buf,u32 sector,u32 cnt)
-{
-	u8 sta=SD_OK;
-	u32 n;
-	long long lsector=sector;
-	if(CardType!=STD_CAPACITY_SD_CARD_V1_1)lsector<<=9;
-	if((u32)buf%4!=0)
-	{
-	 	for(n=0;n<cnt;n++)
-		{
-			memcpy(SDMMC_DATA_BUFFER,buf,512);
-		 	sta=SD_WriteBlocks(SDMMC_DATA_BUFFER,lsector+512*n,512,1);//单个sector的写操作
-			buf+=512;
-		} 
-	}else sta=SD_WriteBlocks(buf,lsector,512,cnt);	//单个/多个sector   
-	return sta;
-}
-
-
-#endif
-
-
-
-

+ 0 - 356
obj/obj_sdmmc_sdcard.h

@@ -1,356 +0,0 @@
-#ifndef __SDMMC_SDCARD_H
-#define __SDMMC_SDCARD_H																			   
-#include "sys_type.h" 													   
-//////////////////////////////////////////////////////////////////////////////////	 
-//本程序只供学习使用,未经作者许可,不得用于其它任何用途
-//ALIENTEK STM32H7开发板
-//SDMMC 驱动代码	(仅提供查询模式驱动代码)
-//正点原子@ALIENTEK
-//技术论坛:www.openedv.com
-//创建日期:2018/7/31
-//版本:V1.0
-//版权所有,盗版必究。
-//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
-//All rights reserved		 
-//********************************************************************************
-//升级说明
-//无
-////////////////////////////////////////////////////////////////////////////////// 	 
- 
- 
-//用户配置区			  
-//SDMMC时钟计算公式:SDMMC_CK时钟=sdmmc_ker_ck/[2*clkdiv];其中,sdmmc_ker_ck来自pll1_q_ck,为200Mhz
-//如果出现驱动错误,请尝试将SDMMC_TRANSFER_CLK_DIV频率降低
-//#define SDMMC_INIT_CLK_DIV        0xFA		//SDMMC初始化频率,200M/(250*2)=400Khz,最大400Kh  
-#define SDMMC_TRANSFER_CLK_DIV    0x04		//SDMMC传输频率,该值太小可能会导致读写文件出错 
-										 
-//SD卡操作 各种错误枚举定义
-typedef enum
-{	 
-	//特殊错误定义 
-	SD_CMD_CRC_FAIL                    = (1),   /*!< Command response received (but CRC check failed)              */
-	SD_DATA_CRC_FAIL                   = (2),   /*!< Data block sent/received (CRC check failed)                   */
-	SD_CMD_RSP_TIMEOUT                 = (3),   /*!< Command response timeout                                      */
-	SD_DATA_TIMEOUT                    = (4),   /*!< Data timeout                                                  */
-	SD_TX_UNDERRUN                     = (5),   /*!< Transmit FIFO underrun                                        */
-	SD_RX_OVERRUN                      = (6),   /*!< Receive FIFO overrun                                          */
-	SD_START_BIT_ERR                   = (7),   /*!< Start bit not detected on all data signals in wide bus mode   */
-	SD_CMD_OUT_OF_RANGE                = (8),   /*!< Command's argument was out of range.                          */
-	SD_ADDR_MISALIGNED                 = (9),   /*!< Misaligned address                                            */
-	SD_BLOCK_LEN_ERR                   = (10),  /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
-	SD_ERASE_SEQ_ERR                   = (11),  /*!< An error in the sequence of erase command occurs.            */
-	SD_BAD_ERASE_PARAM                 = (12),  /*!< An invalid selection for erase groups                        */
-	SD_WRITE_PROT_VIOLATION            = (13),  /*!< Attempt to program a write protect block                     */
-	SD_LOCK_UNLOCK_FAILED              = (14),  /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
-	SD_COM_CRC_FAILED                  = (15),  /*!< CRC check of the previous command failed                     */
-	SD_ILLEGAL_CMD                     = (16),  /*!< Command is not legal for the card state                      */
-	SD_CARD_ECC_FAILED                 = (17),  /*!< Card internal ECC was applied but failed to correct the data */
-	SD_CC_ERROR                        = (18),  /*!< Internal card controller error                               */
-	SD_GENERAL_UNKNOWN_ERROR           = (19),  /*!< General or unknown error                                     */
-	SD_STREAM_READ_UNDERRUN            = (20),  /*!< The card could not sustain data transfer in stream read operation. */
-	SD_STREAM_WRITE_OVERRUN            = (21),  /*!< The card could not sustain data programming in stream mode   */
-	SD_CID_CSD_OVERWRITE               = (22),  /*!< CID/CSD overwrite error                                      */
-	SD_WP_ERASE_SKIP                   = (23),  /*!< Only partial address space was erased                        */
-	SD_CARD_ECC_DISABLED               = (24),  /*!< Command has been executed without using internal ECC         */
-	SD_ERASE_RESET                     = (25),  /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
-	SD_AKE_SEQ_ERROR                   = (26),  /*!< Error in sequence of authentication.                         */
-	SD_INVALID_VOLTRANGE               = (27),
-	SD_ADDR_OUT_OF_RANGE               = (28),
-	SD_SWITCH_ERROR                    = (29),
-	SD_SDMMC_DISABLED                  = (30),
-	SD_SDMMC_FUNCTION_BUSY             = (31),
-	SD_SDMMC_FUNCTION_FAILED           = (32),
-	SD_SDMMC_UNKNOWN_FUNCTION          = (33),
-	//标准错误定义
-	SD_INTERNAL_ERROR                  = (34),
-	SD_NOT_CONFIGURED                  = (35),
-	SD_REQUEST_PENDING                 = (36),
-	SD_REQUEST_NOT_APPLICABLE          = (37),
-	SD_INVALID_PARAMETER               = (38),
-	SD_UNSUPPORTED_FEATURE             = (39),
-	SD_UNSUPPORTED_HW                  = (40),
-	SD_ERROR                           = (41),
-	SD_OK                              = (0) 
-} SD_Error;		  
-
-//SD卡CSD寄存器数据		  
-typedef struct
-{
-	u8  CSDStruct;            /*!< CSD structure */
-	u8  SysSpecVersion;       /*!< System specification version */
-	u8  Reserved1;            /*!< Reserved */
-	u8  TAAC;                 /*!< Data read access-time 1 */
-	u8  NSAC;                 /*!< Data read access-time 2 in CLK cycles */
-	u8  MaxBusClkFrec;        /*!< Max. bus clock frequency */
-	u16 CardComdClasses;      /*!< Card command classes */
-	u8  RdBlockLen;           /*!< Max. read data block length */
-	u8  PartBlockRead;        /*!< Partial blocks for read allowed */
-	u8  WrBlockMisalign;      /*!< Write block misalignment */
-	u8  RdBlockMisalign;      /*!< Read block misalignment */
-	u8  DSRImpl;              /*!< DSR implemented */
-	u8  Reserved2;            /*!< Reserved */
-	u32 DeviceSize;           /*!< Device Size */
-	u8  MaxRdCurrentVDDMin;   /*!< Max. read current @ VDD min */
-	u8  MaxRdCurrentVDDMax;   /*!< Max. read current @ VDD max */
-	u8  MaxWrCurrentVDDMin;   /*!< Max. write current @ VDD min */
-	u8  MaxWrCurrentVDDMax;   /*!< Max. write current @ VDD max */
-	u8  DeviceSizeMul;        /*!< Device size multiplier */
-	u8  EraseGrSize;          /*!< Erase group size */
-	u8  EraseGrMul;           /*!< Erase group size multiplier */
-	u8  WrProtectGrSize;      /*!< Write protect group size */
-	u8  WrProtectGrEnable;    /*!< Write protect group enable */
-	u8  ManDeflECC;           /*!< Manufacturer default ECC */
-	u8  WrSpeedFact;          /*!< Write speed factor */
-	u8  MaxWrBlockLen;        /*!< Max. write data block length */
-	u8  WriteBlockPaPartial;  /*!< Partial blocks for write allowed */
-	u8  Reserved3;            /*!< Reserded */
-	u8  ContentProtectAppli;  /*!< Content protection application */
-	u8  FileFormatGrouop;     /*!< File format group */
-	u8  CopyFlag;             /*!< Copy flag (OTP) */
-	u8  PermWrProtect;        /*!< Permanent write protection */
-	u8  TempWrProtect;        /*!< Temporary write protection */
-	u8  FileFormat;           /*!< File Format */
-	u8  ECC;                  /*!< ECC code */
-	u8  CSD_CRC;              /*!< CSD CRC */
-	u8  Reserved4;            /*!< always 1*/
-} SD_CSD;   
-
-//SD卡CID寄存器数据
-typedef struct
-{
-	u8  ManufacturerID;       /*!< ManufacturerID */
-	u16 OEM_AppliID;          /*!< OEM/Application ID */
-	u32 ProdName1;            /*!< Product Name part1 */
-	u8  ProdName2;            /*!< Product Name part2*/
-	u8  ProdRev;              /*!< Product Revision */
-	u32 ProdSN;               /*!< Product Serial Number */
-	u8  Reserved1;            /*!< Reserved1 */
-	u16 ManufactDate;         /*!< Manufacturing Date */
-	u8  CID_CRC;              /*!< CID CRC */
-	u8  Reserved2;            /*!< always 1 */
-} SD_CID;	 
-//SD卡状态
-typedef enum
-{
-	SD_CARD_READY                  = ((uint32_t)0x00000001),
-	SD_CARD_IDENTIFICATION         = ((uint32_t)0x00000002),
-	SD_CARD_STANDBY                = ((uint32_t)0x00000003),
-	SD_CARD_TRANSFER               = ((uint32_t)0x00000004),
-	SD_CARD_SENDING                = ((uint32_t)0x00000005),
-	SD_CARD_RECEIVING              = ((uint32_t)0x00000006),
-	SD_CARD_PROGRAMMING            = ((uint32_t)0x00000007),
-	SD_CARD_DISCONNECTED           = ((uint32_t)0x00000008),
-	SD_CARD_ERROR                  = ((uint32_t)0x000000FF)
-}SDCardState;
-
-//SD卡信息,包括CSD,CID等数据
-typedef struct
-{
-  SD_CSD SD_csd;
-  SD_CID SD_cid;
-  long long CardCapacity;  	//SD卡容量,单位:字节,最大支持2^64字节大小的卡.
-  u32 CardBlockSize; 		//SD卡块大小	
-  u16 RCA;					//卡相对地址
-  u8 CardType;				//卡类型
-} SD_CardInfo;
-extern SD_CardInfo SDCardInfo;//SD卡信息			 
-////////////////////////////////////////////////////////////////////////////////////////////////////
-//SDMMC卡 指令集
-//拷贝自:stm32f7xx_hal_sd.h
-#define SD_CMD_GO_IDLE_STATE                       ((uint8_t)0U)   /*!< Resets the SD memory card.                                                               */
-#define SD_CMD_SEND_OP_COND                        ((uint8_t)1U)   /*!< Sends host capacity support information and activates the card's initialization process. */
-#define SD_CMD_ALL_SEND_CID                        ((uint8_t)2U)   /*!< Asks any card connected to the host to send the CID numbers on the CMD line.             */
-#define SD_CMD_SET_REL_ADDR                        ((uint8_t)3U)   /*!< Asks the card to publish a new relative address (RCA).                                   */
-#define SD_CMD_SET_DSR                             ((uint8_t)4U)   /*!< Programs the DSR of all cards.                                                           */
-#define SD_CMD_SDMMC_SEN_OP_COND                   ((uint8_t)5U)   /*!< Sends host capacity support information (HCS) and asks the accessed card to send its 
-                                                                       operating condition register (OCR) content in the response on the CMD line.              */
-#define SD_CMD_HS_SWITCH                           ((uint8_t)6U)   /*!< Checks switchable function (mode 0) and switch card function (mode 1).                   */
-#define SD_CMD_SEL_DESEL_CARD                      ((uint8_t)7U)   /*!< Selects the card by its own relative address and gets deselected by any other address    */
-#define SD_CMD_HS_SEND_EXT_CSD                     ((uint8_t)8U)   /*!< Sends SD Memory Card interface condition, which includes host supply voltage information 
-                                                                       and asks the card whether card supports voltage.                                         */
-#define SD_CMD_SEND_CSD                            ((uint8_t)9U)   /*!< Addressed card sends its card specific data (CSD) on the CMD line.                       */
-#define SD_CMD_SEND_CID                            ((uint8_t)10U)  /*!< Addressed card sends its card identification (CID) on the CMD line.                      */
-#define SD_CMD_READ_DAT_UNTIL_STOP                 ((uint8_t)11U)  /*!< SD card doesn't support it.                                                              */
-#define SD_CMD_STOP_TRANSMISSION                   ((uint8_t)12U)  /*!< Forces the card to stop transmission.                                                    */
-#define SD_CMD_SEND_STATUS                         ((uint8_t)13U)  /*!< Addressed card sends its status register.                                                */
-#define SD_CMD_HS_BUSTEST_READ                     ((uint8_t)14U) 
-#define SD_CMD_GO_INACTIVE_STATE                   ((uint8_t)15U)  /*!< Sends an addressed card into the inactive state.                                         */
-#define SD_CMD_SET_BLOCKLEN                        ((uint8_t)16U)  /*!< Sets the block length (in bytes for SDSC) for all following block commands 
-                                                                       (read, write, lock). Default block length is fixed to 512 Bytes. Not effective 
-                                                                       for SDHS and SDXC.                                                                       */
-#define SD_CMD_READ_SINGLE_BLOCK                   ((uint8_t)17U)  /*!< Reads single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of 
-                                                                       fixed 512 bytes in case of SDHC and SDXC.                                                */
-#define SD_CMD_READ_MULT_BLOCK                     ((uint8_t)18U)  /*!< Continuously transfers data blocks from card to host until interrupted by 
-                                                                       STOP_TRANSMISSION command.                                                               */
-#define SD_CMD_HS_BUSTEST_WRITE                    ((uint8_t)19U)  /*!< 64 bytes tuning pattern is sent for SDR50 and SDR104.                                    */
-#define SD_CMD_WRITE_DAT_UNTIL_STOP                ((uint8_t)20U)  /*!< Speed class control command.                                                             */
-#define SD_CMD_SET_BLOCK_COUNT                     ((uint8_t)23U)  /*!< Specify block count for CMD18 and CMD25.                                                 */
-#define SD_CMD_WRITE_SINGLE_BLOCK                  ((uint8_t)24U)  /*!< Writes single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of 
-                                                                       fixed 512 bytes in case of SDHC and SDXC.                                                */
-#define SD_CMD_WRITE_MULT_BLOCK                    ((uint8_t)25U)  /*!< Continuously writes blocks of data until a STOP_TRANSMISSION follows.                    */
-#define SD_CMD_PROG_CID                            ((uint8_t)26U)  /*!< Reserved for manufacturers.                                                              */
-#define SD_CMD_PROG_CSD                            ((uint8_t)27U)  /*!< Programming of the programmable bits of the CSD.                                         */
-#define SD_CMD_SET_WRITE_PROT                      ((uint8_t)28U)  /*!< Sets the write protection bit of the addressed group.                                    */
-#define SD_CMD_CLR_WRITE_PROT                      ((uint8_t)29U)  /*!< Clears the write protection bit of the addressed group.                                  */
-#define SD_CMD_SEND_WRITE_PROT                     ((uint8_t)30U)  /*!< Asks the card to send the status of the write protection bits.                           */
-#define SD_CMD_SD_ERASE_GRP_START                  ((uint8_t)32U)  /*!< Sets the address of the first write block to be erased. (For SD card only).              */
-#define SD_CMD_SD_ERASE_GRP_END                    ((uint8_t)33U)  /*!< Sets the address of the last write block of the continuous range to be erased.           */
-#define SD_CMD_ERASE_GRP_START                     ((uint8_t)35U)  /*!< Sets the address of the first write block to be erased. Reserved for each command 
-                                                                       system set by switch function command (CMD6).                                            */
-#define SD_CMD_ERASE_GRP_END                       ((uint8_t)36U)  /*!< Sets the address of the last write block of the continuous range to be erased. 
-                                                                       Reserved for each command system set by switch function command (CMD6).                  */
-#define SD_CMD_ERASE                               ((uint8_t)38U)  /*!< Reserved for SD security applications.                                                   */
-#define SD_CMD_FAST_IO                             ((uint8_t)39U)  /*!< SD card doesn't support it (Reserved).                                                   */
-#define SD_CMD_GO_IRQ_STATE                        ((uint8_t)40U)  /*!< SD card doesn't support it (Reserved).                                                   */
-#define SD_CMD_LOCK_UNLOCK                         ((uint8_t)42U)  /*!< Sets/resets the password or lock/unlock the card. The size of the data block is set by 
-                                                                       the SET_BLOCK_LEN command.                                                               */
-#define SD_CMD_APP_CMD                             ((uint8_t)55U)  /*!< Indicates to the card that the next command is an application specific command rather 
-                                                                       than a standard command.                                                                 */
-#define SD_CMD_GEN_CMD                             ((uint8_t)56U)  /*!< Used either to transfer a data block to the card or to get a data block from the card 
-                                                                       for general purpose/application specific commands.                                       */
-#define SD_CMD_NO_CMD                              ((uint8_t)64U) 
-
-/** 
-  * @brief Following commands are SD Card Specific commands.
-  *        SDMMC_APP_CMD should be sent before sending these commands. 
-  */
-#define SD_CMD_APP_SD_SET_BUSWIDTH                 ((uint8_t)6U)   /*!< (ACMD6) Defines the data bus width to be used for data transfer. The allowed data bus 
-                                                                       widths are given in SCR register.                                                          */
-#define SD_CMD_SD_APP_STATUS                       ((uint8_t)13U)  /*!< (ACMD13) Sends the SD status.                                                              */
-#define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS        ((uint8_t)22U)  /*!< (ACMD22) Sends the number of the written (without errors) write blocks. Responds with 
-                                                                       32bit+CRC data block.                                                                      */
-#define SD_CMD_SD_APP_OP_COND                      ((uint8_t)41U)  /*!< (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to 
-                                                                       send its operating condition register (OCR) content in the response on the CMD line.       */
-#define SD_CMD_SD_APP_SET_CLR_CARD_DETECT          ((uint8_t)42U)  /*!< (ACMD42) Connects/Disconnects the 50 KOhm pull-up resistor on CD/DAT3 (pin 1) of the card. */
-#define SD_CMD_SD_APP_SEND_SCR                     ((uint8_t)51U)  /*!< Reads the SD Configuration Register (SCR).                                                 */
-#define SD_CMD_SDMMC_RW_DIRECT                     ((uint8_t)52U)  /*!< For SD I/O card only, reserved for security specification.                                 */
-#define SD_CMD_SDMMC_RW_EXTENDED                   ((uint8_t)53U)  /*!< For SD I/O card only, reserved for security specification.                                 */
-
-/** 
-  * @brief Following commands are SD Card Specific security commands.
-  *        SD_CMD_APP_CMD should be sent before sending these commands. 
-  */
-#define SD_CMD_SD_APP_GET_MKB                      ((uint8_t)43U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_GET_MID                      ((uint8_t)44U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_SET_CER_RN1                  ((uint8_t)45U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_GET_CER_RN2                  ((uint8_t)46U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_SET_CER_RES2                 ((uint8_t)47U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_GET_CER_RES1                 ((uint8_t)48U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK   ((uint8_t)18U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK  ((uint8_t)25U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_SECURE_ERASE                 ((uint8_t)38U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_CHANGE_SECURE_AREA           ((uint8_t)49U)  /*!< For SD card only */
-#define SD_CMD_SD_APP_SECURE_WRITE_MKB             ((uint8_t)48U)  /*!< For SD card only */
-
-//CMD8指令
-#define SD_SDMMC_SEND_IF_COND           	  ((uint32_t)SD_CMD_HS_SEND_EXT_CSD)
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-//支持的SD卡定义
-#define STD_CAPACITY_SD_CARD_V1_1			((uint32_t)0x00000000U)
-#define STD_CAPACITY_SD_CARD_V2_0			((uint32_t)0x00000001U)
-#define HIGH_CAPACITY_SD_CARD					((uint32_t)0x00000002U)
-#define MULTIMEDIA_CARD								((uint32_t)0x00000003U)
-#define SECURE_DIGITAL_IO_CARD				((uint32_t)0x00000004U)
-#define HIGH_SPEED_MULTIMEDIA_CARD		((uint32_t)0x00000005U)
-#define SECURE_DIGITAL_IO_COMBO_CARD	((uint32_t)0x00000006U)
-#define HIGH_CAPACITY_MMC_CARD				((uint32_t)0x00000007U)
-
-//SDMMC相关参数定义
-#define NULL 0
-//#define SDMMC_STATIC_FLAGS				((u32)0x000205FF)
-#define SDMMC_CMD0TIMEOUT						((u32)0x00010000)	  
-//#define SDMMC_DATATIMEOUT					((u32)0xFFFFFFFF)	 
-
-//Mask for errors Card Status R1 (OCR Register)  
-#define SD_OCR_ADDR_OUT_OF_RANGE        ((u32)0x80000000)
-#define SD_OCR_ADDR_MISALIGNED          ((u32)0x40000000)
-#define SD_OCR_BLOCK_LEN_ERR            ((u32)0x20000000)
-#define SD_OCR_ERASE_SEQ_ERR            ((u32)0x10000000)
-#define SD_OCR_BAD_ERASE_PARAM          ((u32)0x08000000)
-#define SD_OCR_WRITE_PROT_VIOLATION     ((u32)0x04000000)
-#define SD_OCR_LOCK_UNLOCK_FAILED       ((u32)0x01000000)
-#define SD_OCR_COM_CRC_FAILED           ((u32)0x00800000)
-#define SD_OCR_ILLEGAL_CMD              ((u32)0x00400000)
-#define SD_OCR_CARD_ECC_FAILED          ((u32)0x00200000)
-#define SD_OCR_CC_ERROR                 ((u32)0x00100000)
-#define SD_OCR_GENERAL_UNKNOWN_ERROR    ((u32)0x00080000)
-#define SD_OCR_STREAM_READ_UNDERRUN     ((u32)0x00040000)
-#define SD_OCR_STREAM_WRITE_OVERRUN     ((u32)0x00020000)
-//#define SD_OCR_CID_CSD_OVERWRIETE       ((u32)0x00010000)
-#define SD_OCR_WP_ERASE_SKIP            ((u32)0x00008000)
-#define SD_OCR_CARD_ECC_DISABLED        ((u32)0x00004000)
-#define SD_OCR_ERASE_RESET              ((u32)0x00002000)
-#define SD_OCR_AKE_SEQ_ERROR            ((u32)0x00000008)
-#define SD_OCR_ERRORBITS                ((u32)0xFDFFE008)
-
-//Masks for R6 Response 
-#define SD_R6_GENERAL_UNKNOWN_ERROR     ((u32)0x00002000)
-#define SD_R6_ILLEGAL_CMD               ((u32)0x00004000)
-#define SD_R6_COM_CRC_FAILED            ((u32)0x00008000)
-
-#define SD_VOLTAGE_WINDOW_SD            ((u32)0x80100000)
-#define SD_HIGH_CAPACITY                ((u32)0x40000000)
-#define SD_STD_CAPACITY                 ((u32)0x00000000)
-#define SD_CHECK_PATTERN                ((u32)0x000001AA)
-#define SD_VOLTAGE_WINDOW_MMC           ((u32)0x80FF8000)
-
-#define SD_MAX_VOLT_TRIAL               ((u32)0x0000FFFF)
-#define SD_ALLZERO                      ((u32)0x00000000)
-
-#define SD_WIDE_BUS_SUPPORT             ((u32)0x00040000)
-#define SD_SINGLE_BUS_SUPPORT           ((u32)0x00010000)
-#define SD_CARD_LOCKED                  ((u32)0x02000000)
-#define SD_CARD_PROGRAMMING             ((u32)0x00000007)
-#define SD_CARD_RECEIVING               ((u32)0x00000006)
-#define SD_DATATIMEOUT                  ((u32)0xFFFFFFFF)
-#define SD_0TO7BITS                     ((u32)0x000000FF)
-#define SD_8TO15BITS                    ((u32)0x0000FF00)
-#define SD_16TO23BITS                   ((u32)0x00FF0000)
-#define SD_24TO31BITS                   ((u32)0xFF000000)
-#define SD_MAX_DATA_LENGTH              ((u32)0x01FFFFFF)
-
-#define SD_HALFFIFO                     ((u32)0x00000008)
-#define SD_HALFFIFOBYTES                ((u32)0x00000020)
-
-//Command Class Supported  
-#define SD_CCCC_LOCK_UNLOCK             ((u32)0x00000080)
-#define SD_CCCC_WRITE_PROT              ((u32)0x00000040)
-#define SD_CCCC_ERASE                   ((u32)0x00000020)
-																 
-////////////////////////////////////////////////////////////////////////////////////////////////////
-//相关函数定义
-SD_Error SD_Init(void);
-void SDMMC_Clock_Set(u16 clkdiv);
-void SDMMC_Send_Cmd(u8 cmdindex,u8 waitrsp,u32 arg);
-void SDMMC_Send_Data_Cfg(u32 datatimeout,u32 datalen,u8 blksize,u8 dir);
-SD_Error SD_PowerON(void);    
-SD_Error SD_PowerOFF(void);
-SD_Error SD_InitializeCards(void);
-SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);		  
-SD_Error SD_EnableWideBusOperation(u32 wmode); 
-SD_Error SD_SelectDeselect(u32 addr); 
-SD_Error SD_SendStatus(uint32_t *pcardstatus);
-SDCardState SD_GetState(void);  
-SD_Error SD_ReadBlocks(u8 *buf,long long  addr,u16 blksize,u32 nblks);   
-SD_Error SD_WriteBlocks(u8 *buf,long long addr,u16 blksize,u32 nblks); 
-SD_Error CmdError(void);  
-SD_Error CmdResp7Error(void);
-SD_Error CmdResp1Error(u8 cmd);
-SD_Error CmdResp3Error(void);
-SD_Error CmdResp2Error(void);
-SD_Error CmdResp6Error(u8 cmd,u16*prca);  
-SD_Error SDEnWideBus(u8 enx);	  
-SD_Error IsCardProgramming(u8 *pstatus); 
-SD_Error FindSCR(u16 rca,u32 *pscr);   
-
-u8 SD_ReadDisk(u8*buf,u32 sector,u32 cnt); 	//读SD卡,fatfs/usb调用
-u8 SD_WriteDisk(u8*buf,u32 sector,u32 cnt);	//写SD卡,fatfs/usb调用
-
-
-#endif 
-
-
-
-
-

+ 0 - 545
obj/obj_spi_sd_stm32.c

@@ -1,545 +0,0 @@
-/*-----------------------------------------------------------------------*/
-/* MMC/SDC (in SPI mode) control module  (C)ChaN, 2007                   */
-/*-----------------------------------------------------------------------*/
-/* Only rcvr_spi(), xmit_spi(), disk_timerproc() and some macros         */
-/* are platform dependent.                                               */
-/*-----------------------------------------------------------------------*/
-#include "obj_spi_sd_stm32.h"
-#include "dev_spi_sdcard.h"
-/*--------------------------------------------------------------------------
-
- Module Private Functions
-
- ---------------------------------------------------------------------------*/
- 
-//extern SPI_HandleTypeDef hspi2;
-
-#define SD_SPIDriver	  hspi2 
-
-static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */
-
-static volatile BYTE Timer1, Timer2; /* 100Hz decrement timer */
-
-static BYTE CardType; /* b0:MMC, b1:SDC, b2:Block addressing */
-
-static BYTE PowerFlag = 0; /* indicates if "power" is on */
-
-
-
-
-static
-void SELECT(void)
-{
-	//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
-	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET);
-}
-
-static
-void DESELECT(void)
-{
-	//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
-	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_SET);
-}
-
-static
-void xmit_spi(BYTE Data)
-{
-	while (HAL_SPI_GetState(&SD_SPIDriver) != HAL_SPI_STATE_READY);
-	HAL_SPI_Transmit(&SD_SPIDriver, &Data, 1, 5000);
-}
-
-static BYTE rcvr_spi(void)
-{
-	unsigned char Dummy, Data;
-	Dummy = 0xFF;
-	Data = 0;
-	while ((HAL_SPI_GetState(&SD_SPIDriver) != HAL_SPI_STATE_READY))
-		;
-	HAL_SPI_TransmitReceive(&SD_SPIDriver, &Dummy, &Data, 1, 5000);
-
-	return Data;
-}
-
-static
-void rcvr_spi_m(BYTE *dst) {
-	*dst = rcvr_spi();
-}
-
-/*-----------------------------------------------------------------------*/
-/* Wait for card ready                                                   */
-/*-----------------------------z------------------------------------------*/
-
-static BYTE wait_ready(void) {
-	BYTE res;
-
-	Timer2 = 50;
-	rcvr_spi();
-	do
-		res = rcvr_spi();
-	while ((res != 0xFF) && Timer2);
-
-	return res;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Power Control  (Platform dependent)                                   */
-/*-----------------------------------------------------------------------*/
-/* When the target system does not support socket power control, there   */
-/* is nothing to do in these functions and chk_power always returns 1.   */
-
-static
-void power_on(void) {
-	unsigned char i, cmd_arg[6];
-	unsigned int Count = 0x1FFF;
-
-	DESELECT();
-
-	for (i = 0; i < 10; i++)
-		xmit_spi(0xFF);
-	
-	SELECT();
-
-	cmd_arg[0] = (CMD0 | 0x40);
-	cmd_arg[1] = 0;
-	cmd_arg[2] = 0;
-	cmd_arg[3] = 0;
-	cmd_arg[4] = 0;
-	cmd_arg[5] = 0x95;
-
-	for (i = 0; i < 6; i++)
-		xmit_spi(cmd_arg[i]);
-
-	while ((rcvr_spi() != 0x01) && Count)
-		Count--;
-
-	DESELECT();
-	xmit_spi(0XFF);
-
-	PowerFlag = 1;
-}
-
-static
-void power_off(void) {
-	PowerFlag = 0;
-}
-
-static
-int chk_power(void) /* Socket power state: 0=off, 1=on */
-{
-	return PowerFlag;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Receive a data packet from MMC                                        */
-/*-----------------------------------------------------------------------*/
-
-static bool rcvr_datablock(BYTE *buff, /* Data buffer to store received data */
-UINT btr /* Byte count (must be even number) */
-) {
-	BYTE token;
-
-	Timer1 = 10;
-	do { /* Wait for data packet in timeout of 100ms */
-		token = rcvr_spi();
-	} while ((token == 0xFF) && Timer1);
-	if (token != 0xFE)
-		return FALSE; /* If not valid data token, retutn with error */
-
-	do { /* Receive the data block into buffer */
-		rcvr_spi_m(buff++);
-		rcvr_spi_m(buff++);
-	} while (btr -= 2);
-	rcvr_spi(); /* Discard CRC */
-	rcvr_spi();
-
-	return TRUE; /* Return with success */
-}
-
-/*-----------------------------------------------------------------------*/
-/* Send a data packet to MMC                                             */
-/*-----------------------------------------------------------------------*/
-
-#if _READONLY == 0
-static bool xmit_datablock(const BYTE *buff, /* 512 byte data block to be transmitted */
-BYTE token /* Data/Stop token */
-) {
-	BYTE resp, wc;
-	uint32_t i = 0;
-
-	if (wait_ready() != 0xFF)
-		return FALSE;
-
-	xmit_spi(token); /* Xmit data token */
-	if (token != 0xFD) { /* Is data token */
-		wc = 0;
-		do { /* Xmit the 512 byte data block to MMC */
-			xmit_spi(*buff++);
-			xmit_spi(*buff++);
-		} while (--wc);
-
-		rcvr_spi();
-		rcvr_spi();
-
-		while (i <= 64) {
-			resp = rcvr_spi(); /* Reveive data response */
-			if ((resp & 0x1F) == 0x05) /* If not accepted, return with error */
-				break;
-			i++;
-		}
-		while (rcvr_spi() == 0)
-			;
-	}
-	if ((resp & 0x1F) == 0x05)
-		return TRUE;
-	else
-		return FALSE;
-}
-#endif /* _READONLY */
-
-/*-----------------------------------------------------------------------*/
-/* Send a command packet to MMC                                          */
-/*-----------------------------------------------------------------------*/
-
-static BYTE send_cmd(BYTE cmd, /* Command byte */
-DWORD arg /* Argument */
-) {
-	BYTE n, res;
-
-	if (wait_ready() != 0xFF)
-		return 0xFF;
-
-	/* Send command packet */
-	xmit_spi(cmd); /* Command */
-	xmit_spi((BYTE) (arg >> 24)); /* Argument[31..24] */
-	xmit_spi((BYTE) (arg >> 16)); /* Argument[23..16] */
-	xmit_spi((BYTE) (arg >> 8)); /* Argument[15..8] */
-	xmit_spi((BYTE) arg); /* Argument[7..0] */
-	n = 0;
-	if (cmd == CMD0)
-		n = 0x95; /* CRC for CMD0(0) */
-	if (cmd == CMD8)
-		n = 0x87; /* CRC for CMD8(0x1AA) */
-	xmit_spi(n);
-
-	/* Receive command response */
-	if (cmd == CMD12)
-		rcvr_spi(); /* Skip a stuff byte when stop reading */
-	n = 10; /* Wait for a valid response in timeout of 10 attempts */
-	do
-		res = rcvr_spi();
-	while ((res & 0x80) && --n);
-
-	return res; /* Return with the response value */
-}
-
-/*--------------------------------------------------------------------------
-
- Public Functions
-
- ---------------------------------------------------------------------------*/
-
-/*-----------------------------------------------------------------------*/
-/* Initialize Disk Drive                                                 */
-/*-----------------------------------------------------------------------*/
-
-DSTATUS SD_disk_initialize(BYTE drv /* Physical drive nmuber (0) */
-) {
-	BYTE n, ty, ocr[4];
-
-	if (drv)
-		return STA_NOINIT; /* Supports only single drive */
-	if (Stat & STA_NODISK)
-		return Stat; /* No card in the socket */
-
-	power_on(); /* Force socket power on */
-	//send_initial_clock_train();
-
-	SELECT(); /* CS = L */
-	ty = 0;
-	if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
-		Timer1 = 100; /* Initialization timeout of 1000 msec */
-		if (send_cmd(CMD8, 0x1AA) == 1) { /* SDC Ver2+ */
-			for (n = 0; n < 4; n++)
-				ocr[n] = rcvr_spi();
-			if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
-				do {
-					if (send_cmd(CMD55, 0) <= 1
-							&& send_cmd(CMD41, 1UL << 30) == 0)
-						break; /* ACMD41 with HCS bit */
-				} while (Timer1);
-				if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit */
-					for (n = 0; n < 4; n++)
-						ocr[n] = rcvr_spi();
-					ty = (ocr[0] & 0x40) ? 6 : 2;
-				}
-			}
-		} else { /* SDC Ver1 or MMC */
-			ty = (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 0) <= 1) ? 2 : 1; /* SDC : MMC */
-			do {
-				if (ty == 2) {
-					if (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 0) == 0)
-						break; /* ACMD41 */
-				} else {
-					if (send_cmd(CMD1, 0) == 0)
-						break; /* CMD1 */
-				}
-			} while (Timer1);
-			if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Select R/W block length */
-				ty = 0;
-		}
-	}
-	CardType = ty;
-	DESELECT(); /* CS = H */
-	rcvr_spi(); /* Idle (Release DO) */
-
-	if (ty) /* Initialization succeded */
-		Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
-	else
-		/* Initialization failed */
-		power_off();
-
-	return Stat;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Get Disk Status                                                       */
-/*-----------------------------------------------------------------------*/
-
-DSTATUS SD_disk_status(BYTE drv /* Physical drive nmuber (0) */
-) {
-	if (drv)
-		return STA_NOINIT; /* Supports only single drive */
-	return Stat;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Read Sector(s)                                                        */
-/*-----------------------------------------------------------------------*/
-
-DRESULT SD_disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count) {
-	if (pdrv || !count)
-		return RES_PARERR;
-	if (Stat & STA_NOINIT)
-		return RES_NOTRDY;
-
-	if (!(CardType & 4))
-		sector *= 512; /* Convert to byte address if needed */
-
-	SELECT(); /* CS = L */
-
-	if (count == 1) { /* Single block read */
-		if ((send_cmd(CMD17, sector) == 0) /* READ_SINGLE_BLOCK */
-		&& rcvr_datablock(buff, 512))
-			count = 0;
-	} else { /* Multiple block read */
-		if (send_cmd(CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */
-			do {
-				if (!rcvr_datablock(buff, 512))
-					break;
-				buff += 512;
-			} while (--count);
-			send_cmd(CMD12, 0); /* STOP_TRANSMISSION */
-		}
-	}
-
-	DESELECT(); /* CS = H */
-	rcvr_spi(); /* Idle (Release DO) */
-
-	return count ? RES_ERROR : RES_OK;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Write Sector(s)                                                       */
-/*-----------------------------------------------------------------------*/
-
-#if _READONLY == 0
-DRESULT SD_disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count) {
-	if (pdrv || !count)
-		return RES_PARERR;
-	if (Stat & STA_NOINIT)
-		return RES_NOTRDY;
-	if (Stat & STA_PROTECT)
-		return RES_WRPRT;
-
-	if (!(CardType & 4))
-		sector *= 512; /* Convert to byte address if needed */
-
-	SELECT(); /* CS = L */
-
-	if (count == 1) { /* Single block write */
-		if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
-		&& xmit_datablock(buff, 0xFE))
-			count = 0;
-	} else { /* Multiple block write */
-		if (CardType & 2) {
-			send_cmd(CMD55, 0);
-			send_cmd(CMD23, count); /* ACMD23 */
-		}
-		if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
-			do {
-				if (!xmit_datablock(buff, 0xFC))
-					break;
-				buff += 512;
-			} while (--count);
-			if (!xmit_datablock(0, 0xFD)) /* STOP_TRAN token */
-				count = 1;
-		}
-	}
-
-	DESELECT(); /* CS = H */
-	rcvr_spi(); /* Idle (Release DO) */
-
-	return count ? RES_ERROR : RES_OK;
-}
-#endif /* _READONLY */
-
-/*-----------------------------------------------------------------------*/
-/* Miscellaneous Functions                                               */
-/*-----------------------------------------------------------------------*/
-
-DRESULT SD_disk_ioctl(BYTE drv, /* Physical drive nmuber (0) */
-BYTE ctrl, /* Control code */
-void *buff /* Buffer to send/receive control data */
-) {
-	DRESULT res;
-	BYTE n, csd[16], *ptr = buff;
-	WORD csize;
-
-	if (drv)
-		return RES_PARERR;
-
-	res = RES_ERROR;
-
-	if (ctrl == CTRL_POWER) {
-		switch (*ptr) {
-		case 0: /* Sub control code == 0 (POWER_OFF) */
-			if (chk_power())
-				power_off(); /* Power off */
-			res = RES_OK;
-			break;
-		case 1: /* Sub control code == 1 (POWER_ON) */
-			power_on(); /* Power on */
-			res = RES_OK;
-			break;
-		case 2: /* Sub control code == 2 (POWER_GET) */
-			*(ptr + 1) = (BYTE) chk_power();
-			res = RES_OK;
-			break;
-		default:
-			res = RES_PARERR;
-		}
-	} else {
-		if (Stat & STA_NOINIT)
-			return RES_NOTRDY;
-
-		SELECT(); /* CS = L */
-
-		switch (ctrl) {
-		case GET_SECTOR_COUNT: /* Get number of sectors on the disk (DWORD) */
-			if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) {
-				if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */
-					csize = csd[9] + ((WORD) csd[8] << 8) + 1;
-					*(DWORD*) buff = (DWORD) csize << 10;
-				} else { /* MMC or SDC ver 1.XX */
-					n = (csd[5] & 15) + ((csd[10] & 128) >> 7)
-							+ ((csd[9] & 3) << 1) + 2;
-					csize = (csd[8] >> 6) + ((WORD) csd[7] << 2)
-							+ ((WORD) (csd[6] & 3) << 10) + 1;
-					*(DWORD*) buff = (DWORD) csize << (n - 9);
-				}
-				res = RES_OK;
-			}
-			break;
-
-		case GET_SECTOR_SIZE: /* Get sectors on the disk (WORD) */
-			*(WORD*) buff = 512;
-			res = RES_OK;
-			break;
-
-		case CTRL_SYNC: /* Make sure that data has been written */
-			if (wait_ready() == 0xFF)
-				res = RES_OK;
-			break;
-
-		case MMC_GET_CSD: /* Receive CSD as a data block (16 bytes) */
-			if (send_cmd(CMD9, 0) == 0 /* READ_CSD */
-			&& rcvr_datablock(ptr, 16))
-				res = RES_OK;
-			break;
-
-		case MMC_GET_CID: /* Receive CID as a data block (16 bytes) */
-			if (send_cmd(CMD10, 0) == 0 /* READ_CID */
-			&& rcvr_datablock(ptr, 16))
-				res = RES_OK;
-			break;
-
-		case MMC_GET_OCR: /* Receive OCR as an R3 resp (4 bytes) */
-			if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
-				for (n = 0; n < 4; n++)
-					*ptr++ = rcvr_spi();
-				res = RES_OK;
-			}
-
-//        case MMC_GET_TYPE :    /* Get card type flags (1 byte) */
-//            *ptr = CardType;
-//            res = RES_OK;
-//            break;
-
-		default:
-			res = RES_PARERR;
-		}
-
-		DESELECT(); /* CS = H */
-		rcvr_spi(); /* Idle (Release DO) */
-	}
-
-	return res;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Device Timer Interrupt Procedure  (Platform dependent)                */
-/*-----------------------------------------------------------------------*/
-/* This function must be called in period of 10ms                        */
-
-void disk_timerproc(void) {
-//    BYTE n, s;
-	BYTE n;
-
-	n = Timer1; /* 100Hz decrement timer */
-	if (n)
-		Timer1 = --n;
-	n = Timer2;
-	if (n)
-		Timer2 = --n;
-
-}
-
-volatile unsigned short int sdcard_timer;
-
-void inline sdcard_systick_timerproc(void) {
-	++sdcard_timer;
-	if (sdcard_timer >= 100) {
-		sdcard_timer = 0;
-		disk_timerproc();
-	}
-}
-
-/*---------------------------------------------------------*/
-/* User Provided Timer Function for FatFs module           */
-/*---------------------------------------------------------*/
-/* This is a real time clock service to be called from     */
-/* FatFs module. Any valid time must be returned even if   */
-/* the system does not support a real time clock.          */
-
-DWORD SD_get_fattime(void) {
-
-	return ((2007UL - 1980) << 25) // Year = 2007
-	| (6UL << 21) // Month = June
-			| (5UL << 16) // Day = 5
-			| (11U << 11) // Hour = 11
-			| (38U << 5) // Min = 38
-			| (0U >> 1) // Sec = 0
-	;
-
-}
-

+ 0 - 53
obj/obj_spi_sd_stm32.h

@@ -1,53 +0,0 @@
-#ifndef SD_STM32_HEADER
-#define SD_STM32_HEADER
-
-#include "main.h"
-#include "diskio.h"
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-#include "obj_spi_sd_stm32.h"
-
-#include "ff_gen_drv.h"
-
-
-
-#define TRUE  1
-#define FALSE 0
-//#define bool  char
-//#define BYTE  char
-
-/* Definitions for MMC/SDC command */
-#define CMD0    (0x40+0)    /* GO_IDLE_STATE */
-#define CMD1    (0x40+1)    /* SEND_OP_COND */
-#define CMD8    (0x40+8)    /* SEND_IF_COND */
-#define CMD9    (0x40+9)    /* SEND_CSD */
-#define CMD10    (0x40+10)    /* SEND_CID */
-#define CMD12    (0x40+12)    /* STOP_TRANSMISSION */
-#define CMD16    (0x40+16)    /* SET_BLOCKLEN */
-#define CMD17    (0x40+17)    /* READ_SINGLE_BLOCK */
-#define CMD18    (0x40+18)    /* READ_MULTIPLE_BLOCK */
-#define CMD23    (0x40+23)    /* SET_BLOCK_COUNT */
-#define CMD24    (0x40+24)    /* WRITE_BLOCK */
-#define CMD25    (0x40+25)    /* WRITE_MULTIPLE_BLOCK */
-#define CMD41    (0x40+41)    /* SEND_OP_COND (ACMD) */
-#define CMD55    (0x40+55)    /* APP_CMD */
-#define CMD58    (0x40+58)    /* READ_OCR */
-
-/*-----------------------------------------------------------------------*/
-/* Device Timer Interrupt Procedure  (Platform dependent)                */
-/*-----------------------------------------------------------------------*/
-/* This function must be called in period of 10ms                        */
-
-void sdcard_systick_timerproc(void);
-DSTATUS SD_disk_initialize(BYTE drv);
-DSTATUS SD_disk_status(BYTE drv);
-DRESULT SD_disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
-DRESULT SD_disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
-DRESULT SD_disk_ioctl(BYTE drv, /* Physical drive nmuber (0) */
-BYTE ctrl, /* Control code */
-void *buff /* Buffer to send/receive control data */
-);
-
-#endif
-

+ 0 - 319
sys/sys_malloc.c

@@ -1,319 +0,0 @@
-
-#include "sys_malloc.h"	   
-//////////////////////////////////////////////////////////////////////////////////	 
-//本程序只供学习使用,未经作者许可,不得用于其它任何用途
-//ALIENTEK STM32H7开发板
-//内存管理 驱动代码	   
-//正点原子@ALIENTEK
-//技术论坛:www.openedv.com
-//创建日期:2018/7/30
-//版本:V1.0
-//版权所有,盗版必究。
-//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
-//All rights reserved  
-//********************************************************************************
-//修改说明
-//无
-////////////////////////////////////////////////////////////////////////////////// 	 
-
-
-//内存池(64字节对齐)
-__align(64) u8 mem1base[MEM1_MAX_SIZE];													//内部SRAM内存池
-//内存管理表
-u32 mem1mapbase[MEM1_ALLOC_TABLE_SIZE];													//内部SRAM内存池MAP
-
-#ifdef SRAMEX   	//1		//外部内存池(SDRAM),SDRAM共32MB
-__align(64) u8 mem2base[MEM2_MAX_SIZE] __attribute__((at(0XC01F4000)));					//外部SDRAM内存池,前面2M给LTDC用了(1280*800*2)
-u32 mem2mapbase[MEM2_ALLOC_TABLE_SIZE] __attribute__((at(0XC01F4000+MEM2_MAX_SIZE)));	//外部SDRAM内存池MAP
-#endif
-
-#ifdef SRAM12			//2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-__align(64) u8 mem3base[MEM3_MAX_SIZE] __attribute__((at(0x30000000)));					//内部SRAM1+SRAM2内存池
-u32 mem3mapbase[MEM3_ALLOC_TABLE_SIZE] __attribute__((at(0x30000000+MEM3_MAX_SIZE)));	//内部SRAM1+SRAM2内存池MAP
-#endif
-#ifdef SRAM4		  //3		//SRAM4内存池,SRAM4共64KB
-__align(64) u8 mem4base[MEM4_MAX_SIZE] __attribute__((at(0x38000000)));					//内部SRAM4内存池
-u32 mem4mapbase[MEM4_ALLOC_TABLE_SIZE] __attribute__((at(0x38000000+MEM4_MAX_SIZE)));	//内部SRAM4内存池MAP
-#endif
-#ifdef SRAMDTCM 	//4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-__align(64) u8 mem5base[MEM5_MAX_SIZE] __attribute__((at(0x20000000)));					//内部DTCM内存池
-u32 mem5mapbase[MEM5_ALLOC_TABLE_SIZE] __attribute__((at(0x20000000+MEM5_MAX_SIZE)));	//内部DTCM内存池MAP
-#endif
-#ifdef SRAMITCM 	//5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-__align(64) u8 mem6base[MEM6_MAX_SIZE] __attribute__((at(0x00000000)));					//内部ITCM内存池 
-u32 mem6mapbase[MEM6_ALLOC_TABLE_SIZE] __attribute__((at(0x00000000+MEM6_MAX_SIZE)));	//内部ITCM内存池MAP 
-#endif
-
-
-#ifdef SRAMEX   	//1		//外部内存池(SDRAM),SDRAM共32MB
-
-#endif
-
-#ifdef SRAM12			//2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-
-#endif
-#ifdef SRAM4		  //3		//SRAM4内存池,SRAM4共64KB
-
-#endif
-#ifdef SRAMDTCM 	//4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-
-#endif
-#ifdef SRAMITCM 	//5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-
-#endif
-
-
-
-
-
-//内存管理参数	   
-const u32 memtblsize[SRAMBANK]={
-		MEM1_ALLOC_TABLE_SIZE,
-#ifdef SRAMEX   	//1		//外部内存池(SDRAM),SDRAM共32MB
-		MEM2_ALLOC_TABLE_SIZE,
-#endif
-
-#ifdef SRAM12			//2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-		MEM3_ALLOC_TABLE_SIZE,
-#endif
-	
-#ifdef SRAM4		  //3		//SRAM4内存池,SRAM4共64KB
-		MEM4_ALLOC_TABLE_SIZE,
-#endif
-	
-#ifdef SRAMDTCM 	//4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-		MEM5_ALLOC_TABLE_SIZE,
-#endif
-	
-#ifdef SRAMITCM 	//5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-		MEM6_ALLOC_TABLE_SIZE
-#endif		
-			};	//内存表大小
-const u32 memblksize[SRAMBANK]={
-	MEM1_BLOCK_SIZE,
-#ifdef SRAMEX   	//1		//外部内存池(SDRAM),SDRAM共32MB
-	MEM2_BLOCK_SIZE,
-#endif
-
-#ifdef SRAM12			//2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-	MEM3_BLOCK_SIZE,
-
-#endif
-#ifdef SRAM4		  //3		//SRAM4内存池,SRAM4共64KB
-	MEM4_BLOCK_SIZE,
-#endif
-#ifdef SRAMDTCM 	//4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	MEM5_BLOCK_SIZE,
-#endif
-#ifdef SRAMITCM 	//5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	MEM6_BLOCK_SIZE
-#endif
-	};					//内存分块大小
-const u32 memsize[SRAMBANK]	={
-	MEM1_MAX_SIZE,
-
-#ifdef SRAMEX   	//1		//外部内存池(SDRAM),SDRAM共32MB
-	MEM2_MAX_SIZE,
-#endif
-
-#ifdef SRAM12			//2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-	MEM3_MAX_SIZE,	
-#endif
-#ifdef SRAM4		  //3		//SRAM4内存池,SRAM4共64KB
-	MEM4_MAX_SIZE,
-#endif
-#ifdef SRAMDTCM 	//4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	MEM5_MAX_SIZE,
-#endif
-#ifdef SRAMITCM 	//5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	MEM6_MAX_SIZE
-#endif
-
-	};								//内存总大小
-
-//内存管理控制器
-															
-
-struct _m_mallco_dev mallco_dev=
-{
-	.init = my_mem_init,															//内存初始化
-	.perused =  my_mem_perused,															//内存使用率
-	.membase[SRAMIN] = mem1base,					//内存池
-#ifdef SRAMEX   	//1		//外部内存池(SDRAM),SDRAM共32MB
-	.membase[SRAMEX] = mem2base,
-#endif
-
-#ifdef SRAM12			//2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-	mem3base,
-#endif
-#ifdef SRAM4		  //3		//SRAM4内存池,SRAM4共64KB
-	mem4base,
-#endif
-#ifdef SRAMDTCM 	//4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	mem5base,
-#endif
-#ifdef SRAMITCM 	//5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	mem6base,
-#endif
-	.memmap[SRAMIN] = mem1mapbase,//内存管理状态表
-#ifdef SRAMEX   	//1		//外部内存池(SDRAM),SDRAM共32MB
-	mem2mapbase,
-#endif
-
-#ifdef SRAM12			//2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-	mem3mapbase,
-#endif
-#ifdef SRAM4		  //3		//SRAM4内存池,SRAM4共64KB
-	mem4mapbase,
-#endif
-#ifdef SRAMDTCM 	//4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	mem5mapbase,
-#endif
-#ifdef SRAMITCM 	//5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-	mem6mapbase
-#endif
-
-	.memrdy= {0,0,0,0,0,0,}								  		 					//内存管理未就绪
-};
-
-//复制内存
-//*des:目的地址
-//*src:源地址
-//n:需要复制的内存长度(字节为单位)
-void mymemcpy(void *des,void *src,u32 n)  
-{  
-    u8 *xdes=des;
-	u8 *xsrc=src; 
-    while(n--)*xdes++=*xsrc++;  
-}  
-//设置内存
-//*s:内存首地址
-//c :要设置的值
-//count:需要设置的内存大小(字节为单位)
-void mymemset(void *s,u8 c,u32 count)  
-{  
-    u8 *xs = s;  
-    while(count--)*xs++=c;  
-}	
-//内存管理初始化  
-//memx:所属内存块
-void my_mem_init(u8 memx)  
-{  
-    mymemset(mallco_dev.memmap[memx],0,memtblsize[memx]*4);	//内存状态表数据清零  
- 	mallco_dev.memrdy[memx]=1;								//内存管理初始化OK  
-}  
-//获取内存使用率
-//memx:所属内存块
-//返回值:使用率(扩大了10倍,0~1000,代表0.0%~100.0%)
-u16 my_mem_perused(u8 memx)  
-{  
-    u32 used=0;  
-    u32 i;  
-    for(i=0;i<memtblsize[memx];i++)  
-    {  
-        if(mallco_dev.memmap[memx][i])used++; 
-    } 
-    return (used*1000)/(memtblsize[memx]);  
-}  
-//内存分配(内部调用)
-//memx:所属内存块
-//size:要分配的内存大小(字节)
-//返回值:0XFFFFFFFF,代表错误;其他,内存偏移地址 
-u32 my_mem_malloc(u8 memx,u32 size)  
-{  
-    signed long offset=0;  
-    u32 nmemb;	//需要的内存块数  
-	u32 cmemb=0;//连续空内存块数
-    u32 i;  
-    if(!mallco_dev.memrdy[memx])mallco_dev.init(memx);//未初始化,先执行初始化 
-    if(size==0)return 0XFFFFFFFF;//不需要分配
-    nmemb=size/memblksize[memx];  	//获取需要分配的连续内存块数
-    if(size%memblksize[memx])nmemb++;  
-    for(offset=memtblsize[memx]-1;offset>=0;offset--)//搜索整个内存控制区  
-    {     
-		if(!mallco_dev.memmap[memx][offset])cmemb++;//连续空内存块数增加
-		else cmemb=0;								//连续内存块清零
-		if(cmemb==nmemb)							//找到了连续nmemb个空内存块
-		{
-            for(i=0;i<nmemb;i++)  					//标注内存块非空 
-            {  
-                mallco_dev.memmap[memx][offset+i]=nmemb;  
-            }  
-            return (offset*memblksize[memx]);//返回偏移地址  
-		}
-    }  
-    return 0XFFFFFFFF;//未找到符合分配条件的内存块  
-}  
-//释放内存(内部调用) 
-//memx:所属内存块
-//offset:内存地址偏移
-//返回值:0,释放成功;1,释放失败;  
-u8 my_mem_free(u8 memx,u32 offset)  
-{  
-    int i;  
-    if(!mallco_dev.memrdy[memx])//未初始化,先执行初始化
-	{
-		mallco_dev.init(memx);    
-        return 1;//未初始化  
-    }  
-    if(offset<memsize[memx])//偏移在内存池内. 
-    {  
-        int index=offset/memblksize[memx];			//偏移所在内存块号码  
-        int nmemb=mallco_dev.memmap[memx][index];	//内存块数量
-        for(i=0;i<nmemb;i++)  						//内存块清零
-        {  
-            mallco_dev.memmap[memx][index+i]=0;  
-        }  
-        return 0;  
-    }else return 2;//偏移超区了.  
-}  
-//释放内存(外部调用) 
-//memx:所属内存块
-//ptr:内存首地址 
-void myfree(u8 memx,void *ptr)  
-{  
-	u32 offset;   
-	if(ptr==NULL)return;//地址为0.  
- 	offset=(u32)ptr-(u32)mallco_dev.membase[memx];     
-    my_mem_free(memx,offset);	//释放内存      
-}  
-//分配内存(外部调用)
-//memx:所属内存块
-//size:内存大小(字节)
-//返回值:分配到的内存首地址.
-void *mymalloc(u8 memx,u32 size)  
-{  
-    u32 offset;   
-	offset=my_mem_malloc(memx,size);  	   	 	   
-    if(offset==0XFFFFFFFF)return NULL;  
-    else return (void*)((u32)mallco_dev.membase[memx]+offset);  
-}  
-//重新分配内存(外部调用)
-//memx:所属内存块
-//*ptr:旧内存首地址
-//size:要分配的内存大小(字节)
-//返回值:新分配到的内存首地址.
-void *myrealloc(u8 memx,void *ptr,u32 size)  
-{  
-    u32 offset;    
-    offset=my_mem_malloc(memx,size);   	
-    if(offset==0XFFFFFFFF)return NULL;     
-    else  
-    {  									   
-	    mymemcpy((void*)((u32)mallco_dev.membase[memx]+offset),ptr,size);	//拷贝旧内存内容到新内存   
-        myfree(memx,ptr);  											  		//释放旧内存
-        return (void*)((u32)mallco_dev.membase[memx]+offset);  				//返回新内存首地址
-    }  
-}
-
-
-
-
-
-
-
-
-
-
-
-

+ 0 - 115
sys/sys_malloc.h

@@ -1,115 +0,0 @@
-#ifndef __MALLOC_H
-#define __MALLOC_H
-#include "sys_type.h" 
-//////////////////////////////////////////////////////////////////////////////////	 
-//本程序只供学习使用,未经作者许可,不得用于其它任何用途
-//ALIENTEK STM32H7开发板
-//内存管理 驱动代码	   
-//正点原子@ALIENTEK
-//技术论坛:www.openedv.com
-//创建日期:2018/7/30
-//版本:V1.0
-//版权所有,盗版必究。
-//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
-//All rights reserved  
-//********************************************************************************
-//修改说明
-//无
-////////////////////////////////////////////////////////////////////////////////// 	 
-
- 
-#ifndef NULL
-#define NULL 0
-#endif
-
-//定义六个内存池
-#define SRAMIN	 		0		//AXI内存池,AXI共512KB 
-//#define SRAMEX   	1		//外部内存池(SDRAM),SDRAM共32MB
-//#define SRAM12		2		//SRAM1/2/3内存池,SRAM1+SRAM2,共256KB
-//#define SRAM4		  3		//SRAM4内存池,SRAM4共64KB
-//#define SRAMDTCM 	4		//DTCM内存池,DTCM共128KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-//#define SRAMITCM 	5		//ITCM内存池,DTCM共64 KB,此部分内存仅CPU和MDMA(通过AHBS)可以访问!!!!
-
-
-
-#define SRAMBANK 	6		//定义支持的SRAM块数.	
-
-#ifdef SRAMIN
-//mem1内存参数设定.mem1是H7内部的AXI内存.
-#define MEM1_BLOCK_SIZE			64  	  						//内存块大小为64字节
-#define MEM1_MAX_SIZE			448*1024  						//最大管理内存 448K,H7的AXI内存总共512KB
-#define MEM1_ALLOC_TABLE_SIZE	MEM1_MAX_SIZE/MEM1_BLOCK_SIZE 	//内存表大小
-#endif 
-
-#ifdef SRAMEX
-//mem2内存参数设定.mem2是外部的SDRAM内存
-#define MEM2_BLOCK_SIZE			64  	  						//内存块大小为64字节
-#define MEM2_MAX_SIZE			28912 *1024  					//最大管理内存28912K,外扩SDRAM总共32MB,LTDC占了2MB,还剩30MB.
-#define MEM2_ALLOC_TABLE_SIZE	MEM2_MAX_SIZE/MEM2_BLOCK_SIZE 	//内存表大小
-#endif 	
-
-#ifdef SRAM12
-//mem3内存参数设定.mem3是H7内部的SRAM1+SRAM2内存
-#define MEM3_BLOCK_SIZE			64  	  						//内存块大小为64字节
-#define MEM3_MAX_SIZE			240 *1024  						//最大管理内存240K,H7的SRAM1+SRAM2共256KB
-#define MEM3_ALLOC_TABLE_SIZE	MEM3_MAX_SIZE/MEM3_BLOCK_SIZE 	//内存表大小
-#endif 		
-
-#ifdef SRAM4
-//mem4内存参数设定.mem4是H7内部的SRAM4内存
-#define MEM4_BLOCK_SIZE			64  	  						//内存块大小为64字节
-#define MEM4_MAX_SIZE			60 *1024  						//最大管理内存60K,H7的SRAM4共64KB
-#define MEM4_ALLOC_TABLE_SIZE	MEM4_MAX_SIZE/MEM4_BLOCK_SIZE 	//内存表大小
-#endif 	
-
-#ifdef SRAMDTCM
-//mem5内存参数设定.mem5是H7内部的DTCM内存,此部分内存仅CPU和MDMA可以访问!!!!!!
-#define MEM5_BLOCK_SIZE			64  	  						//内存块大小为64字节
-#define MEM5_MAX_SIZE			120 *1024  						//最大管理内存120K,H7的DTCM共128KB
-#define MEM5_ALLOC_TABLE_SIZE	MEM5_MAX_SIZE/MEM5_BLOCK_SIZE 	//内存表大小
-#endif 	
-
-#ifdef SRAMITCM
-//mem6内存参数设定.mem6是H7内部的ITCM内存,此部分内存仅CPU和MDMA可以访问!!!!!!
-#define MEM6_BLOCK_SIZE			64  	  						//内存块大小为64字节
-#define MEM6_MAX_SIZE			60 *1024  						//最大管理内存60K,H7的ITCM共64KB
-#define MEM6_ALLOC_TABLE_SIZE	MEM6_MAX_SIZE/MEM6_BLOCK_SIZE 	//内存表大小
-#endif 			 
-
-
-//内存管理控制器
-struct _m_mallco_dev
-{
-	void (*init)(u8);					//初始化
-	u16 (*perused)(u8);		  	    	//内存使用率
-	u8 	*membase[SRAMBANK];				//内存池 管理SRAMBANK个区域的内存
-	u32 *memmap[SRAMBANK]; 				//内存管理状态表
-	u8  memrdy[SRAMBANK]; 				//内存管理是否就绪
-};
-extern struct _m_mallco_dev mallco_dev;	 //在mallco.c里面定义
-
-void mymemset(void *s,u8 c,u32 count);	//设置内存
-void mymemcpy(void *des,void *src,u32 n);//复制内存     
-void my_mem_init(u8 memx);				//内存管理初始化函数(外/内部调用)
-u32 my_mem_malloc(u8 memx,u32 size);	//内存分配(内部调用)
-u8 my_mem_free(u8 memx,u32 offset);		//内存释放(内部调用)
-u16 my_mem_perused(u8 memx) ;			//获得内存使用率(外/内部调用) 
-////////////////////////////////////////////////////////////////////////////////
-//用户调用函数
-void myfree(u8 memx,void *ptr);  			//内存释放(外部调用)
-void *mymalloc(u8 memx,u32 size);			//内存分配(外部调用)
-void *myrealloc(u8 memx,void *ptr,u32 size);//重新分配内存(外部调用)
-#endif
-
-
-
-
-
-
-
-
-
-
-
-
-