• AVR Freaks

Hot!preserve program memory range

Author
ffrige
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2020/03/12 01:48:32
  • Location: 0
  • Status: offline
2020/08/27 20:56:12 (permalink)
0

preserve program memory range

I am working with a PIC32MK, the XC32 V2.30 compiler and a Snap programmer. My goal is to preserve a memory area in the flash and use it to save some permanent data. Note that I cannot use the emulated EEPROM because it is too small for my purpose.
 
I have declared the following variable:
//flash memory buffer for historic data
static const unsigned int flash_buffer[PAGE_WORDS * PAGE_MAX] __attribute__ ((__aligned__(PAGE_SIZE))) = { 0 };

All the read/write operations work well. But I need to make sure this area is preserved when I download new versions of the application program. So I went to the Snap properties, enabled "Preserve program memory" and given as a range the location of my variable as I read from the "execution memory" tab after reading the device memory. So far it all works fine.
 
My questions are:
  • how can I guarantee that the physical address of that memory area will stay the same when the size of the application program changes? 
  • how can I guarantee that the address stays the same across devices? Or do I need to check where that variable is allocated for each individual PIC32 that goes through my production line?
...in other words: is there a way to fix that memory location regardless of program size and device? (and maybe optimization?)
 
Finally, one last issue: I keep reading in the datasheets that the flash memory operations will block the program execution, unless my variable and the program are saved into two different memory banks. How can I do that in practice? I currently have no idea in which of the two banks my program and my variable are. 
 
Thanks!
#1

6 Replies Related Threads

    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: preserve program memory range 2020/09/23 04:21:18 (permalink)
    0
    I found a way to use the same memory address across devices regardless of the size of the application: instead of declaring a static variable (which also makes the resulting hex file larger) I simply define a pointer to an address and then use it for all the read/write operations.
     
    unsigned int* flash_buffer = (unsigned int*) 0x9D0F3800;

     
    The address is fixed, far away from where the application is stored, and does not modify the hex file size.
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 18975
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: preserve program memory range 2020/09/23 06:05:08 (permalink)
    0
    You can also use _attribute_ to set the address.
    Note you may need to add const and volatitle if you have any cache issues after a write.
    #3
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: preserve program memory range 2020/09/23 06:27:05 (permalink)
    0
    Yes, I tried with _attribute_, but the problem is that the hex file is much larger because it includes all the size of the memory occupied by that variable. Declaring only a pointer instead of the actual variable makes the hex file much smaller, which for me is critical since I transfer it via a slow Bluetooth connection.
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18975
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: preserve program memory range 2020/09/23 11:02:41 (permalink)
    4 (1)
    I guess that way will make your hex file smaller. Did you try not initializing it ?
    You may want to mark the area are used in your linker script. Or if it is at the end hell the link or there is less memory than there really is This will ensure the compiler does not attempt to use it in the future.
    #5
    ffrige
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2020/03/12 01:48:32
    • Location: 0
    • Status: offline
    Re: preserve program memory range 2020/09/23 18:07:09 (permalink)
    0
    Not initializing it was also my first thought, but I found out that the variable goes in RAM that way, not in flash!
     
    I did put the area at the end of the program memory. I will tell the linker script that there is less memory available for the kseg0_program_mem, thanks for the tip.
    #6
    NorthGuy
    Super Member
    • Total Posts : 6350
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: preserve program memory range 2020/09/24 07:50:44 (permalink)
    4 (2)
    If you encode the HEX file in binary form, you will reduce the transmission size by about 3 times. While doing so, you can re-arrange blocks, remove redundant blocks etc.
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5