My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #include "../inc/MarlinConfigPre.h"
  23. #if ENABLED(MARLIN_DEV_MODE)
  24. #include "gcode.h"
  25. #include "../module/settings.h"
  26. #include "../module/temperature.h"
  27. #include "../libs/hex_print.h"
  28. #include "../HAL/shared/eeprom_if.h"
  29. #include "../HAL/shared/Delay.h"
  30. extern void dump_delay_accuracy_check();
  31. /**
  32. * Dn: G-code for development and testing
  33. *
  34. * See https://reprap.org/wiki/G-code#D:_Debug_codes
  35. *
  36. * Put whatever else you need here to test ongoing development.
  37. */
  38. void GcodeSuite::D(const int16_t dcode) {
  39. switch (dcode) {
  40. case -1:
  41. for (;;); // forever
  42. case 0:
  43. HAL_reboot();
  44. break;
  45. case 1: {
  46. // Zero or pattern-fill the EEPROM data
  47. #if ENABLED(EEPROM_SETTINGS)
  48. persistentStore.access_start();
  49. size_t total = persistentStore.capacity();
  50. int pos = 0;
  51. const uint8_t value = 0x0;
  52. while (total--) persistentStore.write_data(pos, &value, 1);
  53. persistentStore.access_finish();
  54. #else
  55. settings.reset();
  56. settings.save();
  57. #endif
  58. HAL_reboot();
  59. } break;
  60. case 2: { // D2 Read / Write SRAM
  61. #define SRAM_SIZE 8192
  62. uint8_t *pointer = parser.hex_adr_val('A');
  63. uint16_t len = parser.ushortval('C', 1);
  64. uintptr_t addr = (uintptr_t)pointer;
  65. NOMORE(addr, size_t(SRAM_SIZE - 1));
  66. NOMORE(len, SRAM_SIZE - addr);
  67. if (parser.seenval('X')) {
  68. // Write the hex bytes after the X
  69. uint16_t val = parser.hex_val('X');
  70. while (len--) {
  71. *pointer = val;
  72. pointer++;
  73. }
  74. }
  75. else {
  76. while (len--) print_hex_byte(*(pointer++));
  77. SERIAL_EOL();
  78. }
  79. } break;
  80. #if ENABLED(EEPROM_SETTINGS)
  81. case 3: { // D3 Read / Write EEPROM
  82. uint8_t *pointer = parser.hex_adr_val('A');
  83. uint16_t len = parser.ushortval('C', 1);
  84. uintptr_t addr = (uintptr_t)pointer;
  85. NOMORE(addr, size_t(persistentStore.capacity() - 1));
  86. NOMORE(len, persistentStore.capacity() - addr);
  87. if (parser.seenval('X')) {
  88. uint16_t val = parser.hex_val('X');
  89. #if ENABLED(EEPROM_SETTINGS)
  90. persistentStore.access_start();
  91. while (len--) {
  92. int pos = 0;
  93. persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val));
  94. }
  95. SERIAL_EOL();
  96. persistentStore.access_finish();
  97. #else
  98. SERIAL_ECHOLNPGM("NO EEPROM");
  99. #endif
  100. }
  101. else {
  102. // Read bytes from EEPROM
  103. #if ENABLED(EEPROM_SETTINGS)
  104. persistentStore.access_start();
  105. int pos = 0;
  106. uint8_t val;
  107. while (len--) if (!persistentStore.read_data(pos, &val, 1)) print_hex_byte(val);
  108. SERIAL_EOL();
  109. persistentStore.access_finish();
  110. #else
  111. SERIAL_ECHOLNPGM("NO EEPROM");
  112. len = 0;
  113. #endif
  114. SERIAL_EOL();
  115. }
  116. } break;
  117. #endif
  118. case 4: { // D4 Read / Write PIN
  119. // const uint8_t pin = parser.byteval('P');
  120. // const bool is_out = parser.boolval('F'),
  121. // val = parser.byteval('V', LOW);
  122. if (parser.seenval('X')) {
  123. // TODO: Write the hex bytes after the X
  124. //while (len--) {
  125. //}
  126. }
  127. else {
  128. // while (len--) {
  129. // TODO: Read bytes from EEPROM
  130. // print_hex_byte(eeprom_read_byte(*(adr++));
  131. // }
  132. SERIAL_EOL();
  133. }
  134. } break;
  135. case 5: { // D5 Read / Write onboard Flash
  136. #define FLASH_SIZE 1024
  137. uint8_t *pointer = parser.hex_adr_val('A');
  138. uint16_t len = parser.ushortval('C', 1);
  139. uintptr_t addr = (uintptr_t)pointer;
  140. NOMORE(addr, size_t(FLASH_SIZE - 1));
  141. NOMORE(len, FLASH_SIZE - addr);
  142. if (parser.seenval('X')) {
  143. // TODO: Write the hex bytes after the X
  144. //while (len--) {}
  145. }
  146. else {
  147. // while (len--) {
  148. // TODO: Read bytes from EEPROM
  149. // print_hex_byte(eeprom_read_byte(adr++));
  150. // }
  151. SERIAL_EOL();
  152. }
  153. } break;
  154. case 6: // D6 Check delay loop accuracy
  155. dump_delay_accuracy_check();
  156. break;
  157. case 100: { // D100 Disable heaters and attempt a hard hang (Watchdog Test)
  158. SERIAL_ECHOLNPGM("Disabling heaters and attempting to trigger Watchdog");
  159. SERIAL_ECHOLNPGM("(USE_WATCHDOG " TERN(USE_WATCHDOG, "ENABLED", "DISABLED") ")");
  160. thermalManager.disable_all_heaters();
  161. delay(1000); // Allow time to print
  162. DISABLE_ISRS();
  163. // Use a low-level delay that does not rely on interrupts to function
  164. // Do not spin forever, to avoid thermal risks if heaters are enabled and
  165. // watchdog does not work.
  166. for (int i = 10000; i--;) DELAY_US(1000UL);
  167. ENABLE_ISRS();
  168. SERIAL_ECHOLNPGM("FAILURE: Watchdog did not trigger board reset.");
  169. } break;
  170. #if ENABLED(POSTMORTEM_DEBUGGING)
  171. case 451: { // Trigger all kind of faults to test exception catcher
  172. SERIAL_ECHOLNPGM("Disabling heaters");
  173. thermalManager.disable_all_heaters();
  174. delay(1000); // Allow time to print
  175. volatile uint8_t type[5] = { parser.byteval('T', 1) };
  176. // The code below is obviously wrong and it's full of quirks to fool the compiler from optimizing away the code
  177. switch (type[0]) {
  178. case 1: default: *(int*)0 = 451; break; // Write at bad address
  179. case 2: { volatile int a = 0; volatile int b = 452 / a; *(int*)&a = b; } break; // Divide by zero (some CPUs accept this, like ARM)
  180. case 3: { *(uint32_t*)&type[1] = 453; volatile int a = *(int*)&type[1]; type[0] = a / 255; } break; // Unaligned access (some CPUs accept this)
  181. case 4: { volatile void (*func)() = (volatile void (*)()) 0xE0000000; func(); } break; // Invalid instruction
  182. }
  183. break;
  184. }
  185. #endif
  186. }
  187. }
  188. #endif