No change from original version.

Dependencies:   FATFileSystem

Dependents:   SDFile_Logger

Fork of SDFileSystem by Neil Thiessen

Embed: (wiki syntax)

« Back to documentation index

SDFileSystem Class Reference

SDFileSystem Class Reference

SDFileSystem class. More...

#include <SDFileSystem.h>

Public Types

enum  SwitchType {
  SWITCH_NONE, SWITCH_POS_NO, SWITCH_POS_NC, SWITCH_NEG_NO,
  SWITCH_NEG_NC
}
 

Represents the different card detect switch types.

More...
enum  CardType {
  CARD_NONE, CARD_MMC, CARD_SD, CARD_SDHC,
  CARD_UNKNOWN
}
 

Represents the different SD/MMC card types.

More...

Public Member Functions

 SDFileSystem (PinName mosi, PinName miso, PinName sclk, PinName cs, const char *name, PinName cd=NC, SwitchType cdtype=SWITCH_NONE, int hz=1000000)
 Create a virtual file system for accessing SD/MMC cards via SPI.
bool card_present ()
 Determine whether or not a card is present.
SDFileSystem::CardType card_type ()
 Get the detected SD/MMC card type.
bool crc ()
 Get whether or not CRC is enabled for commands and data.
void crc (bool enabled)
 Set whether or not CRC is enabled for commands and data.
bool large_frames ()
 Get whether or not 16-bit frames are enabled for data read/write operations.
void large_frames (bool enabled)
 Set whether or not 16-bit frames are enabled for data read/write operations.
bool write_validation ()
 Get whether or not write validation is enabled for data write operations.
void write_validation (bool enabled)
 Set whether or not write validation is enabled for data write operations.

Detailed Description

SDFileSystem class.

Used for creating a virtual file system for accessing SD/MMC cards via SPI.

Example:

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

 //Create an SDFileSystem object
 SDFileSystem sd(p5, p6, p7, p20, "sd");

 int main()
 {
     //Mount the filesystem
     sd.mount();

     //Perform a write test
     printf("\nWriting to SD card...");
     FILE *fp = fopen("/sd/sdtest.txt", "w");
     if (fp != NULL) {
         fprintf(fp, "We're writing to an SD card!");
         fclose(fp);
         printf("success!\n");
     } else {
         printf("failed!\n");
     }

     //Perform a read test
     printf("Reading from SD card...");
     fp = fopen("/sd/sdtest.txt", "r");
     if (fp != NULL) {
         char c = fgetc(fp);
         if (c == 'W')
             printf("success!\n");
         else
             printf("incorrect char (%c)!\n", c);
         fclose(fp);
     } else {
         printf("failed!\n");
     }

     //Unmount the filesystem
     sd.unmount();
 }

Definition at line 69 of file SDFileSystem.h.


Member Enumeration Documentation

enum CardType

Represents the different SD/MMC card types.

Enumerator:
CARD_NONE 

No card is present.

CARD_MMC 

MMC card.

CARD_SD 

Standard capacity SD card.

CARD_SDHC 

High capacity SD card.

CARD_UNKNOWN 

Unknown or unsupported card.

Definition at line 84 of file SDFileSystem.h.

enum SwitchType

Represents the different card detect switch types.

Enumerator:
SWITCH_NONE 

No card detect switch (assumes socket is always occupied)

SWITCH_POS_NO 

Switch shorts to VDD when the socket is occupied (positive logic, normally open)

SWITCH_POS_NC 

Switch shorts to VDD when the socket is empty (positive logic, normally closed)

SWITCH_NEG_NO 

Switch shorts to GND when the socket is occupied (negative logic, normally open)

SWITCH_NEG_NC 

Switch shorts to GND when the socket is empty (negative logic, normally closed)

Definition at line 74 of file SDFileSystem.h.


Constructor & Destructor Documentation

SDFileSystem ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  cs,
const char *  name,
PinName  cd = NC,
SwitchType  cdtype = SWITCH_NONE,
int  hz = 1000000 
)

Create a virtual file system for accessing SD/MMC cards via SPI.

Parameters:
mosiThe SPI data out pin.
misoThe SPI data in pin.
sclkThe SPI clock pin.
csThe SPI chip select pin.
nameThe name used to access the virtual filesystem.
cdThe card detect pin.
cdtypeThe type of card detect switch.
hzThe SPI bus frequency (defaults to 1MHz).

Definition at line 22 of file SDFileSystem.cpp.


Member Function Documentation

bool card_present (  )

Determine whether or not a card is present.

Returns:
'true' if a card is present, 'false' if no card is present.

Definition at line 64 of file SDFileSystem.cpp.

SDFileSystem::CardType card_type (  )

Get the detected SD/MMC card type.

Returns:
The detected card type as a CardType enum.
Note:
Valid after the filesystem has been mounted.

Definition at line 73 of file SDFileSystem.cpp.

void crc ( bool  enabled )

Set whether or not CRC is enabled for commands and data.

Parameters:
enabledWhether or not to enable CRC for commands and data.

Definition at line 88 of file SDFileSystem.cpp.

bool crc (  )

Get whether or not CRC is enabled for commands and data.

Returns:
'true' if CRC is enabled for commands and data, 'false' if CRC is disabled for commands and data.

Definition at line 82 of file SDFileSystem.cpp.

void large_frames ( bool  enabled )

Set whether or not 16-bit frames are enabled for data read/write operations.

Parameters:
enabledWhether or not 16-bit frames are enabled for data read/write operations.

Definition at line 117 of file SDFileSystem.cpp.

bool large_frames (  )

Get whether or not 16-bit frames are enabled for data read/write operations.

Returns:
'true' if 16-bit frames will be used during data read/write operations, 'false' if 8-bit frames will be used during data read/write operations.

Definition at line 111 of file SDFileSystem.cpp.

void write_validation ( bool  enabled )

Set whether or not write validation is enabled for data write operations.

Parameters:
enabledWhether or not write validation is enabled for data write operations.

Definition at line 129 of file SDFileSystem.cpp.

bool write_validation (  )

Get whether or not write validation is enabled for data write operations.

Returns:
'true' if data writes will be verified using CMD13, 'false' if data writes will not be verified.

Definition at line 123 of file SDFileSystem.cpp.