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 support@ccsinfo.com

MPLAB ICD2 programming without overwriting the EEPROM data

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



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

MPLAB ICD2 programming without overwriting the EEPROM data
PostPosted: Thu Dec 03, 2009 9:45 am     Reply with quote

Dear,

Has someone ever programmed the program memory of a PIC with MPLAB 7.62 and ICD2 without overwriting the internal EEPROM data of the PIC?
I have to update the program but the calibration data stored in the EEPROM must not be affected.

I tried several settings in the Programmer/Settings/Program tab of MPLAB but all settings failed. I have no bootloader implemented, so I only can use the ICD2.

Any ideas?

Best regards
nilsener
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 03, 2009 2:03 pm     Reply with quote

This thread explains where to find the settings:
http://www.ccsinfo.com/forum/viewtopic.php?t=33108&start=1
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Fri Dec 04, 2009 1:42 am     Reply with quote

Dear PCM,

Thanks for your answer but have you really tried it with a PIC?

I tried it as described with the "Preserve EEPROM on Program" checkbox but EEPROM is deleted after programming nevertheless.

I have no other idea what to do.

Best regards
nils
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 04, 2009 2:03 am     Reply with quote

1. Post a short (15 lines max), complete, compilable program that shows
the problem.

2. Post your compiler version.

3. Post your procedure for doing the test, including using MPLAB.

4. Post how you know it that it's failing.
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Fri Dec 04, 2009 2:29 am     Reply with quote

Dear PCM,

1. The program has more than 4000 lines, unfortunately I can not post it.
2. Compiler PCH 4.014
3+4. I calibrate the point 4.00 mA and 20.00 mA of an analogue output 4-20 mA and store the data in the EEPROM. After power off and on the data are still ok, output shows 4.00 mA. I can see the calibrated value 220 for 4.00 mA in the EEPROM on a digital display connected to the PIC. Then programming with "manually select memory and ranges" active and checkbox "Preserve EEPROM on Program" enabled. After that the calibration data are lost, analogue output shows 3.84 mA and if I check calibration data with the display I see that it is overwritten. So I am 100% sure that data are overwritten.

If I disable the checkbox "Erase all before Program" the EEPROM data are OK after programming but then the verify of the program memory fails. I think "Erase all before Program" erases the program memory and the EEPROM and this may be the problem. This checkbox must be splitted into two checkboxes, one for program memory and one for EEPROM but I can not believe that is is impossible to "Preserve EEPROM on Program"?!

Best regards
Nils
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 04, 2009 3:05 am     Reply with quote

You don't have to post a 4000 line program. Just invent a short little
program that demonstrates the problem. You don't need to do
the actual calibration. Just invent some data. Examples:
http://www.ccsinfo.com/forum/viewtopic.php?t=19607&start=1
http://www.ccsinfo.com/forum/viewtopic.php?t=32722&start=1
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Fri Dec 04, 2009 3:52 am     Reply with quote

I found the problem,

if have "#fuses CPD" set that means that EEPROM is code protected.

It seems that MPLAB reads the EEPROM first if checkbox "Preserve EEPROM on Program" is enabled and then reprograms the EEPROM with the read data.

Procedure seems to be:
- read EEPROM
- erase whole part
- write EEPROM
- write program memory

I thougt if checkbox "Preserve EEPROM on Program" is enabled MPLAB simply leaves the EEPROM untoughed.

With "#fuses CPD" MPLAB can not read the EEPROM.

The new problem now is, how to save the EEPROM from being overwritten if "#fuses CPD" is set as it is in the program that should be updated?

Best regards
Nils
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Mon Dec 07, 2009 8:29 am     Reply with quote

Dear,

is anyone here who has an idea how to solve my new problem caused by "#fuses CPD" set? Please have a look to my last message above.

The new problem now is, how to save the EEPROM from being overwritten if "#fuses CPD" is set as it is in the program that should be updated?

The settings "Preserve EEPROM on Program" in MPLAB 7.62 seems not to work with "#fuses CPD" set as the EEPROM is "Code Protected" then and MPLAB can not read it.

Best regards
Nils
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 07, 2009 2:19 pm     Reply with quote

Then post a little program so I can test it. Look at the links that I gave
you to see an example of how to make a short test program.
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Tue Dec 08, 2009 2:04 am     Reply with quote

Ok, here are 2 samples:

the first code writes 0xAA to address 0 of the EEPROM and the 2nd code only reads the EEPROM and is to update of the software.

"#fuses CPD" is set = EEPROM is code protected.
Measuring PIN B5 it has high signal so data are written successful.

Code:

#include<18F2520.h>
#device ADC=10 *=16

#IF  getenv("VERSION") != 4.014
#ERROR  wrong Compiler version, use Version 4.014
#ENDIF

#use standard_io(A)
#use fast_io(B)
#use fast_io(C)
#use standard_io(E)
#use delay (clock = 8000000, RESTART_WDT)

#include <stdlib.h>

#fuses HS,NOWDT,PUT,PROTECT,NOMCLR,CPD,BROWNOUT,NOIESO,NOFCMEN,NODEBUG,INTRC_IO,NOLVP

#ID CHECKSUM                                                 // ID bytes are checksum
#ZERO_RAM                                         

