NetBurner 3.5.0
PDF Version
 
Save to User Parameter Flash

The User Parameter Flash functionality was introduced in the NetBurner 2.x tools. The preferred method for non-volatile storage and settings in the 3.x tool set is the Configuration Server, which provides for multi-platform web access, application access and JSON capabilities. All of these methods are configurable. Please see the configuration users guide and the configuration examples for more information.

In contrast, the User Parameter Flash is a sector of flash memory set aside to be used as raw bulk storage. In situations such as bulk binary storage, or porting a 2.x application to 3.x with minimal changes, this method of storage can be useful.

This example to demonstrates how to read and write data to the on-board flash memory User Parameter Area. The amount of flash space is equal to one flash sector, which will vary from 8k bytes to 64k bytes depending on your platform.

Warning: Data corruption can occur under the following circumstances:

  1. If power is interrupted during the flash programming process. We strongly recommend that UserParameters are not written immediately upon power-up, since it is not uncommon for a user to cycle a power switch on/off quickly every once in a while.
  2. Your application writes beyond the UserParameter size allocated for your platform (8k or 64k). In this situation the application may be corrupted.

Important notes on packed versus integer alignment when using structures and classes: This example uses a structure named NV_SettingsStruct, which consists of types that are 8, 16 and 32 bits long. If you do not add an attribute tag at the end of the structure, the default will be integer-aligned (32-bits in this case). This means that padding will be added to ensure each member will be on an integer boundary.

While this can increase execution speed, it also means that the stored data will be a bit larger, and doing something like an overlay or indexing into the structure with a pointer will not work correctly. To tell the compiler not to use any padding, add __attribute__((packed)); to the end of the structure definition as demonstrated in this example. Be aware that when using a packed structure elsewhere in your application, access is packed as well.