• AVR Freaks

Hot!What is the preferred way to develop a Bootloader for PIC24 devices?

Author
Maldus
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2016/08/17 09:55:57
  • Location: 0
  • Status: offline
2019/07/20 00:15:03 (permalink)
0

What is the preferred way to develop a Bootloader for PIC24 devices?

Hello everyone,
I'm exploring the possibility to add bootloading capabilities to a future product, and I could use some suggestions.
First of all, let me state what I mean by "preferred": the most efficient and fast way to add one to my application, considering that I require no particularly specific use cases. As an example, ST microcontrollers ship with a non-erasable built-in bootloader that can be triggered in various way; connect UART, follow a certain protocol (covered by various available implementation all over the internet) and it's done in a matter of minutes. It is undoubtedly the preferred way to flash ST devices with a bootloader.
 
On the other hand, I could develop my own bootloader logic from scratch: every PIC device has self writing tools and I have enough knowledge of embedded architecture to pull it off; still, I would prefer to avoid reinventing the wheel if possible.
 
I'm resorting to ask on the forum because from experience it is the best way to learn something about Microchip products. I can never tell whether google results or even their own website's answers are legit or bogus and outdated, so I need an opinion on which among the possibilities I've found is the best way to solve the problem:
  • EZBL : specified by Microchip in this page https://www.microchip.com/promo/unified-bootloaders , it seems to be some kind of pluggable library to add a bootloader to any application. My concerns about this solution are: 1. Is this up to date or deprecated? 2. It involves some kind of Makefile configuration to generate code and linker scripts, isn't it just an older version of MCC? 3. Also, the flashing application only works on Windows which is a deal breaker for me.
  • AN1157 : An example bootloader and an Application Note explaining how it works. If I understand correctly it would require me to fiddle with the code (and linker scripts) and adapt it to my situation. It might take a little more effort on my side, but considering that most of Microchip's out-of-the-box solution usually don't work maybe it's for the best? It still seems even more outdated than EZBL.
  • MCC : using Microchip Code Configurator to generate a bootloader. Despite the link specifying EZBL as the official solution I still believe this would be the most up to date way to go. However all of my attempts of working with MCC ended horribly with me wasting the better half of a day finding out what the generator was doing wrong; considering the bootloader is arguably a very delicate functionality I have my doubts it will work without flaws. Then again maybe it can be the one thing MCC gets right.
Do I have it right? What are your opinions on the matter?
#1

5 Replies Related Threads

    BobAGI
    Super Member
    • Total Posts : 1725
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: What is the preferred way to develop a Bootloader for PIC24 devices? 2019/07/20 00:58:41 (permalink)
    0
    Back in 2013 or so I have implemented a serial boot loader with a small footprint using the MC AN1157 manual and code for the PIC24FJ256GB2xx family of chips..
    I modified the protocol over the wire to protect my devices and to make the transfers more robust.
    I also developed PC code to merge the flash image of my application with the bootloader flash so that both get programmed in the factory using the normal programmer.
    It has worked fine for our PIC units.
    The advantage is that the code in the BL does not use interrupts so the vector table can be fully handled by the application code.
     
    EDIT:
    Concerning the linker script it is really pretty simple:
    Use the standard GLD file for your chip and just edit in the needed changes...
    post edited by BobAGI - 2019/07/20 01:01:09

    --
    Bo B
    Sweden & Texas
     
    #2
    jbroadwell81@gmail.com
    Super Member
    • Total Posts : 1446
    • Reward points : 0
    • Joined: 2005/11/02 13:58:11
    • Location: Indianapolis, Indiana
    • Status: offline
    Re: What is the preferred way to develop a Bootloader for PIC24 devices? 2019/07/20 08:10:03 (permalink)
    0
    Our company is using the EZBL for a commercial project, and it's pretty spectacular.  It downloads fast, and does a lot of best practice bootloader stuff like having keys to verify that the code you're downloading is intended for the platform receiving it.  It's a lot to swallow at first, but worth it.   
     
    If you're looking for something lighter weight, take a look at AN1157.
     
    Personally, I find that for my own projects I'm usually happiest writing my own.  Simple ones are pretty easy, once you figure out how to get all the bytes to go in the right places (PIC24 is fiddly that way, because of all the extra 0's you end up with in your hex file since only 3 of 4 bytes will actually program).
     
    Where possible (such as a UART bootloader), I'm a big fan of writing the bootloader first in C under Visual Studio, and simulating it on a PC.  You replace the flash writing parts with file write parts, and when you're done you can compare the file you attempted to send with the file written by the PC compilation of your bootloader, and easily confirm where they are the same.  Then, assuming you have the flash routines, porting them is pretty simple.   The most complicated BL I did was for CAN with a really complex customer's protocol, and this paid off big time due to the ability to easily generate long logs and debug the protocol in VS before moving it to the embedded side.

    http://www.serialwombat.com
    When someone asks you "Can't you just...", watch out.
    #3
    NorthGuy
    Super Member
    • Total Posts : 5805
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: What is the preferred way to develop a Bootloader for PIC24 devices? 2019/07/20 08:25:19 (permalink)
    0
    Maldus
    As an example, ST microcontrollers ship with a non-erasable built-in bootloader that can be triggered in various way; connect UART, follow a certain protocol (covered by various available implementation all over the internet) and it's done in a matter of minutes. It is undoubtedly the preferred way to flash ST devices with a bootloader.

     
    PICs have this too. The protocol they use is called ICSP. It is documented for every PIC. Some also have JTAG.
     
    Maldus
    Do I have it right? What are your opinions on the matter?



    Bootloader is a very simple thing. The easiest way is to get two-partition PIC24. One partition is for the application. The bootloader simply receives data and writes it into the other partition. Then you check integrity, and if you like the result, you switch partitions - next boot will be from the other partition. Now it becomes the application partition and the original partition is now free to write the next version.
     
    Otherwise, you'll need to re-direct IVT, which requires some work and good understanding how IVT works. This also adds latency to your interrupts because they're redirected and redirection takes time. Now you have two different versions of your application - a free one and bootloaded one. Then you need to combine bootloader with the application. This is a lot of things to do compared to a dual-partition case.
     
    #4
    Maldus
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2016/08/17 09:55:57
    • Location: 0
    • Status: offline
    Re: What is the preferred way to develop a Bootloader for PIC24 devices? 2019/07/20 12:31:07 (permalink)
    0

    PICs have this too. The protocol they use is called ICSP. It is documented for every PIC. Some also have JTAG.

    ICSP does not use a bootloader, it's just the default way to program any PIC. STM32 device have both programming/debug pins (using SWD) and an integrated bootloader through UART/I2C/USB...
     

    Bootloader is a very simple thing. The easiest way is to get two-partition PIC24. One partition is for the application. The bootloader simply receives data and writes it into the other partition. Then you check integrity, and if you like the result, you switch partitions - next boot will be from the other partition. Now it becomes the application partition and the original partition is now free to write the next version.

    Ok, this was something I missed. I found out only now about the dual partition feature, and if I understand correctly EZBL supports it. Maybe I'll try it out and work around the problem that Linux is not supported.
    #5
    NorthGuy
    Super Member
    • Total Posts : 5805
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: What is the preferred way to develop a Bootloader for PIC24 devices? 2019/07/20 14:09:09 (permalink)
    0
    Maldus
    ICSP does not use a bootloader ...



    On PIC24, ICSP uses a program implanted into the PIC (to an area which is invisible to the user), which then programs the PIC as instructed. Microchip calls it "programming executive". This program can do practically anything. Whether you want to call it a bootloader or not is a question of semantics.
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5