Skip to content
Block device driver for NOR SPI flash devices that support SFDP, such as the MX25R or SST26F016B
Branch: master
Clone or download
offirko Merge pull request #25 from ARMmbed/move-spif-driver-to-mbed-os
Adding deprecation warning for mbed-os 5.10
Latest commit ac01c51 Oct 4, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
TESTS/block_device/spif prevent unaligned erase Aug 29, 2018
.travis.yml Renamed LICENSE -> Jul 16, 2017 Updating deprication message to have links to new code and documents.… Sep 20, 2018
SPIFBlockDevice.cpp Merge pull request #25 from ARMmbed/move-spif-driver-to-mbed-os Oct 4, 2018
SPIFBlockDevice.h Add return error to API documentation Aug 29, 2018
mbed_lib.json changed conf back to spid-driver Aug 22, 2018


Starting from mbed-os 5.10 this repository is deprecated. Please refer to mbed-os 5.10 documentation and code for more detail on how to enable SPIF support.

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:

// 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
    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, 0, spif.get_erase_size());
    printf("%s", buffer);

    // Deinitialize the device
You can’t perform that action at this time.