From 8e97d5b3ee66cdd47311e1a44154006d8686c20f Mon Sep 17 00:00:00 2001 From: drf5n Date: Mon, 11 Apr 2022 09:48:17 -0400 Subject: [PATCH] FIx EEPROM checksum to not be lastchar or lastchar+1 Per https://github.com/gnea/grbl-Mega/issues/158 the logical OR discards most of the checksum information, resulting in the final chekcsum being either the last character, or the last character +1. This fix brings the checksum in-line with grblHAL's implementation: https://github.com/grblHAL/core/blob/3a84b58d301f04279268b4ef1045fd6bc0961be5/nuts_bolts.c#L267-L278 --- grbl/eeprom.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grbl/eeprom.c b/grbl/eeprom.c index 02caf202f..de40056ef 100644 --- a/grbl/eeprom.c +++ b/grbl/eeprom.c @@ -130,7 +130,7 @@ void eeprom_put_char( unsigned int addr, unsigned char new_value ) void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size) { unsigned char checksum = 0; for(; size > 0; size--) { - checksum = (checksum << 1) || (checksum >> 7); + checksum = (checksum << 1) | (checksum >> 7); checksum += *source; eeprom_put_char(destination++, *(source++)); } @@ -141,7 +141,7 @@ int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, uns unsigned char data, checksum = 0; for(; size > 0; size--) { data = eeprom_get_char(source++); - checksum = (checksum << 1) || (checksum >> 7); + checksum = (checksum << 1) | (checksum >> 7); checksum += data; *(destination++) = data; }