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

Eeprom and Bootloader

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



Joined: 18 Dec 2007
Posts: 76

View user's profile Send private message Send e-mail

Eeprom and Bootloader
PostPosted: Tue Oct 27, 2020 1:52 pm     Reply with quote

16F18324, PCW, 5.092
When I program the MAIN PROGRAM with use of my ICD-U64 I can read and write to the Eeprom.
Code:

#include <16F18324.H>     //4096 Words, Last memory at 0FFFh.
#FUSES RSTOSC_HFINTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,BROWNOUT,BORV27,NOCLKOUT, NOFCMEN,NOSTVREN,NODEBUG,NOLVP
#use delay(clock=8000000)
#include <bootloader.h>       // Mag blijven staan, ook in geval van direct programmeren met ICD-U64
#use rs232(ICD, baud=19200, xmit=PIN_A0)                  //Dit werkt met ICD-U64 en Telnet input 38400

int  Temp0=0, Temp1=0, Temp2=0, Temp3=0, Temp4=0;
// This work's fine.
/*
#rom 0xF000  = {1}
#rom 0xF001  = {2}
#rom 0xF002  = {3}
*/
//Or even better
#ROM int8 getenv("EEPROM_ADDRESS") = {1,2,3}

void main()
{
setup_oscillator(OSC_HFINTRC_8MHZ);
set_tris_a(0b00001110);                              //   0 = output                xmit=PIN_A0, rcv=PIN_A1)
set_tris_c(0b00100111);                              //   0 = output
delay_ms(1000);
///////////////////////////////////////////////////////////////////////////////
while (1)
      {
      delay_ms(1000);
      Temp0 = read_eeprom(0);
         printf("%u",Temp0);
      Temp1 = read_eeprom(1);
         printf("  %u",Temp1);
      Temp2 = read_eeprom(2);
         printf("  %u",Temp2);
      printf("\r\n"); 
      //
      delay_ms(1000);
      write_eeprom (0,4);
      write_eeprom (1,5);
      write_eeprom (2,6);
      }
}


RS232 output:
1 2 3
4 5 6
4 5 6
4 5 6



But when I first program the Bootloader by ICD-U64:

Code:

#include <16F18324.H>

#FUSES RSTOSC_HFINTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,BROWNOUT,BORV27,NOCLKOUT,NOFCMEN,NOSTVREN,NODEBUG,NOLVP

#Device ADC=8
#use delay(clock=8000000)                                                       //Fuses and delay are set, so int osc is set at 8Mhz.

#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)     //Text through the UART
#define _BOOTLOADER
//#define BOOTLOADER_MODE2X
#include <bootloader.h>
#include <loader.c>
#org LOADER_END+1,LOADER_END+2

void application(void)
      {
      while(TRUE);
      }

void main(void)
      {
      setup_oscillator(OSC_HFINTRC_8MHZ);
      setup_dac(DAC_OFF);
      setup_vref(VREF_OFF);
      port_a_pullups(0b00001110);    // 2,3,  Led Pin_A1  Xmit op Pin_A0
      port_c_pullups(0b00000111);    // 0,
      set_tris_a(0b00001110);                              //      0 = output     xmit=PIN_A0, rcv=PIN_A1)
      set_tris_c(0b00100111);                              //      0 = output
      delay_ms(10);
      printf("\r\nStarted\r\n");
      //--------
      if    (!input(PIN_A3))
            {
            printf("\r\nBootloader Version 1.0");        // Let the user know it is ready to accept a download
            printf("\r\nWaiting for download...");
            load_program();
            }
      application();
      }

#int_global
void isr(void)
      {
      jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
      }



And then upload the MAIN PROGRAM by RS232 then {1,2,3} is not programmed at the right location. Later on {4,5,6} are saved and can be read without problems.
Code:

#include <16F18324.H>     //4096 Words, Last memory at 0FFFh.
//#FUSES RSTOSC_HFINTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,BROWNOUT,BORV27,NOCLKOUT, NOFCMEN,NOSTVREN,NODEBUG,NOLVP
#FUSES NONE

