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

Code protection with MPLAB 7.60 and CCS 4.064

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



Joined: 18 Sep 2008
Posts: 9
Location: Gothenburg

View user's profile Send private message

Code protection with MPLAB 7.60 and CCS 4.064
PostPosted: Tue Apr 07, 2009 3:12 am     Reply with quote

Hello,

I've been sitting all day trying to make MPLAB to enable code protection with little to no success. The CPU on the boards I'm programming are PIC18F65J10 and 67J10 and I've tried with #fuses PROTECT and setting it through the configuration bits window. Neither works as they should. Right now it looks like I'm going to have to manually patch the intel hex files at 0x7FF9 after compilation to clear the proper bit.

Am I missing something here? Has anyone else had this problem and if so, how did you resolve it?

Thanks in advance,
Axel Lindholm - Software engineer @ Martinsson Electronics
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Apr 07, 2009 6:08 am     Reply with quote

When you post a small example program we can test your problem. Right now it is guessing:
- MPLAB 7.60 is quiet old, why don't you use the newer 8.30 version?
- Do you have ICD=TRUE in your code? This will affect several fuses settings. Remove this line.

- Is the problem in the hex file or when programming?
- Which programmer are you using?
Axel



Joined: 18 Sep 2008
Posts: 9
Location: Gothenburg

View user's profile Send private message

PostPosted: Tue Apr 07, 2009 6:31 am     Reply with quote

Thanks for the quick reply!

The reason for not using 8.30 is simply that it's the version we run where I work. Company policy simply, stupid as it may sound.

Yes, I do have ICD=TRUE

The problem is that the generated hex file contains a CONFIG1H register with bit 2 set (code-protection disabled).

I'm using the MPLAB ICD2 programmer.

I just tried removing the ICD=TRUE line and it works! Thank you very much for this bit of info. I'm not sure I'm going to use this tho since I found that clearing the bit manually with read/write_program_memory() does the trick and we'll be able to retrofit boards which has already been delivered with a non-protective bootloader this way. However, I'd really like to know why ICD=TRUE screwed things up for me. I suspect it may have something to do with the flash verification when programming the chip, or am I way off?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Apr 07, 2009 6:53 am     Reply with quote

I never fully understood the use of the ICD=TRUE function. Like I mentioned, it does modify several fuses and maybe more. For example some of the old PIC16 processors require a NOP instruction at address 0 for the ICD to work correctly.

I don't like the implicit and hidden functionality, all required changes can be made with other commands and than you can see what is happening. For this reason I don't use the ICD=TRUE command in my code.

Quote:
However, I'd really like to know why ICD=TRUE screwed things up for me. I suspect it may have something to do with the flash verification when programming the chip, or am I way off?
ICD=TRUE overrules the PROTECT fuse setting in your program. And yes, I guess this has to do with FLASH memory verification or some other debug related issue. In some way it makes sense, by setting ICD=TRUE you are telling the compiler you are in the debugging phase of your program development. For a final customer release you would have to change this setting to FALSE.
bsturm



Joined: 23 Feb 2009
Posts: 29

View user's profile Send private message

PostPosted: Tue Apr 07, 2009 8:04 pm     Reply with quote

I just learned something about the #device ICD=TRUE statement. I did not include it and the compiler mapped one of my variables into a reserved area of memory for the debugger. My program was behaving erratically and the watch window showed reserved memory instead of a value.

I found an option in MPLAB to turn on this +ICD fuse and the variable was OK. I then found it easier to add the line #device ICD=TRUE and comment it so I could remember to remove it for production.
picdigger



Joined: 06 Apr 2009
Posts: 7

View user's profile Send private message

PostPosted: Wed Apr 08, 2009 7:46 am     Reply with quote

It is quite useful to check the fuse settings made by MPLAB using Configure->Configuration bits. Sometimes it's "funny" what you find there. Its a good way to "play" with the fuses without to start a real debug session.

BTW, the NOP operation needed at the program start will be replaced by a jump to the "debug-session" if the debugger will used.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Sun Apr 12, 2009 2:47 am     Reply with quote

Axel wrote:

The reason for not using 8.30 is simply that it's the version we run where I work. Company policy simply, stupid as it may sound.

You are lucky. We here use a russian ENIAC-clone scavanged from a junkyard by our company founder in the late 50s, (don't ask why, it's simply a company policy).

We are two dozen of engineers trying to make the Eniac's built-in 'IDE' work with a PIC32, with 2 years of work we have managed to use the Eniac's power supply, and it can also reset the PIC sometime (not reliably yet). However we are stuck with programming thru ICSP.. But our budget is running low now. ...please anybody give a clue Smile
picdigger



Joined: 06 Apr 2009
Posts: 7

View user's profile Send private message

PostPosted: Mon Apr 13, 2009 11:48 pm     Reply with quote

Sounds strange, especially the RESET issue.

- Is the physical interface right, cross check it with the several AppNotes available from Microchip
- Is the clock stable? Use an oscillator to check this.
- Have you ever checked the ICSP using an oscilloscope? May be there are issues like:
-- voltage levels, ripple
-- timing variances (setup-hold-times)
-- clock too high if lines are too long
- Check the generated code using the mixed view (C+ASM) if there is still debug code included
Sergio



Joined: 16 Oct 2003
Posts: 11
Location: Arkansas, USA

View user's profile Send private message

PostPosted: Tue Apr 14, 2009 12:35 pm     Reply with quote

Hi Libor:

I'm real curious what you are using the ENIAC clone for and why.
_________________
Sergio
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 14, 2009 12:40 pm     Reply with quote

It was a joke. You guys are taking his sarcasm seriously.
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