From f1a05d19b0886921cbe3529a22bcf796c174bc4a Mon Sep 17 00:00:00 2001 From: Stuart Pittaway <1201909+stuartpittaway@users.noreply.github.com> Date: Mon, 26 Sep 2022 22:18:15 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20UUID=20fallback=20to=20STM32=20d?= =?UTF-8?q?evice=20SN=20(#24759)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/src/gcode/host/M115.cpp | 37 +++++++++++++++---- .../src/pins/stm32f4/pins_OPULO_LUMEN_REV3.h | 3 ++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Marlin/src/gcode/host/M115.cpp b/Marlin/src/gcode/host/M115.cpp index 7f17617b63..a244e9802f 100644 --- a/Marlin/src/gcode/host/M115.cpp +++ b/Marlin/src/gcode/host/M115.cpp @@ -32,6 +32,10 @@ #include "../../feature/caselight.h" #endif +#if ENABLED(HAS_STM32_UID) && !defined(MACHINE_UUID) + #include "../../libs/hex_print.h" +#endif + //#define MINIMAL_CAP_LINES // Don't even mention the disabled capabilities #if ENABLED(EXTENDED_CAPABILITIES_REPORT) @@ -59,20 +63,37 @@ * the capability is not present. */ void GcodeSuite::M115() { - SERIAL_ECHOLNPGM( - "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " (" __DATE__ " " __TIME__ ") " - "SOURCE_CODE_URL:" SOURCE_CODE_URL " " - "PROTOCOL_VERSION:" PROTOCOL_VERSION " " - "MACHINE_TYPE:" MACHINE_NAME " " - "EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " " + SERIAL_ECHOPGM("FIRMWARE_NAME:Marlin" + " " DETAILED_BUILD_VERSION " (" __DATE__ " " __TIME__ ")" + " SOURCE_CODE_URL:" SOURCE_CODE_URL + " PROTOCOL_VERSION:" PROTOCOL_VERSION + " MACHINE_TYPE:" MACHINE_NAME + " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) #if NUM_AXES != XYZ - "AXIS_COUNT:" STRINGIFY(NUM_AXES) " " + " AXIS_COUNT:" STRINGIFY(NUM_AXES) #endif #ifdef MACHINE_UUID - "UUID:" MACHINE_UUID + " UUID:" MACHINE_UUID #endif ); + // STM32UID:111122223333 + #if ENABLED(HAS_STM32_UID) && !defined(MACHINE_UUID) + // STM32 based devices output the CPU device serial number + // Used by LumenPnP / OpenPNP to keep track of unique hardware/configurations + // https://github.com/opulo-inc/lumenpnp + // Although this code should work on all STM32 based boards + SERIAL_ECHOPGM(" UUID:"); + uint32_t *uid_address = (uint32_t*)UID_BASE; + LOOP_L_N(i, 3) { + const uint32_t UID = uint32_t(READ_REG(*(uid_address))); + uid_address += 4U; + for (int B = 24; B >= 0; B -= 8) print_hex_byte(UID >> B); + } + #endif + + SERIAL_EOL(); + #if ENABLED(EXTENDED_CAPABILITIES_REPORT) // The port that sent M115 diff --git a/Marlin/src/pins/stm32f4/pins_OPULO_LUMEN_REV3.h b/Marlin/src/pins/stm32f4/pins_OPULO_LUMEN_REV3.h index 36dde88105..06bf09402c 100644 --- a/Marlin/src/pins/stm32f4/pins_OPULO_LUMEN_REV3.h +++ b/Marlin/src/pins/stm32f4/pins_OPULO_LUMEN_REV3.h @@ -44,6 +44,9 @@ // I2C MCP3426 (16-Bit, 240SPS, dual-channel ADC) #define HAS_MCP3426_ADC +#ifdef STM32F4 + #define HAS_STM32_UID +#endif // // Servos