rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
stm32_reset_cause.cpp File Reference

Detailed Description

Get Reset Cause for STM32 MCUs.

Date
Dec 10, 2023
Author
Andrey Belomutskiy, (c) 2012-2023
andreika prome.nosp@m.theu.nosp@m.s.pcb.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition in file stm32_reset_cause.cpp.

Functions

static Reset_Cause_t readMCUResetCause ()
 
Reset_Cause_t getMCUResetCause ()
 
const chargetMCUResetCause (Reset_Cause_t cause)
 

Variables

static const volatile Reset_Cause_t resetCause = readMCUResetCause()
 

Function Documentation

◆ getMCUResetCause() [1/2]

Reset_Cause_t getMCUResetCause ( )

Definition at line 77 of file stm32_reset_cause.cpp.

77 {
78 return resetCause;
79}
static const volatile Reset_Cause_t resetCause

◆ getMCUResetCause() [2/2]

const char * getMCUResetCause ( Reset_Cause_t  cause)

Definition at line 81 of file stm32_reset_cause.cpp.

81 {
82 switch (cause) {
84 return "Independent hardware watchdog";
86 return "Window watchdog";
88 return "NVIC_SystemReset or by debugger";
90 return "Reset from NRST pin";
91 case Reset_Cause_POR:
92 return "Power on/power-down reset";
94 return "Reset after illegal Stop, Standby or Shutdown mode entry";
95 case Reset_Cause_BOR:
96 return "BOR reset";
98 return "Firewall reset";
100 return "Option byte load reset";
101 default:
102 return "Unknown";
103 }
104}
@ Reset_Cause_WWatchdog
Definition mpu_util.h:107
@ Reset_Cause_Firewall
Definition mpu_util.h:113
@ Reset_Cause_Soft_Reset
Definition mpu_util.h:108
@ Reset_Cause_Illegal_Mode
Definition mpu_util.h:111
@ Reset_Cause_NRST_Pin
Definition mpu_util.h:109
@ Reset_Cause_POR
Definition mpu_util.h:110
@ Reset_Cause_IWatchdog
Definition mpu_util.h:106
@ Reset_Cause_BOR
Definition mpu_util.h:112
@ Reset_Cause_Option_Byte
Definition mpu_util.h:114

◆ readMCUResetCause()

static Reset_Cause_t readMCUResetCause ( )
static

Definition at line 36 of file stm32_reset_cause.cpp.

36 {
37#ifdef STM32H7XX
38 uint32_t cause = RCC->RSR; // Read the Reset Status Register
39 // keep reset reason visible to main app
40#ifndef EFI_BOOTLOADER
41 // Clear reset flags for future reset detection
42 RCC->RSR |= RCC_RSR_RMVF;
43#endif
44#else
45 uint32_t cause = RCC->CSR; // Read the Control/Status Register
46 // keep reset reason visible to main app
47#ifndef EFI_BOOTLOADER
48 // Clear reset flags for future reset detection
49 RCC->CSR |= RCC_CSR_RMVF;
50#endif
51#endif
52
53 if (cause & BORRSTF) {
54 return Reset_Cause_BOR;
55 } else if (cause & PORRSTF) {
56 return Reset_Cause_POR;
57 } else if (cause & SFTRSTF) {
59 } else if (cause & IWDGRSTF) {
61 } else if (cause & WWDGRSTF) {
63 } else if (cause & LPWRRSTF) {
65 } else if (cause & PINRSTF) {
66 // See STM32 datasheet "Simplified diagram of the reset circuit"
67 // All internal resets happens through driving NRST pin low
68 // This cause rise of PINRSTF bit in CSR register
70 }
72}
@ Reset_Cause_Unknown
Definition mpu_util.h:105

Variable Documentation

◆ resetCause

const volatile Reset_Cause_t resetCause = readMCUResetCause()
static

Definition at line 75 of file stm32_reset_cause.cpp.

Referenced by checkIfResetLoop(), and getMCUResetCause().

Go to the source code of this file.