About IDLOCS..
Good: Can be read even if device is read-protected (so perfect for firmware version / serial and such)
Bad: Only four bytes, at least on older enhanced mid range (PIC16F1xxx parts).
Not sure if you can also use the upper "byte" so have 4x14 bit. Manual says it shouldn't be possible.. but they are initialized as 0x3FFF when you erase the memory and then written as 0x00YY if you use
#pragma IDLOCx 0xYY
This is just a stupid legacy "hangover." You can indeed use the full range of bits on every baseline and mid-range PIC released in the last 25+ years if your compiler and programmer/bootloader handle it. Microchip tools tend not too support the full bit range.
The reason why microchip tools tend to only use the lowest nibble traces waaayyy back to the code protection method of the first 16C5x family where the three nibbles of the 12-bit IDLOCs were XORed together. The idea was to leave the upper two nibbles as '00' so the IDLOCs could be read by an external programmer even if the device was code protected. Some bozo at microchip decided that this lowest common denominator should apply to every generically related PIC henceforth. It just does not make any sense these days as the IDLOCs are not code protected anymore and even can be ported across erase/programming cycles and can be read at runtime by the firmware. There is no reason other than this stupid legacy issue that the full IDLOC cannot be used.
In the PIC32 with a unique serial number that I have seen the serial number is abbreviated as "UID" in the datasheet.
In any case, probably the quickest and easiest solution is what Mike suggested. A 3rd party programmer that supports adding serialization at program-time bypassing the artificial limitation imposed by microchip tools.
I
JUST programmed the OTP in some dsPICs using the IPE
It was written in the datasheed that the upper byte should be kept at 0xFF for the config words, so they would result in a NOP in case they are excecuted by accident.
I would guess this is also the reason because #pragma IDLOCx uses only 8 bits
Then, assuming the same was true for the OTP memory i kept the upper byte at 0xFF, also because i could then access the serial numbers with PSV (cani? i haven't checked, i assume i can)
but the god damn IPE decided to pack the data so
- can't see the whole thing withjust PSV. Not a tragedy, but still..
- what if WANTED to write 0xFF?? In this case i used ASCII characters for the serial number so i'm good, but still..
that really pissed me off and i did NOT expect that to happen. The IPE manual doesn't mention it.