NVStore example for Mbed OS. This is an example of an application that uses the NVStore APIs. The application invokes the NVStore APIs and prints the results after each such invocation.

Required hardware

# Other hardware

Although the board shown in this examples is K64F, the example should work on any Mbed enabled hardware supporting the internal flash driver (has "FLASH" in the "device_has" in targets/target.json file).

Getting started

1. Import the example.

``` mbed import mbed-os-example-nvstore cd mbed-os-example-nvstore ```

2. Keep the default NVStore configuration, which uses the last two sectors (4KB each) as NVStore areas.

3. Compile and generate binary.

For example, for `GCC`:

``` mbed compile -t GCC_ARM -m K64F ```

4. Open a serial console session with the target platform using the following parameters:

  • Baud rate: 115200
  • Data bits: 8
  • Stop bits: 1
  • Parity: None

5. Copy the application `mbed-os-example-nvstore.bin` in the folder `mbed-os-example-nvstore/BUILD/<TARGET NAME>/<PLATFORM NAME>` onto the target board.

6. Press the RESET button on the board to run the program

7. The serial console should now display a series of results following the NVStore API invocations.

8. Now copy `mbed_app-8KB-areas.json` to `mbed_app.json`. This should use 8KB areas (two pairs of last sectors) as NVStore areas.

9. Repeat steps 3-7. Notice the changes in prints of area addresses and sizes and with the amount of possible keys this configuration can hold.

10. To restore the default configuration, copy `mbed_app-default-areas.json` to `mbed_app.json`.

Troubleshooting

If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Jun 03 15:02:15 2019 +0100
Parent:
28:2186be283b24
Commit message:
Merge pull request #40 from 0xc0170/fix_license

add contributing + license files
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-nvstore

Changed in this revision

CONTRIBUTING.md Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
tests/README.md Show annotated file Show diff for this revision Revisions of this file
tests/nvstore.log Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CONTRIBUTING.md	Mon Jun 03 15:02:15 2019 +0100
@@ -0,0 +1,5 @@
+# Contributing to Mbed OS
+
+Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor.
+
+To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
--- a/README.md	Mon Feb 25 16:45:58 2019 +0000
+++ b/README.md	Mon Jun 03 15:02:15 2019 +0100
@@ -37,7 +37,7 @@
    
  4. Open a serial console session with the target platform using the following parameters:
 
-    * **Baud rate:** 115200
+    * **Baud rate:** 9600
     * **Data bits:** 8
     * **Stop bits:** 1
     * **Parity:** None
@@ -47,9 +47,9 @@
  6. Press the **RESET** button on the board to run the program
 
  7. The serial console should now display a series of results following the NVStore API invocations. 
- 
+
  8. Unless specifically configured by the user, NVStore selects the last two flash sectors as its areas, with the minimum size of 4KBs. This means that if the sectors are smaller, a few continuous ones will be used for each area.
- 
+
     If the automatically selected sectors do not fit your flash configuration, you can override this by setting the addresses and sizes of both areas in `mbed_lib.json` for each board. 
     
 	Copy `mbed_app-K64F-8KB-areas.json` to `mbed_app.json` and edit `mbed_app.json` to match your board.
@@ -63,7 +63,6 @@
 	-   `area_2_address`
 	-   `area_2_size`
 	
-	
  9. Repeat steps 3-7. Notice the changes in prints of area addresses and sizes and with the amount of possible keys this configuration can hold.
 
 10. To restore the default configuration, copy `mbed_app-default-areas.json` to `mbed_app.json`.
@@ -71,3 +70,10 @@
 ## Troubleshooting
 
 If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
+
+## License and contributions
+
+The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see [contributing.md](CONTRIBUTING.md) for more info.
+
+This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
+
--- a/mbed_app.json	Mon Feb 25 16:45:58 2019 +0000
+++ b/mbed_app.json	Mon Jun 03 15:02:15 2019 +0100
@@ -1,8 +1,6 @@
 {
     "target_overrides": {
         "*": {
-            "platform.stdio-baud-rate": 115200,
-            "platform.default-serial-baud-rate": 115200,
             "platform.stdio-convert-newlines": 1
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/README.md	Mon Jun 03 15:02:15 2019 +0100
@@ -0,0 +1,12 @@
+# Testing examples
+
+Examples are tested using tool [htrun](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests) and templated print log. 
+
+To run the test, use following command after you build the example:
+```
+mbedhtrun -d D: -p COM4 -m K64F -f .\BUILD\K64F\GCC_ARM\nvstore.bin --compare-log tests\nvstore.log
+```
+
+
+More details about `htrun` are [here](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests#testing-mbed-os-examples).
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/nvstore.log	Mon Jun 03 15:02:15 2019 +0100
@@ -0,0 +1,20 @@
+--- Mbed OS NVStore example ---
+Init NVStore. Return code is 0 \(as expected\).
+NVStore size is \d+.
+NVStore max number of keys is \d+ \(out of 255 possible ones in this flash configuration\).
+NVStore areas:
+Area 0: address 0x[0-9a-fA-F]+, size \d+ \(0x[0-9a-fA-F]+\).
+Area 1: address 0x[0-9a-fA-F]+, size \d+ \(0x[0-9a-fA-F]+\).
+Reset NVStore. Return code is 0 (as expected).
+Set key 1 to value 1000. Return code is 0 \(as expected\).
+Set key 1 to value 2000. Return code is 0 \(as expected\).
+Set key 1 to value 3000. Return code is 0 \(as expected\).
+Get key 1. Value is 3000. Return code is 0 \(as expected\).
+Delete key 1. Return code is 0 \(as expected\).
+Get key 1. Return code is -3 \(as expected\).
+Set key 12 once to value 50. Return code is 0 \(as expected\).
+Set key 12 to value 100. Return code is -9 \(as expected\).
+Get key 12. Value is 50. Return code is 0 \(as expected\).
+Data size for key 12 is 4. Return code is 0 \(as expected\).
+
+--- Mbed OS NVStore example done. ---