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.

M993_M994.cpp 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/MarlinConfig.h"
  23. #if ALL(HAS_SPI_FLASH, SDSUPPORT, MARLIN_DEV_MODE)
  24. #include "../gcode.h"
  25. #include "../../sd/cardreader.h"
  26. #include "../../libs/W25Qxx.h"
  27. /**
  28. * M993: Backup SPI Flash to SD
  29. */
  30. void GcodeSuite::M993() {
  31. if (!card.isMounted()) card.mount();
  32. char fname[] = "spiflash.bin";
  33. card.openFileWrite(fname);
  34. if (!card.isFileOpen()) {
  35. SERIAL_ECHOLNPGM("Failed to open ", fname, " to write.");
  36. return;
  37. }
  38. uint8_t buf[1024];
  39. uint32_t addr = 0;
  40. W25QXX.init(SPI_QUARTER_SPEED);
  41. SERIAL_ECHOPGM("Save SPI Flash");
  42. while (addr < SPI_FLASH_SIZE) {
  43. W25QXX.SPI_FLASH_BufferRead(buf, addr, COUNT(buf));
  44. addr += COUNT(buf);
  45. card.write(buf, COUNT(buf));
  46. if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.');
  47. }
  48. SERIAL_ECHOLNPGM(" done");
  49. card.closefile();
  50. }
  51. /**
  52. * M994: Load a backup from SD to SPI Flash
  53. */
  54. void GcodeSuite::M994() {
  55. if (!card.isMounted()) card.mount();
  56. char fname[] = "spiflash.bin";
  57. card.openFileRead(fname);
  58. if (!card.isFileOpen()) {
  59. SERIAL_ECHOLNPGM("Failed to open ", fname, " to read.");
  60. return;
  61. }
  62. uint8_t buf[1024];
  63. uint32_t addr = 0;
  64. W25QXX.init(SPI_QUARTER_SPEED);
  65. W25QXX.SPI_FLASH_BulkErase();
  66. SERIAL_ECHOPGM("Load SPI Flash");
  67. while (addr < SPI_FLASH_SIZE) {
  68. card.read(buf, COUNT(buf));
  69. W25QXX.SPI_FLASH_BufferWrite(buf, addr, COUNT(buf));
  70. addr += COUNT(buf);
  71. if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.');
  72. }
  73. SERIAL_ECHOLNPGM(" done");
  74. card.closefile();
  75. }
  76. #endif // HAS_SPI_FLASH && SDSUPPORT && MARLIN_DEV_MODE