CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

#serialize using

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
user77



Joined: 15 Jul 2016
Posts: 4

View user's profile Send private message

#serialize using
PostPosted: Thu Dec 03, 2020 4:13 am     Reply with quote

Hi there, I'm using serialize to assign a serial number to every PIC when programed. My problem is when I update the PIC, it replaces serial number with new one got from file, is there a way to avoid serial number update?
Code:

const unsigned int32 serial=0;
#serialize(id=serial,listfile="serial_list.txt",log="log_file.txt")

Thanks
Bye Massimo
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 03, 2020 5:35 am     Reply with quote

While I've never used that feature, I did read the manual about it.
Since you can tell the compiler where it will be stored, I would think you could simply read and test that EEPROM memory location. IF it's not 0xFFFF then write a 'serial number'. Anything other than 0xFFFF would mean the PIC already has a serial number.
Those that use that feature should reply but it sounds good as I'm typing.

Jay
user77



Joined: 15 Jul 2016
Posts: 4

View user's profile Send private message

PostPosted: Tue Dec 08, 2020 5:03 pm     Reply with quote

yes, I already use this function well, I've think your same solution but I don't know a way to read memory area before program chip and then choose if write or not a new serial number
thanks
Max
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Dec 09, 2020 1:29 am     Reply with quote

Key thing to understand is that this is actually a 'programmer' 'function
not a compiler function. So every time you program the chip it moves
forward through it's generated numbers. The compiler stuff is just a
command to the programmer to do this, so 'of course' it updates the
number when you write a new version.
What you can do, is when you write a new version, use a new serial
number file. So serial_list01.txt for version '01', then serial_list02.txt
for version '02' etc..
It is the programmer code that actually increments the number.
If you want to step the number backwards, then you need to be editing the
serial number file.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Dec 09, 2020 7:03 am     Reply with quote

hmm... had another thought while the coffee is slowly dripping..
I don't use an ICD, so can't use #serialize but...
wondering if something like ....
Code:
#if ( read_eeprom(0) != 0xFF)        //check to see if never used
    {#serialize (file=filename.txt) }   //burn a serial number into it

will work ?

My idea is that the ICD reads the PIC first EEPROM location and if it's NOT 0xff, then burn a serial number into it. This way every PIC gets a unique serial number.

Sorry I can't test my idea....hopefully others will.
Jay
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Dec 09, 2020 8:11 am     Reply with quote

temtronic wrote:
hmm... had another thought while the coffee is slowly dripping..
I don't use an ICD, so can't use #serialize but...
wondering if something like ....
Code:
#if ( read_eeprom(0) != 0xFF)        //check to see if never used
    {#serialize (file=filename.txt) }   //burn a serial number into it

will work ?

My idea is that the ICD reads the PIC first EEPROM location and if it's NOT 0xff, then burn a serial number into it. This way every PIC gets a unique serial number.

Sorry I can't test my idea....hopefully others will.
Jay


That won't work. The #serialize is a directive that the programming software uses/triggers on to read the selected txt file, use the number contained therein to stick into the .hex file at the appropriate place in what corresponds to the EEPROM's corresponding place in memory, then use that modified .hex to burn into the PIC. After it's done, it increments the number in the txt file, saves, and exits. The PIC doesn't run anything, so read_eeprom() isn't an option.

While there may be a Rube Goldberg-type method to use a batch file to invoke the programmer software to read the PIC's EEPROM, then, if it already has a serial number, to insert that number into the txt file, invoke the programmer as normal, then, before exiting, restore the appropriate serial number in the txt file.....I already hate myself for suggesting this.

The best way to preserve a serial number is to use this approach with a bootloader: when you originally program the bootloader "at the factory", the unique serial number will be burned at that point, and hopefully immutable.
user77



Joined: 15 Jul 2016
Posts: 4

View user's profile Send private message

PostPosted: Fri Feb 26, 2021 8:22 am     Reply with quote

newguy wrote:


While there may be a Rube Goldberg-type method to use a batch file to invoke the programmer software to read the PIC's EEPROM, then, if it already has a serial number, to insert that number into the txt file, invoke the programmer as normal, then, before exiting, restore the appropriate serial number in the txt file.....I already hate myself for suggesting this.



Don't hate you, is an interesting idea, can you help me to realize it?
Thanks
Max
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 26, 2021 9:23 am     Reply with quote

I just looked at the options for the PICkit3 programmer I use through MPLAB. It allows ME to select what 'memories' I want to NOT be programmed so....

1st PIC program, using 'serialize' as normal....
Now BEFORE the 2nd and newer updates, select to NOT reburn the ID number or whatever EEPROM areas that have the 'serial number' in.

That way the PIC will have only one number and it should remain there, until a 'complete' erase is done.

I've never tried it but it looks good in my mind.......

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group