• AVR Freaks

Hot!PIC32MK Bootloader + Application Issue [Solved]

Page: 12 > Showing page 1 of 2
Author
darren
Starting Member
  • Total Posts : 71
  • Reward points : 0
  • Joined: 2010/10/02 04:31:04
  • Location: 0
  • Status: offline
2020/05/12 07:37:52 (permalink)
0

PIC32MK Bootloader + Application Issue [Solved]

Hi All,
 
I'm developing an application using the PIC32MK1024GDP100 for which I need a bootloader. I'm using Harmoney ver 2.06. So far, I have the application ready and working (when programmed without bootloader). As for the bootloader, I generated one using MHC and confirmed that I have correct communication form the host PC to the device. For both the bootloader and application, I generated the linker script from MHC following the Harmoney Help Volume V part i (page 1219). 
 
I am now trying to debug the application with the bootloader. I added the bootloader in the "Loadables" local folder of the application project and managed to compile. First issue I note is that while the application should have approx. 160k of RAM usage (its a graphic application), when compiling the the bootlader in the Loadables folder it only marks a RAM usage of approx 23k. The flash usage is marked correctly (application approx 331k, bootloader approx. 11k, app + bootloader approx. 341k). 
 
When I run the application, the bootloader recognise there is an application and correctly jumps to the application reset vector and runs the application but soon after I enable the interrupts, I get an exception (code 6, "Instruction bus error"). Disabling the interrupts, the app does work as I need the interrupts enabled but there is not exception generated so I ake it as the interrupts are the issue. I check the application linker and seen that IVT ebase address is 0x9D001000 which, as far as I know is correct. 
 
Does anyone have an idea what is the issue?
 
I attached the linker scripts assuming they'll help (changed the extension so I could attach them). 
 
Thanks
post edited by darren - 2020/05/14 02:06:19
#1

