How do I configure PVD on STM32L081KZT?
Hello STM Community! This is my first Question in this Forum.
I am using a STM32L081KZT and I need to save data, when the Power is unplugged.
My setup is powered by USART and can only be turned off by unplugging the UART cable. In that case I need to save my usage Data to the EEPROM, so I tried using the PVD. I searched the Forum on how to configure this. What I am using now is:
void HAL_PWR_PVDCallback(void)
{
save_archiv(); //This function saves data to the EEPROM
}
void PVD_Init(void)
{
/* Configure the PVD Level */
PWR_PVDTypeDef PVDStruct = {0};
PVDStruct.PVDLevel = PWR_PVDLEVEL_5;
PVDStruct.Mode = PWR_PVD_MODE_IT_RISING_RISING;
HAL_PWR_PVDConfig(&PVDStruct);
/* Enable the PVD Output */
HAL_PWR_EnablePVD();
}And of course calling the PVD_Init() in my main() function.
The Issue here is:
When unplugging and reconnecting the UART (Power), I can clearly see data being saved, but all Variables are 0. First I thought, this might be because the Edge is detected too late and the RAM is already cleared. But now I think it just triggers the Interrupt during startup, when the variables in the RAM are still empty. Unplugging the power will (maybe) not trigger the PVD Interrupt. I already tried changing the mode to PWR_PVD_MODE_IT_RISING_FALLING.
Can anyone tell me, what I am missing?
Help is very appreciated!
