track PC, PSR across WWDG resets
This commit is contained in:
parent
c4c1a76e51
commit
71a44a8284
@ -50,6 +50,10 @@ extern int pos_air_closed;
|
|||||||
extern int precharge_closed;
|
extern int precharge_closed;
|
||||||
extern int pre_and_air_open;
|
extern int pre_and_air_open;
|
||||||
|
|
||||||
|
extern volatile uint32_t wwdg_flag;
|
||||||
|
extern volatile uint32_t wwdg_pc; // PC at the time of WWDG interrupt
|
||||||
|
extern volatile uint32_t wwdg_psr; // PSR at the time of WWDG interrupt
|
||||||
|
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
@ -123,7 +127,7 @@ void Error_Handler(void);
|
|||||||
#define WAKE2_GPIO_Port GPIOB
|
#define WAKE2_GPIO_Port GPIOB
|
||||||
|
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
|
#define WWDG_TRIGGERED_FLAG 0xDEADCAFE // Flag to indicate WWDG was triggered
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -82,6 +82,15 @@ int pos_air_closed;
|
|||||||
int precharge_closed;
|
int precharge_closed;
|
||||||
int pre_and_air_open; // used to be:int precharge_opened = 0; now we read if PC is open from the pin -> high if open
|
int pre_and_air_open; // used to be:int precharge_opened = 0; now we read if PC is open from the pin -> high if open
|
||||||
|
|
||||||
|
/* Variables for WWDG interrupt handling */
|
||||||
|
[[gnu::section(".noinit")]] // keep these variables in .noinit section to preserve their values across resets
|
||||||
|
volatile uint32_t wwdg_flag; // Flag to indicate WWDG was triggered
|
||||||
|
[[gnu::section(".noinit")]]
|
||||||
|
volatile uint32_t wwdg_pc; // PC at the time of WWDG interrupt
|
||||||
|
[[gnu::section(".noinit")]]
|
||||||
|
volatile uint32_t wwdg_psr; // PSR at the time of WWDG interrupt
|
||||||
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@ -220,7 +229,11 @@ int main(void)
|
|||||||
debug_log(LOG_LEVEL_INFO, "Starting BMS...");
|
debug_log(LOG_LEVEL_INFO, "Starting BMS...");
|
||||||
if (wdg_reset) {
|
if (wdg_reset) {
|
||||||
debug_log(LOG_LEVEL_WARNING, "Last reset was caused by watchdog!");
|
debug_log(LOG_LEVEL_WARNING, "Last reset was caused by watchdog!");
|
||||||
|
if (wwdg_flag == WWDG_TRIGGERED_FLAG) {
|
||||||
|
debug_log(LOG_LEVEL_WARNING, "WWDG was triggered! PC: 0x%08lX, PSR: 0x%08lX", wwdg_pc, wwdg_psr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
wwdg_flag = 0; // clear the flag
|
||||||
|
|
||||||
auto ret = battery_init(&hspi1);
|
auto ret = battery_init(&hspi1);
|
||||||
while (ret != HAL_OK) { //TODO: properly handle reapeated initialization failure
|
while (ret != HAL_OK) { //TODO: properly handle reapeated initialization failure
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "stm32h7xx_it.h"
|
#include "stm32h7xx_it.h"
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "cmsis_gcc.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@ -208,9 +209,11 @@ void WWDG_IRQHandler(void)
|
|||||||
/* USER CODE BEGIN WWDG_IRQn 0 */
|
/* USER CODE BEGIN WWDG_IRQn 0 */
|
||||||
// Grab PC from the stack to log it
|
// Grab PC from the stack to log it
|
||||||
uint32_t *stack_pointer = (uint32_t *)__get_MSP();
|
uint32_t *stack_pointer = (uint32_t *)__get_MSP();
|
||||||
uint32_t prev_pc = stack_pointer[6]; // PC is the 7th word in the stack frame
|
wwdg_pc = stack_pointer[6]; // PC is the 7th word in the stack frame
|
||||||
uint32_t prev_psr = stack_pointer[7]; // PSR is the 8th word in the stack frame
|
wwdg_psr = stack_pointer[7]; // PSR is the 8th word in the stack frame
|
||||||
log_fatal("Watchdog triggered! PC: 0x%08lX, PSR: 0x%08lX", prev_pc, prev_psr);
|
wwdg_flag = WWDG_TRIGGERED_FLAG; // Set the flag to indicate WWDG was triggered
|
||||||
|
log_fatal("Watchdog triggered! PC: 0x%08lX, PSR: 0x%08lX", wwdg_pc, wwdg_psr);
|
||||||
|
__DSB(); // Ensure ram is written to before entering the handler
|
||||||
/* USER CODE END WWDG_IRQn 0 */
|
/* USER CODE END WWDG_IRQn 0 */
|
||||||
HAL_WWDG_IRQHandler(&hwwdg1);
|
HAL_WWDG_IRQHandler(&hwwdg1);
|
||||||
/* USER CODE BEGIN WWDG_IRQn 1 */
|
/* USER CODE BEGIN WWDG_IRQn 1 */
|
||||||
|
@ -183,6 +183,13 @@ SECTIONS
|
|||||||
__bss_end__ = _ebss;
|
__bss_end__ = _ebss;
|
||||||
} >DTCMRAM
|
} >DTCMRAM
|
||||||
|
|
||||||
|
/* Keep some data across soft resets */
|
||||||
|
. = ALIGN(4);
|
||||||
|
.no_init :
|
||||||
|
{
|
||||||
|
*(.no_init)
|
||||||
|
} >DTCMRAM
|
||||||
|
|
||||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||||
._user_heap_stack :
|
._user_heap_stack :
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user