void main()
{                              
set_tris_b(0);                              
write_eeprom(0,0xAA);

while(1)
{

if (read_eeprom(0) == 0xAA) output_bit (PIN_B5,1);
else output_bit (PIN_B5,0);

}// End while(1)
} /* End of main*/


Then update the code with "preserve EEPROM on program" enabled.
"#fuses NOCPD" is set = EEPROM is not code protected.
Program only reads the EEPROM.
Measuring PIN B5 it has low signal so data are lost.
Reading the EEPROM with MPLAB has the same result. Data are lost.

Code:

#include<18F2520.h>
#device ADC=10 *=16

#IF  getenv("VERSION") != 4.014
#ERROR  wrong Compiler version, use Version 4.014
#ENDIF

#use standard_io(A)
#use fast_io(B)
#use fast_io(C)
#use standard_io(E)
#use delay (clock = 8000000, RESTART_WDT)

#include <stdlib.h>

#fuses HS,NOWDT,PUT,PROTECT,NOMCLR,NOCPD,BROWNOUT,NOIESO,NOFCMEN,NODEBUG,INTRC_IO,NOLVP

#ID CHECKSUM                                                 // ID bytes are checksum
#ZERO_RAM                                         

void main()
{                              
set_tris_b(0);                              

while(1)
{

if (read_eeprom(0) == 0xAA) output_bit (PIN_B5,1);
else output_bit (PIN_B5,0);

}// End while(1)
} /* End of main*/


The problem seems to be the MPLAB programming procedure:
- read EEPROM (reads garbage becase EEPROM is code protected
- erase whole PIC (program memory and EEPROM)
- write EEPROM (writes the garbage from above)
- write program memory.

MPLAB programming procedure should be:
- erase program memory only
- write program memory
Ttelmah
Guest







PostPosted: Tue Dec 08, 2009 9:23 am     Reply with quote

This is not an MPLAB problem, but a problem with what you are trying to do.

To erase any protection fuse, a full chip erase has to be performed.
Because you have 'protect' selected, for the code memory, the programmer can't perform a verify. Hence it _has_ to erase this fuse, implying a full chip erase is needed. It therefore tries to perform what you are asking for, and save the EEPROM first, but because this is protected, it can't read it....
What you want, can't be done within the bounds of the protection abilities of the chip. It _may_ be possible for the programmer to do what you want, if you run without the protect fuse, but with both this and CPD set, it is not possible to program and verify the code memory, while retaining the EEPROM.

Best Wishes
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Tue Dec 08, 2009 9:43 am     Reply with quote

Hello Ttelmah,

Thanks for answer. I found the following in the 18F2520 datasheet:

"Code protection bits are only set to '1' by a full chip erase or block erase function. The full chip erase and block erase functions can only be initiated via ICSP or an external programmer."

I think if the ICSP initiates a block erase of the program memory instead of a full chip erase, the code protection bit for the program memory should be set to '1' (disabled) and the content of EEPROM should be untouched. After that programming of the program memory should be possible.

Do you agree?

http://ww1.microchip.com/downloads/en/DeviceDoc/39622k.pdf
on page 16 at TABLE 3-1: BULK ERASE OPTIONS

There are options for chip erase as well as for block erase.

I am still searching for a solution to make the block erase with any ICSP.

Best Regards
nilsener
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 08, 2009 2:34 pm     Reply with quote

One question is, why do you care if the eeprom data is Code Protected ?
Do you really care if someone can read your calibration data ? What
can they do with it, without the main program which is code protected ?

Don't you really just want to Write-Protect the eeprom, to prevent your
calibration data from being accidentally over-written ? This can be done
with the WRTD fuse. To my mind, this would be the quick and easy
solution to your problem.
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Wed Dec 09, 2009 1:32 am     Reply with quote

Dear PCM,

From this point of view the code protection of the EEPROM is an error. We make future projects without the code protection. But this earlier project has the code protection and so I have to search for a solution to update the program memory without touching the EEPROM.

Best Regards
nilsener
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Mon Dec 14, 2009 12:23 pm     Reply with quote

Now I build my own incircuit programmer using a PIC and try to bulk erase the program memory of the 18F2520 as it is described in

http://ww1.microchip.com/downloads/en/DeviceDoc/39622k.pdf

on page 16 at TABLE 3-1: BULK ERASE OPTIONS with modified code from TABLE 3-2.

It works very well as long as the code protection bit for Data EEPROM is disabled (CPD=1) at the target device. After that I make a blank check with MPLAB ICD2 and program memory is really erased.

Then I try the same code, but CPD=0 at the target device, and then bulk erasing of program memory fails. Blank check with MPLAB ICD2 fails.

I think this makes absolutely no sense. Why should the CPD bit, that is exclusively to code protect only the data EEPROM, influence any program memory bulk erase operation? So now I think there is a silicon problem with the 18F2520 and it will be very difficult or may be impossible for me to proceed in what I want to do.

I read something that some PIC's have problems to erase the data EEPROM if Vdd is below 4,5V. Tomorrow I will try to erase the entire chip with Vdd = 2V and hope that EEPROM data will retain then. I let you know.

Best Regards
nilsener
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