View previous topic :: View next topic |
Author |
Message |
CYembedded
Joined: 31 Jan 2015 Posts: 6
|
|
Posted: Mon Feb 02, 2015 4:27 am |
|
|
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
|
|
Posted: Mon Feb 02, 2015 5:25 am |
|
|
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
|
|
Posted: Tue Feb 03, 2015 3:57 am |
|
|
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
|
|
Posted: Tue Feb 03, 2015 4:11 am |
|
|
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
|
|
Posted: Tue Feb 10, 2015 3:42 am |
|
|
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
|
|
Posted: Tue Feb 10, 2015 9:06 am |
|
|
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. |
|
|
|