Topic: Creating an Array at set memory location

Hi,
I'm trying to create an array in set memory location, both for FLASH and RAM memory location.  The memory location where they are to go are already set aside as non-program memory.  Should I just create a pointer to the memory locations?  Or do I need to create a table?

What I'm looking for is a line of code that will create a table of type uint16_t of array size 16 both for FLASH and RAM.

FYI:
I'm working on a STM32 processor.  I already know how to create Variables at fixed locations, just not arrays.  What I'm trying to do is have an array in FLASH that then is loaded into RAM.  This will be done during an interrupt.  The reason I need fixed locations is so that I can change the values in the array over USB. I already have that up and running, I just need to have an array now that I can write to.

Any help would be much appreciated.  Thanks,
Timothy Burbridge

Re: Creating an Array at set memory location

Hi Tim

I do not know if you are still working on that issue, but I do not understand
some points in your question.
First one is "both for FLash and RAM" and second one is if you can do this operation
with variable why is different with array?

In case I think a few code lines on how you proceed for variable might help
to understand the operation.

From an outside point of view I wold try to define a section memory at a specific address.
Then define my array telling that it belongs to that section.

Regards
Matloub

Re: Creating an Array at set memory location

Sorry for the confusion. I found a way that works for FLASH, I just use a pointer to the first address and then add to the address for the next index.  This doesn't allow me to use indexing, but it works.  For RAM, I would really prefer to use indexing.

For RAM, I can declare a variable to set memory address:
#define ThrottleVal (*(__IO int16_t*) 0x20004C6E)

For RAM, I can declare an array:
uint16_t ThrottleArray[16];

I haven't been able to figure out how to declare this into a set memory address.  Right now, it puts it somewhere at compile time.  How do I change where it puts this?  If I try "org = 0x20004C70;" before this line, the program won't compile.  It doesn't recognize the "at" statement either.

I'm probably just missing something very simple, so thanks for looking at it,
Timothy Burbridge

Re: Creating an Array at set memory location

Hi Timothy,

You cannot locate objects at absolute addresses using the GCC compiler. You have to declare your object as a specific section, then modify your .ld linker file to properly map the given section at a specific memory address:

uint16_t ThrottleArray[16] __attribute__ ((section(".throttlearray")));

I hope this helps,
Bruno

Bruno Richard, PhD.
RAISONANCE - 17, avenue Jean Kuntzmann - F-38330 Montbonnot St Martin - FRANCE
There are 10 types of people in the world: Those who understand binary, and those who don't.

Re: Creating an Array at set memory location

Hi

To add some precisions on how to proceed if you think this solution would be a good one for your:

1. Use a customize linker script (.ld)
You can open the .elf.ld file corresponding to your project to see how it is working.
Then create your own .ld file wirtting the content of every .ld file included in the .elf.ld.
Change your Ride7 LD linker options to not use default linker script file and point to yours.
Once you are able to compile you can start modification.

2. Create a section
From GNU documentation you can find how to create a section (http://www.gnuarm.com/pdf/ld.pdf).

3. In your code use the attribute keyword referred above to place your array in the good section.

Regards
Matloub

Re: Creating an Array at set memory location

Awesome.  It's exactly what I'll need to do.

Thanks,
Timothy