<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: placing variable in ROM on exact location(using FRDM KE06) in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510192#M32201</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mark:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, actually the hardfault was easy to figure out from your first post. The code &lt;STRONG&gt;aap = aap&lt;/STRONG&gt; is both a read and a write access, but you are placing this variable in flash memory space, which cannot be written with a simple C code instruction. So you need to remove that line of code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However you are right that if the &lt;STRONG&gt;aap&lt;/STRONG&gt; variable is not referenced from your code then the linker discards it. To avoid this you can use the command &lt;STRONG&gt;KEEP&lt;/STRONG&gt;, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14559211726124429 jive_text_macro" data-renderedposition="191_8_1155_128" jivemacro_uid="_14559211726124429"&gt;&lt;P&gt;/* Section created to relocate code in specific Flash address */&lt;/P&gt;&lt;P&gt;.id_firmware :&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEEP(*(.id_firmware))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;} &amp;gt; my_id_firmware&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then any symbols (functions or variables) you place in the input section &lt;STRONG&gt;.id_firmware&lt;/STRONG&gt; will not be optimized out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps you move forward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;Jorge Gonzalez&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 19 Feb 2016 22:34:06 GMT</pubDate>
    <dc:creator>Jorge_Gonzalez</dc:creator>
    <dc:date>2016-02-19T22:34:06Z</dc:date>
    <item>
      <title>placing variable in ROM on exact location(using FRDM KE06)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510187#M32196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone know how to place a variable on a exact location in ROM?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the following methods:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14555258696769536 jive_text_macro" data-renderedposition="138_8_1192_16" jivemacro_uid="_14555258696769536"&gt;&lt;P&gt;volatile int bootStatus __attribute__((at(0xC0))) = 0x66;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14555259019627382" data-renderedposition="180_8_1192_16" jivemacro_uid="_14555259019627382"&gt;&lt;P&gt;int variable2 __attribute__((section(".id_firmware.__at_0xe2"))) = 10;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="_jivemacro_uid_14555248458748372 jive_macro_code jive_text_macro" data-renderedposition="222_8_1192_16" jivemacro_uid="_14555248458748372"&gt;&lt;P&gt;const int x1 __attribute__((at(0x200))) = 10; /* RO */&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14555248754714214 jive_text_macro" data-renderedposition="264_8_1192_16" jivemacro_uid="_14555248754714214"&gt;&lt;P&gt;__attribute__ ((section(".id_firmware"))) uint32_t aap = 0x11223344;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;this one doesn't write the memory on itself but when referring to it in the main on this way:&lt;/P&gt;&lt;P&gt;aap = aap;&lt;/P&gt;&lt;P&gt;it will place the data in opposite order (44332211) and the program gets a hard_fault interrupt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;memory layout in linker file is as follows:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14555248368137392 jive_text_macro" data-renderedposition="410_8_1192_464" jivemacro_uid="_14555248368137392"&gt;&lt;P&gt;MEMORY {&lt;/P&gt;&lt;P&gt;&amp;nbsp; m_interrupts&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (RX)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : ORIGIN = 0x00000000, LENGTH = 0x000000C0&lt;/P&gt;&lt;P&gt;&amp;nbsp; my_id_firmware&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (RX)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : ORIGIN = 0x000000c0, LENGTH = 0x00000340&lt;/P&gt;&lt;P&gt;&amp;nbsp; m_text&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (RX)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : ORIGIN = 0x00000410, LENGTH = 0x00002BF0&lt;/P&gt;&lt;P&gt;&amp;nbsp; m_data&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (RW)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : ORIGIN = 0x1FFFF000, LENGTH = 0x00004000&lt;/P&gt;&lt;P&gt;&amp;nbsp; m_cfmprotrom&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (RX)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : ORIGIN = 0x00000400, LENGTH = 0x00000010&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Define output sections */&lt;/P&gt;&lt;P&gt;SECTIONS&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* The startup code goes first into INTERNAL_FLASH */&lt;/P&gt;&lt;P&gt;&amp;nbsp; .interrupts :&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __vector_table = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEEP(*(.vectortable)) /* Startup code */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp; } &amp;gt; m_interrupts&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Section created to relocate code in specific Flash address */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .id_firmware :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *(.myROM)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;gt; my_id_firmware&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only thing I want is to hardcode a few variables in ROM so that I can access them from a bootloader program as well as the actual firmware program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using MKE06Z128LK4 Microcontroller&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be really great if someone can help me!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Feb 2016 08:46:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510187#M32196</guid>
      <dc:creator>mark313</dc:creator>
      <dc:date>2016-02-15T08:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: placing variable in ROM on exact location(using FRDM KE06)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510188#M32197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mark de Groot:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This guide should be what you are looking for: &lt;A href="http://mcuoneclipse.com/2012/11/01/defining-variables-at-absolute-addresses-with-gcc/" rel="nofollow noopener noreferrer" title="http://mcuoneclipse.com/2012/11/01/defining-variables-at-absolute-addresses-with-gcc/" target="_blank"&gt;Defining Variables at Absolute Addresses with gcc | MCU on Eclipse&lt;/A&gt;&lt;/P&gt;&lt;P&gt;There is also an extensive document about this topic here: &lt;A href="https://community.nxp.com/docs/DOC-104433" rel="nofollow noopener noreferrer" target="_blank"&gt;Relocating Code and Data Using the KDS GCC Linker File for Kinetis&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The correct syntax is the one you have for &lt;STRONG&gt;aap&lt;/STRONG&gt;, but in the linker file the input section should be called &lt;STRONG&gt;.id_firmware&lt;/STRONG&gt; instead of &lt;STRONG&gt;.myROM&lt;/STRONG&gt;, like next:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14555821727125099 jive_text_macro" data-renderedposition="190.5_8_1155_112" jivemacro_uid="_14555821727125099"&gt;&lt;P&gt;&amp;nbsp; .id_firmware :&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *(.id_firmware)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp; } &amp;gt; my_id_firmware&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if you still have issues.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Best Regards!&lt;BR /&gt;Jorge Gonzalez&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Feb 2016 00:22:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510188#M32197</guid>
      <dc:creator>Jorge_Gonzalez</dc:creator>
      <dc:date>2016-02-16T00:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: placing variable in ROM on exact location(using FRDM KE06)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510189#M32198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your answer!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, I still get a hard_fault interrupt when changing .myROM to .id_firmware.&lt;/P&gt;&lt;P&gt;also, thanks for the document, the whole thing makes a bit more sense to me now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Feb 2016 09:45:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510189#M32198</guid>
      <dc:creator>mark313</dc:creator>
      <dc:date>2016-02-16T09:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: placing variable in ROM on exact location(using FRDM KE06)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510190#M32199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case the placement of the variables should not cause any hardfault. If you are still having this issue please share your project with me and I can give it a check.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;Jorge Gonzalez&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Feb 2016 23:07:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510190#M32199</guid>
      <dc:creator>Jorge_Gonzalez</dc:creator>
      <dc:date>2016-02-18T23:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: placing variable in ROM on exact location(using FRDM KE06)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510191#M32200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jorge,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That would be great!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My project is included.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so far!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Feb 2016 09:48:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510191#M32200</guid>
      <dc:creator>mark313</dc:creator>
      <dc:date>2016-02-19T09:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: placing variable in ROM on exact location(using FRDM KE06)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510192#M32201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mark:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, actually the hardfault was easy to figure out from your first post. The code &lt;STRONG&gt;aap = aap&lt;/STRONG&gt; is both a read and a write access, but you are placing this variable in flash memory space, which cannot be written with a simple C code instruction. So you need to remove that line of code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However you are right that if the &lt;STRONG&gt;aap&lt;/STRONG&gt; variable is not referenced from your code then the linker discards it. To avoid this you can use the command &lt;STRONG&gt;KEEP&lt;/STRONG&gt;, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14559211726124429 jive_text_macro" data-renderedposition="191_8_1155_128" jivemacro_uid="_14559211726124429"&gt;&lt;P&gt;/* Section created to relocate code in specific Flash address */&lt;/P&gt;&lt;P&gt;.id_firmware :&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEEP(*(.id_firmware))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;/P&gt;&lt;P&gt;} &amp;gt; my_id_firmware&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then any symbols (functions or variables) you place in the input section &lt;STRONG&gt;.id_firmware&lt;/STRONG&gt; will not be optimized out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps you move forward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;Jorge Gonzalez&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:34:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510192#M32201</guid>
      <dc:creator>Jorge_Gonzalez</dc:creator>
      <dc:date>2016-02-19T22:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: placing variable in ROM on exact location(using FRDM KE06)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510193#M32202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is working!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Feb 2016 08:04:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/placing-variable-in-ROM-on-exact-location-using-FRDM-KE06/m-p/510193#M32202</guid>
      <dc:creator>mark313</dc:creator>
      <dc:date>2016-02-22T08:04:29Z</dc:date>
    </item>
  </channel>
</rss>

