Looking for urgent HELP WITH BOOTLOADER

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
rainer
Posts: 320
Joined: 07 Dec 2006 11:00
Location: Vienna, Austria
Contact:

Looking for urgent HELP WITH BOOTLOADER

#1 Post by rainer » 28 Feb 2024 08:28

Hello.
I am working on a huge project based on PIC17F67K40 MCU. I am writing a relatively complex firmware, using several replacement librariues and also CRTOS, a cooperative multitasking system. This allows me to do 20 things in parallel.

What I need to implement is a bootloader for unattended self-flashing. The principle is simple, I download the new firmware into an external SPI F-RAM chip. After download I verify the CRC32 checksum, When checksum is correct, I set a flag in FRAM and reboot the MCU.
The bootloader connects to this F-RAM and tests the flag. If the flag is found, it starts the self-flashing process. When done, it clears the flag and does another reboot. Now the flag is not detected any more, so the bootloader starts up the main program.

Where I please for your kindly help:
I have absolutely no knowledge in assembly language, I code always (and only) in mikroPascal PRO for PIC. So it is a bit hard to me to figure out how to implement the bootloader.

I want to place the bootloader in uppermost range of FLASH memory. Let's say it starts at $1F000. Everything before this address is main firmware, everything above is bootloader. At top end of main firmware (so directly before $1F000) I place a little code, a jump to the normal entry point of main firmware. So this code is part of the main firmware and outside bootloader, but on a fixed location.
Sop the bootloader will jump to this location, the code there jumps to the real entry point. The benefit of this is:I do not have to modify the bootloader when I change the firmware.
Possibly I can also place a dummy procedure in the main firmware at $1F000, being initially executed. If this is possible, it could behave like the real bootloader, but I do not have to patch startup pointers every time?

It would be very kind if you can help.
I see two options:
  • I use a bootloader written with orgall to be placed completely above $1F000, and I lock out the main program from $1F000...$1FFFF by allocating that memory by a const array.
    In this case, I have to patch the compiled program from external program, because I have to replace the original jump vector by a jump to $1F000, and I have to patch the original jump into last bytes before $1F000 (the jump back to main firmware).
  • I can write a dummy "bootloader" procedure at $1F000 (using org), which is executed first (after restart) and doing nothing else than jumping to the address stored right before of it (where a jump to the real main program is located). All memory above this dummy bootloader will be allocated by a const array, so mikroPascal has to place the entire code below..
    This way I can easily combile the software of main program and bootloader. I merge code from $00000-$1EFFF from main program and code from $1F000-$1FFFF from bootloader.
Please, help. This exceeds my skills in coding this in detail.

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Looking for urgent HELP WITH BOOTLOADER

#2 Post by IvanJeremic » 17 Mar 2024 19:42

Hi,

We do not have an example for the PCI18F67K40 MCU, but i attached the example for PIC18F45K22 in Pascal, and i attached the HEX file for the PIC18F67K40 Bootloader.
https://download.mikroe.com/examples/st ... r-v100.zip
https://download.mikroe.com/documents/d ... asheet.pdf
P18F45K22.rar
(8.45 KiB) Downloaded 5 times
Regards,

Ivan.

Post Reply

Return to “mikroPascal PRO for PIC General”