Const memory with fixed location and size

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

cross mob
Not applicable
Hi,

I do not know whether this post is for DAVE forum or XMC one...let the moderators decide..
I am using XMC1200 for an intelligent lightning system project. I work with XMC1200 LED Lighting Application Kit and DAVE 3.1.10 . I use DMX512RD01_Example1_XMC12 demo project as a base. So far the project goes pretty well. Only few things left to be done and one of it is the next.
1. I need to allocate at least 24 bit number in FLASH memory at known location. My application software will use the number stored in that location. In the software the number will be always set to 0.
2. I must also make this number changing each time when a device is programmed and going out from the production line. So at the end each device will have a unique number in FLASH

Regarding the first part I remember that long time ago we made some variable passing from linker. The allocation was in linker script file...but this linker script looks very different than the one I know...probably because it is gcc linker...
Regarding the second part. I found some posts here how to make the programming with batch files. I will use it as a base...and hex editor will be needed I presume...

Thank you
Cordially,
0 Likes
3 Replies
Not applicable
Hi,

You may refer to "Code in RAM" example for the function allocation.

BR,
Zain
0 Likes
Not applicable
Hi Zain,
Let say I need a following:

const uint32_t MfgAddr __attribute__((section(".MfgAddress"))) = {0x12345678};


And I want this to be nailed in address 0x10032F00 for example, and nobody to able to modify its location.
What should I write to ld file. Currently when I debug it, And read that reference (MfgAddr) I see the instructions are reading something very near in FLASH memory and it is not at fixed location!

Cordially,
Georgi
0 Likes
Not applicable
Hi Georgi,

One way of programming a function in a specific Flash location eg. starting from 0x08010000 in XMC4500
1) Place this function in a separated c file, eg. MyFunction.c
2) Declare this function in main.c, eg. void MyFucntion(void);
3) Define a separated Flash region (eg. FLASH_2) in ld file
MEMORY
{
FLASH_1_cached(RX) : ORIGIN = 0x08000000, LENGTH = 0x10000
FLASH_2_cached(RX) : ORIGIN = 0x08010000, LENGTH = 0x10000

4) Exclude this function object file (eg. MyFunction.o) in ld file
SECTIONS
{
/* TEXT section */

.text : AT (ORIGIN(FLASH_1_uncached))
{
sText = .;
*(.Xmc4500.reset);
*(.Xmc4500.postreset);
*(.XmcStartup);

/* exclude the object file that will run from FLASH_2_cached */
*(EXCLUDE_FILE( *MyFunction.o) *text* )
*(.gnu.linkonce.t.*);
...

However, I am afraid that you are unable to protect this Flash location since you are using XMC1200.

BR,
Zain
0 Likes