Hi,
I want my application to know the cause last reset.
For example, to detect a Power-On-Reset I wanted to use the PORST bit in the systemREG1->SYSESR register.
The problem is that, for some reason, PORST is reset by the initialization code in the sys_startup.c.
/* check for power-on reset condition */ /*SAFETYMCUSW 139 S MR:13.7 <APPROVED> "Hardware status bit read check" */ if ((SYS_EXCEPTION & POWERON_RESET) != 0U) { /* USER CODE BEGIN (12) */ /* USER CODE END */ /* Add condition to check whether PLL can be started successfully */ if (_errata_SSWF021_45_both_plls(PLL_RETRIES) != 0U) { /* Put system in a safe state */ handlePLLLockFail(); } /* clear all reset status flags */ SYS_EXCEPTION = 0xFFFFU; /* USER CODE BEGIN (13) */ /* USER CODE END */ /* USER CODE BEGIN (14) */ /* USER CODE END */ /* USER CODE BEGIN (15) */ /* USER CODE END */ /* continue with normal start-up sequence */ }
When commenting the line with SYS_EXCEPTION = 0xFFFFU, I suddenly have access to the POR bit on the SYSESR register.
My questions:
- Why is SYS_EXCEPTION cleared in sys_startup?
- Is it safe to delete the lines that reset SYS_EXCEPTION in sys_startup ?
- Is there a better way to get the reset cause?
Best Regards,
Gabriel