The end result after doing this is that we will have a loader in the high part of the memory (in this example at adr DEC 60160). Every time the PIC starts it will jump to the loader, there we check if we want to enter the loader or jump back to resume the application software.
This is ONLY tested on 18-series (PIC18F4620).
1: We need to get the library out of the way since PBP usually puts this in the low part of the memory. The easiest way to do this is to modify the PBPPIC18.lib file. Look at these original lines.
ifdef LOADER_USED
LIST
ORG RESET_ORG+8 <---- modify this line
NOLIST
endif
Here i modified it to point to the address where I want my loader to be.
ORG 60160 <---- now all code will be from this adress (Block 470)
Then by using DEFINE LOADER_USED 1 in the LOADER SOFTWARE this part will be activated. So Any software written with this define will be programmed at this address. Not just 4 words in as the usual function. Make sure the loader adress is a multiple of 128, (look at the Erase block below)
By doing this modification the normal use of this DEFINE is hijacked so it will no longer work as the manual sais.
2: Where to put the application code, this is usually adr 8 for normal loaders.
Since the 18-series needs to have the flash memory erased before we can program it again there are som things to think about. We can only erase entire blocks of 128 BYTES at the time, if the adr in the ERASECODE command points inside one block ALL bytes in it will be erased, EVEN positions prior to the address if they are a part of the same block. Blocks are multiples of 128. In the first 3 positions of Block 0 our loader software has written the GOTO instruction and we do not want to loose that. One way is to use READ code and read the information before you ERASE it but this still leaves the danges that something might go wrong and we end up in a position where we no longer can goto the loader.
Plan B: We use DEFINE RESET_ORG 64 in the APPLICATION SOFTWARE to move the application software to start from Block 1. Then we never have to erase block 0. Sure, we lost the space for 28 instructions but if size is a big problem, a loader in PBP is not the right way to go anyway.
To return to the APPLICATION software just use @GOTO 0x0040 (goto adress 64)
Loader code:
DEFINE LOADER_USED 1
pause some
check if we want to change software
if not jump back
for as long as we need
check address so it is not above 60160 and overwrite the loader
Erase block
program block
END
Application software:
DEFINE RESET_ORG 64
and then it is just as always
When developing the APPLICATION SOFTWARE you can just use a normal programmer to program the code if you dont want to use the bootloader. But as soon as the BOOTLOADER is put in the PIC we must use that way of programming otherwise the programmer will erase the goto intruction and we will never enter the loader.
I know it is not a working program example. I use this loader to recieve an encrypted data file that the loader will unpack and write to the flash. The HEX file you want to put in the PIC has to be parsed by either the Loader or by a VB software, I use a VB software to parse and encrypt the HEX file and the loader just decrypts it and write the data.
If there are any questions please let me know but this should at least be a start.
/me
Bookmarks