<?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: Unable to write to MK60 internal Flash if a variable is declared in the section in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1522994#M64040</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Could be a long shot, but have you tried change the attributes of the section to WX (Read/Write and Executable).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Maybe trying to erase a Section with the Read-Only attribute gives an error.&lt;/P&gt;
&lt;P&gt;Again, could be a long shot.&lt;/P&gt;
&lt;P&gt;Let us know if this helps with your problem.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2022 14:40:17 GMT</pubDate>
    <dc:creator>Daniel-Aguirre</dc:creator>
    <dc:date>2022-09-15T14:40:17Z</dc:date>
    <item>
      <title>Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1521322#M64009</link>
      <description>&lt;P&gt;I am using the the NXP MK60FN1M0VLQ12 and I have some variables I want to store in the internal Flash, so I declared a separate section in the linker script and a global struct in it to be referenced by the code. Then to program it I use a slightly modified version of Processor Expert's FMC driver to erase the sector then program 8 bytes at a time.&lt;/P&gt;&lt;P&gt;However, whenever the global variable is declared, I fail to erase/program the flash, and otherwise it works fine. Of course the easy workaround in this case is to use a pointer to the section, but I also plan to rewrite a code section, where this wouldn't work. Does this have to do with the C linker/compiler or is it a MK60 or driver thing?&lt;/P&gt;&lt;P&gt;Here are the concerned code slices:&lt;/P&gt;&lt;P class=""&gt;Linker script:&lt;/P&gt;&lt;P class=""&gt;m_status_page (RX) : ORIGIN = 0x00040000, LENGTH = 0x00001000&lt;/P&gt;&lt;P class=""&gt;.status_page : { . = ALIGN(4); KEEP(*(.STATUS_PAGE)) . = ALIGN(4); } &amp;gt; m_status_page&lt;/P&gt;&lt;P class=""&gt;Global variable declaration:&lt;/P&gt;&lt;P class=""&gt;StatusPage _status_page[TOTAL_STATUS_PAGE_NUMBER] __attribute__ ((section (".STATUS_PAGE")));&lt;/P&gt;&lt;P class=""&gt;Then when I do the execute the following command it does nothing and doesn't throw an error:&lt;/P&gt;&lt;P class=""&gt;flashProgram8Bytes(bytes_to_program, _status_page);&lt;/P&gt;&lt;P class=""&gt;But if I don't declare the _status_page variable for example the following command works:&lt;/P&gt;&lt;P class=""&gt;flashProgram8Bytes(bytes_to_program, 0x00040000);&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:28:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1521322#M64009</guid>
      <dc:creator>LRawlyk</dc:creator>
      <dc:date>2022-09-13T14:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1521331#M64011</link>
      <description>&lt;P&gt;Not sure what your flashProgram8Bytes() does, but if you have data in it, does it perform an erase first?&lt;/P&gt;&lt;P&gt;What if you do that in your code too (erase first)?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:51:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1521331#M64011</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2022-09-13T14:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1521348#M64013</link>
      <description>&lt;P&gt;flashProgram8Bytes() is just an interface to call the Flash driver functions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LDD_TError flashEraseSector(uint8_t sector_number)&lt;BR /&gt;{&lt;BR /&gt;LDD_TError err;&lt;BR /&gt;err = FMC_EraseSector(sector_number);&lt;BR /&gt;if (err == ERR_OK)&lt;BR /&gt;return flashPerformOperation();&lt;BR /&gt;else&lt;BR /&gt;return err;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;LDD_TError flashEraseBlock(uint8_t block_number)&lt;BR /&gt;{&lt;BR /&gt;LDD_TError err;&lt;BR /&gt;err = FMC_EraseBlock(block_number);&lt;BR /&gt;if (err == ERR_OK)&lt;BR /&gt;return flashPerformOperation();&lt;BR /&gt;else&lt;BR /&gt;return err;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;LDD_TError flashProgram8Bytes(uint8_t* source_ptr, LDD_FLASH_TAddress destination_ptr)&lt;BR /&gt;{&lt;BR /&gt;LDD_TError err;&lt;BR /&gt;err = FMC_Write8Bytes(source_ptr, destination_ptr);&lt;BR /&gt;if (err == ERR_OK)&lt;BR /&gt;return flashPerformOperation();&lt;BR /&gt;else&lt;BR /&gt;return err;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;LDD_TError flashPerformOperation(void)&lt;BR /&gt;{&lt;BR /&gt;LDD_FLASH_TOperationStatus status;&lt;BR /&gt;status = FMC_PerformOperation();&lt;BR /&gt;if (status == LDD_FLASH_DONE)&lt;BR /&gt;{&lt;BR /&gt;status = FMC_GetOperationResult();&lt;BR /&gt;if (status == LDD_FLASH_IDLE)&lt;BR /&gt;return ERR_OK;&lt;BR /&gt;else&lt;BR /&gt;return ERR_FAILED;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;return ERR_RANGE;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am erasing the Flash first. The real code is more complicated than this, but what I'm doing is basically:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;flashEraseSector((uint32_t)_status_page / MK60_FLASH_SECTOR_SIZE);&lt;/P&gt;&lt;P&gt;uint8_t bytes_to_program[8];&lt;/P&gt;&lt;P&gt;for (int i=0; i &amp;lt; data_size; i+=8)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; initialize_bytes();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flashProgram8Bytes(bytes_to_program, _status_page + i);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The flash remains untouched after erases and program commands like this, but it works fine if I remove the _status_page declaration and replace it with 0x00040000 for example.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 15:14:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1521348#M64013</guid>
      <dc:creator>LRawlyk</dc:creator>
      <dc:date>2022-09-13T15:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1522994#M64040</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Could be a long shot, but have you tried change the attributes of the section to WX (Read/Write and Executable).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Maybe trying to erase a Section with the Read-Only attribute gives an error.&lt;/P&gt;
&lt;P&gt;Again, could be a long shot.&lt;/P&gt;
&lt;P&gt;Let us know if this helps with your problem.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 14:40:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1522994#M64040</guid>
      <dc:creator>Daniel-Aguirre</dc:creator>
      <dc:date>2022-09-15T14:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523060#M64041</link>
      <description>&lt;P&gt;Hello, no this is a legitimate try, but I've already tried it without success.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 16:29:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523060#M64041</guid>
      <dc:creator>LRawlyk</dc:creator>
      <dc:date>2022-09-15T16:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523068#M64042</link>
      <description>&lt;P&gt;I actually just realized something I should've before.&lt;/P&gt;&lt;P&gt;When I declare a variable in the section it's getting 0 initialized. If I declare an uint32_t I'm getting 4 bytes 0 initialized, if I declare an uint32_t[2] I get 8 bytes, and so on.&lt;/P&gt;&lt;P&gt;However I don't know if this is normal and what's the link to not being able to erase or program the flash...&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 15 Sep 2022 16:46:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523068#M64042</guid>
      <dc:creator>LRawlyk</dc:creator>
      <dc:date>2022-09-15T16:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523073#M64044</link>
      <description>&lt;P&gt;You are telling that when sending the value as a constant (without the label), works.&lt;/P&gt;&lt;P&gt;What if instead of just putting the label, you send it through a function that returns the constant value. That could also help to understand if the linker if taking the label as the&amp;nbsp;&lt;SPAN&gt;0x00040000 value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Instead of&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;flashEraseSector((uint32_t)_status_page / MK60_FLASH_SECTOR_SIZE);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could be&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;flashEraseSector((uint32_t) returnAsConstant(_status_page) / MK60_FLASH_SECTOR_SIZE);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Again, could be another long shot.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 16:55:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523073#M64044</guid>
      <dc:creator>Daniel-Aguirre</dc:creator>
      <dc:date>2022-09-15T16:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523464#M64056</link>
      <description>&lt;P&gt;From I can see the way the parameter is passed to the driver function has no effect in making it work or not.&lt;/P&gt;&lt;P&gt;When I declare a variable in the section, whether I point to the variable or I use the section address directly (0x00040000 in this case), the variable gets 0 initialized and I can't erase or program the flash. And when it isn't declared it works, but of course in this case I use an address since the variable isn't declared.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 07:34:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1523464#M64056</guid>
      <dc:creator>LRawlyk</dc:creator>
      <dc:date>2022-09-16T07:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1524334#M64061</link>
      <description>&lt;P&gt;Looking deeper in the RM, it is told that " A write operation to program flash memory or to data flash memory results in a bus error. " [Page 585,&amp;nbsp;K60 Sub-Family Reference Manual, Rev. 6.1, Aug 2012].&lt;/P&gt;
&lt;P&gt;The FMC seems to be more of a read acceleration for Program and Data Flash Memory, but does not have the capabilities to write to them.&lt;/P&gt;
&lt;P&gt;Seems strange that you can write using FMC, but that could be why they are getting 0 initialized.&lt;/P&gt;
&lt;P&gt;As a summary, seems to be more of a MK60 platform related.&lt;/P&gt;
&lt;P&gt;Please, let us know if this information is helpful or not&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 13:47:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1524334#M64061</guid>
      <dc:creator>Daniel-Aguirre</dc:creator>
      <dc:date>2022-09-19T13:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write to MK60 internal Flash if a variable is declared in the section</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1525616#M64070</link>
      <description>&lt;P&gt;That's interesting because we've had applications developed that fully rely on the FMC writing to program flash for firmware upgrade purposes (using the workaround to not define variables in the section or to not define sections at all). That seems to be a bug turned into a feature then...&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 07:25:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Unable-to-write-to-MK60-internal-Flash-if-a-variable-is-declared/m-p/1525616#M64070</guid>
      <dc:creator>LRawlyk</dc:creator>
      <dc:date>2022-09-21T07:25:11Z</dc:date>
    </item>
  </channel>
</rss>

