1.. zephyr:code-sample:: nvs
2   :name: Non-Volatile Storage (NVS)
3   :relevant-api: nvs_high_level_api
4
5   Store and retrieve data from flash using the NVS API.
6
7Overview
8********
9
10This is a simple application demonstrating use of the NVS
11module for non-volatile (flash) storage.  In this application,
12a counter is incremented on every reboot and stored in flash,
13the application reboots, and the reboot counter data is retrieved.
14
15Requirements
16************
17
18* A board with flash support
19
20Building and Running
21********************
22
23This sample can be found under :zephyr_file:`samples/subsys/nvs` in the Zephyr tree.
24
25The sample can be built for several platforms, the following commands build the
26application for the nrf51dk/nrf51822 board.
27
28.. zephyr-app-commands::
29   :zephyr-app: samples/subsys/nvs
30   :board: nrf51dk/nrf51822
31   :goals: build flash
32   :compact:
33
34After flashing the image to the board the output on the console shows the
35reboot counter and the boards reboots several times to show the reboot counter
36is incremented.
37
38Sample Output
39=============
40
41.. code-block:: console
42
43   ***** Booting Zephyr OS v1.12.0-rc1-176-gf091be783 *****
44   [fs/nvs] [DBG] nvs_reinit: (Re)Initializing sectors
45   [fs/nvs] [DBG] _nvs_sector_init: f->write_location set to c
46   [fs/nvs] [INF] nvs_mount: maximum storage length 256 byte
47   [fs/nvs] [INF] nvs_mount: write-align: 1, write-addr: c
48   [fs/nvs] [INF] nvs_mount: entry sector: 0, entry sector ID: 1
49   No address found, adding 192.168.1.1 at id 1
50   No key found, adding it at id 2
51   No Reboot counter found, adding it at id 3
52   Id: 4 not found, adding it
53   Longarray not found, adding it as id 4
54   Reboot counter history: ...0
55   Oldest reboot counter: 0
56   Rebooting in ...5...4...3...2...1
57   ***** Booting Zephyr OS v1.12.0-rc1-176-gf091be783 *****
58   [fs/nvs] [INF] nvs_mount: maximum storage length 256 byte
59   [fs/nvs] [INF] nvs_mount: write-align: 1, write-addr: c7
60   [fs/nvs] [INF] nvs_mount: entry sector: 0, entry sector ID: 1
61   Entry: 1, Address: 192.168.1.1
62   Id: 2, Key: ff fe fd fc fb fa f9 f8
63   Id: 3, Reboot_counter: 1
64   Id: 4, Data: DATA
65   Id: 5, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18
66   Reboot counter history: ...1...0
67   Oldest reboot counter: 0
68   Rebooting in ...5...4...3...2...1
69   ...
70