🩹 Patch STM32 serial UUID (#26737)
Followup to #26715 Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
ef04680cc5
commit
f9d5ee04b4
|
@ -763,7 +763,7 @@
|
||||||
SERIAL_CHAR('\t');
|
SERIAL_CHAR('\t');
|
||||||
st.printLabel();
|
st.printLabel();
|
||||||
SERIAL_CHAR('\t');
|
SERIAL_CHAR('\t');
|
||||||
print_hex_long(drv_status, ':');
|
print_hex_long(drv_status, ':', true);
|
||||||
if (drv_status == 0xFFFFFFFF || drv_status == 0) SERIAL_ECHOPGM("\t Bad response!");
|
if (drv_status == 0xFFFFFFFF || drv_status == 0) SERIAL_ECHOPGM("\t Bad response!");
|
||||||
SERIAL_EOL();
|
SERIAL_EOL();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -88,14 +88,15 @@ void GcodeSuite::M115() {
|
||||||
* This code should work on all STM32-based boards.
|
* This code should work on all STM32-based boards.
|
||||||
*/
|
*/
|
||||||
#if ENABLED(STM32_UID_SHORT_FORM)
|
#if ENABLED(STM32_UID_SHORT_FORM)
|
||||||
uint32_t * const UID = (uint32_t*)UID_BASE;
|
const uint32_t * const UID = (uint32_t*)UID_BASE;
|
||||||
SERIAL_ECHO(hex_long(UID[0]), hex_long(UID[1]), hex_long(UID[2]));
|
for (uint8_t i = 0; i < 3; i++) print_hex_long(UID[i]);
|
||||||
#else
|
#else
|
||||||
uint16_t * const UID = (uint16_t*)UID_BASE;
|
const uint16_t * const UID = (uint16_t*)UID_BASE; // Little-endian!
|
||||||
SERIAL_ECHO(
|
SERIAL_ECHO(F("CEDE2A2F-"));
|
||||||
F("CEDE2A2F-"), hex_word(UID[0]), C('-'), hex_word(UID[1]), C('-'), hex_word(UID[2]), C('-'),
|
for (uint8_t i = 1; i <= 6; i++) {
|
||||||
hex_word(UID[3]), hex_word(UID[4]), hex_word(UID[5])
|
print_hex_word(UID[(i % 2) ? i : i - 2]); // 1111-0000-3333-222255554444
|
||||||
);
|
if (i <= 3) SERIAL_ECHO(C('-'));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -27,57 +27,43 @@
|
||||||
#include "hex_print.h"
|
#include "hex_print.h"
|
||||||
#include "../core/serial.h"
|
#include "../core/serial.h"
|
||||||
|
|
||||||
|
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 >> 8, o + 0);
|
||||||
|
__hex_byte(w , o + 2);
|
||||||
|
}
|
||||||
|
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]; }
|
||||||
|
char* _hex_word(const uint16_t w) { __hex_word(w); return &_hex[6]; }
|
||||||
|
char* _hex_long(const uint32_t l) { __hex_long(l); return &_hex[2]; }
|
||||||
|
|
||||||
|
char* hex_address(const void * const a) {
|
||||||
#ifdef CPU_32_BIT
|
#ifdef CPU_32_BIT
|
||||||
constexpr int byte_start = 4;
|
(void)_hex_long((uintptr_t)a);
|
||||||
static char _hex[] = "0x00000000";
|
|
||||||
#else
|
|
||||||
constexpr int byte_start = 0;
|
|
||||||
static char _hex[] = "0x0000";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char* hex_byte(const uint8_t b) {
|
|
||||||
_hex[byte_start + 4] = hex_nybble(b >> 4);
|
|
||||||
_hex[byte_start + 5] = hex_nybble(b);
|
|
||||||
return &_hex[byte_start + 4];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void __hex_word(const uint16_t w) {
|
|
||||||
_hex[byte_start + 2] = hex_nybble(w >> 12);
|
|
||||||
_hex[byte_start + 3] = hex_nybble(w >> 8);
|
|
||||||
_hex[byte_start + 4] = hex_nybble(w >> 4);
|
|
||||||
_hex[byte_start + 5] = hex_nybble(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* _hex_word(const uint16_t w) {
|
|
||||||
__hex_word(w);
|
|
||||||
return &_hex[byte_start + 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
char* _hex_long(const uintptr_t l) {
|
|
||||||
_hex[2] = hex_nybble(l >> 28);
|
|
||||||
_hex[3] = hex_nybble(l >> 24);
|
|
||||||
_hex[4] = hex_nybble(l >> 20);
|
|
||||||
_hex[5] = hex_nybble(l >> 16);
|
|
||||||
__hex_word((uint16_t)(l & 0xFFFF));
|
|
||||||
return &_hex[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
char* hex_address(const void * const w) {
|
|
||||||
#ifdef CPU_32_BIT
|
|
||||||
(void)hex_long((uintptr_t)w);
|
|
||||||
#else
|
|
||||||
(void)hex_word((uintptr_t)w);
|
|
||||||
#endif
|
|
||||||
return _hex;
|
return _hex;
|
||||||
|
#else
|
||||||
|
_hex[4] = '0'; _hex[5] = 'x';
|
||||||
|
(void)_hex_word((uintptr_t)a);
|
||||||
|
return &_hex[4];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_hex_nybble(const uint8_t n) { SERIAL_CHAR(hex_nybble(n)); }
|
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_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_address(const void * const w) { SERIAL_ECHO(hex_address(w)); }
|
||||||
|
|
||||||
void print_hex_long(const uint32_t w, const char delimiter/*='\0'*/) {
|
void print_hex_long(const uint32_t w, const char delimiter/*='\0'*/, const bool prefix/*=false*/) {
|
||||||
SERIAL_ECHOPGM("0x");
|
if (prefix) SERIAL_ECHOPGM("0x");
|
||||||
for (int B = 24; B >= 8; B -= 8) {
|
for (int B = 24; B >= 8; B -= 8) {
|
||||||
print_hex_byte(w >> B);
|
print_hex_byte(w >> B);
|
||||||
if (delimiter) SERIAL_CHAR(delimiter);
|
if (delimiter) SERIAL_CHAR(delimiter);
|
||||||
|
|
|
@ -30,16 +30,17 @@
|
||||||
constexpr char hex_nybble(const uint8_t n) {
|
constexpr char hex_nybble(const uint8_t n) {
|
||||||
return (n & 0xF) + ((n & 0xF) < 10 ? '0' : 'A' - 10);
|
return (n & 0xF) + ((n & 0xF) < 10 ? '0' : 'A' - 10);
|
||||||
}
|
}
|
||||||
char* hex_byte(const uint8_t b);
|
|
||||||
char* _hex_word(const uint16_t w);
|
char* _hex_word(const uint16_t w);
|
||||||
char* hex_address(const void * const w);
|
char* _hex_long(const uint32_t l);
|
||||||
char* _hex_long(const uintptr_t l);
|
|
||||||
|
|
||||||
|
char* hex_byte(const uint8_t b);
|
||||||
template<typename T> char* hex_word(T w) { return _hex_word((uint16_t)w); }
|
template<typename T> char* hex_word(T w) { return _hex_word((uint16_t)w); }
|
||||||
template<typename T> char* hex_long(T w) { return _hex_long((uint32_t)w); }
|
template<typename T> char* hex_long(T w) { return _hex_long((uint32_t)w); }
|
||||||
|
|
||||||
|
char* hex_address(const void * const w);
|
||||||
|
|
||||||
void print_hex_nybble(const uint8_t n);
|
void print_hex_nybble(const uint8_t n);
|
||||||
void print_hex_byte(const uint8_t b);
|
void print_hex_byte(const uint8_t b);
|
||||||
void print_hex_word(const uint16_t w);
|
void print_hex_word(const uint16_t w);
|
||||||
void print_hex_address(const void * const w);
|
void print_hex_address(const void * const w);
|
||||||
void print_hex_long(const uint32_t w, const char delimiter='\0');
|
void print_hex_long(const uint32_t w, const char delimiter='\0', const bool prefix=false);
|
||||||
|
|
Loading…
Reference in a new issue