Skip to content

Commit d5be6d6

Browse files
author
Cruz Monrreal
authored
Merge pull request #18 from ARMmbed/add-spifblockdevice
Add SPIFBlockDevice example
2 parents 73c555e + ec8e130 commit d5be6d6

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

SPIFBlockDevice/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPIFBlockDevice example
2+
3+
SPIFBlockDevice usage example for Mbed OS
4+

SPIFBlockDevice/main.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "mbed.h"
2+
#include "SPIFBlockDevice.h"
3+
4+
// Create flash device on SPI bus with PTE5 as chip select
5+
SPIFBlockDevice spif(PTE2, PTE4, PTE1, PTE5);
6+
7+
int main() {
8+
printf("spif test\n");
9+
10+
// Initialize the SPI flash device, and print the memory layout
11+
spif.init();
12+
printf("spif size: %llu\n", spif.size());
13+
printf("spif read size: %llu\n", spif.get_read_size());
14+
printf("spif program size: %llu\n", spif.get_program_size());
15+
printf("spif erase size: %llu\n", spif.get_erase_size());
16+
17+
// Write "Hello World!" to the first block
18+
char *buffer = (char*)malloc(spif.get_erase_size());
19+
sprintf(buffer, "Hello World!\n");
20+
spif.erase(0, spif.get_erase_size());
21+
spif.program(buffer, 0, spif.get_erase_size());
22+
23+
// Read back what was stored
24+
spif.read(buffer, 0, spif.get_erase_size());
25+
printf("%s", buffer);
26+
27+
// Deinitialize the device
28+
spif.deinit();
29+
}

SPIFBlockDevice/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0

0 commit comments

Comments
 (0)