|
|
View previous topic :: View next topic |
Author |
Message |
Geps
Joined: 05 Jul 2010 Posts: 129
|
CCS Bootloader Question |
Posted: Wed Jan 07, 2015 9:09 am |
|
|
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
|
|
Posted: Sat Jan 10, 2015 12:08 pm |
|
|
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 |
|
|
|
|
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
|