Retrieving Serial Number in Firmware not working

I have been using the following code for months, which successfully retrieves the device Serial Number. This is running on many devices, all successfully. All devices are Borons running OS4.0.2

However, after a recent update to one of my devices, this isn't working anymore. I have uploaded this exact code, and the result is shown below. I am pretty stumped as to how this could function on my other devices, and this device, but now does not function.

#include "deviceid_hal.h"

void setup() {

    char tmp[64] = {};
    int sz = hal_get_device_serial_number(tmp, sizeof(tmp), nullptr);
    if (sz > 0) {
        Serial.printf("Device serial: %s", tmp);
    } else {
        Serial.printf("\nDevice serial: unknown (error=%d)", sz);

void loop() {
  // The core of your code will likely live here.



Serial monitor opened successfully:

Device serial: unknown (error=-1)

What could be going on?

EDIT: Just updated the problem device to OS4.1.0, same issue.

The only reasons hal_get_device_serial_number returns -1 are:

  • An error occurred reading the OTP (one-time programmable) memory of the nRF52 MCU. It could be damaged.
  • The 15 bytes of serial number were not all printable ASCII characters. This indicates the serial number field in OTP could be corrupted, since it should have been set to a valid value during manufacturing.

Borons should have the serial number field set. Some older Gen 2 devices don't have a serial number programmed on the device.

Good to know...

This device was reporting correctly, then all of the sudden it wasn't.

So the only two options are corrupted/damaged OTP mem?

Looks like it:

Actually, try using hal_get_device_hw_version. It's several lines down from that. It will return the error code from hal_exflash_read_special which may help narrowing down the problem.

I get 0 when I run my hal_get_device_hw_version test. Not convinced I'm going about it correctly. Can you provide an example?