The wait in mci_WaitForEvent will delay all card transactions.

Dependencies:   FATFileSystem

Fork of EALib by EmbeddedArtists AB

Embed: (wiki syntax)

« Back to documentation index

SPIFI Class Reference

SPIFI Class Reference

SPIFI Example. More...

#include <SPIFI.h>

Public Member Functions

SpifiError init ()
 Initializes the SPIFI ROM driver making the content of the external serial flash available.
Device device ()
 Returns the detected external serial flash.
uint32_t memorySize ()
 Returns the size (in bytes) of the external serial flash.
uint32_t eraseBlockSize ()
 Returns the size of an erase block (in bytes) on the external serial flash.
uint32_t getVerificationErrorAddr ()
 Returns the address where the verifcation failed.
void internalData (SPIFIobj **initData, const SPIFI_RTNS **romPtr)
 Used by the QSPIFileSystem class to get access to all spifi internal data.
SpifiError program (uint32_t dest, unsigned len, char *src, Options options, bool verify=false, char *scratch=NULL)
 Copies len data from src to dest.
SpifiError erase (uint32_t dest, unsigned len, char *src, bool verify=false, char *scratch=NULL)
 Erases the content of the memory at the specified address.

Detailed Description

SPIFI Example.

 #include "mbed.h"
 #include "SPIFI.h"

 int main(void) {
    SPIFI::SpifiError err;

    err = SPIFI::instance().init();
    if (err != SPIFI::Ok) {
        printf("Failed to initialize SPIFI, error %d\n", err);
    }
    
    // Write "Hello World!" into the first bytes of the SPIFI
    char buff[20] = "Hello World!";
    err = SPIFI::instance().program(0, strlen(buff)+1, buff, SPIFI::EraseAsRequired);
    if (err != SPIFI::Ok) {
        printf("Failed to write to SPIFI, error %d\n", err);
    }

    // Now verify that it can be read
    if (memcmp((char*)SPIFI::SpifiMemBase, buff, strlen(buff)+1) == 0) {
        printf("Readback from memory OK: '%s'\n", SPIFI::SpifiMemBase);
    } else {
        printf("Spifi does not contain the correct data!\n");
    }
 }

Definition at line 39 of file SPIFI.h.


Member Function Documentation

Device device (  )

Returns the detected external serial flash.

Returns:
The detected device or UnknownDevice

Definition at line 96 of file SPIFI.h.

SPIFI::SpifiError erase ( uint32_t  dest,
unsigned  len,
char *  src,
bool  verify = false,
char *  scratch = NULL 
)

Erases the content of the memory at the specified address.

Scratch should be NULL or the address of an area of RAM that the SPIFI driver can use to save data during erase operations. If provided, the scratch area should be as large as the smallest erase size that is available throughout the serial flash device. If scratch is NULL (zero) and an erase is necessary, any bytes in the first erase block before dest are left in erased state (all ones), as are any bytes in the last erase block after dest + len

Parameters:
destAddress to start erasing at, highest byte must be 0x00 or 0x28 as in 0x28000000
lenNumber of bytes to erase
verifyShould the erased area be verified to make sure it is all 0xff
scratchUsed to preserve content of flash outside of erased area. Size of buffer must be at least the size of one erase block.
Returns:
Ok on success An error code on failure

Definition at line 218 of file SPIFI.cpp.

uint32_t eraseBlockSize (  )

Returns the size of an erase block (in bytes) on the external serial flash.

Returns:
The erase block size in bytes

Definition at line 110 of file SPIFI.h.

uint32_t getVerificationErrorAddr (  )

Returns the address where the verifcation failed.

Use only after a Verification error code has been retured from one of the other functions

Returns:
The address to where the program or erase operation failed

Definition at line 118 of file SPIFI.h.

SPIFI::SpifiError init (  )

Initializes the SPIFI ROM driver making the content of the external serial flash available.

Returns:
Ok on success An error code on failure

Definition at line 105 of file SPIFI.cpp.

void internalData ( SPIFIobj **  initData,
const SPIFI_RTNS **  romPtr 
)

Used by the QSPIFileSystem class to get access to all spifi internal data.

Parameters:
initDataThe parameter returned by spifi_init
romPtrThe location of the SPIFI ROM driver in memory

Definition at line 125 of file SPIFI.h.

uint32_t memorySize (  )

Returns the size (in bytes) of the external serial flash.

Returns:
The size in bytes

Definition at line 103 of file SPIFI.h.

SPIFI::SpifiError program ( uint32_t  dest,
unsigned  len,
char *  src,
Options  options,
bool  verify = false,
char *  scratch = NULL 
)

Copies len data from src to dest.

This function will split len > 256 into writes of 256 bytes each.

Programming means that a bit can either be left at 0, or programmed from 1 to 0. Changing bits from 0 to 1 requires an erase operation. While bits can be individually programmed from 1 to 0, erasing bits from 0 to 1 must be done in larger chunks (manufacturer dependant but typically 4Kbyte to 64KByte at a time).

Specify how/when erasing is done with the options parameter:

  • ForceErase causes len bytes to be erased starting at dest. If a scratch buffer (must be the size of an erase block) is provided then only the len bytes will be erased. If no scratch buffer is provided then the erase block surrounding dest will be erased.
  • EraseAsRequired tests if the destination can be written to without erasing. If it can then no erasing is done. If it can't then behaviour is the same as if ForceErase was specified.
  • CallerErase tests if the destination can be written to without erasing. If it can then a data is written. If it can't then an error code is returned and nothing is written.

Scratch should be NULL or the address of an area of RAM that the SPIFI driver can use to save data during erase operations. If provided, the scratch area should be as large as the smallest erase size that is available throughout the serial flash device. If scratch is NULL (zero) and an erase is necessary, any bytes in the first erase block before dest are left in erased state (all ones), as are any bytes in the last erase block after dest + len

Parameters:
destAddress to write to, highest byte must be 0x00 or 0x28 as in 0x28000000
lenNumber of bytes to write
srcData to write
optionsHow to handle content of destination
verifyShould all writes be verified or not
scratchUsed with ForceErase and EraseAsRequired option to preserve content of flash outside of written area. Size of buffer must be at least the size of one erase block.
Returns:
Ok on success An error code on failure

Definition at line 167 of file SPIFI.cpp.