MCU adressing question

Thread Starter

blukrr

Joined Mar 20, 2016
1
Dear All,

I'm new to embedded programming and I'm now developing an application to run on a STM32F4 MCU, I'll have to access internal memory to get status or I/Os and other information by means of a HMI using a RS-232 interface to pool this information.
I would like to know the best approach to code my C application to make sure that the internal memory variable's address won't change from time to time, especially when I add new variables to the code. If this happens it will be a pain to re point the HMI to the correct memory address back again.

I though about using a big array for all the variables and then using a #define for those array offsets so I can know what's each memory address is for. Arrays are consecutive memory address so at least I know nothing is going to change in between them, but the starting address could change which could mess all of the rest of the addresses.

Best regards,
Blukrr
 

MrChips

Joined Oct 2, 2009
30,708
Welcome to AAC.

What tool-chain are you using?

Usually, one does not have to be concerned with where your variables are located. Just let the compiler, header files and tool-chain take care of things.

Sometimes you may want a data array to begin at a specific location in memory. For this you can do something such as:

#define DATA_ADDRESS 0x20000000
#define DATA_SIZE 1024

short my_data[DATA_SIZE] @ DATA_ADDRESS;

Hope this helps.
 

ErnieM

Joined Apr 24, 2011
8,377
Why would you expect the address to change from time to time, and how would you know if it did?

You either get an array by declaring an array variable, or by getting some memory from say an alloc() call. Either way should give you a pointer to the start of the array just using the standard C constructs.

In the case of an alloc() call, sure the address changes on each call but you would not use the old address on a new call, right?

And welcome to the forums!
 
Top