From c0029e1d978650bc0ea712a8ab42b94a5179da68 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 25 Mar 2018 12:57:43 -0500 Subject: [PATCH] Don't lose half of the processor's serial number Before this change, `microcontroller.cpu.uid` returned values where the top 4 bits of each byte were zero, because of an incorrect bitmask used in this function. --- ports/atmel-samd/common-hal/microcontroller/Processor.c | 2 +- ports/nrf/common-hal/microcontroller/Processor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index 1c57808f7d..5c0d72c96a 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -243,7 +243,7 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { for (int i=0; i<4; i++) { for (int k=0; k<4; k++) { - raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xf; + raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff; } } } diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c index cf808cdf4c..0cceb6a665 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.c +++ b/ports/nrf/common-hal/microcontroller/Processor.c @@ -76,7 +76,7 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { for (int i=0; i<2; i++) { for (int k=0; k<4; k++) { - raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xf; + raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff; } } }