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

Problem with write_program_memory()

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



Joined: 24 Feb 2010
Posts: 22

View user's profile Send private message

Problem with write_program_memory()
PostPosted: Tue May 18, 2010 7:09 am     Reply with quote

Hi all,

I am using a PIC24HJ128GP502 with version 4.107 of the PCD compiler.

I am writing a bootloader and I am trying to save the goto instruction and reset address (located at 0x0000 - 0x0004). My plan is then, after erasing the program memory up to my bootloader, to restore these values so that the PIC will go to the bootloader after a reset.

My code looks something like this at the moment:

Code:
   unsigned int8 goto_val[4] = {0xff, 0xff, 0xff, 0xff};
   unsigned int8 reset_val[4] = {0xff, 0xff, 0xff, 0xff};
   
   //Backup the boot information
   read_program_memory(0x000, goto_val, 4);
   read_program_memory(0x002, reset_val, 4);
   
   //Erase the memory
   //erase_memory();

   //Restore the boot information
   write_program_memory(0x00, goto_val, 4);
   write_program_memory(0x02, reset_val, 4);


And here is my erase function:

Code:
void erase_memory()
{
   unsigned int32 erase;
   
   for (erase = 0; erase < LOADER_START_ADDR; erase += (getenv("FLASH_ERASE_SIZE")/2))
   {
      erase_program_memory(erase);
   }   
}


My problem is, that the values don't get restored after the erase. I does work, however, while I'm debugging with my ICD3, but it won't run correctly on its own.

I tried inserting a delay between the erase and the restore, but that didn't produce any fruit either.

Does anyone know how I can fix this?

[EDIT] Also, I noticed that in the generated HEX file, if the starting address of the user program was 0x200, the HEX file has it as 0x400. Why is that? Is it something I can always expect? Because then I could always subtract 0x200 from the HEX address before writing the value to the program memory.
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