https://github.com/armmbed/spif-driver
Block device driver for NOR SPI flash devices that support SFDP, such as the MX25R or SST26F016B
https://github.com/armmbed/spif-driver
Last synced: 6 months ago
JSON representation
Block device driver for NOR SPI flash devices that support SFDP, such as the MX25R or SST26F016B
- Host: GitHub
- URL: https://github.com/armmbed/spif-driver
- Owner: ARMmbed
- License: apache-2.0
- Created: 2017-02-14T16:35:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-04T09:39:26.000Z (over 7 years ago)
- Last Synced: 2025-06-25T20:12:42.846Z (7 months ago)
- Language: C++
- Homepage:
- Size: 82 KB
- Stars: 26
- Watchers: 101
- Forks: 16
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Warning
Starting from mbed-os 5.10 this repository is deprecated.
Please refer to mbed-os 5.10 [documentation](https://github.com/ARMmbed/mbed-os-5-docs/blob/development/docs/api/storage/SPIFBlockDevice.md) and [code](https://github.com/ARMmbed/mbed-os/tree/master/components/storage/blockdevice/COMPONENT_SPIF) 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:
https://en.wikipedia.org/wiki/Flash_memory#NOR_memories
``` cpp
// 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();
}
```