Go to file
Offir Kochalsky b042ba6d19 changed conf back to spid-driver 2018-08-22 15:50:09 +03:00
TESTS/block_device/spif changed conf back to spid-driver 2018-08-22 15:50:09 +03:00
.travis.yml Added support for Travis CI 2017-07-16 15:45:59 -05:00
LICENSE.md Renamed LICENSE -> LICENSE.md 2017-07-16 13:02:37 -05:00
README.md Added support for Travis CI 2017-07-16 15:45:59 -05:00
SPIFBlockDevice.cpp RDID is a register read that should use general command 2018-08-20 16:02:26 +03:00
SPIFBlockDevice.h Include DigitalOut.h instead of mbed.h 2018-08-19 11:51:50 +03:00
mbed_lib.json changed conf back to spid-driver 2018-08-22 15:50:09 +03:00

README.md

SPI Flash Driver

Block device driver for NOR based SPI flash devices that support SFDP.

NOR based SPI flash supports byte-sized read and writes, with an erase size of around 4kbytes. An erase sets a block to all 1s, with successive writes clearing set bits.

More info on NOR flash can be found on wikipedia: https://en.wikipedia.org/wiki/Flash_memory#NOR_memories

// Here's an example using the MX25R SPI flash device on the K82F
#include "mbed.h"
#include "SPIFBlockDevice.h"

// Create flash device on SPI bus with PTE5 as chip select
SPIFBlockDevice spif(PTE2, PTE4, PTE1, PTE5);

int main() {
    printf("spif test\n");

    // Initialize the SPI flash device and print the memory layout
    spif.init();
    printf("spif size: %llu\n",         spif.size());
    printf("spif read size: %llu\n",    spif.get_read_size());
    printf("spif program size: %llu\n", spif.get_program_size());
    printf("spif erase size: %llu\n",   spif.get_erase_size());

    // Write "Hello World!" to the first block
    char *buffer = (char*)malloc(spif.get_erase_size());
    sprintf(buffer, "Hello World!\n");
    spif.erase(0, spif.get_erase_size());
    spif.program(buffer, 0, spif.get_erase_size());

    // Read back what was stored
    spif.read(buffer, 0, spif.get_erase_size());
    printf("%s", buffer);

    // Deinitialize the device
    spif.deinit();
}