Hot!c application works fine without Bootloader, but fails with Bootloader SOLVED !

Author
zonneke75
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2018/09/24 11:52:32
  • Location: 0
  • Status: offline
2018/09/25 01:46:32 (permalink)
0

c application works fine without Bootloader, but fails with Bootloader SOLVED !

Hi,
I have an application which runs just fine without using a bootloader (without code offset). but when i do use the BL i get wrong reactions to my c code. For example :

if (Motors[n].bInitialised == 1) {

mc_CheckForFaults(&Motors[n]); -> this line is executed even while Motors[n].bInitialised = 0.


So i dig deeper and looked at the assembly code. When i step there in the assembly code i see a call to 0x71D , but when executing that instruction the code jumps to 0xF1D . This explains the wrong behavior, why did XC8 v2.0 create the wrong assembly, and how can i prevent this wrong behavior?

My bootloader addres range is 0 - 5FF , application addres range : 600-3F7F



I did set my userapp offset in project settings to 0x600
I see immediatly when the program fails, because i use a heartbeat led which blinks every 0.5 seconds, it uses a timer interupt. This leds blinks with whole different timing and pattern when the program fails.
To be clear, i'm not in bootloader mode at that stage, the bootloader start up the user code fine, but then all those strange effects begins. This was not the case while the user code was much smaller (40% of flash). That code worked fine with BL.
Now we are at 70% and use a big struct of 115 bytes. Can that cause this problem?
 
MPLAB v4.2 , XC8 2.0 PRO
Thank you
Steve
 
post edited by zonneke75 - 2018/10/15 06:18:44
#1

12 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 2546
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 02:14:20 (permalink)
    +1 (1)
    Please give us the designation of your PIC.
    And - btw - did you try XC8 1.45 ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    zonneke75
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/24 11:52:32
    • Location: 0
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 03:03:16 (permalink)
    0
    16F1779 , I only have license for XC8 2.0. Did not try free mode though , But Then my flash Will be near to full and this project is still evolving . Thank you
    #3
    du00000001
    Just Some Member
    • Total Posts : 2546
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 04:45:32 (permalink)
    +1 (1)
    XC8 2.0 has already become somewhat notorious here for some "specialties" sad: sad
     
    Where applicable, the current recommendation tends to be to try 1.45 (provided your device is supported by it).
    In your case (having a PRO license for 2.0 but not for 1.45), it might not work this way. But at least give it a try.
     
    Beyond that, I doubt that your problem is with the compiler. (You could check the HEX file.)
    How do you program the device? via the boot loader? Could it be the data stream to be flashed somehow gets corrupted?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    zonneke75
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/24 11:52:32
    • Location: 0
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 05:43:50 (permalink)
    0
    Hi,
    Thank you for the respons .
    xc8 2.0 is notorious But on the other hand you dont think Its the compiler, isn’t that contradicting? :) ... iT Also happens when I load the full project with mplab ICE . It’s not an bootloader issue .
    What i’m Affraid the most of is that disassembly says call x71D but instructionpointer jumps to xF1D. How is that possible? Instruction out of range ?
    #5
    qhb
    Superb Member
    • Total Posts : 9614
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 05:47:05 (permalink)
    +2 (2)
    zonneke75
    ...
    What i’m Affraid the most of is that disassembly says call x71D but instructionpointer jumps to xF1D. How is that possible? Instruction out of range ?

    That is how PIC16F chips work.
    All GOTOs and CALLs only work within a 0x800 long "page", and the page select bits select which page is currently active.
     
    #6
    zonneke75
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/24 11:52:32
    • Location: 0
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 06:03:19 (permalink)
    0
    So that call is valid ? Or did the compiler forget to switch Page select bits in this case?
    #7
    qhb
    Superb Member
    • Total Posts : 9614
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 06:07:05 (permalink)
    +1 (1)
    That is how the call is encoded. The disassembler has no idea what the page select bits may be, so it just shows the offset.
     
    #8
    hasanyildiz
    Starting Member
    • Total Posts : 58
    • Reward points : 0
    • Joined: 2015/09/04 03:33:31
    • Location: 0
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 08:57:32 (permalink)
    +1 (1)
    Hi,
    May be your interrupt code is not pointed correctly, when interrupt generated program runs from wrong location.
    #9
    mlp
    boots too small
    • Total Posts : 709
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 12:57:41 (permalink)
    +1 (1)
    hasanyildiz
    May be your interrupt code is not pointed correctly, when interrupt generated program runs from wrong location.

    But we can't tell, because you have not shown your code.
     
    (walks away, shaking head)
     

    Mark (this opinion available for hire)
    #10
    zonneke75
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/24 11:52:32
    • Location: 0
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/09/25 21:47:47 (permalink)
    0
    Thank you for the response.
    Unfortunattely I can’t share code, But today I can try to make a small version, But before the code + BL worked while iT was still small.. I Will give iT a try.
    The interrupts are configured trough MCC , is There Something I need to setup manually in code or linker/compiler to point interrupts correctly ?
    #11
    picmaster75
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2018/09/21 03:45:11
    • Location: 0
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/10/15 06:01:15 (permalink)
    +2 (2)
    Problem solved,
    XC global compiler setting, stack type need to be Compiled instead of hybrid.
    #12
    zonneke75
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/24 11:52:32
    • Location: 0
    • Status: offline
    Re: c application works fine without Bootloader, but fails with Bootloader 2018/10/15 06:14:59 (permalink)
    0
    correct , setting stack type to Compiled solved the problem
     
    thank you !
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5