24 Replies Related Threads

    optimus_jack
    Senior Member
    • Total Posts : 105
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/12 20:46:02 (permalink)
    0
    @darren you can give a try with Harmonn3 based bootloader. below is the example
    https://github.com/Microc...er/bootloader/firmware
    #2
    darren
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2010/10/02 04:31:04
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/13 01:49:46 (permalink)
    0
    Hi optimus_jack,
     
    Thanks for the link but still have the same issue. I now realised that when I compile the application using the custom linker script without the bootloader project in the loadables folder, the RAM usage is still wrong. So the issue is coming from the custom linker script.  
     
    Any idea why my 150kB frame buffer is being ignored by the custom linker but not by the default linker script?
    As a side note, does anyone know which linker script is used by XC32 by default on the PIC32MK? Comparing the default with the custom linker may help...
    #3
    Stefiff
    Senior Member
    • Total Posts : 99
    • Reward points : 0
    • Joined: 2012/07/15 15:26:29
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/13 04:18:50 (permalink)
    0
    About RAM/Memory.
    What you see as allocated memory, is allocated by the compiler. If you have something / variables set to fixed addresses, they are not visible because the compiler does not allocate them.
     
    Problem with Interrupts.
    It depends on many things, not just the linker script. In the bootloader, depends on which modules are used by the processor. In what mode does the processor itself work. Usually here working in single mode. Interruptions are minimal or not allowed at all. MVEC=0.
    The moment you jump in to the application, the compiler will try to re-initialize the CPU with all vectors and stack (first MVEC=0 will be). Therefore, it is desirable, at the time of exit from the bootloader, to set them to default. Stop ALL modules. Later here MVEC=1.
    For MK, I don't know exactly, but for MX and MZ, the address with the table with the vectors must be at an address multiple of 4K. This is related to the registry that is responsible for this.
     
    _ebase_address =  0x9FC00300; - is bad idea
     
    Unfortunately, when you use harmony, you have no control over exactly what happens and what is used.
     
    #4
    darren
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2010/10/02 04:31:04
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/14 02:05:14 (permalink)
    0
    Hi Stefiff,
     
    Thanks for your reply. I have tried change the _ebase_address to a multiple of 4k (0x9FC01000) but still didn't work. Finally, I managed to find the default linker used for the PIC32MK1024GPD100 and updated the starting address of the application and removed the boot section. It worked. I attached both the bootloader and application linkers should anyone finds himself in the same situation. 
     
    #5
    MPaulHolmes
    Junior Member
    • Total Posts : 96
    • Reward points : 0
    • Joined: 2009/10/31 10:52:40
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/25 08:08:14 (permalink)
    0
    I've never tried a bootloader before, and a lot of the conversation on this thread was confusing to me.  I don't even know what to ask.  Basically, my microcontroller is the p32mk1024MCF100 (and maybe sometimes the p32mk512mcf100).  If I started with the above 2 attachments, what would I need to do to get a functional bootloader for those microcontrollers?  
     
    I started to wade into this:
    https://github.com/Microchip-MPLAB-Harmony/bootloader
     
    But it didn't specifically mention my microcontrollers.  I had no idea what random stuff to change for my microcontrollers to work, since it all just seems like a black box to me.
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 18976
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/25 09:11:14 (permalink)
    0
    Are you using Harmony to create a bootloader?
    Which version of Harmony, and what kind of bootloader?
    #7
    MPaulHolmes
    Junior Member
    • Total Posts : 96
    • Reward points : 0
    • Joined: 2009/10/31 10:52:40
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/25 09:24:41 (permalink)
    5 (1)
    I am willing to use harmony if that will work well.  I have the latest version of harmony (I just updated it today).  I'm not sure what it updated to (since I never use it), but I did update it.  I was going to use this:
    https://github.com/Microchip-MPLAB-Harmony/bootloader
     
    And was going to use the UART bootloader.  But then I was reading this thread, and it sounded like I am going to have to make a bunch of random changes that make no sense to me to get it working.
    #8
    MPaulHolmes
    Junior Member
    • Total Posts : 96
    • Reward points : 0
    • Joined: 2009/10/31 10:52:40
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/05/25 10:05:50 (permalink)
    0
    trying to delete the post.  oh well.
    post edited by MPaulHolmes - 2020/05/25 16:32:26
    #9
    hud789
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2020/06/09 09:08:28
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue 2020/06/30 16:18:55 (permalink)
    0
    So basically it is the linker scripts causes the issue? Any theory behind it? I have the similar issue with my PIC32MK1024GPE64 bootloader with CAN communication. I have a working application, but if called from bootloader, it had exception. But If I simplify the application to just a led blinking function, it works fine.
    #10
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/16 17:54:42 (permalink)
    0
    Is any of you guys willing to write a simple post to describe a step-by-step procedure on how to get a bootloader working on the PIC32(MK)?
     
    I have read posts on this forum, gone through microchip notes and documents, I understand the concept, but I fail to understand how to get this thing done in practice.
     
    I have never used Harmony and I am not interested in using it unless absolutely forced to do so. Is it possible to generate and use a simple UART bootloader without Harmony?
     
    If I copy the source code from here (https://github.com/Microchip-MPLAB-Harmony/bootloader_apps_uart) in a new empty project, would I be able to download it on the PIC and have the bootloader working right away? Or are there other obscure settings I would have to worry about? What are the linker scripts everyone is talking about above? I have never used linker scripts in my applications and I have no idea how to use them.
     
    Also, the documentation says the UART bootloader takes bin files, but when I generate one from my current application I get a 45Mb file in place of a 800Kb hex file. There's no way I am going to send 45Mb over email to my customer every time I release a new firmware update. Is there an alternative using the hex instead of the bin?
     
    Thanks!
    #11
    domble
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/01/25 04:11:53
    • Location: UK
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/17 03:48:59 (permalink)
    0
    Think the .bin file should be smaller than the .hex file - I guess less than half the size.  I used https://sourceforge.net/projects/hex2bin/ which seems to work for generating a .bin file from the unified .hex file generated by a MPLAB (harmony) project and bootloader project.  My .hex file was 690kbytes, the .bin file was 263kbytes.
    Seems odd to me that the Harmony bootloader app for PC (written in python) needs a .bin file and wasn't written to convert the .hex file itself.  Unless there's a 'proper' way to get a .bin file which wasn't obvious to me.
    #12
    LdB_ECM
    Super Member
    • Total Posts : 454
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/17 05:43:02 (permalink)
    0
    The format of an Intel hex file is trivial convert it yourself on the fly you only have to deal with each line in the file one by one.
     
    Every line starts with a ":" and then 5 hex things follow and there are 2 special markers for extended file
    : 11 2222 33 44444444444444444444444444444444 55 \n
     
    https://www.kanda.com/blo...l-hex-files-explained/
    #13
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/17 17:49:58 (permalink)
    0
    Ok, thanks for the suggestions. I was generating the bin file directly from the build process of the MPLABX, which for some reason resulted in a gigantic file.
     
    As for the bootloader itself I guess I'll have to download Harmony and start working with it. I've been reluctant for so long but it looks like all of you guys are using it. 
    #14
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/18 16:48:47 (permalink)
    0
    @domble I tried the program you suggested but I still get a 45MB output binary file. It must have something to do with the start address in memory, which for the PIC32MK is 9d00000. A quick inspection of the bin file shows that it is essentially all empty, maybe just filler holes all the way to that starting memory address. There must be a way to avoid that but I can't figure it out.
     
    Maybe parsing the hex myself in the bootloader is an easier option...
    #15
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/19 18:34:37 (permalink)
    0
    Ok, I was able to solve the problem by adding a line to the linker script to remove the configuration bits:
    /DISCARD/ : { *(.config_*) }

    That way all the hex code addresses are close together and the binary file comes out much smaller, as all the empty holes are removed.
    #16
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/21 01:13:40 (permalink)
    0
    I was able to download the Harmony3 UART bootloader to the PIC32MK, then connect to it via serial port and use the provided python script to download the binary file of the user application (which was implemented without harmony). It all works fine as long as the application is simple and just toggles an LED. But if I activate a Timer interrupt the corresponding ISR is never executed. What could be the problem?
     
    Interrupts are not active in the bootloader (MVEC = 0), only in the user app (MVEC = 1).
    If I use the application alone without bootloader then everything works fine.  
    #17
    domble
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2007/01/25 04:11:53
    • Location: UK
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/21 02:40:08 (permalink)
    0
    The "discard config" incantation was indeed in 'my' (app) linker file... to stop linker complaining about mismatching config bits in the event that they were set differently in bootloader and app... I'd not spotted the extra implications - just got lucky?  :-)
    #18
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/21 03:07:33 (permalink)
    0
    Nice! Did you then by any chance add any extra trick to get the interrupts working in the app?
    #19
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: PIC32MK Bootloader + Application Issue [Solved] 2020/09/21 23:37:17 (permalink)
    4 (2)
    Alright, I figured that one out too, finally. The Harmony bootloader disables all the peripherals it does not need using the PMD registers. The user application needs to reactivate all the needed peripheral otherwise the corresponding interrupts will not work.
    I had never used Harmony, and never manually disabled peripherals before because power consumption is not an issue for me, so I didn't know of the PMD registers... 
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5