You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/04.pro/boards/portenta-h7/tutorials/flash-optimized-key-value-store/content.md
+13-13Lines changed: 13 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -39,15 +39,15 @@ The core software of Portenta H7 is based on the Mbed OS operating system, allow
39
39
40
40
Mbed OS has a rich API for managing storage on different mediums, ranging from the small internal Flash memory of a microcontroller to external SecureDigital cards with large data storage space.
41
41
42
-
In this tutorial, we are going to save a value persistently inside the Flash memory. That allows to access that value even after a reset of the microcontroller. We will retrieve some information from a Flash block by using the [FlashIAPBlockDevice](https://os.mbed.com/docs/mbed-os/v6.9/apis/flashiapblockdevice.html) and the [TDBStore](https://os.mbed.com/docs/mbed-os/v6.9/apis/kvstore.html) APIs. We will use the `FlashIAPBlockDevice` class to create a block device on the free space of the Flash and we will create a Key-Value Store in it using the `TDBStore` API.
42
+
In this tutorial, you are going to save a value persistently inside the Flash memory. That allows to access that value even after a reset of the microcontroller. You will retrieve some information from a Flash block by using the [FlashIAPBlockDevice](https://os.mbed.com/docs/mbed-os/v6.9/apis/flashiapblockdevice.html) and the [TDBStore](https://os.mbed.com/docs/mbed-os/v6.9/apis/kvstore.html) APIs. You will use the `FlashIAPBlockDevice` class to create a block device on the free space of the Flash and you will create a Key-Value Store in it using the `TDBStore` API.
43
43
44
-
***Important: The TBStore API optimizes for access speed, reduce [wearing of the flash](https://en.wikipedia.org/wiki/Flash_memory#Memory_wear) and minimize storage overhead. TBStore is also resilient to power failures. If you want to use the flash memory of the microcontroller, always prefer the TDBStore approach over a direct access to the FlashIAP block device.***
44
+
***Important: The TBStore API optimizes for access speed, reduce [wearing of the flash](https://en.wikipedia.org/wiki/Flash_memory#Memory_wear) and minimize storage overhead. TBStore is also resilient to power failures. If you want to use the Flash memory of the microcontroller, always prefer the TDBStore approach over a direct access to the FlashIAP block device.***
45
45
46
46
### 1. The Basic Setup
47
-
Begin by plugging in your Portenta board to the computer using a USB-C cable and open the Arduino IDE or the Arduino Pro IDE. If this is your first time running Arduino sketch files on the board, we suggest you check out how to [set up the Portenta H7 for Arduino](setting-up-portenta) before you proceed.
47
+
Begin by plugging in your Portenta board to the computer using a USB-C cable and open the Arduino IDE. If this is your first time running Arduino sketch files on the board, we suggest you check out how to [set up the Portenta H7 for Arduino](https://docs.arduino.cc/tutorials/portenta-h7/setting-up-portenta) before you proceed.
48
48
49
49
### 2. Create the Structure of the Program
50
-
Let's program the Portenta with a sketch. We will also define a few helper functions in a supporting header file.
50
+
Let's program the Portenta with a sketch. You will also define a few helper functions in a supporting header file.
51
51
52
52
* Create a new sketch named `FlashKeyValue.ino`
53
53
* Create a new file named `FlashIAPLimits.h` to store the helper functions in a reusable file.
Go to `FlashKeyValue.ino` and include the libraries that we need from **MBED** and our header helper (`FlashIAPLimits.h`). The `getFlashIAPLimits()` function which is defined in the `FlashIAPLimits.h` header takes care of not overwriting data already stored on the Flash and aligns the start and stop addresses with the size of the Flash sector. We use those calculated limits to create a block device and a `TDBStore` on top of them.
121
+
Go to `FlashKeyValue.ino` and include the libraries that you need from **MBED** and your header helper (`FlashIAPLimits.h`). The `getFlashIAPLimits()` function which is defined in the `FlashIAPLimits.h` header takes care of not overwriting data already stored on the Flash and aligns the start and stop addresses with the size of the Flash sector. You can use those calculated limits to create a block device and a `TDBStore` on top of them.
122
122
123
123
```cpp
124
124
#include <FlashIAPBlockDevice.h>
@@ -144,7 +144,7 @@ struct SketchStats {
144
144
};
145
145
```
146
146
147
-
In the `setup()` function at the beginning we will wait until the Serial port is ready and then print some info about the FlashIAP block device (`blockDevice`).
147
+
In the `setup()` function at the beginning you will have to wait until the Serial port is ready and then print some info about the FlashIAP block device (`blockDevice`).
148
148
149
149
```cpp
150
150
voidsetup()
@@ -171,7 +171,7 @@ void setup()
171
171
172
172
```
173
173
174
-
After that, initialize the TDBstore (our storage space), set the key for the store data (`stats`), initialize the value that we will save `runCount` and declare an object to fetch the previous values (`previousStats`).
174
+
After that, initialize the TDBstore (our storage space), set the key for the store data (`stats`), initialize the value that you will save `runCount` and declare an object to fetch the previous values (`previousStats`).
175
175
176
176
```cpp
177
177
// Initialize the key-value store
@@ -191,7 +191,7 @@ After that, initialize the TDBstore (our storage space), set the key for the sto
191
191
SketchStats previousStats;
192
192
```
193
193
194
-
Now that we have everything ready, lets retrieve the previous values from the store, and update the store with the new values.
194
+
Now that you have everything ready, let's retrieve the previous values from the store and update the store with the new values.
195
195
196
196
```cpp
197
197
// Get previous run stats from the key-value store
@@ -240,9 +240,9 @@ Now that we have everything ready, lets retrieve the previous values from the st
240
240
241
241
To finish the sketch, create `getSketchStats` and `setSketchStats` functions at the bottom of the sketch (after the `setup()` and `loop()`).
242
242
243
-
The `getSketchStats` function tries to retrieve the stats values stored in the Flash using the key `key` and returns them via the `stats` pointer parameter. Our `SketchStats` data struct is very simple and has a fixed size. We can therefore deserialize the buffer with a simple `memcpy`.
243
+
The `getSketchStats` function tries to retrieve the stats values stored in the Flash using the key `key` and returns them via the `stats` pointer parameter. Our `SketchStats` data struct is very simple and has a fixed size. You can therefore deserialize the buffer with a simple `memcpy`.
244
244
245
-
The `setSketchStats` function stores the `stats` data and assigns the key `key` to it. The key will be created in the key-value store if it doesn't exist yet.
245
+
The `setSketchStats` function stores the `stats` data and assigns the key `key` to it. The key will be created in the key-value store if it does not exist yet.
246
246
247
247
```cpp
248
248
// Retrieve SketchStats from the key-value store
@@ -277,7 +277,7 @@ int setSketchStats(const char* key, SketchStats stats)
277
277
278
278
### 5. Results
279
279
280
-
Upload the sketch and the output should be similar to the following:
280
+
Upload the sketch, the output should be similar to the following:
281
281
282
282
```
283
283
FlashIAPBlockDevice + TDBStore Test
@@ -303,9 +303,9 @@ Current Stats
303
303
Push the reset button to restart the sketch. The values of the stats have been updated. `Previous Stats` which is retrieved from the key-value store now contains values from the previous execution.
304
304
305
305
## Conclusion
306
-
We have learned how to use the available space in the Flash memory of the microcontroller to create a key-value store and use it to retrieve and store data.
306
+
You have learned how to use the available space in the Flash memory of the microcontroller to create a key-value store and use it to retrieve and store data.
307
307
308
-
It's not recommended to use the Flash of the microcontroller as the primary storage for data-intensive applications. It is best suited for read/write operations that are performed only once in a while such as storing and retrieving application configurations or persistent parameters.
308
+
It is not recommended to use the Flash of the microcontroller as the primary storage for data-intensive applications. It is best suited for read/write operations that are performed only once in a while such as storing and retrieving application configurations or persistent parameters.
0 commit comments