From e97fc5e595e37d8a662e1400e17433a480290bd8 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 25 Jun 2022 17:19:53 -0400 Subject: [PATCH 1/2] stm32/serialno: Fixed a small regression that made it in with #1041 resulting in a transposition of alpha characters in serial numbers --- src/platforms/stm32/serialno.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/stm32/serialno.c b/src/platforms/stm32/serialno.c index 67776cfca62..38492fc2ff7 100644 --- a/src/platforms/stm32/serialno.c +++ b/src/platforms/stm32/serialno.c @@ -30,7 +30,7 @@ char *serial_no_read(char *s) s[7U - i] = ((unique_id >> (i * 4U)) & 0x0FU) + '0'; /* If the character is something above 9, then add the offset to make it ASCII A-F */ if (s[7U - i] > '9') - s[7U - i] += 16; /* 'A' - '9' = 17, less 1 gives 16. */ + s[7U - i] += 7; /* 'A' - '9' = 8, less 1 gives 7. */ } #elif DFU_SERIAL_LENGTH == 13 /* Use the same serial number as the ST DFU Bootloader.*/ @@ -53,7 +53,7 @@ char *serial_no_read(char *s) /* If the character is something above 9, then add the offset to make it ASCII A-F */ if (s[chunk + (7U - nibble)] > '9') - s[chunk + (7U - nibble)] += 16; /* 'A' - '9' = 17, less 1 gives 16. */ + s[chunk + (7U - nibble)] += 7; /* 'A' - '9' = 8, less 1 gives 7. */ } #else # WARNING "Unhandled DFU_SERIAL_LENGTH" From 885d785fd9195e37a3d9fcc644f4148664c7a08f Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sun, 26 Jun 2022 16:45:51 -0400 Subject: [PATCH 2/2] stm32/serialno: Fixed a regression in 24 character serial number suport which was causing them to display all 0's --- src/platforms/stm32/serialno.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/platforms/stm32/serialno.c b/src/platforms/stm32/serialno.c index 38492fc2ff7..b47d74b5eb0 100644 --- a/src/platforms/stm32/serialno.c +++ b/src/platforms/stm32/serialno.c @@ -47,13 +47,14 @@ char *serial_no_read(char *s) for (size_t i = 0; i < 24U; ++i) { const size_t chunk = i >> 3U; const size_t nibble = i & 7U; + const size_t idx = (chunk << 3U) + (7U - nibble); if (nibble == 0) unique_id = unique_id_p[chunk]; - s[chunk + (7U - nibble)] = ((unique_id >> (i * 4)) & 0x0F) + '0'; + s[idx] = ((unique_id >> (i * 4)) & 0x0F) + '0'; /* If the character is something above 9, then add the offset to make it ASCII A-F */ - if (s[chunk + (7U - nibble)] > '9') - s[chunk + (7U - nibble)] += 7; /* 'A' - '9' = 8, less 1 gives 7. */ + if (s[idx] > '9') + s[idx] += 7; /* 'A' - '9' = 8, less 1 gives 7. */ } #else # WARNING "Unhandled DFU_SERIAL_LENGTH"