#use delay(clock=8000000)
#include <bootloader.h>       // Mag blijven staan, ook in geval van direct programmeren met ICD-U64
#use rs232(ICD, baud=19200, xmit=PIN_A0)                  //Dit werkt met ICD-U64 en Telnet input 38400

int  Temp0=0, Temp1=0, Temp2=0, Temp3=0, Temp4=0;
// This work's fine.
/*
#rom 0xF000  = {1}
#rom 0xF001  = {2}
#rom 0xF002  = {3}
*/
//Or even better
#ROM int8 getenv("EEPROM_ADDRESS") = {1,2,3}

void main()
{
setup_oscillator(OSC_HFINTRC_8MHZ);
set_tris_a(0b00001110);                              //   0 = output                xmit=PIN_A0, rcv=PIN_A1)
set_tris_c(0b00100111);                              //   0 = output
delay_ms(1000);
///////////////////////////////////////////////////////////////////////////////
while (1)
      {
      delay_ms(1000);
      Temp0 = read_eeprom(0);
         printf("%u",Temp0);
      Temp1 = read_eeprom(1);
         printf("  %u",Temp1);
      Temp2 = read_eeprom(2);
         printf("  %u",Temp2);
      printf("\r\n"); 
      //
      delay_ms(1000);
      write_eeprom (0,4);
      write_eeprom (1,5);
      write_eeprom (2,6);
      }
}



RS232 output:
Started
4 5 6
4 5 6
4 5 6



Any idea what's wrong?
gaugeguy



Joined: 05 Apr 2011
Posts: 287

View user's profile Send private message

PostPosted: Tue Oct 27, 2020 3:42 pm     Reply with quote

Nothing is wrong. The bootloader will only load operational code, not EEPROM presets. Normally this is what is wanted so that operational code can be updated by the bootloader without losing calibration values or settings in EEPROM.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Oct 28, 2020 1:49 am     Reply with quote

Also, the actual code to write to the EEPROM, is different to the code to write
the program memory, so a 'bootloader' which uses program memory write
instructions, can't write to the EEPROM.
temtronic



Joined: 01 Jul 2010
Posts: 9093
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 28, 2020 5:04 am     Reply with quote

It would be disastrous IF the EEPROM could be rewritten by the bootloader !
As gaugeguy say, typically EEPROM holds config data, either 'presets' or '1time calibration data'...
Say limits for garage door openers (THAT I found out the hard way....),
or say User IDs/Passwords/Login Info (BTW never erase 'all cookies' on your PC !).
Perhaps the PIC has config data for a calibrated analog sensor, that would be lost, requiring a new 'sensor calibration' to be done, but 'on the bench' !
Another could be the GPS location data, or well water level data.


Jay
bschriek



Joined: 18 Dec 2007
Posts: 76

View user's profile Send private message Send e-mail

PostPosted: Wed Oct 28, 2020 5:28 am     Reply with quote

OK, that makes sense!

So the solution is to remove the line underneath from the MAIN PROGRAM and add the line to the Bootloader and then it will run fine from the begin.

Code:
#ROM int8 getenv("EEPROM_ADDRESS") = {1,2,3}


Thank you for your help.
bschriek



Joined: 18 Dec 2007
Posts: 76

View user's profile Send private message Send e-mail

PostPosted: Wed Oct 28, 2020 11:52 am     Reply with quote

Tested and solved!

But another question if you have some time left.
Underneath the first lines of the file BOOTLOADER.H file
//////////////////////////////////////////////////////////////////////////
//// BOOTLOADER.H ////
//// ////
//// This include file must be included by any application loaded ////
//// by the example bootloader (ex_bootloader.c). ////
//// ////
//// The directives in this file relocate the reset and interrupt ////
//// vectors as well as reserving space for the bootloader. ////
//// ////
//// LOADER_END may need to be adjusted for a specific chip and ////
//// bootloader. LOADER_END must be 1 minus a multiple of ////
//// FLASH_ERASE_SIZE. ////
///////////////////////////////////////////////////////////////////////////


But in my case I had to add #include <bootloader.h>
To the Bootloader and MAIN PROGRAM file. Is this right?

And 2nd question, what value must be used for LOADER_END in my case?
I didn't changed this value and still everything works fine.

Thank you again and I hope this clarifies the bootloader for others too.
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