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

CCS Bootloader Question

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



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

CCS Bootloader Question
PostPosted: Wed Jan 07, 2015 9:09 am     Reply with quote

Hi,

I'm trying to create a bootloader using the CCS example as a template but the following lines don't make sense to me....can anyone shed some light please?

Snippets:

Code:
read_program_memory(getenv("PROGRAM_MEMORY"), rBuffer[0].buffer, ((getenv("FLASH_ERASE_SIZE")/2) - (getenv("PROGRAM_MEMORY") % (getenv("FLASH_ERASE_SIZE")/2)))*2);
                                          erase_program_memory(addr);
                                          write_program_memory(getenv("PROGRAM_MEMORY"), rBuffer[0].buffer, ((getenv("FLASH_ERASE_SIZE")/2) - (getenv("PROGRAM_MEMORY") % (getenv("FLASH_ERASE_SIZE")/2)))*2);


Code:

read_program_memory(getenv("PROGRAM_MEMORY"), rBuffer[0].buffer, ((getenv("FLASH_ERASE_SIZE")/2) - (getenv("PROGRAM_MEMORY") % (getenv("FLASH_ERASE_SIZE")/2)))*2);
                                    write_program_memory(addr, data, count);
                                    write_program_memory(getenv("PROGRAM_MEMORY"), rBuffer[0].buffer, ((getenv("FLASH_ERASE_SIZE")/2) - (getenv("PROGRAM_MEMORY") % (getenv("FLASH_ERASE_SIZE")/2)))*2);


In both cases, they seem to write back the same data they are reading from the chip....for what reason?

Cheers,
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Jan 10, 2015 12:08 pm     Reply with quote

because the flash memory is organized in pages, requires you erase a whole page at a time.

When you're writing out to memory, sometimes you're writing in a page that might already have data before you erase it.

So you have to buffer that data, merge it with the new data (if needed) and then write the whole page back out.


A good example of that is the last page of a lot of PICs where the MCU CONFIG is stored. It's only a few words in some cases versus the page that's 1KB in size.

you have to make sure you read the config words into your buffer, merge with your code that is in the page (but excludes the config addresses) and then write the whole thing back out.

Make sense?
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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