From 9809dfc9a4de5e3e159cc9bd866240b706fe3a40 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Wed, 3 Aug 2022 10:47:11 +0100 Subject: Improved diagnostics a little when in expansion board mode --- src/CAN/CommandProcessor.cpp | 8 ++++- src/Platform/Platform.cpp | 82 ++++++++++++++++++++------------------------ src/Platform/Platform.h | 1 + 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/CAN/CommandProcessor.cpp b/src/CAN/CommandProcessor.cpp index 9b5b61b5..d85c0b0c 100644 --- a/src/CAN/CommandProcessor.cpp +++ b/src/CAN/CommandProcessor.cpp @@ -332,7 +332,13 @@ static GCodeResult EutGetInfo(const CanMessageReturnInfo& msg, const StringRef& case CanMessageReturnInfo::typeDiagnosticsPart0: extra = LastDiagnosticsPart; - reply.lcatf("%s (%s%s)", VERSION, DATE, TIME_SUFFIX); + // Report the firmware version and board type + reply.lcatf("%s version %s (%s%s) running on %s", FIRMWARE_NAME, VERSION, DATE, TIME_SUFFIX, reprap.GetPlatform().GetElectronicsString()); + // Show the up time and reason for the last reset + { + const uint32_t now = (uint32_t)(millis64()/1000u); // get up time in seconds + reply.lcatf("Last reset %02d:%02d:%02d ago, cause: %s", (unsigned int)(now/3600), (unsigned int)((now % 3600)/60), (unsigned int)(now % 60), Platform::GetResetReasonText()); + } break; case CanMessageReturnInfo::typeDiagnosticsPart0 + 1: diff --git a/src/Platform/Platform.cpp b/src/Platform/Platform.cpp index 5d78759c..966906b5 100644 --- a/src/Platform/Platform.cpp +++ b/src/Platform/Platform.cpp @@ -1583,6 +1583,42 @@ void Platform::InitialiseInterrupts() noexcept //extern "C" uint32_t longestWriteWaitTime, shortestWriteWaitTime, longestReadWaitTime, shortestReadWaitTime; //extern uint32_t maxRead, maxWrite; +/*static*/ const char *Platform::GetResetReasonText() noexcept +{ +#if SAME5x + const uint8_t resetReason = RSTC->RCAUSE.reg; + // The datasheet says only one of these bits will be set + if (resetReason & RSTC_RCAUSE_POR) { return "power up"; } + if (resetReason & RSTC_RCAUSE_BODCORE) { return "core brownout"; } + if (resetReason & RSTC_RCAUSE_BODVDD) { return "Vdd brownout"; } + if (resetReason & RSTC_RCAUSE_WDT) { return "watchdog"; } + if (resetReason & RSTC_RCAUSE_NVM) { return "NVM"; } + if (resetReason & RSTC_RCAUSE_EXT) { return "reset button"; } + if (resetReason & RSTC_RCAUSE_SYST) { return "software"; } + if (resetReason & RSTC_RCAUSE_BACKUP) { return "backup/hibernate"; } + return "unknown"; +#elif defined(__LPC17xx__) + if (LPC_SYSCTL->RSID & RSID_POR) { return "power up"; } + if (LPC_SYSCTL->RSID & RSID_EXTR) { return "reset button"; } + if (LPC_SYSCTL->RSID & RSID_WDTR) { return "watchdog"; } + if (LPC_SYSCTL->RSID & RSID_BODR) { return "brownout"; } + if (LPC_SYSCTL->RSID & RSID_SYSRESET) { return "software"; } + if (LPC_SYSCTL->RSID & RSID_LOCKUP) { return "lockup"; } + return "unknown"; +#else + constexpr const char *_ecv_array resetReasons[8] = { "power up", "backup", "watchdog", "software", +# ifdef DUET_NG + // On the SAM4E a watchdog reset may be reported as a user reset because of the capacitor on the NRST pin. + // The SAM4S is the same but the Duet Maestro has a diode in the reset circuit to avoid this problem. + "reset button or watchdog", +# else + "reset button", +# endif + "unknown", "unknown", "unknown" }; + return resetReasons[(REG_RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos]; +#endif +} + // Return diagnostic information void Platform::Diagnostics(MessageType mtype) noexcept { @@ -1601,51 +1637,7 @@ void Platform::Diagnostics(MessageType mtype) noexcept // Show the up time and reason for the last reset const uint32_t now = (uint32_t)(millis64()/1000u); // get up time in seconds - -#if SAME5x - { - String resetString; - resetString.printf("Last reset %02d:%02d:%02d ago, cause", (unsigned int)(now/3600), (unsigned int)((now % 3600)/60), (unsigned int)(now % 60)); - const uint8_t resetReason = RSTC->RCAUSE.reg; - // The datasheet says only one of these bits will be set, but we don't assume that - if (resetReason & RSTC_RCAUSE_POR) { resetString.cat(": power up"); } - if (resetReason & RSTC_RCAUSE_BODCORE) { resetString.cat(": core brownout"); } - if (resetReason & RSTC_RCAUSE_BODVDD) { resetString.cat(": Vdd brownout"); } - if (resetReason & RSTC_RCAUSE_WDT) { resetString.cat(": watchdog"); } - if (resetReason & RSTC_RCAUSE_NVM) { resetString.cat(": NVM"); } - if (resetReason & RSTC_RCAUSE_EXT) { resetString.cat(": reset button"); } - if (resetReason & RSTC_RCAUSE_SYST) { resetString.cat(": software"); } - if (resetReason & RSTC_RCAUSE_BACKUP) { resetString.cat(": backup/hibernate"); } - resetString.cat('\n'); - Message(mtype, resetString.c_str()); - } -#elif defined(__LPC17xx__) - // Reset Reason - MessageF(mtype, "Last reset %02d:%02d:%02d ago, cause: ", - (unsigned int)(now/3600), (unsigned int)((now % 3600)/60), (unsigned int)(now % 60)); - - if (LPC_SYSCTL->RSID & RSID_POR) { Message(mtype, "[power up]"); } - if (LPC_SYSCTL->RSID & RSID_EXTR) { Message(mtype, "[reset button]"); } - if (LPC_SYSCTL->RSID & RSID_WDTR) { Message(mtype, "[watchdog]"); } - if (LPC_SYSCTL->RSID & RSID_BODR) { Message(mtype, "[brownout]"); } - if (LPC_SYSCTL->RSID & RSID_SYSRESET) { Message(mtype, "[software]"); } - if (LPC_SYSCTL->RSID & RSID_LOCKUP) { Message(mtype, "[lockup]"); } - - Message(mtype, "\n"); -#else - const char *_ecv_array resetReasons[8] = { "power up", "backup", "watchdog", "software", -# ifdef DUET_NG - // On the SAM4E a watchdog reset may be reported as a user reset because of the capacitor on the NRST pin. - // The SAM4S is the same but the Duet M has a diode in the reset circuit to avoid this problem. - "reset button or watchdog", -# else - "reset button", -# endif - "?", "?", "?" }; - MessageF(mtype, "Last reset %02d:%02d:%02d ago, cause: %s\n", - (unsigned int)(now/3600), (unsigned int)((now % 3600)/60), (unsigned int)(now % 60), - resetReasons[(REG_RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos]); -#endif + MessageF(mtype, "Last reset %02d:%02d:%02d ago, cause: %s\n", (unsigned int)(now/3600), (unsigned int)((now % 3600)/60), (unsigned int)(now % 60), GetResetReasonText()); // Show the reset code stored at the last software reset { diff --git a/src/Platform/Platform.h b/src/Platform/Platform.h index b8eca7d9..9e0c9986 100644 --- a/src/Platform/Platform.h +++ b/src/Platform/Platform.h @@ -328,6 +328,7 @@ public: void Exit() noexcept; // Shut down tidily. Calling Init after calling this should reset to the beginning void Diagnostics(MessageType mtype) noexcept; + static const char *GetResetReasonText() noexcept; GCodeResult DiagnosticTest(GCodeBuffer& gb, const StringRef& reply, OutputBuffer*& buf, unsigned int d) THROWS(GCodeException); static bool WasDeliberateError() noexcept { return deliberateError; } void LogError(ErrorCode e) noexcept { errorCodeBits |= (uint32_t)e; } -- cgit v1.2.3