In this use case, the RWW EEPROM emulator module is configured, and a sample page is read and written.
The first byte of the first RWW EEPROM page is toggled, and a LED is turned ON or OFF to reflect the new state. Each time the device is reset, the LED should toggle to a different state to indicate correct non-volatile storage and retrieval.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your user application:
{
while (true) {
}
}
}
}
#if (SAMD || SAMR21)
void SYSCTRL_Handler(void)
{
if (SYSCTRL->INTFLAG.reg & SYSCTRL_INTFLAG_BOD33DET) {
SYSCTRL->INTFLAG.reg = SYSCTRL_INTFLAG_BOD33DET;
}
}
#endif
{
#if (SAMD || SAMR21)
struct bod_config config_bod33;
bod_get_config_defaults(&config_bod33);
config_bod33.action = BOD_ACTION_INTERRUPT;
config_bod33.level = 48;
bod_set_config(BOD_BOD33, &config_bod33);
bod_enable(BOD_BOD33);
SYSCTRL->INTENSET.reg = SYSCTRL_INTENCLR_BOD33DET;
#endif
}
Add to user application initialization (typically the start of main()
):
Workflow
- Attempt to initialize the RWW EEPROM emulator service, storing the error code from the initialization function into a temporary variable.
- Check if the emulator service failed to initialize for any other reason; if so, assume the emulator physical memory is unformatted or corrupt and erase/re-try initialization. Config BOD to give an early warning to prevent data loss.
Use Case
Code
Copy-paste the following code to your user application:
page_data[0] = !page_data[0];
page_data[1]=0x1;
while (true) {
}
Workflow
- Create a buffer to hold a single emulated RWW EEPROM page of memory, and read out logical RWW EEPROM page zero into it.
- Toggle the first byte of the read page.
page_data[0] = !page_data[0];
- Output the toggled LED state onto the board LED.
- Write the modified page back to logical RWW EEPROM page zero, flushing the internal emulator write cache afterwards to ensure it is immediately written to physical non-volatile memory.
- Modify data and write back to logical EEPROM page zero. The data is not committed and should call
rww_eeprom_emulator_commit_page_buffer
to ensure that any outstanding cache data is fully written to prevent data loss when detecting a BOD early warning.