Topic : Creating an Array at set memory location

Forum : ARM

Original Post
Post Information Post
March 22, 2010 - 5:33pm
Guest

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

Replies
Post Information Post
+1
0
-1
March 30, 2010 - 10:54am
Guest

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

+1
0
-1
March 30, 2010 - 5:39pm
Guest

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

+1
0
-1
March 31, 2010 - 8:52am
Raisonance Support Team

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

+1
0
-1
April 1, 2010 - 3:29pm
Guest

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

+1
0
-1
April 1, 2010 - 5:27pm
Guest

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

Thanks,
Timothy

+1
0
-1
September 5, 2013 - 4:20am
Guest

Hi Tim. I am trying to do the same thing on a STM32F4 but haven't figured that out. I was using pointers with a 128K x 16bit SRAM memory but I needed to replace that with a larger memory, 512K x 16bit, and it has got very confusing having to write 16-bit word to 32-bit memory location using pointers. setting up a section for the SRAM would make my life a lot easier! could please let me know how to proceed?

thank you!