STM32+SDIO+FATFS文件系统 直读SD卡
#include"diskio.h"
#include"stm32f10x.h"
#include"stm32_eval_sdio_sd.h"
#defineBLOCK_SIZE 512/* Block Size in Bytes */
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
DSTATUS disk_initialize (
BYTE drv/* Physical drive nmuber (0..) */
)
{
SD_Error Status;
/* Supports only singledriveFATFS支持多个设备所以有个设备号drive nmuber当然了我就一个SD卡所以只有零号*/
if (drv)
{
return STA_NOINIT;
}
/*-------------------------- SD Init ----------------------------- */
Status = SD_Init();
if (Status!=SD_OK )
{
return STA_NOINIT;
}
else
{
return RES_OK;
}
}
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
DSTATUS disk_status (
BYTE drv/* Physical drive nmuber (0..) */
)
{
return RES_OK;//懒的管了 有空写写 可以加个
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
DRESULT disk_read (
BYTE drv,/* Physical drive nmuber (0..) */
BYTE *buff,/* Data buffer to store read data */
DWORD sector,/* Sector address (LBA) 注意这个是扇区地址也就是第几个扇区*/
BYTE count/* Number of sectors to read (1..255) 读取的扇区数*/
)
{
//SD_Error Status;
if (count > 1)
{
SD_ReadMultiBlocks(buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);//扇区地址*512就是实际地址 默认一个扇区就是512个字节
}
else
{
SD_ReadBlock(buff, sector*BLOCK_SIZE, BLOCK_SIZE);
}
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
#if _READONLY == 0
DRESULT disk_write (
BYTE drv,/* Physical drive nmuber (0..) */
const BYTE *buff,/* Data to be written */
DWORD sector,/* Sector address (LBA) */
BYTE count/* Number of sectors to write (1..255) */
)
{
if (count > 1)
{
SD_WriteMultiBlocks((uint8_t *)buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
/*这里大家看到了有个地址转换 因为DMA仅仅支持4字节指针的所以在函数内部还是有个转换的这里最好优化一下能提高效率*/
}
else
{
SD_WriteBlock((uint8_t *)buff,sector*BLOCK_SIZE, BLOCK_SIZE);
}
return RES_OK;
}
#endif/* _READONLY */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
DRESULT disk_ioctl (
BYTE drv,/* Physical drive nmuber (0..) */
BYTE ctrl,/* Control code */
void *buff/* Buffer to send/receive control data 若是用到擦除函数这个函数一定要补完的有空再写写吧我这简单的返回就好了*/
)
{
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Get current time */
/*-----------------------------------------------------------------------*/
DWORD get_fattime(void)
{
return ((2011UL-1980) < 25)// Year = 2011
| (3UL < 21)// Month = Mar
| (26UL < 16)// Day = 26
| (13U < 11)// Hour = 13
| (19U < 5)// Min =19
| (0U >> 1) // Sec = 0
;
}
最终无优化编译后 :Program Size: Code=10904RO-data=336RW-data=56ZI-data=2304
RO是程序中的指令和常量RW是程序中的已初始化变量
ZI是程序中的未初始化的变量
我觉得这个大小对于STM32103FZE来说完全可以接受
STM32SDIOFATFS文件系统直读SD 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)