2009-05-13 09:28 AM
How to place variable at absolute memory location in Flash?????
2011-05-17 04:12 AM
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.2011-05-17 04:12 AM
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