diff --git a/Marlin/src/gcode/host/M115.cpp b/Marlin/src/gcode/host/M115.cpp index 33fc074b726c..114e3cbc72ff 100644 --- a/Marlin/src/gcode/host/M115.cpp +++ b/Marlin/src/gcode/host/M115.cpp @@ -88,13 +88,13 @@ void GcodeSuite::M115() { * This code should work on all STM32-based boards. */ #if ENABLED(STM32_UID_SHORT_FORM) - uint32_t * const UID = (uint32_t*)UID_BASE; + const uint32_t * const UID = (uint32_t*)UID_BASE; for (uint8_t i = 0; i < 3; i++) print_hex_long(UID[i]); #else - uint16_t * const UID = (uint16_t*)UID_BASE; // Little-endian! + const uint16_t * const UID = (uint16_t*)UID_BASE; // Little-endian! SERIAL_ECHO(F("CEDE2A2F-")); - for (uint8_t i = 1; i < 7; i++) { - print_hex_word((i % 2) ? UID[i] : UID[i - 2]); // 1111-0000-3333-2222555544447777 + for (uint8_t i = 1; i <= 6; i++) { + print_hex_word(UID[(i % 2) ? i : i - 2]); // 1111-0000-3333-2222555544446666 if (i <= 3) SERIAL_ECHO(C('-')); } #endif diff --git a/Marlin/src/libs/hex_print.cpp b/Marlin/src/libs/hex_print.cpp index 90f3fab818cd..9a354011e841 100644 --- a/Marlin/src/libs/hex_print.cpp +++ b/Marlin/src/libs/hex_print.cpp @@ -27,19 +27,19 @@ #include "hex_print.h" #include "../core/serial.h" -static char _hex[] = "0x00000000"; +static char _hex[] = "0x00000000"; // 0:adr32 2:long 4:adr16 6:word 8:byte inline void __hex_byte(const uint8_t b, const uint8_t o=8) { _hex[o + 0] = hex_nybble(b >> 4); _hex[o + 1] = hex_nybble(b); } inline void __hex_word(const uint16_t w, const uint8_t o=6) { - __hex_byte(w >> 2, o + 0); - __hex_byte(w >> 0, o + 2); + __hex_byte(w >> 8, o + 0); + __hex_byte(w , o + 2); } -inline void __hex_long(const uint16_t w) { - __hex_word(w >> 4, 2); - __hex_word(w >> 0, 6); +inline void __hex_long(const uint32_t w) { + __hex_word(w >> 16, 2); + __hex_word(w , 6); } char* hex_byte(const uint8_t b) { __hex_byte(b); return &_hex[8]; } @@ -51,7 +51,7 @@ char* hex_address(const void * const a) { (void)_hex_long((uintptr_t)a); return _hex; #else - hex[4] = '0'; hex[5] = 'x'; + _hex[4] = '0'; _hex[5] = 'x'; (void)_hex_word((uintptr_t)a); return &_hex[4]; #endif @@ -59,7 +59,7 @@ char* hex_address(const void * const a) { void print_hex_nybble(const uint8_t n) { SERIAL_CHAR(hex_nybble(n)); } void print_hex_byte(const uint8_t b) { SERIAL_ECHO(hex_byte(b)); } -void print_hex_word(const uint16_t w) { SERIAL_ECHO(hex_word(w)); } +void print_hex_word(const uint16_t w) { SERIAL_ECHO(_hex_word(w)); } void print_hex_address(const void * const w) { SERIAL_ECHO(hex_address(w)); } void print_hex_long(const uint32_t w, const char delimiter/*='\0'*/, const bool prefix/*=false*/) {