• AVR Freaks

Hot!pic32mx boot sequence what happens after reset?

Author
bastl
New Member
  • Total Posts : 30
  • Reward points : 0
  • Joined: 2018/12/27 07:25:34
  • Location: 0
  • Status: offline
2019/02/05 17:35:08 (permalink)
0

pic32mx boot sequence what happens after reset?

Hello, I ask this because the boot process is a big black hole in the documents.
After pressing reset, I guess:
- all the peripherals (-registers) are in there "default state", most 0.
- the register $pc is set to 0xBFC0 0000 (boot flash) like the other internal MPU registers are set to there value
  and the instruction at ($pc) is executed.
 
Now if I have a c, c++ project in MPLAB X IDE or a xc32-as project, hexfile in MPLAB X IPE what does each do at($pc_reset)...12k, and how can I and where, effect, change it in or with that, which apps?
 
- then the "boot loader" does "jr.hb ($t0) #where $t0 = 0xBD00 0000 (program flash)".
- now my project is executed,  the memory can be partitioned if I want and a user programm can be called with "jalr".
 
 I ask this, because my LED is not lightning, so my hexfile is not executed.
#1

15 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17229
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/05 20:15:01 (permalink)
    5 (1)
    "I ask this, because my LED is not lightning, so my hexfile is not executed".  Bad Guess. ( possible, but not likely.)
     
    Are YOU Using a Bootloader?
     
    After The PIC starts a the Reset Vector. (assuming you are using C, or even C++) there will be a jump to the C Start up code. The will clear memory and init variables Per The GCC version of the C Spec.  After that The C Start up will call main();  then it is all you.  Note there are configuration  that must be configured in you program.  If they are wrong, then nothing happening is a possibility.   This would assume your Hardware is Good.
     
    Start with you actual Problem not a Guess about how to solve it.
    Include your Full PIC Part number. Mplab Version, Compiler Version. Language ASM, C, C++, And what Hardware you are using. 
    #2
    bastl
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 09:25:42 (permalink)
    0
    I am a beginner so I use assembler, the xc32-as with the PICkit 4.
    There I can read out the chip and can see what's in the memory regions.
    The boot memory is empty, does not get written!
    And xc32-as seems not to know the directive .startup to write code to it.
    Now I don't know how to write code there - the boot region is not write protected!
    #3
    NKurzman
    A Guy on the Net
    • Total Posts : 17229
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 10:25:36 (permalink)
    0
    So ASM  The Short Answer is it is ASM you do everything, "It" Does Nothing.
    You need a "blank" ASM Project.
     
    Look in C:\Program Files (x86)\Microchip\xc32\v2.10\examples\assembly_examples ( Assuming you have V2.10)
    The segment you want your reset vector is already named in the Default Link script that XC32 will use if you do not supply your own.
    If that does not help, Ask about how to get started with a PIC32MX ASM Project.
    Be sure you address the Configuration bits.
     
    Being a Beginner does not require you to use ASM.  C is easier in some respects.  Beginning with ASM will force you to learn more about the chip, and improve your skills.  So I am not discouraging it.
    #4
    bastl
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 12:20:40 (permalink)
    0
    Yes, I'm responsible for everything ! -> xc32-as .
    Yes, I use a linker script, \32MX340F512H\procdefs.ld, but that does nothing with the beginning of boot memory.
    So I read the paragraph sections carefully at http://ww1.microchip.com/downloads/en/DeviceDoc/50002186A.pdf.
    and like this can be written to a specific address (all at once):
     
    .section bootmem, code, address(0x9FC00000)
     
    If PICkit-4 really writes to it and if that address is the first that is executed - I don't know.
    MPLAB X IPE says there is something if I load the hexfile but at that point it isn't written yet to the chip.
    #5
    Mysil
    Super Member
    • Total Posts : 3321
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 13:37:02 (permalink)
    0
    Hi,
    If you program in assembly language only, you may do everything yourself, if you want to.
    There are a few assembly language examples installed together with the compiler.
    You may try to undeerstand those first, before trying to do everything from scratch.
     
    Source code for: crt0.S     aka: C runtime startup
    is somewhere among the files installed together with the compiler.
    It is mentioned in XC32 Compiler users guide, chapter 3.6.17
    It is a assembler language file that you may study if wanted.
    It do some initialization, including initializing the stack pointer
    It is reasonably well commented, but is intended to work for many variants of PIC32M device types,
    so there is a lot of if's and but's.
     
    If a simple program doesn't work, there is a lot of possibilities that the problem is somewhere else.
     
    Not all CPU and SFR registers are cleared by a hardware Reset. Datasheet have specifications of what registers are initialized in various type of Reset:  Power On Reset,  MCLR Reset, Software Reset, ...
    RAM memory is Not changed by processor Reset,
    initial values for global and static variables, are copied from Flash to RAM memory by the startup code,
    according to what is specified in C language source code and compiler rules.
     
        Mysil
     
     
    #6
    qhb
    Superb Member
    • Total Posts : 9919
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 14:10:35 (permalink)
    5 (1)
    bastl
    Hello, I ask this because the boot process is a big black hole in the documents.

    That is because normally there is no "boot process". This is not a PC, the chip runs code directly from where it is stored.
    It is possible to install a "boot loader" if you want to be able to update the firmware without a device programmer, but that is not the primary way that the chip is designed.
     
    #7
    bastl
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 17:47:29 (permalink)
    0
    It is a uc32 board with PIC32MX340F512H and I thought PICkit 4 has erased all so the boot-mem, too,
    but now I get that there is an area that the PICkit 4 can not programm - this boot-mem from 0x1FC00000-0x1FC02FEF.
    So it couldn't have erased that area I hope and the program start is somewhere else and not at PA 0x1D000000,
    VA 0x9FC00000 or 0xBD000000.
    I also thought that "main" is linked and called but than "main" has to be set to a special position that is called.
    Is there a simple c example for the uc32 board (pic32mx) that I can test to see what has to be included and so, maybe with a port example, because my board led is connected to RG6. I search all the time. The template I have done, but then ... ???.
    Or someone knows where "main" has to reside (VA).
    Many thanks!
    #8
    Mysil
    Super Member
    • Total Posts : 3321
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 18:17:40 (permalink)
    0
    Hi,
    Even if a MPLAB project contain only assembly language source files,
    C runtime startup code will be inserted by the by the linker,
    and placed at the Reset address  0xBFC00000.
    Unless: 'Do not link crt0 startup code'   have been specified in MPLAB linker options.
     
    Startup code will jump to  main 
    This will be placed by linker in program memory, 0x9D000x00, but the first page is not used.
     
        Mysil
    #9
    NKurzman
    A Guy on the Net
    • Total Posts : 17229
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 18:31:56 (permalink)
    0
    "now I get that there is an area that the PICkit 4 can not programm - this boot-mem from 0x1FC00000-0x1FC02FEF."
    Wrong. 
    As pointed out this in Not a PC.  There are no reserved or hidden memory.  (except if You are Debugging, The Debugger will reserve part of the Boot Memory).
     
    See if the Company You bought is from has Sample Projects in ASM.
    https://forum.digilentinc.com/topic/916-sample-assembly-code-for-chipkit-uc32/
      
    I posted you to were there is ASM example code in XC32. 
    #10
    bastl
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 18:52:57 (permalink)
    0
    Mysil
    Startup code will jump to  main 
    This will be placed by linker in program memory, 0x9D000x00, but the first page is not used.
     
        Mysil


    O.K.that helps me a lot, thanks.
    Yes, I don't use MPLAB X IDE for assemble.
    I use this make file in a shell and a highlighting editor and MPLAB X IPE for burning the hexfile and PICkit 4 of course.
    make
    xc32-as --warn test.s -o test.o
    xc32-ld test.o -o test.elf -T C:\Microchip\xc32\v2.15\pic32mx\lib\proc\32MX340F512H\procdefs.ld
    xc32-bin2hex test.elf

    #11
    Mysil
    Super Member
    • Total Posts : 3321
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/06 19:46:06 (permalink)
    5 (1)
    Hi,
    Why do you not use MPLAB X and and the Debugger and examples provided with the compiler installation,
    to study and understand how it can be done?
     
    Boot memory is also erased by flash memory erase, when PICkit 4 issue the bulk erase command.
    When there is code in the Reset address and onwards, it is because linker have placed startup code,
    and programmer have written it there. 
     
    Boot flash memory from BFC00000 to BFC02FFF is also used by Interrupt vectors, Debugger code and Configuration bits.
    This is all erased when the device is erased, and written by the programmer,
    if the .hex file have the information.
     
    Main program entry point do not have to be placed at any particular address,
    the Linker will resolve the actual address when building the program image.
    It must have the correct global symbol, for the linker to find.
     
        Mysil
    #12
    bastl
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/07 13:30:05 (permalink)
    0
    Yes, an example would be nice but I can't get those installed to work.
    that would be very bad if the boot-mem is erased, because the PICkit 4 can not program that area !!!
    error: "0x1FC00000-0x1FC02FFF is outside the range of the device." ->12k boot-mem
    It seams that this area can only be programmed by software running on the uC32 board.
    But you can not run a bootloader update software if it don't get executed, but if you can set the $pc with the PICkit 4.
    Or is there a config file for that device in MPLAB X IPE where the areas are defined or/and limited?
    Digilent writes in the uc32 document:
    Digilent, chipKIT™ uC32™ Board Reference Manual
    ...
    The Microchip MPLAB® IDE or the MPLAB® X IDE can be used to program and debug code running on the uC32
    board. These programs can be downloaded from the Microchip web site.
    Using the Microchip development tools to program the uC32 board will cause the boot loader to be erased. To use
    the board with the MPIDE again, it is necessary to program the boot loader back onto the board. The boot loader
    image can be downloaded from the Digilent Uno32 product page.
    ...


    That doesn't mater, because I will use professional tools from Microchip.
    The examples that are installed in MPLAB X IDE v5.10 seems to be to old and don't work with the xc32 v2.15 compiler.?
     
     
    #13
    NKurzman
    A Guy on the Net
    • Total Posts : 17229
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/07 14:00:52 (permalink)
    0
    1. The PICKit4 should be able to write to every byte of flash. If not that is a bug in MPLabX, report it.
    2. The examples are in the v2.15 compilers folder, not MPLabX.
    3. Be careful with the addresses on the PIC32. There a 3 overlapping memory spaces. The pickit4 only deals with Physical The program cacheable and none cacheable. The linker script uses all of them. .
    #14
    bastl
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/07 17:36:27 (permalink)
    0
    O.K many thanks. I'll have a look to these examples
    And yes, I can write and read the boot-mem -> sorry, sorry ...
     
    ... maybe I'll get it sometimes...
    #15
    bastl
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2018/12/27 07:25:34
    • Location: 0
    • Status: offline
    Re: pic32mx boot sequence what happens after reset? 2019/02/08 15:24:17 (permalink)
    5 (1)
    Now I get it, the led is blinking.
    For those who are interested in assembler xc32-as I attached the file test3.s .
    Now I can look if I get c or c++ examples to work ...
    Many thanks to all for the great help!
    #16
    Jump to:
    © 2019 APG vNext Commercial Version 4.5