pic18f45k22 bootloader.c

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
makpinar1988
Posts: 4
Joined: 14 Sep 2014 13:50

pic18f45k22 bootloader.c

#1 Post by makpinar1988 » 15 Sep 2014 16:00

Hello,

I have examined the proposed bootloader example for 18f45k22.

I have a few questions:
1- is it possible to program the configuration registers by using bootloader software?
2- as far as i understood, application code is stored in the FLASH started from the address of 0x40(h). is it correct?
3- In the bootlader firmware,

FLASH_Erase_Write_64(START_PROGRAM_ADDR, block)
{
'--- goto main
block[0] = 0x60 '/0xF03EEF60
block[1] = 0xEF
block[2] = 0x3E
block[3] = 0xF0
}

this code block can be decoded as "goto 0x3e60(h)".
i am not sure but the address may be multiplied by 2 since FLASH is 16bits.
So, the result is 0x7cc0(h) which is the starting address of the boatloader firmawre.

This instructions are written to the address of START_PROGRAM_ADDR (0x7FC0).

When bootloader is not triggered by the PC software, the boatlaoder firmware jumps the 0x7fc0 address.
So, i think in this address, there must be an instruction which supplies the jump to the beginning of the application code.
But, if i am not wrong, it jumps to the beginning of the boatloader firmware again. So, there will be a loop.
I could not find where bootloader firmware jumps to the application code.

Thanks.

Best Regars,
Murat

Digital Design Engineer

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: pic18f45k22 bootloader.c

#2 Post by dejan.odabasic » 17 Sep 2014 15:40

Hello,

1 - It's not possible to program config bits on PIC18 by bootlaoder.
2 - application code is stored in the FLASH started from the address 0, take a closer look:

Code: Select all

void Write_Begin(){
  FLASH_Erase_Write_64(START_PROGRAM_ADDR, block); // First 64byte packet will be written to START_PROGRAM_ADDR
  //--- goto main - first four bytes altered with goto bootloader
  block[0] = 0x60;  //0xF03EEF60
  block[1] = 0xEF;
  block[2] = 0x3E;
  block[3] = 0xF0;
}

// Starting value for j  is 0, not 0x40
      if (!j)
        Write_Begin();   // First 64byte packet will be written to START_PROGRAM_ADDR and then first four bytes altered with goto bootloader
      if (j<BOOTLOADER_START_ADDR){
        FLASH_Erase_Write_64(j, block);
      }

      i = 0;
      j += 0x40; // Address increment 64 bytes - FLASH_Erase_Write_64
3 - There is no loop, if bootloader is not triggered in time (for ~5 sec) execution of main program will start(if programmed) or wait for next reset to establish connection with mikroBootloader application.

Best regards.

makpinar1988
Posts: 4
Joined: 14 Sep 2014 13:50

Re: pic18f45k22 bootloader.c

#3 Post by makpinar1988 » 18 Sep 2014 11:30

in practice, it works correctly.

On the other hand, when i take a look at the code,
when j equls to 0, "Write_Begin()" function is called.
if i am not wrong, this function writes to the 0x7FC0(START_PROGRAM_ADDR) address, not to 0x0000.
With the help of that function "goto application code" is written to the 0x7FC0(START_PROGRAM_ADDR) .

Then, the first 4 bytes of the same block is changed as "goto bootloader" and it is written to the address of 0x0000.
So you are right, the application code is written starting from 0x0000.
Then j is incremented to 0x0040 and while j is lower than bootloader starting adress, flash is written.

Everything is clear for me now about bootloader code.

one more thing, İ want to explain.

block[0] = 0x60; //0xF03EEF60
block[1] = 0xEF;
block[2] = 0x3E;
block[3] = 0xF0;

is decoded as "goto 0x3e60" according to the datasheet of the pic18f45k22.
while address information is transferring to the Program Counter in mcu,
it is multiplied by 2. So, it jumps to the 0X7CC0.



Best Regards,
Murat

Post Reply

Return to “mikroBasic PRO for PIC General”