• AVR Freaks

Hot!NVM data array problems (too large and in the wrong place)

Author
Thorben.Z
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2017/06/03 06:33:33
  • Location: 0
  • Status: offline
2020/07/09 16:17:56 (permalink)
0

NVM data array problems (too large and in the wrong place)

I'm using a pic32mx170f256b and am trying to create a reserved memory area from 0x9d020000 to the end of NVM to store a firmware update.

I am currently allocating an array like this (smaller than I need obviously):
uint8_t data[0x1000] __attribute__((address(0x9d020000), keep));

But the memory usage increases by 0x2010 (subtracting the before and after memory usage tells me this).
 
In addition to that the array is not located at 0x9d020000, and if I add the space(prog) attribute the compiler refuses to build saying : 
Link Error: Could not allocate section '_05f34ae05f07a499' at 0x9d020000 SIZE 4096
Link Error: Could not allocate program memory

 
I honestly don't know where it put the variable when not using the space attribute, as a debug build crashed even before the program starts...
 
What am I doing wrong/is there a better way to reserve the upper half of memory?
 
#1

8 Replies Related Threads

    moser
    Super Member
    • Total Posts : 587
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: NVM data array problems (too large and in the wrong place) 2020/07/13 04:20:51 (permalink)
    +1 (1)
    I have no idea about your issue. And I could be completely wrong with the following. But I would have expected, that you need to use both const and volatile:
    uint8_t const volatile data[0x1000] __attribute__(( /*   [...]   */ ));

     
    const should tell the compiler to place it into program memory. Maybe without const the compiler probably tries to allocate it in his RAM data section, because that's the default for non-const variables. Read the XC32 compiler manual about __attribute__(( space( ... ) )).
     
    volatile is needed, because you are going to change that memory later after compilation, and you need to enforce that it always really does a real read of the memory and doesn't make any assumptions during optimization.
     
     
     
    #2
    Thorben.Z
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: NVM data array problems (too large and in the wrong place) 2020/07/14 14:24:36 (permalink)
    0
    Unfortunately this doesn't work :/
    But I did manage to get it to build by moving the definition to the .c file???
    Not sure what difference that makes but it does... At that point the memory usage was correct too (an increase in size by 0x1000 resulted in a usage of 0x1000 bytes more in the dashboard).
     
    But I found another issue:
    XC32 maps the interrupt vectors into the upper memory region, that I wanted to reserve.
    If I remember correctly the addresses for those are mappable in the architecture, so how can I tell XC32 to do that?
    #3
    ric
    Super Member
    • Total Posts : 28365
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: NVM data array problems (too large and in the wrong place) 2020/07/14 15:13:28 (permalink)
    +1 (1)
    Nothing that actually causes memory to be allocated should appear in a header file, it should be in a C file.
    Otherwise if two C files reference the same header, it will try to allocate the memory twice. "Include guards" will NOT prevent this!
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18901
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: NVM data array problems (too large and in the wrong place) 2020/07/14 15:21:29 (permalink)
    0
    Thorben.Z
    But I found another issue:
    XC32 maps the interrupt vectors into the upper memory region, that I wanted to reserve.
    If I remember correctly the addresses for those are mappable in the architecture, so how can I tell XC32 to do that?



    You will need to change the Linker script. Note the certain Segment have Specific alignment requirements.
    Note you could define your segment in the Linker script.
     
    #5
    moser
    Super Member
    • Total Posts : 587
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: NVM data array problems (too large and in the wrong place) 2020/07/15 00:26:41 (permalink)
    0
    Thorben.Z
    Unfortunately this doesn't work :/
    But I did manage to get it to build by moving the definition to the .c file???
    Not sure what difference that makes but it does...

    Make sure you understand the difference of a variable definition and a variable declaration. 
     
    Variable definition into .c file.
    Variable declaration into .h file.
    The declaration is only needed if you intend to use that variable elsewhere.
    For creating the declaration basically copy the definition, add the extern keyword and remove any initialization. Keep the qualifiers (const, volatile) and any __attribute__.
    #6
    Thorben.Z
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: NVM data array problems (too large and in the wrong place) 2020/07/16 04:59:46 (permalink)
    0
    "it will try to allocate the memory twice."
    Oh man I completely ignored that fact... The problems make a lot more sense now.
     
    "You will need to change the Linker script."
    I've tried that before, by using the default linker script, but didn't get it to build, even without modification.
    There was a comment in it that said something along the lines of "hey this file isn't actually used so have fun trying to figure this out...", so that is probably the issue. But with the (at least to me) confusing syntax I didn't even know what was missing.
    Are there any default linker scripts available? A quick google search turned up nothing.
     
    On a side note I tried to use the compiler option that reserves memory but that gave me some weird kind of error message about a compiler bug or something (I'm not at home and can't look up what exactly it said sorry). Is that a known issue?
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 18901
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: NVM data array problems (too large and in the wrong place) 2020/07/16 09:32:02 (permalink)
    0
    I will Use the Default Linker script in the compilers folder unless you goto XC32-ld and check use Response File.
    You can make a copy of the on in the compiler folder.
    Copy it to you project and edit it.  You will need to add it to you project. 
     
    optionally, You may be able to add a section on the command line.
    #8
    Thorben.Z
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2017/06/03 06:33:33
    • Location: 0
    • Status: offline
    Re: NVM data array problems (too large and in the wrong place) 2020/07/17 13:55:13 (permalink)
    0
    Ok I just found the script and got it working (at least I think :P).
    There are some more issues, but I'll make a post in the appropriate part of the forum for this.
     
    Thanks a lot :D
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5