Example for reading and writing SD card using SPI mode.

Dependencies:   mbed

Fork of Demo_NucleoF4xx_SD_Card by 不韋 呂

Embed: (wiki syntax)

« Back to documentation index

SDFileSystem Class Reference

SDFileSystem Class Reference

Access the filesystem on an SD Card using SPI. More...

#include <SDFileSystem.h>

Inherits FATFileSystem.

Public Member Functions

 SDFileSystem (PinName mosi, PinName miso, PinName sclk, PinName cs, const char *name)
 Create the File System for accessing an SD Card using SPI.
virtual FileHandle * open (const char *name, int flags)
 Opens a file on the filesystem.
virtual int remove (const char *filename)
 Removes a file path.
virtual int format ()
 Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster.
virtual DirHandle * opendir (const char *name)
 Opens a directory on the filesystem.
virtual int mkdir (const char *name, mode_t mode)
 Creates a directory path.

Detailed Description

Access the filesystem on an SD Card using SPI.

 #include "mbed.h"
 #include "SDFileSystem.h"

 SDFileSystem sd(p5, p6, p7, p12, "sd"); // MOSI, MISO, SCLK, SSEL
  
 int main() {
     FILE *fp = fopen("/sd/mbed.txt", "w");
     fprintf(fp, "Hello World!\n");
     fclose(fp);
 }

Definition at line 44 of file SDFileSystem.h.


Constructor & Destructor Documentation

SDFileSystem ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  cs,
const char *  name 
)

Create the File System for accessing an SD Card using SPI.

Parameters:
mosiSPI mosi pin connected to SD Card
misoSPI miso pin conencted to SD Card
sclkSPI sclk pin connected to SD Card
csDigitalOut pin used as SD Card chip select
nameThe name used to access the virtual filesystem

Definition at line 123 of file SDFileSystem.cpp.


Member Function Documentation

int format (  ) [virtual, inherited]

Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster.

Definition at line 111 of file FATFileSystem.cpp.

int mkdir ( const char *  name,
mode_t  mode 
) [virtual, inherited]

Creates a directory path.

Definition at line 129 of file FATFileSystem.cpp.

FileHandle * open ( const char *  name,
int  flags 
) [virtual, inherited]

Opens a file on the filesystem.

Definition at line 68 of file FATFileSystem.cpp.

DirHandle * opendir ( const char *  name ) [virtual, inherited]

Opens a directory on the filesystem.

Definition at line 120 of file FATFileSystem.cpp.

int remove ( const char *  filename ) [virtual, inherited]

Removes a file path.

Definition at line 102 of file FATFileSystem.cpp.