From 60c9c66839be433a0848916e4bf20dc711d3ca4e Mon Sep 17 00:00:00 2001 From: kywwilson11 Date: Thu, 5 Jun 2025 13:21:19 -0500 Subject: [PATCH] Added support obtaining the unique id for the stm32g0x1. Changed copyright to apache copyright. Altered stm32_uid function to take uint32_t pointer instead of a twelve byte uint8_t array. Refined code in stm32_uid.c. Fixed style and indentation. Signed-off-by: kywwilson11 --- arch/arm/src/stm32f0l0g0/CMakeLists.txt | 3 +- arch/arm/src/stm32f0l0g0/Make.defs | 2 +- .../stm32f0l0g0/hardware/stm32g0_memorymap.h | 1 + arch/arm/src/stm32f0l0g0/stm32_uid.c | 47 +++++++++++++++++++ arch/arm/src/stm32f0l0g0/stm32_uid.h | 38 +++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 arch/arm/src/stm32f0l0g0/stm32_uid.c create mode 100644 arch/arm/src/stm32f0l0g0/stm32_uid.h diff --git a/arch/arm/src/stm32f0l0g0/CMakeLists.txt b/arch/arm/src/stm32f0l0g0/CMakeLists.txt index d82a808b285..713ce2811ee 100644 --- a/arch/arm/src/stm32f0l0g0/CMakeLists.txt +++ b/arch/arm/src/stm32f0l0g0/CMakeLists.txt @@ -32,7 +32,8 @@ list( stm32_lowputc.c stm32_serial.c stm32_lsi.c - stm32_rcc.c) + stm32_rcc.c + stm32_uid.c) if(CONFIG_STM32F0L0G0_RTC_LSECLOCK OR CONFIG_LCD_LSECLOCK) list(APPEND SRCS stm32_lse.c) diff --git a/arch/arm/src/stm32f0l0g0/Make.defs b/arch/arm/src/stm32f0l0g0/Make.defs index 3178c7be86a..24416451888 100644 --- a/arch/arm/src/stm32f0l0g0/Make.defs +++ b/arch/arm/src/stm32f0l0g0/Make.defs @@ -23,7 +23,7 @@ include armv6-m/Make.defs CHIP_CSRCS = stm32_start.c stm32_gpio.c stm32_exti_gpio.c stm32_irq.c -CHIP_CSRCS += stm32_lowputc.c stm32_serial.c stm32_rcc.c stm32_lsi.c +CHIP_CSRCS += stm32_lowputc.c stm32_serial.c stm32_rcc.c stm32_lsi.c stm32_uid.c ifneq ($(CONFIG_STM32F0L0G0_RTC_LSECLOCK)$(CONFIG_STM32F0L0G0_LCD_LSECLOCK),) CHIP_CSRCS += stm32_lse.c diff --git a/arch/arm/src/stm32f0l0g0/hardware/stm32g0_memorymap.h b/arch/arm/src/stm32f0l0g0/hardware/stm32g0_memorymap.h index 5c9eb92b550..acb6f6bf8d7 100644 --- a/arch/arm/src/stm32f0l0g0/hardware/stm32g0_memorymap.h +++ b/arch/arm/src/stm32f0l0g0/hardware/stm32g0_memorymap.h @@ -123,6 +123,7 @@ * this address range */ +#define STM32_SYSMEM_UID 0x1fff7590 /* The 96-bit unique device identifier */ #define STM32_SCS_BASE 0xe000e000 #define STM32_DEBUGMCU_BASE 0xe0042000 diff --git a/arch/arm/src/stm32f0l0g0/stm32_uid.c b/arch/arm/src/stm32f0l0g0/stm32_uid.c new file mode 100644 index 00000000000..a57b048b8a7 --- /dev/null +++ b/arch/arm/src/stm32f0l0g0/stm32_uid.c @@ -0,0 +1,47 @@ +/**************************************************************************** + * arch/arm/src/stm32f0l0g0/stm32_uid.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + **************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "hardware/stm32_memorymap.h" + +#include "stm32_uid.h" + +#ifdef STM32_SYSMEM_UID + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void stm32_get_uniqueid(uint32_t *uid) +{ + int i; + + for (i = 0; i < 3; i++) + { + *(uid + i) = *((uint32_t *)(STM32_SYSMEM_UID) + i); + } +} + +#endif /* STM32_SYSMEM_UID */ diff --git a/arch/arm/src/stm32f0l0g0/stm32_uid.h b/arch/arm/src/stm32f0l0g0/stm32_uid.h new file mode 100644 index 00000000000..34661df85de --- /dev/null +++ b/arch/arm/src/stm32f0l0g0/stm32_uid.h @@ -0,0 +1,38 @@ +/**************************************************************************** + * arch/arm/src/stm32f0l0g0/stm32_uid.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32F0L0G0_STM32_UID_H +#define __ARCH_ARM_SRC_STM32F0L0G0_STM32_UID_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void stm32_get_uniqueid(uint32_t *uid); + +#endif /* __ARCH_ARM_SRC_STM32F0L0G0_STM32_UID_H */ \ No newline at end of file