Skip to content

Commit

Permalink
🚸 UUID fallback to STM32 device SN (MarlinFirmware#24759)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
2 people authored and Andy-Big committed Jul 2, 2023
1 parent 2f27a1f commit 32dd893
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Marlin/src/gcode/host/M115.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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)
Expand Down Expand Up @@ -69,17 +73,34 @@ void GcodeSuite::M115() {
"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
);
sprintf(string, "%u", settings.datasize());
strcat(string, "\n");
SERIAL_ECHOLNPGM("EPROM datasize: ", settings.datasize(), "\n");


// 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
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/pins/stm32f4/pins_OPULO_LUMEN_REV3.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

// I2C MCP3426 (16-Bit, 240SPS, dual-channel ADC)
#define HAS_MCP3426_ADC
#ifdef STM32F4
#define HAS_STM32_UID
#endif

//
// Servos
Expand Down

0 comments on commit 32dd893

Please sign in to comment.