MCU adressing question

Discussion in 'Embedded Systems and Microcontrollers' started by blukrr, Mar 20, 2016.

  1. blukrr

    Thread Starter New Member

    Mar 20, 2016
    1
    0
    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
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    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.
     
    blukrr likes this.
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    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!
     
Loading...