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

Bootloader on PIC18F45K22
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
haxan7



Joined: 27 Jul 2013
Posts: 79

View user's profile Send private message

PostPosted: Sun Jun 29, 2014 12:57 pm     Reply with quote

Going to the device manager and turning on the Flow Control and disabling the FIFO buffer did not work.

I noticed that there is an option of transmit delay in Tera Term, I turned on the transmit delay of 2 ms/char and voila the boot-loader updated successfully. And is working fine now.

I think that the problem is due to Windows 8 on my system.


Thanks PCM programmer, temtronic and Ttelmah for all your help.
CYembedded



Joined: 31 Jan 2015
Posts: 6

View user's profile Send private message

PostPosted: Sat Jan 31, 2015 5:46 am     Reply with quote

Hi,
I have a problem with 45k22 bootloader.
I wrote the bootloader.hex into the pic and it works fine.

But the problem is when I loaded the application hex file after the bootloader
and reset the pic, my application doesnt work.

What is the main problem? how can I solve it?

Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Sat Jan 31, 2015 9:35 am     Reply with quote

Impossible for use to guess. No data.

One possibility is that you are not including bootloader.h when you compile the application. Look at how bootload.c is setup. You can't just compile an ordinary application, and use it with a bootloader. The application _must_ be compiled to work with the bootloader.
CYembedded



Joined: 31 Jan 2015
Posts: 6

View user's profile Send private message

PostPosted: Mon Feb 02, 2015 3:49 am     Reply with quote

Hi,
my app program includes bootloader.h
but the program doesn't work.

My bootloader:

Code:

#include <main.h>
#fuses HSH,NOWDT,NOPROTECT,NOPLLEN
#use delay(internal=16MHz)
#use rs232(baud=9600, xmit=PIN_D6, rcv=PIN_D7, ERRORS)
#define PUSH_BUTTON PIN_A1

#define _bootloader

#include <bootloader.h>
#include <loader.c>

#if defined(__PCH__)
#org 0x40,0x9F
#else
#org 0x20,0x3F
#endif

void application(void)
{
   output_high(pin_b5);
   printf("\r\napplication...");
  while(TRUE);
}

void main()
{
   output_high(pin_b5);
   if(!input(PUSH_BUTTON))
   {
      printf("\r\nBootloader Version 1.0\r\n");
   
      // Let the user know it is ready to accept a download
      printf("\r\nWaiting for download...");
      load_program();
      printf("\r\n!!!");
   }

   application();
}



My application program:

Code:

#include <main.h>
#fuses HSH,NOWDT,NOPROTECT,NOPLLEN
#use delay(internal=16MHz)
#use rs232(baud=9600, xmit=PIN_D6, rcv=PIN_D7, stream=rs232, ERRORS)

#include <bootloader.h>

#use fast_io(b)

void main()
{
   
   int8 i;
   output_high(pin_b5);
   delay_ms(200);
   
   fprintf(rs232, "\r\nApplication Version 1.0\r\n");

   while(TRUE)
      printf(rs232, "%u ",++i);
}


I load the application program but I cannot see the "Application Version 1.0" from the serial.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Mon Feb 02, 2015 4:00 am     Reply with quote

Two things:

First your fuses. You have an external high speed crystal selected, _and_ the internal oscillator. Only one can be right. If you are running the internal oscillator get rid of the HSH fuse.

Then you are loading the 'application' in the bootloader at the wrong location. It has to sit where the 'real' code will sit when it is loaded by the bootloader, or the vectoring won't jump to it (so the real code won't run). This #ORG, creates a 'stub' so the bootloader knows where the real code it. You are placing it down inside the bootloader's memory space.
This is the killer.....

Put back the version out of the bootloader code:
Code:

#if defined(__PCM__)
 #org LOADER_END+1,LOADER_END+2
#elif defined(__PCH__)
 #org LOADER_END+2,LOADER_END+4
#endif
void application(void) {
  while(TRUE);
}

Note that this creates the 'dummy' routine _after_ the bootloader.
CYembedded



Joined: 31 Jan 2015
Posts: 6

View user's profile Send private message

PostPosted: Mon Feb 02, 2015 4:27 am     Reply with quote

Thanks for your reply.
I corrected the wrong lines and at last I got this error in my bootloader:

OUT of ROM, A segment or the program is too large application
Seg 00500-00502, 0004 left, need 00012

Bootloader program :
Code:

#include <main.h>
#fuses NOWDT,NOPROTECT,NOPLLEN
#use delay(internal=16MHz)
#use rs232(baud=9600, xmit=PIN_D6, rcv=PIN_D7, ERRORS)
#define PUSH_BUTTON PIN_A1

#define _bootloader

#include <bootloader.h>
#include <loader.c>

#if defined(__PCM__)
 #org LOADER_END+1,LOADER_END+2
#elif defined(__PCH__)
 #org LOADER_END+2,LOADER_END+4
#endif

void application(void)
{
   output_high(pin_b5);
   printf("\r\napplication...");
  while(TRUE);
}

void main()
{
   output_high(pin_b5);
   if(!input(PUSH_BUTTON))
   {
      printf("\r\nBootloader Version 1.0\r\n");
   
      // Let the user know it is ready to accept a download
      printf("\r\nWaiting for download...");
      load_program();
      printf("\r\n!!!");
   }

   application();
}

Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Mon Feb 02, 2015 5:25 am     Reply with quote

You are missing the point fractionally.

You have the dummy application, actually containing code in the bootloader.

It _musn't_.

It is just a dummy to be there as a 'placeholder'.

Because you have code in it, it won't fit in the space allocated for it.

Look at the 'application' as I post it. Look at your's.....
CYembedded



Joined: 31 Jan 2015
Posts: 6

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 3:57 am     Reply with quote

Thanks for your interest.
The application worked fine. In gpio and sending string from the serial there is no problem.
The only problem I have just noticed that interrupts are not working.
When I loaded the program by Pickit2 without a bootloader it works fine.

When I loaded the program with a bootloader, I can control the gpios and serial port etc. but Interrupts (int_rda and int_rda2) are not working.

Is the problem with bootloader ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 4:11 am     Reply with quote

That's because you have left the interrupt re-vector stub out of your bootloader.....

Again look at the example. Note this bit:
Code:

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


This is the re-vector stub, that handles transferring interrupt traffic up to programs compiled to load with the bootloader. It's perfectly OK to leave it out if you are not using interrupts in the main code, but it is essential for these to work. Hence I didn't worry about it being missing.

If you have removed it because you are using interrupts in your bootloader, then you need to handle these correctly (it is possible), but you have to have this stub, and then inside it add a test to see if you are in the bootloader or in the main code. If in main code handle the re-vectoring, otherwise then test yourself for the interrupt required, and call the required routines.

Generally it is quicker for the main code, and less bulky, to not use interrupts in the bootloader.
CYembedded



Joined: 31 Jan 2015
Posts: 6

View user's profile Send private message

PostPosted: Tue Feb 10, 2015 3:42 am     Reply with quote

Hi Ttelmah,
I worked my bootloader successfully at last.
Now I wonder whether I can program my PIC by an external eeprom or flash memory IC. In order to do that I hope I should change the codes in loader.c with read_eeprom() functions instead of getc() or etc. ? Is it true?
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Tue Feb 10, 2015 9:06 am     Reply with quote

No. You'd need 'read_external_eeprom'. Read_eeprom is for the internal EEPROM. Do a search on the forum, this has been discussed in the past.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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