diff --git a/main.cpp b/main.cpp index 95944af..75e1268 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include "lorawan/LoRaWANInterface.h" #include "lorawan/system/lorawan_data_structures.h" #include "mbed.h" +#include "nvstore.h" #if MBED_CONF_APP_DHT_ENABLED #include "DHT.h" @@ -67,6 +68,35 @@ HX711 loadcell(MBED_CONF_APP_HX711_DATA, MBED_CONF_APP_HX711_CLK); int main(void) { lorawan_status_t retcode; +#if NVSTORE_ENABLED + NVStore &nvstore = NVStore::get_instance(); + int rc; + uint16_t key; + // Values read or written by NVStore need to be aligned to a uint32_t address (even if their sizes + // aren't) + uint32_t value; + // Initialize NVstore. Note that it can be skipped, as it is lazily called by all other APIs + rc = nvstore.init(); + printf("Init NVStore. \n"); + // Show NVStore size, maximum number of keys and area addresses and sizes + printf("NVStore size is %d.\n", nvstore.size()); + printf("NVStore max number of keys is %d (out of %d possible ones in this flash configuration).\n", + nvstore.get_max_keys(), nvstore.get_max_possible_keys()); + printf("NVStore areas:\n"); + for (uint8_t area = 0; area < NVSTORE_NUM_AREAS; area++) { + uint32_t area_address; + size_t area_size; + nvstore.get_area_params(area, area_address, area_size); + printf("Area %d: address 0x%08lx, size %d (0x%x).\n", area, area_address, area_size, area_size); + } +#else + printf("NVStore is disabled for this board\n"); +#endif + +while(1) { + wait(1); +} + #if MBED_CONF_APP_HX711_ENABLED loadcell.powerDown(); loadcell.setScale(MBED_CONF_APP_HX711_SCALE); diff --git a/mbed_app.json b/mbed_app.json index e72b2ef..4553c62 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -87,7 +87,12 @@ "hx711-clk": "D6", "hx711-data": "D7", "hx711-scale": "21000.0f", - "hx711-offset": 59600 + "hx711-offset": 59600, + "nvstore.max_keys": 20, + "nvstore.area_1_address": "0x0802e000", + "nvstore.area_1_size" : "0x1000", + "nvstore.area_2_address": "0x0802f000", + "nvstore.area_2_size" : "0x1000" }, "MTB_RAK811": {