[arm-gnu] Placing variable at absolute address in RAM

Moses McKnight moses at texband.net
Thu Apr 5 17:17:52 UTC 2012


Ok, looks like you're right there - bad example.  But I think my basic
idea is correct.  Here is yet another link - see the post by Paul Curtis
(he is a compiler writer) near the end.


excerpt:

struct my_placed_vars *my_vars = (void *)0x40003000; // EASY!

#define MY_VAR_1 (my_vars->var_1)
#define MY_VAR_2 (my_vars->var_2)

COMPLETELY PORTABLE AMONGST ALL COMPILERS FOR THE GIVEN TARGET!


On 04/05/2012 12:07 PM, Mark Deneen wrote:
> In your example, nothing has been declared.  Types have been defined,
> and you have a preprocessor macro mapping a particular address to a
> type, but nothing has been declared.
>
> I don't think that it's doing what you think it is doing.  You're
> fine in this situation simply because you are accessing peripheral
> registers and not SRAM.
>
> -M
>
> ----- Original Message ----- Actually, I think it does.  That example
> just reserved 4 bytes (sizeof(int)), but you can just as easily use a
> struct or probably even an array.
>
> Here's an example from the LPC17xx.h header from and NXP cortex-M3
> chip.
>
> typedef struct { volatile uint32_t mask[512]; }
> LPC_CANAF_RAM_TypeDef;
>
> #define LPC_APB0_BASE         (0x40000000UL) #define
> LPC_CANAF_RAM_BASE    (LPC_APB0_BASE + 0x38000) #define LPC_CANAF_RAM
> ((LPC_CANAF_RAM_TypeDef *) LPC_CANAF_RAM_BASE)
>
> See the core_cm3.h file from CMSIS for more examples.
>
> If I'm not mistaken when you declare a variable the compiler/linker
> always reserves enough memory for that type - even when you specify
> the starting address like this.
>
>
> _______________________________________________ arm-gnu mailing list
> arm-gnu at codesourcery.com
> http://sourcerytools.com/cgi-bin/mailman/listinfo/arm-gnu
>



More information about the arm-gnu mailing list