Copy-paste the following setup code to your user application:
void configure_eeprom(void)
{
enum status_code error_code = eeprom_emulator_init();
if (error_code == STATUS_ERR_NO_MEMORY) {
while (true) {
}
}
else if (error_code != STATUS_OK) {
eeprom_emulator_erase_memory();
eeprom_emulator_init();
}
}
#if (SAMD || SAMR21)
void SYSCTRL_Handler(void)
{
if (SYSCTRL->INTFLAG.reg & SYSCTRL_INTFLAG_BOD33DET) {
SYSCTRL->INTFLAG.reg |= SYSCTRL_INTFLAG_BOD33DET;
eeprom_emulator_commit_page_buffer();
}
}
#endif
static void configure_bod(void)
{
#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;
system_interrupt_enable(SYSTEM_INTERRUPT_MODULE_SYSCTRL);
#endif
}
Add to user application initialization (typically the start of
main()):
configure_eeprom();