How do you assign FLASH memory to value

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do you assign FLASH memory to value

2,164 Views
tbiberdorf
Contributor IV

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.

pastedImage_1.png

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

0 Kudos
3 Replies

1,810 Views
tbiberdorf
Contributor IV

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.

0 Kudos

1,810 Views
lpcxpresso_supp
NXP Employee
NXP Employee

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:

  • When creating "additional blocks" in flash, you need to take care with start addresses - in particular if they do not start on a sector boundary (as yours does not). In such cases, you may end up erasing any information earlier in the flash sector in some circumstances when programming your "additional block".
  • If you are starting "additional blocks" on such boundaries, you may sometimes seen strange behaviour when flash programming due to alignment issues with the sections in the ELF file. In such cases, try adding the "--nmagic" option to the "Other options" in the "Linker - Miscellaneous" settings in  project properties to turn the default ELD section alignment off.

Regards,

MCUXpresso IDE Support

0 Kudos

1,810 Views
kerryzhou
NXP TechSupport
NXP TechSupport

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!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos