little llumpu / USBMSD_AT45

Dependents:   USBMSD_AT45_HelloWorld

Embed: (wiki syntax)

« Back to documentation index

USBMSD_AT45 Class Reference

USBMSD_AT45 Class Reference

USBMSD device (USB flashdisk) with Atmel AT45DBxx serial flash. More...

#include <USBMSD_AT45.h>

Public Member Functions

 USBMSD_AT45 (PinName mosi, PinName miso, PinName sclk, PinName ncs, int transport_block_size)
 Constructor.
virtual int disk_read (char *data, int block)
 disk_read()
virtual int disk_write (const char *data, int block)
 disk_write()
virtual int disk_size ()
 disk_size()
virtual int disk_sectors ()
 disk_sectors()
virtual int disk_status ()
 disk_status()
virtual int disk_initialize ()
 disk_initialize()

Detailed Description

USBMSD device (USB flashdisk) with Atmel AT45DBxx serial flash.

Example:

 #include "mbed.h"
 #include "USBMSD_AT45.h"

 USBMSD_AT45 Flash(p5, p6, p7, p8, 512);  // Mosi, Miso, Sclk, CS, Size of block being transported over USB
                                 // each time. Can be 512, 1024, 2048, 4096. Best is to select same
                                 // size as AT45DBxx SRAM buffer size. If page size of flash is not
                                 // binary 2^N (256, 512, 1024 bytes) but is 264, 528 or 1056 bytes
                                 // before each write we read block being written to SRAM then rewrite
                                 // part of them with data from host and write whole SRAM buffer back
                                 // to flash. This avoids to data being rewritten in other blocks
                                 // we actually do not write to.
 int main() {

  while(1) {

  // Do something else here

   }
  }

Definition at line 56 of file USBMSD_AT45.h.


Constructor & Destructor Documentation

USBMSD_AT45 ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  ncs,
int  transport_block_size 
)

Constructor.

Create an instance of the USBMSD_AT45 connected to specfied SPI pins, with the specified CHIP SELECT pin

Parameters:
mosiThe SPI mosi Pin (p5 or p11)
misoThe SPI miso Pin (p6 or p12)
sclkThe SPI sclk Pin (p7 or p13)
ncsThe SPI chip select Pin (any digital out pin)
transport_block_sizeThe size of block being transported over USB

Definition at line 47 of file USBMSD_AT45.cpp.


Member Function Documentation

int disk_initialize (  ) [virtual]

disk_initialize()

This method is called when disk_status returns 0x01 (not initialized)

Definition at line 68 of file USBMSD_AT45.cpp.

int disk_read ( char *  data,
int  block 
) [virtual]

disk_read()

Reads block of data from storage chip. Size of block is set in constructor

Parameters:
dataPointer to buffer where data will be read to
blockNumber of requested block

Definition at line 104 of file USBMSD_AT45.cpp.

int disk_sectors (  ) [virtual]

disk_sectors()

Parameters:
returnsCount of sectors of storage chip

Definition at line 89 of file USBMSD_AT45.cpp.

int disk_size (  ) [virtual]

disk_size()

Parameters:
returnsSize of storage chip in bytes

Definition at line 82 of file USBMSD_AT45.cpp.

int disk_status (  ) [virtual]

disk_status()

Parameters:
returnsStatus of storage chip - 0x00 ready, 0x01 not initialized (disk_initialize is then called)

Definition at line 96 of file USBMSD_AT45.cpp.

int disk_write ( const char *  data,
int  block 
) [virtual]

disk_write()

Writes block of data to storage chip. Size of block is set in constructor

Parameters:
dataPointer to buffer from which contains data to be written to storage chip
blockNumber of block to be written to

Definition at line 216 of file USBMSD_AT45.cpp.