Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Nordic Semiconductor nRF5 based boards #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion MCU.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,23 @@ Todo

# Raspberry Pi Pico - RP2040

Todo
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version=1.3.0
author=Luiz Henrique Cassettari
maintainer=Luiz Henrique Cassettari <[email protected]>
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
Expand Down
11 changes: 11 additions & 0 deletions src/ArduinoUniqueID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion src/ArduinoUniqueID.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down