View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
Starting with bootloader |
Posted: Sun Dec 27, 2020 11:12 am |
|
|
Hello I'm trying to understand how bootloader works on PIC&CCS.
I already have a huge program with no bootloader running on a PIC18F67J50 and now I need to add a bootloader.
1) If the bootloader needs to access USB and a I2C memory the bootloader must have their owns routines?
I think yes, because the main program will be erased.
2)What about the interrupts vectors? How they works when the main program run and how when the bootloader runs?
Also I tried to move the program to a higher address without luck.
Code: | #include <18F67J50.h>
#fuses INTRC_PLL,PLL2,NOCPUDIV,NOIESO,NOFCMEN,STVREN,CCP2E7,NOWDT,WDT2048,PROTECT //WDT8Seg. No crystal
#build(reset=0x200:0x207, interrupt=0x208:0x2ff)
#build(memory=0x2000:0x2FFF)
//#ROM 0 = {0xFFFF} // Insert NOP at address 0
void main()
{
char buffer[64];
setup_oscillator(OSC_PLL_ON|OSC_NORMAL);
read_program_memory(0x0000, buffer, 64);
delay_cycles(1);
delay_cycles(1);
write_program_memory(0x1000, buffer, 64);
delay_cycles(1);
delay_cycles(1);
while(1)
{
delay_cycles(1);
delay_cycles(1);
}
} |
Now I'm using a PIC18F67J50 but probably also will need to use the same bootloader with a PIC24FJ1024GB606. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Dec 27, 2020 12:09 pm |
|
|
Yes.
Normally you don't use interrupts in the bootloader. Instead poll
the interrupt flags. Otherwise it gets awkward.
The bootloader revectors the interrupts for the main code.
A program moved to a higher address, cannot run without the bootloader
loaded to handle jumping to it on boot and revectoring the interrupts. |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Sun Dec 27, 2020 12:35 pm |
|
|
How I can use USB CDC CCS library with the bootloader?
I mean it must have separated routines. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Dec 27, 2020 12:50 pm |
|
|
The USB CDC library, offers an option to poll rather than use the
interrupt. Look at the example USB bootloader. |
|
|
|