Including core functions inside library

Hello everyone,
I'm currently trying to add support for RPI Pico to ArduinoUniqueID library for a project I'm working on.
After going through the Pico SDK documentation (by the way I'm using the awesome unofficial porting) I understood that Pico somehow implements ID feature and this can be easily accomplished via the pico_get_unique_board_id built-in function. Now onto the real question:

I managed to get the device ID by writing a sketch that includes the specified core library (#include <pico/unique_id.h>), but doing the same inside the UniqueID library ends up returning always zeros. After doing some debug I discovered that even if the .h file was included just fine, his related implementation in the .c file was not linked, exposing the core prototypes but not their respective implementations.

I've already made sure that the library is wrapped to be included in a cpp file, tried to edit the makefiles and moved files around; bringing the core library inside the library folder and including it with a relative path managed to partially solve the issue, but it's a rather undesirable solution. Any idea why this doesn't work? I'll paste the code I've written for some context.
Thank you for your time.

#elif defined(ARDUINO_ARCH_RP2040)
	pico_unique_board_id_t pico;
	for (int i = 0; i <8; i++) {
		id[i] =[i];


did you find a solution?
I have the same issue, pico_get_unique_board_id returning only zeros

(I use the philhower core)

Hello there! It's been quite some time but if I remember correctly the reason why this happens is because the microcontroller ID gets written in memory only after boot, so calling that method before this happens returns only zeros.
The simplest workaround was to create a function that returns the device ID instead of trying to retrieve it asap, so that the above code can be run after the ID gets correctly stored in memory.

If you are intrested, me and my collegues have designed a simple library for this that includes the Pico (as well as other boards). We added some fancy stuff as requirement for other projects, but it's all open source if you want to take a look at it.

that is a helppull information, thank you very much!

nice one, but I only need RP2040 :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.