Skip to content

Commit c53aded

Browse files
authored
Merge pull request #579 from pennam/reset-reason
Add functions and example to read reset reason from RTC backup register 8
2 parents 5b077a5 + 4969b78 commit c53aded

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "STM32H747_System.h"
2+
3+
void setup() {
4+
Serial.begin(115200);
5+
while (!Serial) {}
6+
7+
reset_reason_t resetReason = STM32H747::getResetReason();
8+
Serial.println(getString(resetReason));
9+
}
10+
11+
String getString(reset_reason_t val) {
12+
switch (val){
13+
case RESET_REASON_POWER_ON:
14+
return "Reset Reason Power ON";
15+
case RESET_REASON_PIN_RESET:
16+
return "Reset Reason PIN Reset";
17+
case RESET_REASON_BROWN_OUT:
18+
return "Reset Reason Brown Out";
19+
case RESET_REASON_SOFTWARE:
20+
return "Reset Reason Software";
21+
case RESET_REASON_WATCHDOG:
22+
return "Reset Reason Watchdog";
23+
case RESET_REASON_LOCKUP:
24+
return "Reset Reason Lockup";
25+
case RESET_REASON_WAKE_LOW_POWER:
26+
return "Reset Reason Wake Low Power";
27+
case RESET_REASON_ACCESS_ERROR:
28+
return "Reset Reason Access Error";
29+
case RESET_REASON_BOOT_ERROR:
30+
return "Reset Reason Boot Error";
31+
case RESET_REASON_MULTIPLE:
32+
return "Reset Reason Multiple";
33+
case RESET_REASON_PLATFORM:
34+
return "Reset Reason Platform";
35+
case RESET_REASON_UNKNOWN:
36+
return "Reset Reason Unknown";
37+
default:
38+
return "N/A";
39+
}
40+
}
41+
42+
void loop() {
43+
delay(1000);
44+
}

libraries/STM32H747_System/src/Portenta_System.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Portenta_System: public STM32H747
1212
Portenta_System() {};
1313
virtual bool begin();
1414
virtual bool enterLowPower();
15+
1516
String getBoardRevision();
1617
uint16_t getCarrierSpecs();
1718
};

libraries/STM32H747_System/src/STM32H747_System.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "STM32H747_System.h"
22
#include "Wire.h"
3-
#include "mbed.h"
43

54
#define PMIC_ADDRESS 0x08
65

6+
extern RTC_HandleTypeDef RTCHandle;
7+
78
uint8_t STM32H747::readReg(uint8_t subAddress) {
89
char response = 0xFF;
910
Wire1.beginTransmission(PMIC_ADDRESS);
@@ -23,6 +24,18 @@ void STM32H747::setRegister(uint8_t reg, uint8_t val) {
2324
Wire1.endTransmission();
2425
}
2526

27+
uint32_t STM32H747::readBackupRegister(RTCBackup reg) {
28+
return HAL_RTCEx_BKUPRead(&RTCHandle, (uint32_t)reg);
29+
}
30+
31+
void STM32H747::writeBackupRegister(RTCBackup reg, uint32_t data) {
32+
HAL_RTCEx_BKUPWrite(&RTCHandle, (uint32_t)reg, data);
33+
}
34+
35+
reset_reason_t STM32H747::getResetReason() {
36+
return (reset_reason_t)readBackupRegister(RTCBackup::DR8);
37+
}
38+
2639
/*
2740
* This function disables the external oscillators and use the HSI instead.
2841
* If lowspeed = true : f = 100MHz

libraries/STM32H747_System/src/STM32H747_System.h

+39
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,51 @@
22
#define H747_System_h_
33

44
#include "Arduino.h"
5+
#include "mbed.h"
6+
7+
enum class RTCBackup {
8+
DR0, /* RESERVED Arduino Magic */
9+
DR1, /* RESERVED OTA storage type */
10+
DR2, /* RESERVED OTA offset */
11+
DR3, /* RESERVED OTA update size */
12+
DR4, /* RESERVED MCUboot scratch storage type */
13+
DR5, /* RESERVED MCUboot scratch offset */
14+
DR6, /* RESERVED MCUboot scratch size */
15+
DR7, /* RESERVED MCUboot debug */
16+
DR8, /* RESERVED Reset reason */
17+
DR9,
18+
DR10,
19+
DR11,
20+
DR12,
21+
DR13,
22+
DR14,
23+
DR15,
24+
DR16,
25+
DR17,
26+
DR18,
27+
DR19,
28+
DR20,
29+
DR21,
30+
DR22,
31+
DR23,
32+
DR24,
33+
DR25,
34+
DR26,
35+
DR27,
36+
DR28,
37+
DR29,
38+
DR30,
39+
DR31,
40+
};
541

642
class STM32H747 {
743

844
public:
945
virtual bool begin() = 0;
1046
virtual bool enterLowPower() = 0;
47+
static reset_reason_t getResetReason();
48+
static uint32_t readBackupRegister(RTCBackup register);
49+
static void writeBackupRegister(RTCBackup register, uint32_t data);
1150

1251
protected:
1352
uint8_t readReg(uint8_t subAddress);

0 commit comments

Comments
 (0)