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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. /**
  31. * Dn: G-code for development and testing
  32. *
  33. * See https://reprap.org/wiki/G-code#D:_Debug_codes
  34. *
  35. * Put whatever else you need here to test ongoing development.
  36. */
  37. void GcodeSuite::D(const int16_t dcode) {
  38. switch (dcode) {
  39. case -1:
  40. for (;;); // forever
  41. case 0:
  42. HAL_reboot();
  43. break;
  44. case 1: {
  45. // Zero or pattern-fill the EEPROM data
  46. #if ENABLED(EEPROM_SETTINGS)
  47. persistentStore.access_start();
  48. size_t total = persistentStore.capacity();
  49. int pos = 0;
  50. const uint8_t value = 0x0;
  51. while(total--) {
  52. persistentStore.write_data(pos, &value, 1);
  53. }
  54. persistentStore.access_finish();
  55. #else
  56. settings.reset();
  57. settings.save();
  58. #endif
  59. HAL_reboot();
  60. } break;
  61. case 2: { // D2 Read / Write SRAM
  62. #define SRAM_SIZE 8192
  63. uint8_t *pointer = parser.hex_adr_val('A');
  64. uint16_t len = parser.ushortval('C', 1);
  65. uintptr_t addr = (uintptr_t)pointer;
  66. NOMORE(addr, (size_t)(SRAM_SIZE - 1));
  67. NOMORE(len, SRAM_SIZE - addr);
  68. if (parser.seenval('X')) {
  69. // Write the hex bytes after the X
  70. uint16_t val = parser.hex_val('X');
  71. while (len--) {
  72. *pointer = val;
  73. pointer++;
  74. }
  75. }
  76. else {
  77. while (len--) print_hex_byte(*(pointer++));
  78. SERIAL_EOL();
  79. }
  80. } break;
  81. #if ENABLED(EEPROM_SETTINGS)
  82. case 3: { // D3 Read / Write EEPROM
  83. uint8_t *pointer = parser.hex_adr_val('A');
  84. uint16_t len = parser.ushortval('C', 1);
  85. uintptr_t addr = (uintptr_t)pointer;
  86. #ifndef MARLIN_EEPROM_SIZE
  87. #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
  88. #endif
  89. NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1));
  90. NOMORE(len, MARLIN_EEPROM_SIZE - addr);
  91. if (parser.seenval('X')) {
  92. uint16_t val = parser.hex_val('X');
  93. #if ENABLED(EEPROM_SETTINGS)
  94. persistentStore.access_start();
  95. while(len--) {
  96. int pos = 0;
  97. persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val));
  98. }
  99. SERIAL_EOL();
  100. persistentStore.access_finish();
  101. #else
  102. SERIAL_ECHOLN("NO EEPROM");
  103. #endif
  104. }
  105. else {
  106. while (len--) {
  107. // Read bytes from EEPROM
  108. #if ENABLED(EEPROM_SETTINGS)
  109. persistentStore.access_start();
  110. uint8_t val;
  111. while(len--) {
  112. int pos = 0;
  113. if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) {
  114. print_hex_byte(val);
  115. }
  116. }
  117. SERIAL_EOL();
  118. persistentStore.access_finish();
  119. #else
  120. SERIAL_ECHOLN("NO EEPROM");
  121. #endif
  122. }
  123. SERIAL_EOL();
  124. }
  125. } break;
  126. #endif
  127. case 4: { // D4 Read / Write PIN
  128. // const uint8_t pin = parser.byteval('P');
  129. // const bool is_out = parser.boolval('F'),
  130. // val = parser.byteval('V', LOW);
  131. if (parser.seenval('X')) {
  132. // TODO: Write the hex bytes after the X
  133. //while (len--) {
  134. //}
  135. }
  136. else {
  137. // while (len--) {
  138. // TODO: Read bytes from EEPROM
  139. // print_hex_byte(eeprom_read_byte(*(adr++));
  140. // }
  141. SERIAL_EOL();
  142. }
  143. } break;
  144. case 5: { // D4 Read / Write onboard Flash
  145. #define FLASH_SIZE 1024
  146. uint8_t *pointer = parser.hex_adr_val('A');
  147. uint16_t len = parser.ushortval('C', 1);
  148. uintptr_t addr = (uintptr_t)pointer;
  149. NOMORE(addr, (size_t)(FLASH_SIZE - 1));
  150. NOMORE(len, FLASH_SIZE - addr);
  151. if (parser.seenval('X')) {
  152. // TODO: Write the hex bytes after the X
  153. //while (len--) {
  154. //}
  155. }
  156. else {
  157. // while (len--) {
  158. // TODO: Read bytes from EEPROM
  159. // print_hex_byte(eeprom_read_byte(adr++));
  160. // }
  161. SERIAL_EOL();
  162. }
  163. } break;
  164. case 100: { // D100 Disable heaters and attempt a hard hang (Watchdog Test)
  165. SERIAL_ECHOLN("Disabling heaters and attempting to trigger Watchdog");
  166. SERIAL_ECHOLN("(USE_WATCHDOG " TERN(USE_WATCHDOG, "ENABLED", "DISABLED") ")");
  167. thermalManager.disable_all_heaters();
  168. delay(1000); // Allow time to print
  169. DISABLE_ISRS();
  170. // Use a low-level delay that does not rely on interrupts to function
  171. // Do not spin forever, to avoid thermal risks if heaters are enabled and
  172. // watchdog does not work.
  173. DELAY_US(10000000);
  174. ENABLE_ISRS();
  175. SERIAL_ECHOLN("FAILURE: Watchdog did not trigger board reset.");
  176. }
  177. }
  178. }
  179. #endif