From fd7611f144fb778d7908fe08cd3285334c151843 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Mon, 13 Mar 2023 12:52:10 +0100 Subject: [PATCH] arch/nrf53: add UID support --- arch/arm/src/nrf53/Make.defs | 1 + .../nrf53/hardware/nrf53_memorymap_cpuapp.h | 2 +- arch/arm/src/nrf53/nrf53_uid.c | 51 +++++++++++++++++++ arch/arm/src/nrf53/nrf53_uid.h | 36 +++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 arch/arm/src/nrf53/nrf53_uid.c create mode 100644 arch/arm/src/nrf53/nrf53_uid.h diff --git a/arch/arm/src/nrf53/Make.defs b/arch/arm/src/nrf53/Make.defs index c12dc5421f..659da945dd 100644 --- a/arch/arm/src/nrf53/Make.defs +++ b/arch/arm/src/nrf53/Make.defs @@ -25,6 +25,7 @@ CHIP_CSRCS += nrf53_systick.c endif CHIP_CSRCS += nrf53_start.c nrf53_clockconfig.c nrf53_irq.c nrf53_utils.c CHIP_CSRCS += nrf53_allocateheap.c nrf53_lowputc.c nrf53_gpio.c +CHIP_CSRCS += nrf53_uid.c ifeq ($(CONFIG_NRF53_APPCORE),y) CHIP_CSRCS += nrf53_oscconfig.c diff --git a/arch/arm/src/nrf53/hardware/nrf53_memorymap_cpuapp.h b/arch/arm/src/nrf53/hardware/nrf53_memorymap_cpuapp.h index 288d75f19c..9618d1bf62 100644 --- a/arch/arm/src/nrf53/hardware/nrf53_memorymap_cpuapp.h +++ b/arch/arm/src/nrf53/hardware/nrf53_memorymap_cpuapp.h @@ -100,7 +100,7 @@ #define NRF53_VMC_BASE 0x50081000 #define NRF53_CACHEDATA_BASE 0x00F00000 #define NRF53_CACHEINFO_BASE 0x00F00000 -#define NRF53_FCIR_BASE 0x00FF0000 +#define NRF53_FICR_BASE 0x00FF0000 #define NRF53_UICR_BASE 0x00FF8000 #define NRF53_CTI_BASE 0xE0042000 #define NRF53_TAD_BASE 0xE0080000 diff --git a/arch/arm/src/nrf53/nrf53_uid.c b/arch/arm/src/nrf53/nrf53_uid.c new file mode 100644 index 0000000000..c471d99251 --- /dev/null +++ b/arch/arm/src/nrf53/nrf53_uid.c @@ -0,0 +1,51 @@ +/**************************************************************************** + * arch/arm/src/nrf53/nrf53_uid.c + * + * 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 "arm_internal.h" +#include "nrf53_uid.h" + +#include "hardware/nrf53_ficr.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void nrf53_get_uniqueid(uint8_t uniqueid[]) +{ + uint32_t uid0 = getreg32(NRF53_FICR_BASE + + NRF53_FICR_INFO_DEVICEID0_OFFSET); + uint32_t uid1 = getreg32(NRF53_FICR_BASE + + NRF53_FICR_INFO_DEVICEID1_OFFSET); + + uniqueid[0] = (uint8_t)((uid0 >> 0) & 0xff); + uniqueid[1] = (uint8_t)((uid0 >> 8) & 0xff); + uniqueid[2] = (uint8_t)((uid0 >> 16) & 0xff); + uniqueid[3] = (uint8_t)((uid0 >> 24) & 0xff); + uniqueid[4] = (uint8_t)((uid1 >> 0) & 0xff); + uniqueid[5] = (uint8_t)((uid1 >> 8) & 0xff); + uniqueid[6] = (uint8_t)((uid1 >> 16) & 0xff); + uniqueid[7] = (uint8_t)((uid1 >> 24) & 0xff); +} diff --git a/arch/arm/src/nrf53/nrf53_uid.h b/arch/arm/src/nrf53/nrf53_uid.h new file mode 100644 index 0000000000..4d53e8baed --- /dev/null +++ b/arch/arm/src/nrf53/nrf53_uid.h @@ -0,0 +1,36 @@ +/**************************************************************************** + * arch/arm/src/nrf53/nrf53_uid.h + * + * 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_NRF53_NRF53_UID_H +#define __ARCH_ARM_SRC_NRF53_NRF53_UID_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void nrf53_get_uniqueid(uint8_t uniqueid[]); + +#endif /* __ARCH_ARM_SRC_NRF53_NRF53_UID_H */