The CCS tool suite has a number of features to help adding serial numbers to product firmware. In your source code the primary method uses the pre-procssor directive #serialize. The CCS device Adding Serial Numbers to Production Images. The CCS tool suite has a number of features to help adding serial numbers to product firmware. In your source code the primary method uses the pre-processor directive #serialize. The CCS device programmers must be used to take advantage of this feature. It works by adding a special comment line to the hex file.
Location of the serial number
The usual way to handle the location is to use a const declaration like one of the following:
const int32 serial_number;
const char sn;
Then in #serialize add something like id=serial_number.
You can also place the serial number in EEPROM by specifying an address like:
Usually the format can be figured out from the const however you can specify it using one of:
binary=x - x is the number of bytes.
string=x - x is the number of characters.
unicode=n - If n is a 0, the string format is normal unicode.
For n>0 n indicates the string number in a USB descriptor.
Serial number source
There are four ways to specify where the serial number comes from:
file="filename.txt" - The file x is used to read the initial serial number from, and this file is updated by the ICD programmer. It is assumed this is a one line file with the serial number. The programmer will increment the serial number.
listfile="filename.txt" - The file x is used to read the initial serial number from, and this file is updated by the ICD programmer. It is assumed this is a file one serial number per line. The programmer will read the first line then delete that line from the file.
next="x" - The serial number X is used for the first load, then the hex file is updated to increment x by one.
prompt="text" - If specified the user will be prompted for a serial number on each load. If used with one of the above three options then the default value the user may use is picked according to the above rules.
log=xxx - A file may optionally be specified to keep a log of the date, time, hex file name and serial number each time the part is programmed. If no id=xxx is specified then this may be used as a simple log of all loads of the hex file.
//Prompt user for serial number to be placed at address of serialNumA
//Default serial number = 200
int8 const serialNumA=100;
//Adds serial number log in seriallog.txt
//Retrieves serial number from serials.txt
//Place serial number at EEPROM address 0, reserving 1 byte
#serialize(dataee=0,binary=1,next="45",prompt="Put in S/N")
//Place string serial number at EEPROM address 0, reserving 2 bytes
prompt="Put in S/N")
USB_STRING_DESC is a table of USB strings and is read by the CCS C Compiler's USB stack when the host PC reads a string from the PIC®. A value of 3 is passed to the Unicode parameter, to tell the #serialize that the serial number should be encoded as a Unicode string and that it should overwrite the 4th string in USB_STRING_DESC (the first string in USB_STRING_DESC is 0). In the device descriptor for your USB device, the field identifying which string to use for the serial number should also have been set to 3.
#serialize(id=USB_STRING_DESC, unicode=3, prompt="SN#")
Using a CCS device programmer but not the compiler?
The same features can be used by editing the hex file using the CCSload utility. Select the FILE page and then SERIAL NUMBERS and you can fill in manually the parameters:
Save or Save-As the hex file and the serial number works as it did with the compiler directives.
Like us on Facebook. Follow us on Twitter.
CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit https://www.ccsinfo.com.
PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.