Skip to content

Add SPIFBlockDevice example #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SPIFBlockDevice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPIFBlockDevice example

SPIFBlockDevice usage example for Mbed OS

29 changes: 29 additions & 0 deletions SPIFBlockDevice/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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();
}
1 change: 1 addition & 0 deletions SPIFBlockDevice/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0