Skip to content

Add functions and example to read reset reason from RTC backup register 8 #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "STM32H747_System.h"

void setup() {
Serial.begin(115200);
while (!Serial) {}

reset_reason_t resetReason = STM32H747::getResetReason();
Serial.println(getString(resetReason));
}

String getString(reset_reason_t val) {
switch (val){
case RESET_REASON_POWER_ON:
return "Reset Reason Power ON";
case RESET_REASON_PIN_RESET:
return "Reset Reason PIN Reset";
case RESET_REASON_BROWN_OUT:
return "Reset Reason Brown Out";
case RESET_REASON_SOFTWARE:
return "Reset Reason Software";
case RESET_REASON_WATCHDOG:
return "Reset Reason Watchdog";
case RESET_REASON_LOCKUP:
return "Reset Reason Lockup";
case RESET_REASON_WAKE_LOW_POWER:
return "Reset Reason Wake Low Power";
case RESET_REASON_ACCESS_ERROR:
return "Reset Reason Access Error";
case RESET_REASON_BOOT_ERROR:
return "Reset Reason Boot Error";
case RESET_REASON_MULTIPLE:
return "Reset Reason Multiple";
case RESET_REASON_PLATFORM:
return "Reset Reason Platform";
case RESET_REASON_UNKNOWN:
return "Reset Reason Unknown";
default:
return "N/A";
}
}

void loop() {
delay(1000);
}
1 change: 1 addition & 0 deletions libraries/STM32H747_System/src/Portenta_System.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Portenta_System: public STM32H747
Portenta_System() {};
virtual bool begin();
virtual bool enterLowPower();

String getBoardRevision();
uint16_t getCarrierSpecs();
};
Expand Down
15 changes: 14 additions & 1 deletion libraries/STM32H747_System/src/STM32H747_System.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "STM32H747_System.h"
#include "Wire.h"
#include "mbed.h"

#define PMIC_ADDRESS 0x08

extern RTC_HandleTypeDef RTCHandle;

uint8_t STM32H747::readReg(uint8_t subAddress) {
char response = 0xFF;
Wire1.beginTransmission(PMIC_ADDRESS);
Expand All @@ -23,6 +24,18 @@ void STM32H747::setRegister(uint8_t reg, uint8_t val) {
Wire1.endTransmission();
}

uint32_t STM32H747::readBackupRegister(RTCBackup reg) {
return HAL_RTCEx_BKUPRead(&RTCHandle, (uint32_t)reg);
}

void STM32H747::writeBackupRegister(RTCBackup reg, uint32_t data) {
HAL_RTCEx_BKUPWrite(&RTCHandle, (uint32_t)reg, data);
}

reset_reason_t STM32H747::getResetReason() {
return (reset_reason_t)readBackupRegister(RTCBackup::DR8);
}

/*
* This function disables the external oscillators and use the HSI instead.
* If lowspeed = true : f = 100MHz
Expand Down
39 changes: 39 additions & 0 deletions libraries/STM32H747_System/src/STM32H747_System.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,51 @@
#define H747_System_h_

#include "Arduino.h"
#include "mbed.h"

enum class RTCBackup {
DR0, /* RESERVED Arduino Magic */
DR1, /* RESERVED OTA storage type */
DR2, /* RESERVED OTA offset */
DR3, /* RESERVED OTA update size */
DR4, /* RESERVED MCUboot scratch storage type */
DR5, /* RESERVED MCUboot scratch offset */
DR6, /* RESERVED MCUboot scratch size */
DR7, /* RESERVED MCUboot debug */
DR8, /* RESERVED Reset reason */
DR9,
DR10,
DR11,
DR12,
DR13,
DR14,
DR15,
DR16,
DR17,
DR18,
DR19,
DR20,
DR21,
DR22,
DR23,
DR24,
DR25,
DR26,
DR27,
DR28,
DR29,
DR30,
DR31,
};

class STM32H747 {

public:
virtual bool begin() = 0;
virtual bool enterLowPower() = 0;
static reset_reason_t getResetReason();
static uint32_t readBackupRegister(RTCBackup register);
static void writeBackupRegister(RTCBackup register, uint32_t data);

protected:
uint8_t readReg(uint8_t subAddress);
Expand Down