anywill 发表于 2016-10-31 18:12:53

ARM®mbed OS 提高 SD卡 1 文件系统


【STM32 Mbed帖子大集合】


前言:
SD卡被广泛用于存储设备如:手机,MP3播放器,
SD卡是存储大量非易失性数据非常便宜的选择(即断电,数据也不会丢失)。
是数据记录和存储音频/图像的理想选择。
SD和MMC卡,支持多种协议,但通常都是基于SPI协议。
它使用一个通用的SPI接口,
SD卡是块设备。以块大小(通常为512字节)的倍数读/写数据;
接口界面基本上是“从块地址n读”,“写块地址M”。
文件系统(如FAT)是在此之上的抽象
SDFileSystem是此例程的库文件允许SD卡以SPI接口类似文件系统读写 ,此库支持:FAT12 / FAT16 / FAT32
SD / SDHC cards up to 32Gb
long filenames
time stamp
本例程基于一个SparkFun的MicroSD卡模块,
http://developer.mbed.org/media/uploads/simon/xusd-breakout_i_ma.jpg.pagespeed.ic.ipnOw2rc3y.webp
(可以使用SPI端口以及任何DigitalOut)接线:
SparkFun MicroSD Breakout Board          mbed 板
CSo--------------------------------------------o D6    (DigitalOut cs)
DIo--------------------------------------------o D4    (SPI mosi)
VCC o-------------------------------------------o VOUT   
SCK o-------------------------------------------o D3    (SPI sclk)   
GND o-------------------------------------------o GND   
DOo-------------------------------------------o D5    (SPI miso)   
CDo
移植前连接的是xbed LPC1768 sd(p5, p6, p7, p8, "sd");

SparkFun的MicroSD接口板
的MicroSD突围mbed
VCC引脚3.3V。不要使用5V。5V电源会损坏SD卡模块。
CD(卡检测)引脚是可选的,并且在本示例程序未使用。
CD连接到GND时,表示没有卡存在。一旦卡插入则与GND的连接断开。
它可使用DigitalIn pin读取,模式设置为上拉。

#include "mbed.h"
#include "SDFileSystem.h"
//SDHC support till 32GB
//SPI
SDFileSystem sd(D5, D6, D7, D8, "sd"); // the pinout on the mbed Cool Components workshop board
//xbed LPC1768 使用(p5, p6, p7, p8, "sd")
int main() {
    printf("Hello World!\n");   

    mkdir("/sd/mydir", 0777);

    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
    if(fp == NULL) {
      error("Could not open file for write\n");
    }
    fprintf(fp, "Hello fun SD Card World!");
    fclose(fp);

    printf("Goodbye World!\n");
}


参考

[*]SD Card Specification
[*]Notes on the development of this library: SDCards!
[*]SD association SD Card Formatter - SD cards come formatted, use this to reformat an SD card when needed
[*]Reading the directory on an SD card contains additional example code that may be helpful when working with SD card directories.


anywill 发表于 2016-10-31 18:17:33

本帖最后由 anywill 于 2016-10-31 20:11 编辑

mbed official/ SDFileSystem库文件





xyx365 发表于 2016-10-31 18:55:13

谢谢分享

suoma 发表于 2016-10-31 20:32:18

用mbed做一个串口透传的,谢谢

haifeng-388081 发表于 2016-10-31 20:43:01

6666666666

peter001 发表于 2016-11-1 01:05:25

好东西:lol

高二毛 发表于 2016-11-1 08:27:45

感谢楼主分享。你这个系列弄完,可以出本书了哈。期待。。。:D

笑鸟007 发表于 2016-11-1 09:29:08

:):):):)这个可以有!

adlu 发表于 2017-11-13 09:49:39

mark to learn
页: [1]
查看完整版本: ARM®mbed OS 提高 SD卡 1 文件系统