• AVR Freaks

LockedXC8 and reset vector

Author
CiccioB
Starting Member
  • Total Posts : 50
  • Reward points : 0
  • Joined: 2013/12/11 05:32:50
  • Location: 0
  • Status: offline
2013/12/11 06:53:27 (permalink)
0

XC8 and reset vector


Hello,I am new here.
I have been using MPLAB+C18 Compiler for few years, I have used MPLABX+C18 for a few projects and now I am trying MPLABX (v1.95, latest available versione) and XC8 Compiler to migrate to a more modern solution. Apart the fact that MPABX is not compatible with ICD2 (which I have not understood why, does Microchip want me to buy IDC3 at all costs? ) forcing me to use MPLAB for writing the application and the old MPLAB to debug it, I have now few quirks with XC8 compiler.

I am porting an application that was thought to work with USB Bootloader on a PIC18F4550.
I have read the documentation and solved the different #pragma management between the new XC8 compiler vs the "old" C18.I came here to understand why the _asm directive didn't work just to find that its name changed to #asm.
Then also for the __interrupt(type) qualifier that is now "interrupt type" (without brackets). This one gave me a bit more headaches.
Documentation under this point of view is quite disappointing being outdated or fuzzy.

So, I finally managed to have the high and low IRQ mapped from the bootloader to the application space starting from address 0x800, but I have not seen any way to map the reset vector.
That is, I have not found a way to make the application jump to a custom address after a reset.
I have also seen that nowhere in the support forum this problem has been discussed. Probabily I have missed something, but again documentation is not very clear.
Is that option buried somewhere in the project XC8 configuration options? Why there's not a __interrupt reset type as there are for high_priority and low_priority types?
 
Thanks in advance for any eventual anser
#1

