Use planner buffer for EEPROM save/restore.
Reset printer after restore.
This commit is contained in:
parent
095864aae3
commit
ad0f7ff33b
|
|
@ -1961,14 +1961,14 @@ void gcode_M767() {
|
||||||
// Only if no other files open and not printing
|
// Only if no other files open and not printing
|
||||||
if (IS_SD_PRINTING || is_usb_printing)
|
if (IS_SD_PRINTING || is_usb_printing)
|
||||||
return;
|
return;
|
||||||
|
// Make sure plan buffer is idle - we use it for SD buffer
|
||||||
|
st_synchronize();
|
||||||
|
|
||||||
// Reset SD card and write to root
|
// Reset SD card and write to root
|
||||||
card.initsd();
|
card.initsd();
|
||||||
// Overwrite existing
|
// Overwrite existing
|
||||||
card.openFile((char *)"eesave.hex", false, true);
|
card.openFile((char *)"eesave.hex", false, true);
|
||||||
linebfr = (char *)malloc(EELINESIZE + 1);
|
linebfr = (char *)block_buffer;
|
||||||
if (!linebfr)
|
|
||||||
kill();
|
|
||||||
|
|
||||||
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
||||||
int8_t cksum = EECHUNKSIZE;
|
int8_t cksum = EECHUNKSIZE;
|
||||||
|
|
@ -1982,14 +1982,12 @@ void gcode_M767() {
|
||||||
|
|
||||||
nch += sprintf_P(linebfr + nch, PSTR("%02X\n"), (-cksum) & 0xFF);
|
nch += sprintf_P(linebfr + nch, PSTR("%02X\n"), (-cksum) & 0xFF);
|
||||||
if (card.write_buf(linebfr, nch) != nch) {
|
if (card.write_buf(linebfr, nch) != nch) {
|
||||||
free(linebfr);
|
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNRPGM(MSG_SD_ERR_WRITE_TO_FILE);
|
SERIAL_ERRORLNRPGM(MSG_SD_ERR_WRITE_TO_FILE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(linebfr);
|
|
||||||
// Close file
|
// Close file
|
||||||
card.closefile(false);
|
card.closefile(false);
|
||||||
SERIAL_ECHOLNPGM("EEPROM saved");
|
SERIAL_ECHOLNPGM("EEPROM saved");
|
||||||
|
|
@ -2034,6 +2032,9 @@ void gcode_M768() {
|
||||||
if (IS_SD_PRINTING || is_usb_printing)
|
if (IS_SD_PRINTING || is_usb_printing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Make sure plan buffer is idle - we use it for SD buffer
|
||||||
|
st_synchronize();
|
||||||
|
|
||||||
// Reset SD card and write to root
|
// Reset SD card and write to root
|
||||||
card.initsd();
|
card.initsd();
|
||||||
// Open existing
|
// Open existing
|
||||||
|
|
@ -2041,19 +2042,16 @@ void gcode_M768() {
|
||||||
if (!card.isFileOpen())
|
if (!card.isFileOpen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
linebfr = (char *)malloc(EELINESIZE + 1);
|
// Borrowing the planner
|
||||||
if (!linebfr)
|
linebfr = (char *)block_buffer;
|
||||||
kill();
|
|
||||||
|
|
||||||
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
||||||
if (card.read_buf(linebfr, EELINESIZE) != EELINESIZE) {
|
if (card.read_buf(linebfr, EELINESIZE) != EELINESIZE) {
|
||||||
free(linebfr);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Validate buffer header
|
// Validate buffer header
|
||||||
if ((linebfr[0] != ':') || (bfrVal(&linebfr[1], 2) != EECHUNKSIZE) ||
|
if ((linebfr[0] != ':') || (bfrVal(&linebfr[1], 2) != EECHUNKSIZE) ||
|
||||||
(bfrVal(&linebfr[7], 2) != 0)) {
|
(bfrVal(&linebfr[7], 2) != 0)) {
|
||||||
free(linebfr);
|
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Header mis-match");
|
SERIAL_ERRORLNPGM("Header mis-match");
|
||||||
return;
|
return;
|
||||||
|
|
@ -2065,7 +2063,6 @@ void gcode_M768() {
|
||||||
cksum += bfrVal(&linebfr[i], 2);
|
cksum += bfrVal(&linebfr[i], 2);
|
||||||
}
|
}
|
||||||
if (cksum != 0) {
|
if (cksum != 0) {
|
||||||
free(linebfr);
|
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Bad checksum");
|
SERIAL_ERRORLNPGM("Bad checksum");
|
||||||
return;
|
return;
|
||||||
|
|
@ -2073,7 +2070,6 @@ void gcode_M768() {
|
||||||
|
|
||||||
addrs = bfrVal(&linebfr[3], 4);
|
addrs = bfrVal(&linebfr[3], 4);
|
||||||
if (addrs > 4064) {
|
if (addrs > 4064) {
|
||||||
free(linebfr);
|
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Bad EEPROM offset");
|
SERIAL_ERRORLNPGM("Bad EEPROM offset");
|
||||||
return;
|
return;
|
||||||
|
|
@ -2086,9 +2082,11 @@ void gcode_M768() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// All done with restore
|
// All done with restore
|
||||||
free(linebfr);
|
|
||||||
card.closefile();
|
card.closefile();
|
||||||
SERIAL_ECHOLNPGM("EEPROM restored");
|
SERIAL_ECHOLNPGM("EEPROM restored");
|
||||||
|
delay(1000); // Wait a bit, then hard reset
|
||||||
|
cli();
|
||||||
|
asm volatile("jmp 0x00000");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue