How to realize data saving into FLASH while power supply drops?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User15581
Level 1
Level 1
I'm using XMC4800, and the code is as follow:


#define E_EEPROM_XMC4_FLASH_BANK0_BASE (0x0c01c000U)
uint32_t temp_count[] = {0};

void XMC_FLASH_Program(uint32_t *address, const uint32_t *data, uint8_t length)
{
uint32_t idx;

for (idx = 0U; idx < length; idx += 2U)
{
XMC_FLASH_lLoadPageCommand(data[idx], data[idx + 1U]);
}

XMC_FLASH_lWritePageCommand(address);

while ((FLASH0->FSR & (uint32_t)FLASH_FSR_PBUSY_Msk) != 0U){}
}

void NMI_Handler(void)
{
XMC_SCU_TRAP_Disable(XMC_SCU_TRAP_BROWNOUT);
temp_count[0]++;
XMC_FLASH_Program(E_EEPROM_XMC4_FLASH_BANK0_BASE, temp_count, 1);
__BKPT();
}

int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init(); /* Initialization of DAVE APPs */

if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

temp_count[0] = *( __IO uint32_t*)E_EEPROM_XMC4_FLASH_BANK0_BASE;
XMC_FLASH_EraseSector(E_EEPROM_XMC4_FLASH_BANK0_BASE);
XMC_SCU_TRAP_Enable(XMC_SCU_TRAP_BROWNOUT);
XMC_SCU_POWER_EnableMonitor(145, 1);

while(1U)
{

}
}


What I want is the value of E_EEPROM_XMC4_FLASH_BANK0_BASE increases by 1 when I shut down the power supply.
I wonder whether I'm doing it in the right way, cause it doesn't work.
0 Likes
1 Reply
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

Are you not missing the XMC_FLASH_lEnterPageModeCommand(); in the XMC_FLASH_Program() function?

Regards,
Jesus
0 Likes