cancel
Showing results for 
Search instead for 
Did you mean: 

How to place variable at absolute memory location in Flash?????

hemant
Associate II
Posted on May 13, 2009 at 18:28

How to place variable at absolute memory location in Flash?????

2 REPLIES 2
hemant
Associate II
Posted on May 17, 2011 at 13:12

Hello,

I am using Eclipse + GNU C compiler + STM32F103ZC.

I want to store certain variables at fixed (Absolute) memory locations in Flash.

e.g.

vu16 CalConstantLo __at__ 0x08001FFFE;

vu16 CalConstantHi __at__ 0x08001FFFF;

Can some help me by educating me how to do this with GNU C compiler?

Regards,

Hemant.

darcy
Associate II
Posted on May 17, 2011 at 13:12

Easy peasy...

vu16 *CalConstantLo = (vu16*)0x08001FFFE;

The major down side of this is that the compiler won't reserve that area of memory for that variable. The method you've given below is an extension added by Keil to their compiler.

The only 'safe' way to do this with GCC is to modify the section placement and create your own section of x bytes in size at the top of FLASH. I've just been there and have had to do this myself. If you can ensure that code will never fill up to that point in flash then you can use the above method. If you want to make certain that it's always reserved then you'll need to reserve the top 'page' (1-2K depending on uC) as a section.

Then you'd have something like...

extern const uint32_t __custom_settings_start__;

extern const uint32_t __custom_settings_end__;

#define FLASH_PAGE_SIZE 0x0400 //This only applies to Low and Medium density devices...

static flash_settings_t const * ptr_flash_settings = (flash_settings_t const *)&__custom_settings_start__;

Use the FWLib examples to show you how to do the rest