My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

backtrace.cpp 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #if defined(__arm__) || defined(__thumb__)
  23. #include "backtrace.h"
  24. #include "unwinder.h"
  25. #include "unwmemaccess.h"
  26. #include "../../../core/serial.h"
  27. #include <stdarg.h>
  28. // Dump a backtrace entry
  29. static bool UnwReportOut(void* ctx, const UnwReport* bte) {
  30. int *p = (int*)ctx;
  31. (*p)++;
  32. SERIAL_CHAR('#'); SERIAL_ECHO(*p); SERIAL_ECHOPGM(" : ");
  33. SERIAL_ECHOPGM(bte->name ? bte->name : "unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function, PrintBase::Hex);
  34. SERIAL_CHAR('+'); SERIAL_ECHO(bte->address - bte->function);
  35. SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address, PrintBase::Hex); SERIAL_CHAR('\n');
  36. return true;
  37. }
  38. #ifdef UNW_DEBUG
  39. void UnwPrintf(const char* format, ...) {
  40. char dest[256];
  41. va_list argptr;
  42. va_start(argptr, format);
  43. vsprintf(dest, format, argptr);
  44. va_end(argptr);
  45. TX(&dest[0]);
  46. }
  47. #endif
  48. /* Table of function pointers for passing to the unwinder */
  49. static const UnwindCallbacks UnwCallbacks = {
  50. UnwReportOut,
  51. UnwReadW,
  52. UnwReadH,
  53. UnwReadB
  54. #ifdef UNW_DEBUG
  55. , UnwPrintf
  56. #endif
  57. };
  58. void backtrace() {
  59. UnwindFrame btf;
  60. uint32_t sp = 0, lr = 0, pc = 0;
  61. // Capture the values of the registers to perform the traceback
  62. __asm__ __volatile__ (
  63. " mov %[lrv],lr\n"
  64. " mov %[spv],sp\n"
  65. " mov %[pcv],pc\n"
  66. : [spv]"+r"( sp ),
  67. [lrv]"+r"( lr ),
  68. [pcv]"+r"( pc )
  69. ::
  70. );
  71. // Fill the traceback structure
  72. btf.sp = sp;
  73. btf.fp = btf.sp;
  74. btf.lr = lr;
  75. btf.pc = pc | 1; // Force Thumb, as CORTEX only support it
  76. // Perform a backtrace
  77. SERIAL_ERROR_MSG("Backtrace:");
  78. int ctr = 0;
  79. UnwindStart(&btf, &UnwCallbacks, &ctr);
  80. }
  81. #else // !__arm__ && !__thumb__
  82. void backtrace() {}
  83. #endif