From 440be49862f83bca497673f7f44f08d7883b6e05 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Fri, 14 Aug 2026 15:59:10 +0200 Subject: [PATCH] arch/arm/src/common/stm32: read UID with 32-bit accesses STM32H5 stores the UID in flash memory that supports only 16-bit or 32-bit read accesses. The 8-bit reads introduced with the stm32_uid unification generate an AHB bus error and hard fault the chip when the Ethernet driver reads the MAC address. Read the UID as three 32-bit words into an aligned buffer and copy it to the caller's buffer. On little-endian ARM the resulting byte order is identical to byte reads, so behavior is unchanged for the other STM32 families. Fixes: https://github.com/apache/nuttx/issues/19771 Signed-off-by: raiden00pl Assisted-by: Claude Code --- arch/arm/src/common/stm32/stm32_uid.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/common/stm32/stm32_uid.c b/arch/arm/src/common/stm32/stm32_uid.c index 190f38b975f..e710dabcf64 100644 --- a/arch/arm/src/common/stm32/stm32_uid.c +++ b/arch/arm/src/common/stm32/stm32_uid.c @@ -40,6 +40,9 @@ #include +#include + +#include "arm_internal.h" #include "chip.h" #include "stm32_uid.h" @@ -51,12 +54,19 @@ void stm32_get_uniqueid(uint8_t uniqueid[12]) { + uint32_t uid[3]; int i; - for (i = 0; i < 12; i++) + /* Read the UID with 32-bit accesses. Some parts (STM32H5) store the UID + * in flash memory that does not support 8-bit reads. + */ + + for (i = 0; i < 3; i++) { - uniqueid[i] = *((uint8_t *)(STM32_SYSMEM_UID) + i); + uid[i] = getreg32(STM32_SYSMEM_UID + 4 * i); } + + memcpy(uniqueid, uid, 12); } #endif /* STM32_SYSMEM_UID */