From 2ac4f85d3924adf8365173363e226927fc257016 Mon Sep 17 00:00:00 2001 From: JohnK1987 Date: Wed, 23 Jun 2021 20:19:33 +0000 Subject: [PATCH] First release --- .gitignore | 10 ++++++++ main.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ mbed-os.lib | 1 + mbed_app.json | 39 +++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 main.cpp create mode 100644 mbed-os.lib create mode 100644 mbed_app.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..642d602 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.build +.mbed +projectfiles +*.py* +mbed-os +BUILD + +compile_commands.json +.clangd +.cache diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fc7504d --- /dev/null +++ b/main.cpp @@ -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"); +} + diff --git a/mbed-os.lib b/mbed-os.lib new file mode 100644 index 0000000..14ba57b --- /dev/null +++ b/mbed-os.lib @@ -0,0 +1 @@ +https://github.com/ARMmbed/mbed-os#9738b27c7df897c29e9769911d6794ba3e5b3f19 \ No newline at end of file diff --git a/mbed_app.json b/mbed_app.json new file mode 100644 index 0000000..53efc66 --- /dev/null +++ b/mbed_app.json @@ -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" + } + } +} \ No newline at end of file