From f02a7b560b606663af456c5f3ab7ee5e297a694d Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Wed, 3 Nov 2021 22:18:00 +0530 Subject: [PATCH] AP_HAL_ChibiOS: update last_crash_dump api --- libraries/AP_HAL_ChibiOS/Util.cpp | 19 ++++++++++++++----- libraries/AP_HAL_ChibiOS/Util.h | 3 ++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/Util.cpp b/libraries/AP_HAL_ChibiOS/Util.cpp index ed996b5a78..8c4475d55d 100644 --- a/libraries/AP_HAL_ChibiOS/Util.cpp +++ b/libraries/AP_HAL_ChibiOS/Util.cpp @@ -700,7 +700,7 @@ void Util::log_stack_info(void) } #if defined(HAL_CRASH_DUMP_FLASHPAGE) && !defined(HAL_BOOTLOADER_BUILD) -void Util::last_crash_dump(ExpandingString &str) const +size_t Util::last_crash_dump_size() const { #if HAL_GCS_ENABLED // get dump size @@ -708,17 +708,26 @@ void Util::last_crash_dump(ExpandingString &str) const char* dump_start = (char*)stm32_flash_getpageaddr(HAL_CRASH_DUMP_FLASHPAGE); if (!(dump_start[0] == 0x63 && dump_start[1] == 0x43)) { // there's no valid Crash Dump - GCS_SEND_TEXT(MAV_SEVERITY_INFO, "No Crash Detected!"); - return; + return 0; } if (size == 0xFFFFFFFF) { GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "Crash Dump incomplete, dumping what we got!"); size = stm32_flash_getpagesize(HAL_CRASH_DUMP_FLASHPAGE); } - str.append(dump_start, size); + return size; #endif + return 0; } -#endif + +void* Util::last_crash_dump_ptr() const +{ + if (last_crash_dump_size() == 0) { + GCS_SEND_TEXT(MAV_SEVERITY_INFO, "No Crash Detected!"); + return nullptr; + } + return (void*)stm32_flash_getpageaddr(HAL_CRASH_DUMP_FLASHPAGE); +} +#endif // HAL_CRASH_DUMP_FLASHPAGE // set armed state void Util::set_soft_armed(const bool b) diff --git a/libraries/AP_HAL_ChibiOS/Util.h b/libraries/AP_HAL_ChibiOS/Util.h index d1328ebe3a..f0b95df931 100644 --- a/libraries/AP_HAL_ChibiOS/Util.h +++ b/libraries/AP_HAL_ChibiOS/Util.h @@ -141,7 +141,8 @@ private: #if defined(HAL_CRASH_DUMP_FLASHPAGE) && !defined(HAL_BOOTLOADER_BUILD) // get last crash dump - void last_crash_dump(ExpandingString &str) const override; + size_t last_crash_dump_size() const override; + void* last_crash_dump_ptr() const override; #endif };