diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 0345ba39..5f204e63 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -9,8 +9,16 @@ #include "mesh_bed_leveling.h" #endif -void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) +#ifdef DEBUG_EEPROM_WRITE +#define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value), #value) +#else //DEBUG_EEPROM_WRITE +#define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value), 0) +#endif //DEBUG_EEPROM_WRITE +void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size, char* name) { +#ifdef DEBUG_EEPROM_WRITE + printf_P(PSTR("EEPROM_WRITE_VAR addr=0x%04x size=0x%02hhx name=%s\n"), pos, size, name); +#endif //DEBUG_EEPROM_WRITE while (size--) { uint8_t * const p = (uint8_t * const)pos; uint8_t v = *value; @@ -28,9 +36,17 @@ void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) }; } -#define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value)) -void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) + +#ifdef DEBUG_EEPROM_READ +#define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value), #value) +#else //DEBUG_EEPROM_READ +#define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value), 0) +#endif //DEBUG_EEPROM_READ +void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size, char* name) { +#ifdef DEBUG_EEPROM_READ + printf_P(PSTR("EEPROM_READ_VAR addr=0x%04x size=0x%02hhx name=%s\n"), pos, size, name); +#endif //DEBUG_EEPROM_READ do { *value = eeprom_read_byte((unsigned char*)pos); @@ -38,7 +54,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) value++; }while(--size); } -#define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value)) + //====================================================================================== #define EEPROM_OFFSET 20 // IMPORTANT: Whenever there are changes made to the variables stored in EEPROM diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index f3abac3f..d1ddc61e 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -1,5 +1,146 @@ #include "Dcodes.h" -#include "Marlin.h" +//#include "Marlin.h" +#include "language.h" +#include "cmdqueue.h" +#include +#include + + +#define DBG(args...) printf_P(args) + +inline void print_hex_nibble(uint8_t val) +{ + putchar((val > 9)?(val - 10 + 'a'):(val + '0')); +} + +void print_hex_byte(uint8_t val) +{ + print_hex_nibble(val >> 4); + print_hex_nibble(val & 15); +} + +void print_hex_word(uint16_t val) +{ + print_hex_byte(val >> 8); + print_hex_byte(val & 255); +} + +void print_eeprom(uint16_t address, uint16_t count, uint8_t countperline = 16) +{ + while (count) + { + print_hex_word(address); + putchar(' '); + uint8_t count_line = countperline; + while (count && count_line) + { + uint8_t data = 0; + putchar(' '); + print_hex_byte(eeprom_read_byte((uint8_t*)address++)); + count_line--; + count--; + } + putchar('\n'); + } +} + +int parse_hex(char* hex, uint8_t* data, int count) +{ + int parsed = 0; + while (*hex) + { + if (count && (parsed >= count)) break; + char c = *(hex++); + if (c == ' ') continue; + if (c == '\n') break; + uint8_t val = 0x00; + if ((c >= '0') && (c <= '9')) val |= ((c - '0') << 4); + else if ((c >= 'a') && (c <= 'f')) val |= ((c - 'a' + 10) << 4); + else return -parsed; + c = *(hex++); + if ((c >= '0') && (c <= '9')) val |= (c - '0'); + else if ((c >= 'a') && (c <= 'f')) val |= (c - 'a' + 10); + else return -parsed; + data[parsed] = val; + parsed++; + } + return parsed; +} + + +void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperline = 16) +{ + while (count) + { + if (type == 2) + print_hex_nibble(address >> 16); + print_hex_word(address); + putchar(' '); + uint8_t count_line = countperline; + while (count && count_line) + { + uint8_t data = 0; + switch (type) + { + case 0: data = *((uint8_t*)address++); break; + case 1: data = eeprom_read_byte((uint8_t*)address++); break; + case 2: data = pgm_read_byte_far((uint8_t*)address++); break; + } + putchar(' '); + print_hex_byte(data); + count_line--; + count--; + } + putchar('\n'); + } +} + +#ifdef DEBUG_DCODE3 +#define EEPROM_SIZE 0x1000 +void dcode_3() +{ + DBG(_N("D3 - Read/Write EEPROM\n")); + uint16_t address = 0x0000; //default 0x0000 + uint16_t count = EEPROM_SIZE; //default 0x1000 (entire eeprom) + if (code_seen('A')) // Address (0x0000-0x0fff) + address = (strchr_pointer[1] == 'x')?strtol(strchr_pointer + 2, 0, 16):(int)code_value(); + if (code_seen('C')) // Count (0x0001-0x1000) + count = (int)code_value(); + address &= 0x1fff; + if (count > EEPROM_SIZE) count = EEPROM_SIZE; + if ((address + count) > EEPROM_SIZE) count = EEPROM_SIZE - address; + if (code_seen('X')) // Data + { + uint8_t data[16]; + count = parse_hex(strchr_pointer + 1, data, 16); + if (count > 0) + { + for (int i = 0; i < count; i++) + eeprom_write_byte((uint8_t*)(address + i), data[i]); + printf_P(_N("%d bytes written to EEPROM at address 0x%04x"), count, address); + putchar('\n'); + } + else + count = 0; + } + print_mem(address, count, 1); +/* while (count) + { + print_hex_word(address); + putchar(' '); + uint8_t countperline = 16; + while (count && countperline) + { + uint8_t data = eeprom_read_byte((uint8_t*)address++); + putchar(' '); + print_hex_byte(data); + countperline--; + count--; + } + putchar('\n'); + }*/ +} +#endif //DEBUG_DCODE3 #ifdef DEBUG_DCODES @@ -29,76 +170,9 @@ extern float current_temperature_pinda; extern float axis_steps_per_unit[NUM_AXIS]; -inline void print_hex_nibble(uint8_t val) -{ - putchar((val > 9)?(val - 10 + 'a'):(val + '0')); -} - -void print_hex_byte(uint8_t val) -{ - print_hex_nibble(val >> 4); - print_hex_nibble(val & 15); -} - -void print_hex_word(uint16_t val) -{ - print_hex_byte(val >> 8); - print_hex_byte(val & 255); -} - -void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperline = 16) -{ - while (count) - { - if (type == 2) - print_hex_nibble(address >> 16); - print_hex_word(address); - putchar(' '); - uint8_t count_line = countperline; - while (count && count_line) - { - uint8_t data = 0; - switch (type) - { - case 0: data = *((uint8_t*)address++); break; - case 1: data = eeprom_read_byte((uint8_t*)address++); break; - case 2: data = pgm_read_byte_far((uint8_t*)address++); break; - } - putchar(' '); - print_hex_byte(data); - count_line--; - count--; - } - putchar('\n'); - } -} - //#define LOG(args...) printf(args) #define LOG(args...) -int parse_hex(char* hex, uint8_t* data, int count) -{ - int parsed = 0; - while (*hex) - { - if (count && (parsed >= count)) break; - char c = *(hex++); - if (c == ' ') continue; - if (c == '\n') break; - uint8_t val = 0x00; - if ((c >= '0') && (c <= '9')) val |= ((c - '0') << 4); - else if ((c >= 'a') && (c <= 'f')) val |= ((c - 'a' + 10) << 4); - else return -parsed; - c = *(hex++); - if ((c >= '0') && (c <= '9')) val |= (c - '0'); - else if ((c >= 'a') && (c <= 'f')) val |= (c - 'a' + 10); - else return -parsed; - data[parsed] = val; - parsed++; - } - return parsed; -} - void dcode__1() { printf("D-1 - Endless loop\n"); @@ -177,52 +251,6 @@ void dcode_2() }*/ } -void dcode_3() -{ - LOG("D3 - Read/Write EEPROM\n"); - uint16_t address = 0x0000; //default 0x0000 - uint16_t count = 0x2000; //default 0x2000 (entire eeprom) - if (code_seen('A')) // Address (0x0000-0x1fff) - address = (strchr_pointer[1] == 'x')?strtol(strchr_pointer + 2, 0, 16):(int)code_value(); - if (code_seen('C')) // Count (0x0001-0x2000) - count = (int)code_value(); - address &= 0x1fff; - if (count > 0x2000) count = 0x2000; - if ((address + count) > 0x2000) count = 0x2000 - address; - if (code_seen('X')) // Data - { - uint8_t data[16]; - count = parse_hex(strchr_pointer + 1, data, 16); - if (count > 0) - { - for (int i = 0; i < count; i++) - eeprom_write_byte((uint8_t*)(address + i), data[i]); - LOG(count, DEC); - LOG(" bytes written to EEPROM at address "); - print_hex_word(address); - putchar('\n'); - } - else - count = 0; - } - print_mem(address, count, 1); -/* while (count) - { - print_hex_word(address); - putchar(' '); - uint8_t countperline = 16; - while (count && countperline) - { - uint8_t data = eeprom_read_byte((uint8_t*)address++); - putchar(' '); - print_hex_byte(data); - countperline--; - count--; - } - putchar('\n'); - }*/ -} - void dcode_4() { LOG("D4 - Read/Write PIN\n"); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e2e53484..c82aea24 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -535,6 +535,9 @@ static void get_arc_coordinates(); static bool setTargetedHotend(int code); static void print_time_remaining_init(); +uint16_t gcode_in_progress = 0; +uint16_t mcode_in_progress = 0; + void serial_echopair_P(const char *s_P, float v) { serialprintPGM(s_P); SERIAL_ECHO(v); } void serial_echopair_P(const char *s_P, double v) @@ -1974,7 +1977,8 @@ void loop() checkHitEndstops(); lcd_update(0); #ifdef FILAMENT_SENSOR - fsensor_update(); + if (mcode_in_progress != 600) //M600 not in progress + fsensor_update(); #endif //FILAMENT_SENSOR #ifdef TMC2130 tmc2130_check_overtemp(); @@ -3186,8 +3190,6 @@ extern uint8_t st_backlash_x; extern uint8_t st_backlash_y; #endif //BACKLASH_Y -uint16_t gcode_in_progress = 0; -uint16_t mcode_in_progress = 0; void process_commands() { @@ -7101,11 +7103,11 @@ Sigma_Exit: } } // end if(code_seen('T')) (end of T codes) -#ifdef DEBUG_DCODES else if (code_seen('D')) // D codes (debug) { switch((int)code_value()) { +#ifdef DEBUG_DCODES case -1: // D-1 - Endless loop dcode__1(); break; case 0: // D0 - Reset @@ -7114,8 +7116,12 @@ Sigma_Exit: dcode_1(); break; case 2: // D2 - Read/Write RAM dcode_2(); break; +#endif //DEBUG_DCODES +#ifdef DEBUG_DCODE3 case 3: // D3 - Read/Write EEPROM dcode_3(); break; +#endif //DEBUG_DCODE3 +#ifdef DEBUG_DCODES case 4: // D4 - Read/Write PIN dcode_4(); break; case 5: // D5 - Read/Write FLASH @@ -7144,9 +7150,9 @@ Sigma_Exit: dcode_9125(); break; #endif //FILAMENT_SENSOR +#endif //DEBUG_DCODES } } -#endif //DEBUG_DCODES else { diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index a280eda1..66008be3 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -33,11 +33,13 @@ extern int8_t FSensorStateMenu; void fsensor_stop_and_save_print(void) { + printf_P(PSTR("fsensor_stop_and_save_print\n")); stop_and_save_print_to_ram(0, 0); //XYZE - no change } void fsensor_restore_print_and_continue(void) { + printf_P(PSTR("fsensor_restore_print_and_continue\n")); restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change } @@ -240,12 +242,12 @@ bool fsensor_check_autoload(void) fsensor_autoload_c--; if (fsensor_autoload_c == 0) fsensor_autoload_sum = 0; // puts_P(_N("fsensor_check_autoload\n")); - if (fsensor_autoload_c != fsensor_autoload_c_old) - printf_P(PSTR("fsensor_check_autoload dy=%d c=%d sum=%d\n"), dy, fsensor_autoload_c, fsensor_autoload_sum); +// if (fsensor_autoload_c != fsensor_autoload_c_old) +// printf_P(PSTR("fsensor_check_autoload dy=%d c=%d sum=%d\n"), dy, fsensor_autoload_c, fsensor_autoload_sum); // if ((fsensor_autoload_c >= 15) && (fsensor_autoload_sum > 30)) if ((fsensor_autoload_c >= 10) && (fsensor_autoload_sum > 15)) { - puts_P(_N("fsensor_check_autoload = true !!!\n")); +// puts_P(_N("fsensor_check_autoload = true !!!\n")); return true; } return false; @@ -412,10 +414,10 @@ void fsensor_update(void) { if (fsensor_printing_saved) { + fsensor_restore_print_and_continue(); fsensor_printing_saved = false; fsensor_watch_runout = true; fsensor_err_cnt = 0; - fsensor_restore_print_and_continue(); } else if (fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX)) { @@ -423,6 +425,19 @@ void fsensor_update(void) fsensor_printing_saved = true; fsensor_err_cnt = 0; +/* + st_synchronize(); + for (int axis = X_AXIS; axis <= E_AXIS; axis++) + current_position[axis] = st_get_position_mm(axis); + + current_position[E_AXIS] -= 3; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 200 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] += 3; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 200 / 60, active_extruder); + st_synchronize(); +*/ enquecommand_front_P((PSTR("G1 E-3 F200"))); process_commands(); @@ -437,9 +452,11 @@ void fsensor_update(void) if (fsensor_err_cnt == 0) { fsensor_restore_print_and_continue(); + fsensor_printing_saved = false; } else { +// printf_P(PSTR("fsensor_update - M600\n")); eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1); eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1); enquecommand_front_P((PSTR("M600"))); diff --git a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h index 7203fe5c..abd9ab7b 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h @@ -113,6 +113,7 @@ #define PAT9125 #define FILAMENT_SENSOR +#define DEBUG_DCODE3 //#define DEBUG_BUILD #ifdef DEBUG_BUILD diff --git a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h index 75b73341..99609cf5 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h @@ -114,6 +114,7 @@ #define PAT9125 #define FILAMENT_SENSOR +#define DEBUG_DCODE3 //#define DEBUG_BUILD #ifdef DEBUG_BUILD diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 56b8b333..e87915c7 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -147,6 +147,8 @@ #define MINTEMP_MINAMBIENT 25 #define MINTEMP_MINAMBIENT_RAW 978 +#define DEBUG_DCODE3 + //#define DEBUG_BUILD //#define DEBUG_SEC_LANG //secondary language debug output at startup //#define DEBUG_W25X20CL //debug external spi flash