13 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17837
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:XC8 and reset vector 2013/12/11 10:37:50 (permalink)
    0
    XC8 can be used with MPLab 8.92 and an ICD2.
    use an ASM goto or branch.
    Look at some of the Bootloader eaxamlpes. some are for Hi-Tech / XC8
    Look in the compiler sample folder
     
    #2
    CiccioB
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2013/12/11 05:32:50
    • Location: 0
    • Status: offline
    Re:XC8 and reset vector 2013/12/12 01:52:57 (permalink)
    0
    Yes, I know XC8 can be used with "old" MPLAB. However I find the new MPLABX a better solution as an IDE.
     
    I know about making a goto with ASM, but I have not found any example that shows how to map the reset vector at the correct remapped address in the application. You can easily (syntax issues apart) map the high and low priority vectors, but there's nothing about the reset vector. Neither in the documentation nor in any example I have looked at.
    Do you have a link to a precise example about that?
     
    BTW: why Microchip didn't add a "reset" interrupt type to make things easy and omogeneous with the new ISR handling?
     
     
    #3
    newfound
    Super Member
    • Total Posts : 1846
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:XC8 and reset vector 2013/12/12 02:48:46 (permalink)
    0 (2)
    Read the XC8 user guide.  CODEOFFSET is what you want.
    #4
    CiccioB
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2013/12/11 05:32:50
    • Location: 0
    • Status: offline
    Re:XC8 and reset vector 2013/12/12 13:00:52 (permalink)
    0
    I already read the XC8 documentation (and the C18 migration document too) and I already have understood the CODEOFFSET switch.
    But that does not answer the simple question that, as I can see, none has still solved:
    how can I map the reset vector.
    There's nothing in the documentation I have read that says a word about remapping it. Only the high and low priority ISR. 
    It may be that the documentation I have is outdated about that argument as it is about the asm and __interrupt syntax.
     
    When information is not easily available, it is quite frustrating going here and there to read this or that just to find out that the answer is not there.
    Instead of pointing to some generic documentation it would be much more helpful to have the single line code, or code snippet, that remaps the reset vector as it is for the high and low priority vector.
     
    It seems that the only way to place the wanted call into the reset vector is using the funct() @ vector_location. Is it right?
     
     
     
    #5
    mad_c
    Super Member
    • Total Posts : 1194
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re:XC8 and reset vector 2013/12/12 14:11:37 (permalink)
    0
    CiccioB

    I already read the XC8 documentation (and the C18 migration document too) and I already have understood the CODEOFFSET switch.
    But that does not answer the simple question that, as I can see, none has still solved:
    how can I map the reset vector.
    There's nothing in the documentation I have read that says a word about remapping it. Only the high and low priority ISR. 

    If you have read about the--CODEOFFSET option in the User's Guide, noted that it shifts the reset vector as well as the interrupts, tried experimenting with this option, but found that it does not meet your needs, then you might need to explain in more detail exactly what you want. If you use the CODEOFFSET option, it will simply offset all the vectors (reset and any applicable interrupts) by the amount you specify. It is up to you, the programmer, to work out how you get from the actual device vector to where the remapped software entry points will be located. That is usually done by a boot loader that performs a jump to  these locations.
     
    Jeff.
     
    #6
    CiccioB
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2013/12/11 05:32:50
    • Location: 0
    • Status: offline
    Re:XC8 and reset vector 2013/12/12 15:48:37 (permalink)
    0
    The question is simple, maybe I could not make me clear previously: how do I put custom code in the reset vector?
     
    Bootloader vectors jumps to remapped ones thanks to the --CODEOFFSET relocation. So the vector mapped at 0x08 in my case jumps to 0x808 which I could make it jump again to my ISR routine placed into my application memory space. I could to that because the compiler allows me to use the void interrupt high_priority myHighISR(void) syntax (and previously the pragma) that automatically place whatever is in this function (which should be max 16 words) into remapped 0x808 memory location. Same for the low priority ISR.
    However there's not such facility for reset vector. Bootloader jumps from 0x000 to remapped 0x800 which is populated with some default code that is not the one I want. There''s not a way to put my jump to anywhere I want as it is for high and low priority ISR
     
    So my question is, how could I make the reset vector to jump to whatever I want when using a remapping bootloader?
     
    I thought there was something like void interrupt reset myResetISR(void) syntax possible, which would make things easy and coherent with what was already implemented for high and low priority ISR. But there's not. Or all the documentation I could find does not report anything about that.
     
    So I imagine that to put a custom jump into the reset vector the only possible way is to use the @ memory_location mapping for functions.
    Is that correct or did I miss some document that better explain this?
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 17837
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:XC8 and reset vector 2013/12/12 16:44:44 (permalink)
    0
     Bootloader jumps from 0x000 to remapped 0x800 which is populated with some default code that is not the one I want. There''s not a way to put my jump to anywhere I want as it is for high and low priority ISR
    No  You can Jump where ever you want from the Bootloader.  But to Start the C Program you Must GOTO 0x800.
    If you neede different startup code That is a sererat issue
    #8
    newfound
    Super Member
    • Total Posts : 1846
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:XC8 and reset vector 2013/12/12 19:06:34 (permalink)
    0
    Right! You asked the wrong question and expressed frustration when you did get what you wanted. You are looking to change the start-up code not the reset vector which always will be mapped at 0x0000 + codeoffset. It has to be of course because there is no way for the bootloader to know where else to enter the user app.
     
    However I do agree that the XC8 documentation is very terse and it is difficult to find out how to do things that where previously very easy to do with MPASM and MPLABC18 and custom linker scripts.
     
    Jeff is highly knowledgeable and tries to help but it doesn't change the fact that the documentation is rather poor, outdated and incorrect as proven by two threads I started on similar issues.
     
    #9
    CiccioB
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2013/12/11 05:32:50
    • Location: 0
    • Status: offline
    Re:XC8 and reset vector 2013/12/13 02:25:42 (permalink)
    0
    It may be that I have not understood correctly how the reset vector works with XC8.
    As already pointed out the documentation is fuzzy about this topic.
     
    I have not understood how to make the application jump back to the bootloader (or a different adress) when the reset is performed.
    AFAIK the reset vector is thought to allow the program to jump to a precise memory location when the reset is performed. But I could not make it do that as I can't populate the reset vector with the code I want.
    With C18 you could easily place a jump to the address you wanted. I could not find this option with XC8.
     
    #10
    NKurzman
    A Guy on the Net
    • Total Posts : 17837
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:XC8 and reset vector 2013/12/14 13:33:58 (permalink)
    +1 (1)
    CiccioB

    It may be that I have not understood correctly how the reset vector works with XC8.
    As already pointed out the documentation is fuzzy about this topic.

    I have not understood how to make the application jump back to the bootloader (or a different adress) when the reset is performed.
    AFAIK the reset vector is thought to allow the program to jump to a precise memory location when the reset is performed. But I could not make it do that as I can't populate the reset vector with the code I want.
    With C18 you could easily place a jump to the address you wanted. I could not find this option with XC8.



    That is not clear to me.
    the PIC Jumps to zero on reset.  You can play with that is the bootloader as long as you jump to the beginning of the C program to run it.
     
    That said State the Problem, not your solution from a different compiler.
    The way C18 did things may be completely different then XC8.  Trying to make XC8 do it is putting a square peg in a round hole.
    #11
    CiccioB
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2013/12/11 05:32:50
    • Location: 0
    • Status: offline
    Re:XC8 and reset vector 2013/12/14 18:41:05 (permalink)
    0 (2)
    NKurzman
    That is not clear to me. 
    the PIC Jumps to zero on reset.  You can play with that is the bootloader as long as you jump to the beginning of the C program to run it.

    The  PIC jumps to zero, which with the bootloader ISR rempapping makes it jump to you relocation (0x800 in may case) which then jumps to.. well, I do not know nor I have control of it
     
    NKurzman
    That said State the Problem, not your solution from a different compiler.
    The way C18 did things may be completely different then XC8.  Trying to make XC8 do it is putting a square peg in a round hole.

    Nonetheless the option to make your code jump to where ever you need is lacking in XC8, while it is provided by C18.
    I do not want to force the compiler to do anything more than needed or already available with the older version. Given any syntax Microchip thinks is best for this purpose, this option should be provided. Up to now the only workaround I could find to this missing feature is to reloacte a function to 0x800 address. It doesn't have to be an interrupt defined function, so the trick should not have any side effect.
     
     
    #12
    newfound
    Super Member
    • Total Posts : 1846
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:XC8 and reset vector 2013/12/14 18:59:59 (permalink)
    +1 (1)
    CiccioB

    Nonetheless the option to make your code jump to where ever you need is lacking in XC8, while it is provided by C18.

     
    This from the XC8 help documentaion.
    The Powerup Routine
    Some hardware configurations require special initialization, often within the first few instruction cycles after Reset. To achieve this there is a hook to the Reset vector provided via the powerup routine.
    This routine can be supplied in a user-defined assembler module that will be executed immediately after Reset. A template powerup routine is provided in the file [size="10.0pt"]powerup.as which is located in the [size="10.0pt"]sources directory of your compiler distribution. Refer to comments in this file for more details.
    The file should be copied to your working directory, modified and included into your project as a source file. No special linker options or other code is required. The compiler will detect if you have defined a powerup routine and will automatically use it, provided the code in this routine is contained in a psect called [size="10.0pt"]powerup.
    For correct operation (when using the default compiler-generated runtime startup code), the code must end with a [size="10.0pt"]GOTO instruction to the label called [size="10.0pt"]start. As with all user-defined assembly code, any code inside this file must take into consideration program memory paging and/or data memory banking, as well as any applicable errata issues for the device you are using. The program’s entry point is already defined by the runtime startup code, so this should not be specified in the powerup routine with the end directive (if used).


     
    #13
    NKurzman
    A Guy on the Net
    • Total Posts : 17837
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:XC8 and reset vector 2013/12/17 16:35:39 (permalink)
    +2 (2)
    "Nonetheless the option to make your code jump to where ever you need is lacking in XC8, while it is provided by C18. "
    The inability to jump anywhere in code is a feature of C.
    I am unclear of what you want, But XC8 will support the asm GOTO opcode.
    I feel you are tring to put a square peg in a round hole.  instaed of using the round peg.
    The way C18 did things was different than XC8.  The solution will be different also.
    since you did not state the initial problem, you did not findout how to do it the way XC8 wants.
    #14
    Jump to:
    © 2019 APG vNext Commercial Version 4.5