From b241543d3d787e6156b46a2a006a11ce48b173dd Mon Sep 17 00:00:00 2001 From: Ricky Cheung Date: Sat, 11 Jan 2025 00:07:26 +0800 Subject: [PATCH] Add support for Nordic Semiconductor nRF5 based boards The BSP comes from https://github.com/sandeepmistry/arduino-nRF5, which provides only NRF5x_SERIES variable for identification. Update messaging around the project also to reflect the addition of support. Signed-off-by: Ricky Cheung --- MCU.md | 21 ++++++++++++++++++++- README.md | 3 ++- library.properties | 2 +- src/ArduinoUniqueID.cpp | 11 +++++++++++ src/ArduinoUniqueID.h | 6 +++++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/MCU.md b/MCU.md index 63ee1aa..0ca6b2d 100644 --- a/MCU.md +++ b/MCU.md @@ -113,4 +113,23 @@ Todo # Raspberry Pi Pico - RP2040 -Todo \ No newline at end of file +Todo + +# Nordic Semiconductor nRF5 based boards + +Unique ID copies the `DEVICEID` information from a struct located at a specific memory location provided by the BSP ([NRF_FICR_Type](https://github.com/sandeepmistry/arduino-nRF5/blob/master/cores/nRF5/SDK/components/device/nrf52.h#L713)). + +| UniqueID8 | nRF5 | +| :-------: | :------: | +| Byte 0| Byte 0 | +| Byte 1| Byte 1 | +| Byte 2| Byte 2 | +| Byte 3| Byte 3 | +| Byte 4| Byte 0 | +| Byte 5| Byte 1 | +| Byte 6| Byte 2 | +| Byte 7| Byte 3 | + +## Tested Microcontroller + +* Micro:bit diff --git a/README.md b/README.md index 9e594c9..6323c50 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ArduinoUniqueID -This Library gets the Unique ID / Manufacture Serial Number from the Atmel AVR, SAM, SAMD, STM32, and ESP Microcontroller. +This Library gets the Unique ID / Manufacture Serial Number from the Atmel AVR, SAM, SAMD, STM32, ESP and nRF5 Microcontroller. [![Compile Sketch](https://github.com/ricaun/ArduinoUniqueID/actions/workflows/Compile-Sketch.yml/badge.svg)](https://github.com/ricaun/ArduinoUniqueID/actions) @@ -16,6 +16,7 @@ ArduinoUniqueID supports the [Microcontrollers](MCU.md). * Espressif ESP * Teensy * Raspberry Pi Pico - RP2040 +* Nordic Semiconductor nRF5 based boards (e.g. Micro:bit) # Installation diff --git a/library.properties b/library.properties index bcf3010..14e2bd1 100644 --- a/library.properties +++ b/library.properties @@ -3,7 +3,7 @@ version=1.3.0 author=Luiz Henrique Cassettari maintainer=Luiz Henrique Cassettari sentence=Arduino Library to gets the Manufacture Serial Number from the Atmel AVR, SAM, SAMD, STM32, and ESP Microcontroller. -paragraph=The ArduinoUniqueID Library use the buildin feature to select the manufacture serial number from the microcontroler. Suported microcontroler: Atmega328pb, Atmega328p, Atmega2560, Attiny85, SAM3X8E, SAMD21, STM32, ESP8266 & ESP32. +paragraph=The ArduinoUniqueID Library use the buildin feature to select the manufacture serial number from the microcontroler. Suported microcontroler: Atmega328pb, Atmega328p, Atmega2560, Attiny85, SAM3X8E, SAMD21, STM32, ESP8266, ESP32 & nRF5. category=Other url=https://github.com/ricaun/ArduinoUniqueID architectures=avr, esp8266, esp32, sam, samd, stm32, rp2040, mbed_rp2040, mbed_nano, teensy diff --git a/src/ArduinoUniqueID.cpp b/src/ArduinoUniqueID.cpp index 1b2044b..ccc7f41 100644 --- a/src/ArduinoUniqueID.cpp +++ b/src/ArduinoUniqueID.cpp @@ -191,6 +191,17 @@ ArduinoUniqueID::ArduinoUniqueID() id[8] = SIGROW.SERNUM8; id[9] = SIGROW.SERNUM9; +#elif defined(NRF51_SERIES) || defined(NRF52_SERIES) || defined(NRF53_SERIES) + NRF_FICR_Type ficr = *NRF_FICR; + id[0] = ficr.DEVICEID[0] >> 24; + id[1] = ficr.DEVICEID[0] >> 16; + id[2] = ficr.DEVICEID[0] >> 8; + id[3] = ficr.DEVICEID[0]; + id[4] = ficr.DEVICEID[1] >> 24; + id[5] = ficr.DEVICEID[1] >> 16; + id[6] = ficr.DEVICEID[1] >> 8; + id[7] = ficr.DEVICEID[1]; + #endif } diff --git a/src/ArduinoUniqueID.h b/src/ArduinoUniqueID.h index 653afb0..9d5a8d2 100644 --- a/src/ArduinoUniqueID.h +++ b/src/ArduinoUniqueID.h @@ -24,8 +24,9 @@ #include "pico/bootrom.h" } #elif defined(ARDUINO_ARCH_MEGAAVR) +#elif defined(NRF51_SERIES) || defined(NRF52_SERIES) || defined(NRF53_SERIES) #else -#error "ArduinoUniqueID only works on AVR, SAM, SAMD, STM32, Teensy, RP2040, megaAVR and ESP Architecture" +#error "ArduinoUniqueID only works on AVR, SAM, SAMD, STM32, Teensy, RP2040, megaAVR, nRF5 and ESP Architecture" #endif #if defined(ARDUINO_ARCH_AVR) @@ -65,6 +66,9 @@ #elif defined(ARDUINO_ARCH_MEGAAVR) #define UniqueIDsize 10 #define UniqueIDbuffer 10 +#elif defined(NRF51_SERIES) || defined(NRF52_SERIES) || defined(NRF53_SERIES) +#define UniqueIDsize 8 +#define UniqueIDbuffer 8 #endif #define UniqueID8 (_UniqueID.id + UniqueIDbuffer - 8)