Skip to content

Commit ebb1419

Browse files
authored
Merge pull request #506 from arduino/martab1994-patch-2
Update content.md
2 parents 95e02ce + 14cd1af commit ebb1419

File tree

1 file changed

+13
-13
lines changed
  • content/hardware/04.pro/boards/portenta-h7/tutorials/flash-optimized-key-value-store

1 file changed

+13
-13
lines changed

content/hardware/04.pro/boards/portenta-h7/tutorials/flash-optimized-key-value-store/content.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ The core software of Portenta H7 is based on the Mbed OS operating system, allow
3939

4040
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.
4141

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.
4343

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.***
4545

4646
### 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.
4848

4949
### 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.
5151

5252
* Create a new sketch named `FlashKeyValue.ino`
5353
* Create a new file named `FlashIAPLimits.h` to store the helper functions in a reusable file.
@@ -118,7 +118,7 @@ FlashIAPLimits getFlashIAPLimits()
118118
```
119119
120120
### 4. Make the Key Store Program
121-
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.
122122
123123
```cpp
124124
#include <FlashIAPBlockDevice.h>
@@ -144,7 +144,7 @@ struct SketchStats {
144144
};
145145
```
146146

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`).
148148

149149
```cpp
150150
void setup()
@@ -171,7 +171,7 @@ void setup()
171171

172172
```
173173
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`).
175175
176176
```cpp
177177
// Initialize the key-value store
@@ -191,7 +191,7 @@ After that, initialize the TDBstore (our storage space), set the key for the sto
191191
SketchStats previousStats;
192192
```
193193

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.
195195

196196
```cpp
197197
// 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
240240

241241
To finish the sketch, create `getSketchStats` and `setSketchStats` functions at the bottom of the sketch (after the `setup()` and `loop()`).
242242

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`.
244244

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.
246246

247247
```cpp
248248
// Retrieve SketchStats from the key-value store
@@ -277,7 +277,7 @@ int setSketchStats(const char* key, SketchStats stats)
277277
278278
### 5. Results
279279
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:
281281
282282
```
283283
FlashIAPBlockDevice + TDBStore Test
@@ -303,9 +303,9 @@ Current Stats
303303
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.
304304
305305
## 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.
307307
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.
309309
310310
### Next Steps
311311

0 commit comments

Comments
 (0)