Skip to content

[BUG] STM32_UID still broken, the serial number its is prining out is garbage. #26731

@ellensp

Description

@ellensp

Did you test the latest bugfix-2.1.x code?

Yes, and the problem still exists.

Bug Description (Updated)

If you enable HAS_STM32_UID on a test device It now prints out a serial number, but the number is not correct

First a red hearing, the old code did not give correct results, see notes below. So comparing old results to current results will not help

But the output is still incorrect

On my hardware the Device electronic signature is the following 0x004d0030 0x4646500a 0x20353631

If you enable STM32_UID_SHORT_FORM so the UID is formatted the same as the hex dump above

using current code
SERIAL_ECHO(hex_long(UID[0]), hex_long(UID[1]), hex_long(UID[2]));
results in 203536312035363120353631 <- incorrect values

expanding out the code to multiple SERIAL_ECHO lines

      SERIAL_ECHO(hex_long(UID[0]));
      SERIAL_ECHO(hex_long(UID[1]));
      SERIAL_ECHO(hex_long(UID[2]));

results in 004D00304646500A20353631 <- correct result

With STM32_UID_SHORT_FORM disabled you get similar results

long form of code, with corrected indexes

      SERIAL_ECHO(F("CEDE2A2F-"), hex_word(UID[1]));
      SERIAL_ECHO(C('-'), hex_word(UID[0]));
      SERIAL_ECHO(C('-'), hex_word(UID[3]));
      SERIAL_ECHO(C('-'), hex_word(UID[2]));
      SERIAL_ECHO(hex_word(UID[5]));
      SERIAL_ECHO(hex_word(UID[4]));

results in CEDE2A2F-004D-0030-4646-500A20353631 <- correct result

but the index corrected condensed version

      SERIAL_ECHO(
        F("CEDE2A2F-"), hex_word(UID[1]), C('-'), hex_word(UID[0]), C('-'), hex_word(UID[3]), C('-'),
        hex_word(UID[2]), hex_word(UID[5]), hex_word(UID[4])
      );

results in CEDE2A2F-3631-3631-3631-363136313631 <- incorrect values

Bug Timeline

recent

Expected behavior

Correct serial number should be reported

Actual behavior

you effectively get a random repeating numbers

Steps to Reproduce

  1. #define HAS_STM32_UID 1
  2. hack in this code into M115 to display correct UID
   SERIAL_ECHOPGM(" Correct UUID:");
    uint32_t *uid_address = (uint32_t*)UID_BASE;
    for (uint8_t i = 0; i < 3; ++i) {
      const uint32_t UID = uint32_t(*(uid_address));
      uid_address += 1U;  
      for (int B = 24; B >= 0; B -= 8) print_hex_byte(UID >> B);
    }
  1. compile and upload
  2. send a M115 and note serial number difference

Version of Marlin Firmware

Bugfix-2.1.x

Don't forget to include

test Configuration.zip

=== Related Issues
#26715
#26698
#26724
#26727

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions