I would like to assign a FLASH memory location to a value.
Previously under KDS I was able to make a linker section and then assign a variable to that value.
snippet from linker file:
.macaddr : AT(0x0007FFF0)
{
KEEP(*(.macaddr))
} > m_text
then in my code, I create a variable macaddr_data[16] and used __attribute__ ((section(".macaddr"))) to instruct the linker to place the variable into my assigned section.
unsigned char __attribute__ ((section(".macaddr"))) macaddr_data[16] = MAC_INITIALIZER;
Now under MCUXpresso, I created a section called macaddr to my memory location.
then in my code I use the following assignment:
__attribute__ ((section(".macaddr"))) unsigned char macaddr_data[16] = {0x00, 0x21, 0x6f, 0xFF, 0xBE, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
I do not receive any compiler/linker warnings or errors, when I analyze the .map file I so see my section .macaddr present, but when I run my code my initialized value of {0x00, 0x21, 0x6f, 0xFF, 0xBE, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} is not there and I don't understand why.
Can someone please provide me the correct syntax to perform this operation?
Thanks
I was pointed to the following document that helped me out.
Note: I did find that when adding data (vrs a function as detailed in the attached document), if you do not access the memory in your code, the compile will optimize out the assignment.
so in my case I'm adding a new assignment to .newmacaddr using the variable macaddr_data[]
__attribute__ ((used,section(".newmacaddr"))) unsigned char macaddr_data[16] = MAC_INITIALIZER;
somewhere in my code if I don't reference macaddr_addr, the array data MAC_INITIALIZER will not be made.
I would not recommend turning off the managed linker script mechanism as that document seems to suggest.
You also need to be careful with the "used" attribute, as it often doesn't do what you would expect/hope.
Thus if you aren't going to reference your array (which you might want to make const?) in your code, instead, assuming that you have created your ".macaddr" section as previously described, create a linkscripts folder inside your project, and copy the rodata.ldt file from the /Wizards/linker folder of your project install.
Then modify the copy of rodata.ldt in your linkscripts folder from:
*(.rodata.$${memory.alias}*) *(.rodata.$${memory.name}*)
to:
*(.rodata.$${memory.alias}*) *(.rodata.$${memory.name}*) <#if memory.alias=="Flash2"> KEEP(*(.macaddr)) </#if>
For more details, please see section 12.10, "Freemarker Linker Script Templates", of the MCUXpresso IDE v10.0.2 User Guide.
A couple of other points:
Regards,
MCUXpresso IDE Support
Hi Terry Biberdorf,
Thanks a lot for your solutions sharing.
If you still have question, just let us know in the community.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------