-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2ac4f85
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.build | ||
.mbed | ||
projectfiles | ||
*.py* | ||
mbed-os | ||
BUILD | ||
|
||
compile_commands.json | ||
.clangd | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "mbed.h" //mbed-os 6.10 Nucleo-F429ZI | ||
#include "KVStore.h" | ||
#include "kvstore_global_api.h" | ||
#include "FileSystemStore.h" | ||
|
||
#define err_code(res) MBED_GET_ERROR_CODE(res) | ||
|
||
char key[] = {"key"}; | ||
size_t actual_size = 0; | ||
const size_t buffer_size = 20; | ||
char buffer[buffer_size] = {}; | ||
|
||
KVStore::info_t info; | ||
|
||
KVStore *kvstore = nullptr; | ||
FileSystem *fs = nullptr; | ||
BlockDevice *bd = nullptr; | ||
int res; | ||
|
||
int main() | ||
{ | ||
printf("Example of KVStore with FileSystem\n"); | ||
|
||
fs = FileSystem::get_default_instance(); | ||
|
||
printf("Mounting...\n"); | ||
if((res = fs->mount(bd))!= 0) printf("fs_mount() error: %d\n", err_code(res)); | ||
else printf("Mounted\n"); | ||
/*if (res) { | ||
res = fs->reformat(bd); | ||
printf("Error: %d (Format)\n ", err_code(res)); | ||
}*/ | ||
|
||
kvstore = new FileSystemStore(fs); | ||
|
||
printf("kv_init()\n"); | ||
if((res = kvstore->init())!=0) printf("kv_init error: %d (init)\n ", err_code(res)); | ||
|
||
printf("kv_get_info of a key\n"); | ||
if((res = kvstore->get_info(key, &info))!=0) printf("kv_get_info error: %d\n", err_code(res)); | ||
else printf("kv_get_info key: %s\nkv_get_info info - size: %u, flags: %u\n", key, info.size, info.flags); | ||
|
||
// Press and hold user button and press reset with it, that will call reset and change of value | ||
if(DigitalIn(USER_BUTTON).read()) | ||
{ | ||
printf("KVStore::reset()\n"); | ||
kvstore->reset(); | ||
printf("Please enter a short string!\n"); | ||
char str[10]; | ||
scanf("%10s",str); | ||
printf("KVStore::set() - %s\n", str); | ||
if ((res = kvstore->set(key, str, strlen(str), 0))!= 0) | ||
{ | ||
printf("KVStore::set() error: %d (set)\n ", err_code(res)); | ||
} | ||
} | ||
|
||
printf("KVStore::get()\n"); | ||
if ((res = kvstore->get(key, buffer, buffer_size, &actual_size, 0))!= 0) printf("KVStore::get() error: %d\n", err_code(res)); | ||
else printf("KVStore::get() - data: %s\n", buffer); | ||
|
||
printf("Example end!\r\n"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://github.com/ARMmbed/mbed-os#9738b27c7df897c29e9769911d6794ba3e5b3f19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"target_overrides": { | ||
"*": { | ||
"platform.stdio-convert-newlines": true, | ||
"platform.stdio-baud-rate": 115200, | ||
"platform.default-serial-baud-rate": 115200, | ||
"mbed-trace.enable": true, | ||
"target.printf_lib": "std", | ||
"target.default_lib": "std", | ||
"target.features_add": ["STORAGE"], | ||
"target.components_add":["SD"], | ||
"storage.storage_type": "FILESYSTEM" | ||
}, | ||
"NUCLEO_F303RE": { | ||
"sd.SPI_MOSI" : "PB_5", | ||
"sd.SPI_MISO" : "PB_4", | ||
"sd.SPI_CLK" : "PB_3", | ||
"sd.SPI_CS" : "PA_10" | ||
}, | ||
"NUCLEO_F429ZI": { | ||
"sd.SPI_MOSI" : "PB_5", | ||
"sd.SPI_MISO" : "PB_4", | ||
"sd.SPI_CLK" : "PB_3", | ||
"sd.SPI_CS" : "PA_4" | ||
}, | ||
"NUCLEO_F767ZI": { | ||
"sd.SPI_MOSI" : "PB_5", | ||
"sd.SPI_MISO" : "PB_4", | ||
"sd.SPI_CLK" : "PB_3", | ||
"sd.SPI_CS" : "PA_4" | ||
}, | ||
"NUCLEO_L432KC": { | ||
"sd.SPI_MOSI" : "PA_7", | ||
"sd.SPI_MISO" : "PA_6", | ||
"sd.SPI_CLK" : "PA_5", | ||
"sd.SPI_CS" : "PA_4" | ||
} | ||
} | ||
} |