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 support@ccsinfo.com

Bootloader doesn't write eeprom

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



Joined: 14 Sep 2011
Posts: 2

View user's profile Send private message

Bootloader doesn't write eeprom
PostPosted: Wed Sep 14, 2011 6:29 am     Reply with quote

Hi,
I tried to use the bootloader example and it starts well, interrupts are ok, but in the hex file there's an initial configuration of the eeprom, that bootloader doesn't write...is this normal?

P.S. I'm able to compile the example only with an old version of ccs, not the last.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Sep 14, 2011 6:52 am     Reply with quote

Normal.

Many bootloaders don't write the eeprom. If not then they may be persuaded to with the right options, or maybe commands from the host software.

Even more refuse to write the configuration; mainly as it can make the bootloader die. I made the mistake of trying to load a debug version of application code using a bootloader. It all worked fine up to the moment the loader wrote the config words. Then it stopped dead. Never to run again, at least not by the bootloader. Pretty obvious when you think about it.

Also PICs have various protection built in. These may prevent writing and/or reading of various parts of all the different memory sections. What is protected and what is not varies a lot between different PICs. This protection is controlled by the config words and generally when using a bootloader that means the config which the bootloader was assembled with.

Some bootloaders actually use a byte, generally the last, in eeprom to control whether it runs or your application code does. These are often the type that run in the first part of program memory: the part that can be seperately protected as a boot block just for use with bootloaders. These require you to alter the vectors from normal. The other type of bootloader lives at the top of memory and generally doesn't need you to modify your code (or does the tiny mod for you as it loads). However PICs doesn't provide any special hardware protection for this type of bootloader.

So, yes, its normal. You may be able to set some option in the PC application to tell the loader to load eeprom, but not all bootloaders do.

RF Developer
PwtEma



Joined: 14 Sep 2011
Posts: 2

View user's profile Send private message

PostPosted: Wed Sep 21, 2011 2:28 am     Reply with quote

Thanks for your help.
I have modified the example Very Happy
diogoc



Joined: 12 Feb 2008
Posts: 19

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Wed Mar 26, 2014 4:46 am     Reply with quote

Can you share the modifications for eeprom write?

It should be in this section, but I can't understand how:

Code:
if ((addr < LOADER_ADDR || addr > LOADER_END) && addr < getenv("PROGRAM_MEMORY")){
  for (i = 9,dataidx=0; i < buffidx-3; i += 2)
     data[dataidx++]=atoi_b16(&buffer[i]);

  #if getenv("FLASH_ERASE_SIZE") > getenv("FLASH_WRITE_SIZE")
     if ((addr!=next_addr) && (addr > (next_addr + (getenv("FLASH_ERASE_SIZE") - (next_addr % getenv("FLASH_ERASE_SIZE"))))) && ((addr & (getenv("FLASH_ERASE_SIZE")-1)) != 0)){
       #if ((getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE")) != 0)
          if (addr > (getenv("PROGRAM_MEMORY") - (getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE"))))
          {
             read_program_memory(getenv("PROGRAM_MEMORY"), buffer, getenv("FLASH_ERASE_SIZE") - (getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE")));
             erase_program_eeprom(addr);
             write_program_memory(getenv("PROGRAM_MEMORY"), buffer, getenv("FLASH_ERASE_SIZE") - (getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE")));
          }
          else
       #endif
            erase_program_eeprom(addr);
     }
   
        next_addr = addr + count;
  #endif
           
  #if ((getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE")) != 0)
    if (addr == (getenv("PROGRAM_MEMORY") - (getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE")))){
       read_program_memory(getenv("PROGRAM_MEMORY"), buffer, getenv("FLASH_ERASE_SIZE") - (getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE")));
       write_program_memory(addr, data, count);
       write_program_memory(getenv("PROGRAM_MEMORY"), buffer, getenv("FLASH_ERASE_SIZE") - (getenv("PROGRAM_MEMORY") % getenv("FLASH_ERASE_SIZE")));
    }
    else
  #endif
      write_program_memory(addr, data, count);
}
spilz



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

PostPosted: Thu May 14, 2015 10:19 am     Reply with quote

Hello

Actually I have the same problem in my project.

Did someone find the solution? And can he share it ?

My other question : does the usb bootloader.exe can send it ?
Or do we have to change it too?

Thanks for your help and share

Regards

Spilz
Ttelmah



Joined: 11 Mar 2010
Posts: 19430

View user's profile Send private message

PostPosted: Thu May 14, 2015 12:28 pm     Reply with quote

First understand that the bootloader is only an _example_. You can modify it any way you want.
Writing the EEPROM, is relatively simple. Just look for the address used by it on your chip. Get the programming specification for the chip (from the MicroChip site), and this will tell you the address used. Or the getenv function with 'EEPROM_ADDRESS, will tell you where it is, and modify the limit tests, so that if a byte arrives with an address between EEPROM_ADDRESS, and EEPROM_ADDRESS+EEPROM_SIZE, this is accepted and written, using the EEPROM_WRITE function (instead of the program memory write function). You have to change the function used, because an extra bit has to be set in the write to say that the EEPROM is being written, and the EEPROM doesn't erase in pages.

Generally all bootloader transmission programs do _not_ test the addresses they send (they can't do, since they do not know how large the memory on the target chip is), so will actually happily send the EEPROM data.

Adding this write, _will_ increase the size of the bootloader, so you may well need to change the loader_end address.

It's common to not write the EEPROM with the code, instead have the code do this itself. If (for instance), you are sending configuration data, have the configuration structure declared in the code, with default values, and and have code check when it starts, if the version stored in the EEPROM, is later than the default version, if it is, use this, if not, write the code defaults to the EEPROM. This can then use the same code used to write the values when they change (saving space).
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