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.

gcode_d.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 "../libs/hex_print.h"
  27. #include "../HAL/shared/eeprom_if.h"
  28. /**
  29. * Dn: G-code for development and testing
  30. *
  31. * See https://reprap.org/wiki/G-code#D:_Debug_codes
  32. *
  33. * Put whatever else you need here to test ongoing development.
  34. */
  35. void GcodeSuite::D(const int16_t dcode) {
  36. switch (dcode) {
  37. case -1:
  38. for (;;); // forever
  39. case 0:
  40. HAL_reboot();
  41. break;
  42. case 1: {
  43. // Zero or pattern-fill the EEPROM data
  44. #if ENABLED(EEPROM_SETTINGS)
  45. persistentStore.access_start();
  46. size_t total = persistentStore.capacity();
  47. int pos = 0;
  48. const uint8_t value = 0x0;
  49. while(total--) {
  50. persistentStore.write_data(pos, &value, 1);
  51. }
  52. persistentStore.access_finish();
  53. #else
  54. settings.reset();
  55. settings.save();
  56. #endif
  57. HAL_reboot();
  58. } break;
  59. case 2: { // D2 Read / Write SRAM
  60. #define SRAM_SIZE 8192
  61. uint8_t *pointer = parser.hex_adr_val('A');
  62. uint16_t len = parser.ushortval('C', 1);
  63. uintptr_t addr = (uintptr_t)pointer;
  64. NOMORE(addr, (size_t)(SRAM_SIZE - 1));
  65. NOMORE(len, SRAM_SIZE - addr);
  66. if (parser.seenval('X')) {
  67. // Write the hex bytes after the X
  68. uint16_t val = parser.hex_val('X');
  69. while (len--) {
  70. *pointer = val;
  71. pointer++;
  72. }
  73. }
  74. else {
  75. while (len--) print_hex_byte(*(pointer++));
  76. SERIAL_EOL();
  77. }
  78. } break;
  79. case 3: { // D3 Read / Write EEPROM
  80. uint8_t *pointer = parser.hex_adr_val('A');
  81. uint16_t len = parser.ushortval('C', 1);
  82. uintptr_t addr = (uintptr_t)pointer;
  83. #ifndef MARLIN_EEPROM_SIZE
  84. #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
  85. #endif
  86. NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1));
  87. NOMORE(len, MARLIN_EEPROM_SIZE - addr);
  88. if (parser.seenval('X')) {
  89. uint16_t val = parser.hex_val('X');
  90. #if ENABLED(EEPROM_SETTINGS)
  91. persistentStore.access_start();
  92. while(len--) {
  93. int pos = 0;
  94. persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val));
  95. }
  96. SERIAL_EOL();
  97. persistentStore.access_finish();
  98. #else
  99. SERIAL_ECHOLN("NO EEPROM");
  100. #endif
  101. }
  102. else {
  103. while (len--) {
  104. // Read bytes from EEPROM
  105. #if ENABLED(EEPROM_SETTINGS)
  106. persistentStore.access_start();
  107. uint8_t val;
  108. while(len--) {
  109. int pos = 0;
  110. if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) {
  111. print_hex_byte(val);
  112. }
  113. }
  114. SERIAL_EOL();
  115. persistentStore.access_finish();
  116. #else
  117. SERIAL_ECHOLN("NO EEPROM");
  118. #endif
  119. }
  120. SERIAL_EOL();
  121. }
  122. } break;
  123. case 4: { // D4 Read / Write PIN
  124. // const uint8_t pin = parser.byteval('P');
  125. // const bool is_out = parser.boolval('F'),
  126. // val = parser.byteval('V', LOW);
  127. if (parser.seenval('X')) {
  128. // TODO: Write the hex bytes after the X
  129. //while (len--) {
  130. //}
  131. }
  132. else {
  133. // while (len--) {
  134. // TODO: Read bytes from EEPROM
  135. // print_hex_byte(eeprom_read_byte(*(adr++));
  136. // }
  137. SERIAL_EOL();
  138. }
  139. } break;
  140. case 5: { // D4 Read / Write onboard Flash
  141. #define FLASH_SIZE 1024
  142. uint8_t *pointer = parser.hex_adr_val('A');
  143. uint16_t len = parser.ushortval('C', 1);
  144. uintptr_t addr = (uintptr_t)pointer;
  145. NOMORE(addr, (size_t)(FLASH_SIZE - 1));
  146. NOMORE(len, FLASH_SIZE - addr);
  147. if (parser.seenval('X')) {
  148. // TODO: Write the hex bytes after the X
  149. //while (len--) {
  150. //}
  151. }
  152. else {
  153. // while (len--) {
  154. // TODO: Read bytes from EEPROM
  155. // print_hex_byte(eeprom_read_byte(adr++));
  156. // }
  157. SERIAL_EOL();
  158. }
  159. } break;
  160. }
  161. }
  162. #endif