Skip to content

Commit a3825b9

Browse files
committed
Add FlashIAPBlockDevice example
1 parent d5be6d6 commit a3825b9

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

FlashIAPBlockDevice/README.md

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

FlashIAPBlockDevice/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 "FlashIAPBlockDevice.h"
3+
4+
// Create flash IAP block device
5+
FlashIAPBlockDevice bd;
6+
7+
int main() {
8+
printf("FlashIAPBlockDevice test\n");
9+
10+
// Initialize the flash IAP block device and print the memory layout
11+
bd.init();
12+
printf("Flash block device size: %llu\n", bd.size());
13+
printf("Flash block device read size: %llu\n", bd.get_read_size());
14+
printf("Flash block device program size: %llu\n", bd.get_program_size());
15+
printf("Flash block device erase size: %llu\n", bd.get_erase_size());
16+
17+
// Write "Hello World!" to the first block
18+
char *buffer = (char*)malloc(bd.get_erase_size());
19+
sprintf(buffer, "Hello World!\n");
20+
bd.erase(0, bd.get_erase_size());
21+
bd.program(buffer, 0, bd.get_erase_size());
22+
23+
// Read back what was stored
24+
bd.read(buffer, 0, bd.get_erase_size());
25+
printf("%s", buffer);
26+
27+
// Deinitialize the device
28+
bd.deinit();
29+
}

FlashIAPBlockDevice/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)