High-speed access version sd-driver.
Dependents: SDBlockDevice_GR_PEACH SDBlockDevice_GR_PEACH HagridOS5
This library has modified SDBlockDevice.h based on revision "14: c7dba87" of sd-driver.
https://github.com/ARMmbed/sd-driver
features/filesystem/spif/README.md@0:b22a1df967cb, 2017-03-23 (annotated)
- Committer:
- dkato
- Date:
- Thu Mar 23 08:25:54 2017 +0000
- Revision:
- 0:b22a1df967cb
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:b22a1df967cb | 1 | # SPI Flash Driver |
dkato | 0:b22a1df967cb | 2 | |
dkato | 0:b22a1df967cb | 3 | Block device driver for NOR based SPI flash devices that support SFDP. |
dkato | 0:b22a1df967cb | 4 | |
dkato | 0:b22a1df967cb | 5 | 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. |
dkato | 0:b22a1df967cb | 6 | |
dkato | 0:b22a1df967cb | 7 | More info on NOR flash can be found on wikipedia: |
dkato | 0:b22a1df967cb | 8 | https://en.wikipedia.org/wiki/Flash_memory#NOR_memories |
dkato | 0:b22a1df967cb | 9 | |
dkato | 0:b22a1df967cb | 10 | ``` cpp |
dkato | 0:b22a1df967cb | 11 | // Here's an example using the MX25R SPI flash device on the K82F |
dkato | 0:b22a1df967cb | 12 | #include "mbed.h" |
dkato | 0:b22a1df967cb | 13 | #include "SPIFBlockDevice.h" |
dkato | 0:b22a1df967cb | 14 | |
dkato | 0:b22a1df967cb | 15 | // Create flash device on SPI bus with PTE5 as chip select |
dkato | 0:b22a1df967cb | 16 | SPIFBlockDevice spif(PTE2, PTE4, PTE1, PTE5); |
dkato | 0:b22a1df967cb | 17 | |
dkato | 0:b22a1df967cb | 18 | int main() |
dkato | 0:b22a1df967cb | 19 | { |
dkato | 0:b22a1df967cb | 20 | printf("spif test\n"); |
dkato | 0:b22a1df967cb | 21 | |
dkato | 0:b22a1df967cb | 22 | // Initialize the SPI flash device and print the memory layout |
dkato | 0:b22a1df967cb | 23 | spif.init(); |
dkato | 0:b22a1df967cb | 24 | printf("spif size: %llu\n", spif.size()); |
dkato | 0:b22a1df967cb | 25 | printf("spif read size: %llu\n", spif.get_read_size()); |
dkato | 0:b22a1df967cb | 26 | printf("spif program size: %llu\n", spif.get_program_size()); |
dkato | 0:b22a1df967cb | 27 | printf("spif erase size: %llu\n", spif.get_erase_size()); |
dkato | 0:b22a1df967cb | 28 | |
dkato | 0:b22a1df967cb | 29 | // Write "Hello World!" to the first block |
dkato | 0:b22a1df967cb | 30 | uint8_t *buffer = malloc(spif.get_erase_size()); |
dkato | 0:b22a1df967cb | 31 | sprintf(buffer, "Hello World!\n"); |
dkato | 0:b22a1df967cb | 32 | spif.erase(0, spif.get_erase_size()); |
dkato | 0:b22a1df967cb | 33 | spif.program(buffer, 0, spif.get_erase_size()); |
dkato | 0:b22a1df967cb | 34 | |
dkato | 0:b22a1df967cb | 35 | // Read back what was stored |
dkato | 0:b22a1df967cb | 36 | spif.read(buffer, 0, spif.get_erase_size()); |
dkato | 0:b22a1df967cb | 37 | printf("%s", buffer); |
dkato | 0:b22a1df967cb | 38 | |
dkato | 0:b22a1df967cb | 39 | // Deinitialize the device |
dkato | 0:b22a1df967cb | 40 | spif.deinit(); |
dkato | 0:b22a1df967cb | 41 | } |
dkato | 0:b22a1df967cb | 42 | ``` |
dkato | 0:b22a1df967cb | 43 |