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

write_program_memory and code protect

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







write_program_memory and code protect
PostPosted: Mon Oct 09, 2006 6:39 am     Reply with quote

Can I use the "write_program_memory" function to write a little area of memory when the fuse PROTECT is set?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 11, 2006 12:45 am     Reply with quote

Quote:

Can I use the "write_program_memory" function to write a little area of
memory when the fuse PROTECT is set ?

See the test program posted below. The PROTECT fuse will set all
the CPx configs bits = 0, which protects all the ROM except for the
"boot block"in the bottom 0x200 bytes. The CPB fuse must be added
to protect the boot block. The test program does that.

Here's the output of the program. First, 8 bytes of the flash memory
are erased, starting at address 0x4000. Then I read it and display it.
It's all FF's, so that proves that it was erased. Then I write some
data to it, and read it back. This proves that you can read and
write to flash memory which is code protected by using the CCS
read_program_memory() and write_program_memory() functions.
Quote:

Flash write size = 8

Flash memory after being erased: FF FF FF FF FF FF FF FF

Flash memory after being written: 01 02 03 04 05 06 07 08


Here's what program memory looks like, when I use the ICD2
to try and read it, after the it's been programmed with the program
below (which has the PROTECT and CPB fuses enabled).
You can't read it. It's protected.
Code:

  0000    0000     NOP
  0002    0000     NOP
  0004    0000     NOP
  0006    0000     NOP
  0008    0000     NOP
  000A    0000     NOP
  000C    0000     NOP
  000E    0000     NOP
  0010    0000     NOP
  etc.


Here's the test program.
Code:

#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP, PROTECT, CPB
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define ROM_ADDR  0x4000

//====================================
void main(void)
{
int8 i;
int8 write_data[8] = {1,2,3,4,5,6,7,8};
int8 read_data[8]  = {0,0,0,0,0,0,0,0};

printf("Flash write size = %u\n\r", getenv("FLASH_WRITE_SIZE"));
printf("\n\r");

// Erase flash memory.
erase_program_eeprom(ROM_ADDR);

// Read flash memory.
read_program_memory(ROM_ADDR, read_data, sizeof(read_data));

// Display it, to show it's erased.
printf("Flash memory after being erased: ");
for(i = 0; i < sizeof(read_data); i++)
    printf("%X ", read_data[i]);
printf("\n\r");
printf("\n\r");

// Now write 8 bytes.
write_program_memory(ROM_ADDR, write_data, sizeof(write_data));

// Read them back.
read_program_memory(ROM_ADDR, read_data, sizeof(read_data));

// Display data read from Flash memory.
printf("Flash memory after being written: ");
for(i = 0; i < sizeof(read_data); i++)
    printf("%X ", read_data[i]);
printf("\n\r");
printf("\n\r");

while(1);
}

I tested this with PCH vs. 3.249.
ckielstra



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

View user's profile Send private message

PostPosted: Wed Oct 11, 2006 1:54 am     Reply with quote

As an additional note:
PICC C Manual, March 2006 wrote:
Some processors allow different levels for certain fuses. To access these levels, assign a value to the fuse. For example, on the 18F452, the fuse PROTECT=6 would place the value 6 into CONFIG5L, protecting code blocks 0 and 3.
picerno
Guest







PostPosted: Wed Oct 11, 2006 2:12 am     Reply with quote

Quote:

See the test program posted below. The PROTECT fuse will set all
the CPx configs bits = 0, which protects all the ROM except for the
"boot block"in the bottom 0x200 bytes. The CPB fuse must be added
to protect the boot block.


It's true, but it is possible on 18FXX only. Ok, if protected, it is impossible.
Thank you
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