My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

backtrace.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016, 2017 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "backtrace.h"
  23. #if defined(__arm__) || defined(__thumb__)
  24. #include "unwinder.h"
  25. #include "unwmemaccess.h"
  26. #include "../Marlin.h"
  27. // Dump a backtrace entry
  28. static bool UnwReportOut(void* ctx, const UnwReport* bte) {
  29. int *p = (int*)ctx;
  30. (*p)++;
  31. SERIAL_CHAR('#'); SERIAL_PRINT(*p,DEC); SERIAL_ECHOPGM(" : ");
  32. SERIAL_ECHOPGM(bte->name ? bte->name : "unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function, HEX);
  33. SERIAL_CHAR('+'); SERIAL_PRINT(bte->address - bte->function,DEC);
  34. SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address,HEX); SERIAL_CHAR('\n');
  35. return true;
  36. }
  37. #ifdef UNW_DEBUG
  38. void UnwPrintf(const char* format, ...) {
  39. char dest[256];
  40. va_list argptr;
  41. va_start(argptr, format);
  42. vsprintf(dest, format, argptr);
  43. va_end(argptr);
  44. TX(&dest[0]);
  45. }
  46. #endif
  47. /* Table of function pointers for passing to the unwinder */
  48. static const UnwindCallbacks UnwCallbacks = {
  49. UnwReportOut,
  50. UnwReadW,
  51. UnwReadH,
  52. UnwReadB
  53. #ifdef UNW_DEBUG
  54. , UnwPrintf
  55. #endif
  56. };
  57. void backtrace(void) {
  58. UnwindFrame btf;
  59. uint32_t sp = 0, lr = 0, pc = 0;
  60. // Capture the values of the registers to perform the traceback
  61. __asm__ __volatile__ (
  62. " mov %[lrv],lr\n"
  63. " mov %[spv],sp\n"
  64. " mov %[pcv],pc\n"
  65. : [spv]"+r"( sp ),
  66. [lrv]"+r"( lr ),
  67. [pcv]"+r"( pc )
  68. ::
  69. );
  70. // Fill the traceback structure
  71. btf.sp = sp;
  72. btf.fp = btf.sp;
  73. btf.lr = lr;
  74. btf.pc = pc | 1; // Force Thumb, as CORTEX only support it
  75. // Perform a backtrace
  76. SERIAL_ERROR_START();
  77. SERIAL_ERRORLNPGM("Backtrace:");
  78. int ctr = 0;
  79. UnwindStart(&btf, &UnwCallbacks, &ctr);
  80. }
  81. #else // !__arm__ && !__thumb__
  82. void backtrace(void) {}
  83. #endif