View previous topic :: View next topic |
Author |
Message |
user77
Joined: 15 Jul 2016 Posts: 4
|
#serialize using |
Posted: Thu Dec 03, 2020 4:13 am |
|
|
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: 9216 Location: Greensville,Ontario
|
|
Posted: Thu Dec 03, 2020 5:35 am |
|
|
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
|
|
Posted: Tue Dec 08, 2020 5:03 pm |
|
|
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: 19480
|
|
Posted: Wed Dec 09, 2020 1:29 am |
|
|
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: 9216 Location: Greensville,Ontario
|
|
Posted: Wed Dec 09, 2020 7:03 am |
|
|
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
|
|
Posted: Wed Dec 09, 2020 8:11 am |
|
|
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
|
|
Posted: Fri Feb 26, 2021 8:22 am |
|
|
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: 9216 Location: Greensville,Ontario
|
|
Posted: Fri Feb 26, 2021 9:23 am |
|
|
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 |
|
|
|