Description
u8_load_user_values()
loads user defined data from the protected memory area into the buffer.
Syntax
u8_load_user_values( opv_user_values, size_of_user_values );
Parameters
void* opv_user_values: pointer to the struct / variable that should get filled with the stored user data.
size_t size_of_user_values: size of the buffer opv_user_values
Returns
uint8_t –
0: Settings could be loaded from flash
1: size_of_user_values is out of range (max. 3kB)
Example Code
This example shows how to read, set and store user defined data from/to the protected flash memory.
#define WIFI_STORAGE_MAGIC_WORD 0xA6E3B911
typedef struct {
uint32_t u32_magicWord;
char ac_ssid[32];
char ac_pass[32];
} WiFiSSIDPass;
WiFiSSIDPass t_cons_curr_wifi_settings;
void setup()
{
Serial.begin();
while (!Serial)
{
yield(); // wait for PC CAN2SER-monitor to open
}
// delete the buffer first
memset(&t_cons_curr_wifi_settings, 0, sizeof(t_cons_curr_wifi_settings));
// load the presistant data struct from the protected area
BOOTLOADER_SETTING.u8_load_user_values(&t_cons_curr_wifi_settings,
sizeof(t_cons_curr_wifi_settings));
// check if the values are valid
if(t_cons_curr_wifi_settings.u32_magicWord != WIFI_STORAGE_MAGIC_WORD)
{
Serial.println("There is no valid data in the protected memory available");
Serial.println("lets write some settings.");
String s_newSSID = "myWifiNetwork";
String s_newPass = "myWifiPassword";
// Create and store the new values
s_newSSID.toCharArray(t_cons_curr_wifi_settings.ac_ssid,
sizeof(t_cons_curr_wifi_settings.ac_ssid));
s_newPass.toCharArray(t_cons_curr_wifi_settings.ac_pass,
sizeof(t_cons_curr_wifi_settings.ac_pass));
t_cons_curr_wifi_settings.u32_magicWord = WIFI_STORAGE_MAGIC_WORD;
BOOTLOADER_SETTING.u8_store_user_values(&t_cons_curr_wifi_settings,
sizeof(t_cons_curr_wifi_settings));
}
else
{
Serial.println("There is valid data in the protected memory for us:");
Serial.println("ssid:'" + String(t_cons_curr_wifi_settings.ac_ssid) + "'");
Serial.println("pass:'" + String(t_cons_curr_wifi_settings.ac_pass) + "'");
}
}
void loop ()
{
}
Notes and Warnings
It has to be made sure that the max. number of erase/write cycles to the flash memory will not be exceeded during its targeted lifetime. Refrain from changing and storing values in any regular manner. E.g. don’t use it for counters etc. that get modified and stored too often.
See also
Chapter ‘Memory’ in the users manual
u8_store_user_values()