Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnK1987 committed Jun 23, 2021
0 parents commit 2ac4f85
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
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
64 changes: 64 additions & 0 deletions main.cpp
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");
}

1 change: 1 addition & 0 deletions mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os#9738b27c7df897c29e9769911d6794ba3e5b3f19
39 changes: 39 additions & 0 deletions mbed_app.json
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"
}
}
}

0 comments on commit 2ac4f85

Please sign in to comment.