How to locate const in flash memory?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User5327
Level 4
Level 4
Hi all,
I need to use a table of const in my project. I need to locate this constants in concrete adresses on Flash.
What is the simpliest way to do this?

I tried create new section in Project Properties / C/C++ Build / Memory Settings Page
And use it in program like in gcc manual:
http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html

const uint8_t my_array[] __attribute__ ((section ("FLASH_2_uncached"))) = {0x01,0x02,0x03};

But it does'nt work 😞

#define MyValue (*(unsigned char *)(0x0C000100))
MyValue = 10;

This does'nt work too. I think that i will have to set linker, but I do not know how.

Any advice please?
0 Likes
2 Replies
Not applicable
Hi David,

I've tried to place a variable in Flash_1_uncatched region [FLASH_1_uncached(RX) : ORIGIN = 0x0C000000, LENGTH = 0x100000].
In *.ld,
Uncached_Code ABSOLUTE(__exidx_end | 0x04000000):
{
Uncached_Code_Start = .;
* (Uncached_Code);
. = ALIGN(4);
Uncached_Code_End = ABSOLUTE(.);
} > FLASH_1_uncached

/* CONST data section */
.rodata ABSOLUTE(Uncached_Code_End): AT(Uncached_Code_End | 0x04000000)


In main.c,
unsigned int MyData __attribute__ ((section("Uncached_Code")));
MyData = 0xAA;


Perhaps you can try to adapt to your case?!

BR,
Zain
0 Likes
User5327
Level 4
Level 4
Thank you very much!
It works perfectly 🙂
0 Likes