View previous topic :: View next topic |
Author |
Message |
gurdeepsembi
Joined: 22 Dec 2010 Posts: 14 Location: UK
|
Cannot get code protect to work |
Posted: Fri May 13, 2011 4:55 am |
|
|
Hi All,
I am using a PIC18F2520 and cannot get the code protect to work. I have tried the suggestion in topic below with no luck so far:
http://www.ccsinfo.com/forum/viewtopic.php?t=40974&highlight=code+protect
I can still 'read' the code back from the PIC. I am programming the PIC using an MPLAB ICD3. I have set MPLAB to 'Release'. The lst file has the following at the end:
Configuration Fuses:
Word 1: C800 INTRC_IO FCMEN IESO
Word 2: 1917 NOPUT BROWNOUT BORV27 WDT WDT4096
Word 3: 8700 CCP2C1 PBADEN LPT1OSC MCLR
Word 4: 0081 STVREN NOLVP NOXINST NODEBUG
Word 5: 0000 PROTECT CPB CPD
Word 6: E00F NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 0000 EBTR EBTRB
The fuses I have set in my code are:
Code: |
#FUSES WDT //Use Watch Dog Timer
#FUSES WDT4096 //Watch Dog Timer uses 1:4096 Postscale
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES BROWNOUT //Enable brownout reset
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOPUT //No Power Up Timer
#FUSES CPD //EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //Debug mode for use with ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES EBTR //Memory protected from table reads
#FUSES EBTRB //Boot block protected from table reads
#FUSES MCLR //Master Clear pin enabled
#FUSES PROTECT //Code protected from reading
#FUSES CPB //Boot Block code protection
#FUSES NOWRTB //Boot block not write protected
|
Is there anything I am doing wrong?
CCS C Compiler version is PCH Version 4.114
Thanks for your help in advance! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 13, 2011 1:34 pm |
|
|
Try a simple program like this one.
Code: |
#include <18F2620.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP, PROTECT, CPB
#use delay(clock=4M)
//========================================
void main(void)
{
while(1);
} |
|
|
|
gurdeepsembi
Joined: 22 Dec 2010 Posts: 14 Location: UK
|
|
Posted: Mon May 16, 2011 3:45 am |
|
|
Hi PCM Programmer,
Thanks once again for your help. The code was indeed protected. I was just making wrong assumptions.
I thought that if I tried to read from the PIC, MPLAB would give me an error message saying it was unable to read the PIC which does not happen, it just says the read operation is complete.
But after the read operation is complete, if I select View->Program Memory or View->EEPROM then there are only zero's there so it has not read the program back.
All is working OK. Thanks for your help. much appreciated. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon May 16, 2011 4:19 am |
|
|
Normally you would expect to get data back, not zeros, but it to be scrambled.
This is how you 'verify' a chip with code protect.
The sequence is to program and verify the chip with CP off, then enable just the CP fuse(s), and read back the chip. You store what you get. Then in future, you write the chips with CP enabled, and verify them against what you have stored. The same program should always return the same scrambled data, but the 'point' is that what it returns, is not readable, and if you write this to a chip, won't run. Hence 'protected'.
I'd suspect that MPLAB, is hiding the data if it sees the CP fuse(s).
Best Wishes |
|
|
gurdeepsembi
Joined: 22 Dec 2010 Posts: 14 Location: UK
|
|
Posted: Mon May 16, 2011 5:29 am |
|
|
Hi Ttelmah,
Thanks for the info. I tried your method and if CP fuses are OFF then I can read back the program memory and it shows the disassembly listing as well. As soon as I turn ON the CP fuses it only reads back 'zeros'.
I think you may be right in saying MPLAB is masking everything as 'zeros'. In any case it seems to work. If I write back what I have just read, the PIC just sits there doing nothing so it has basically written the zero's to the PIC.
Thanks all for your help, it is much appreciated.
Gurdeep |
|
|
|