<?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: Write Data to Internal Flash While the Code is Secured in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946222#M54587</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I realised&amp;nbsp;something. I'm writing 2 different calibration data to flash. So I have planned the flash memory orientation like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;#define FLASH_SIZE_KB&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;32&lt;BR /&gt;#define FLASH_END_ADDR&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( FLASH_SIZE_KB * 1024 )&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Result: 32768&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;#define CAL1_SIZE&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration1_t))&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;&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;&lt;SPAN style="background-color: #f6f6f6;"&gt;//Result: 104&lt;/SPAN&gt;&lt;BR /&gt;#define CAL1_FLASH_ADDR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( FLASH_END_ADDR - CAL1_SIZE )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;//Result: 32664&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;#define CAL2_SIZE&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration2_t))&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;&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;&amp;nbsp;/&lt;SPAN style="background-color: #f6f6f6;"&gt;/Result: 276&lt;/SPAN&gt;&lt;BR /&gt;#define CAL2_FLASH_ADDR&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( CAL1_FLASH_ADDR - CAL2_SIZE )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;//Result: 32388&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code snippet does not work properly. I also added the result of the calculations in the comment for you to check.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I set the addresses to below (constant addresses) and it is working well now:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;P&gt;#define FLASH_SIZE_KB &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;32&lt;BR /&gt;#define FLASH_END_ADDR &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( FLASH_SIZE_KB * 1024 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define CAL1_SIZE &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration1_t))&lt;BR /&gt;#define CAL1_FLASH_ADDR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;32000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define CAL2_SIZE &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration2_t))&lt;BR /&gt;#define CAL2_FLASH_ADDR &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;31000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What do you think causes the problem in the first snippet? Why it does not work when I don't set constant addresses? My calibration structs are aligned as 4 bytes. So there should not be any problem with padding.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Aug 2019 11:42:59 GMT</pubDate>
    <dc:creator>abdullah_cinar</dc:creator>
    <dc:date>2019-08-27T11:42:59Z</dc:date>
    <item>
      <title>Write Data to Internal Flash While the Code is Secured</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946217#M54582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to write 384 bytes of calibration data to the flash on my MKV10Z32. I also have the flash secured. The write operation and flash secure operation works well. But when I try to read my calibration data on device startup, it works unexpectedly. It succeeds to read the calibration data on a startup, but when I reset the device, it can not read it at this startup. Then I reset the device again and now it can read it. It&amp;nbsp;works on one startup and it does not work at the next startup and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I know, there shouldn't be any restriction to read/write to flash from firmware when the flash is secure. Please help me to solve this issue because I can not get any reason for this to happen...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attached my flash file that contains flash protection operation, read calibration and write calibration functions.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2019 14:34:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946217#M54582</guid>
      <dc:creator>abdullah_cinar</dc:creator>
      <dc:date>2019-08-20T14:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Write Data to Internal Flash While the Code is Secured</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946218#M54583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I recommend you to check chapter 30.4.12 from the &lt;A href="https://www.nxp.com/webapp/Download?colCode=KV10P48M75RM"&gt;Reference Manual&lt;/A&gt;. Related text quoted below:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;The flash memory module holds off CPU access during the reset sequence. Flash reads are possible when the hold is removed. Completion of the reset sequence is marked by setting CCIF which enables&lt;/P&gt;&lt;P&gt;flash user commands.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I believe you are reading flash when the reset sequence has not been completed. This will result in unexpected behavior.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if this helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Felipe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2019 21:04:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946218#M54583</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2019-08-21T21:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Write Data to Internal Flash While the Code is Secured</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946219#M54584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Felipe,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the answer. I was not able to find the support tickets, so I had created this topic first. But since you are handling both of them, we can close the case and continue from here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My flash secure function call was done after my flash read function call (read calibration data). So after reading your answer, I changed the order and put the flash&amp;nbsp;secure function call at the very beginning of my initializations. I also added a dummy delay at device startup to wait for things to get ready.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I realized that if I put the flash secure operation at the beginning of my initializations, I can not read the calibration data even once. Now I'm not sure if it is because I can not write my calibration data to flash after the flash secure operation or because I can not read it. How do I know what cause the problem? If I disable flash secure operation, I can read and write to flash successfully without any problem on device resets. I can also double check it by reading the flash hex (since there is not security). But I don't know how to know the cause of the problem when the device is secured.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there is something wrong with my flash secure operation, can you please give me a routine to prevent others to read our hex firmware from outside? We don't want to limit the flash read/write operations which&amp;nbsp;are requested by the firmware itself. Our hardware and firmware are ready except this flash security operation. We have completed the firmware test, then I added the flash security function and finish the development process and get to the production stage. But I realized that this function affects the test of the application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for the long post.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Aug 2019 06:46:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946219#M54584</guid>
      <dc:creator>abdullah_cinar</dc:creator>
      <dc:date>2019-08-22T06:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: Write Data to Internal Flash While the Code is Secured</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946220#M54585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Through firmware, the user can read, erase, and program the flash in the same way, even if the device is secured. The flash is not accessible to the outside world, but from within the part, the flash can be used normally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check chapter 30.4.11.2 of the Reference Manual.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;EM&gt;If the flash security byte is successfully programmed, its new value takes affect after the&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;next chip reset.&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Could you please try to read and write the flash after startup?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Felipe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Aug 2019 22:48:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946220#M54585</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2019-08-26T22:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Write Data to Internal Flash While the Code is Secured</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946221#M54586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Felipe,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already know that the protection takes effect after the chip reset. Did you review the code I attached above? I'm calling the flash secure function first and then read and write data to flash. I tested it after several chip resets but I still can not read it when the flash secure function is called. If I comment out the flash secure function call, it works successfully. Can you please help me to find the problem? Is that related to my flash protection function? Am I doing something wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Aug 2019 06:38:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946221#M54586</guid>
      <dc:creator>abdullah_cinar</dc:creator>
      <dc:date>2019-08-27T06:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Write Data to Internal Flash While the Code is Secured</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946222#M54587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I realised&amp;nbsp;something. I'm writing 2 different calibration data to flash. So I have planned the flash memory orientation like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;#define FLASH_SIZE_KB&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;32&lt;BR /&gt;#define FLASH_END_ADDR&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( FLASH_SIZE_KB * 1024 )&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Result: 32768&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;#define CAL1_SIZE&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration1_t))&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;&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;&lt;SPAN style="background-color: #f6f6f6;"&gt;//Result: 104&lt;/SPAN&gt;&lt;BR /&gt;#define CAL1_FLASH_ADDR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( FLASH_END_ADDR - CAL1_SIZE )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;//Result: 32664&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="margin: 0px; padding: 0px;"&gt;#define CAL2_SIZE&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration2_t))&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;&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;&amp;nbsp;/&lt;SPAN style="background-color: #f6f6f6;"&gt;/Result: 276&lt;/SPAN&gt;&lt;BR /&gt;#define CAL2_FLASH_ADDR&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( CAL1_FLASH_ADDR - CAL2_SIZE )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;//Result: 32388&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code snippet does not work properly. I also added the result of the calculations in the comment for you to check.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I set the addresses to below (constant addresses) and it is working well now:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;P&gt;#define FLASH_SIZE_KB &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;32&lt;BR /&gt;#define FLASH_END_ADDR &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( FLASH_SIZE_KB * 1024 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define CAL1_SIZE &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration1_t))&lt;BR /&gt;#define CAL1_FLASH_ADDR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;32000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define CAL2_SIZE &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( sizeof(calibration2_t))&lt;BR /&gt;#define CAL2_FLASH_ADDR &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;31000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What do you think causes the problem in the first snippet? Why it does not work when I don't set constant addresses? My calibration structs are aligned as 4 bytes. So there should not be any problem with padding.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Aug 2019 11:42:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946222#M54587</guid>
      <dc:creator>abdullah_cinar</dc:creator>
      <dc:date>2019-08-27T11:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Write Data to Internal Flash While the Code is Secured</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946223#M54588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I finally solved the problem. I found out that it is only allowed to write 1 sector of flash in a flash program routine. My flash addresses were corresponding to such an address that does not end up writing only 1 sector but writing some of the data to 1 sector and overflowing to the other sector. So I changed my code, I am calculating the addresses with respect to the sector sizes. I set each address to one of a sector start:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;BR /&gt;#define FLASH_SIZE_KB &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;32&lt;/P&gt;&lt;P&gt;#define SECTOR_SIZE&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; 1024&lt;/P&gt;&lt;P&gt;#define FLASH_END_ADDR &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( FLASH_SIZE_KB * 1024)&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define CAL1_SIZE &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;&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;&amp;nbsp;&amp;nbsp;( sizeof(calibration1_t))&lt;/P&gt;&lt;P&gt;#define CAL2_SIZE &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;&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;&amp;nbsp;&amp;nbsp;( sizeof(calibration2_t))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;CAL1_Addr = FLASH_END_ADDR - CAL1_SIZE;&lt;/P&gt;&lt;P&gt;/* Put the start address to the start of a sector (to prevent splitting the data to 2 sectors) */&lt;BR /&gt;if( (CAL1_Addr % SECTOR_SIZE) != 0)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;CAL1_Addr = CAL1_Addr - ( CAL1_Addr % &lt;SPAN style="background-color: #f6f6f6;"&gt;SECTOR_SIZE&lt;/SPAN&gt; );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Result:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;31744&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CAL2_Addr = CAL1_Addr - CAL2_SIZE;&lt;/P&gt;&lt;P&gt;/* Put the start address to the start of a sector (to prevent splitting the data to 2 sectors) */&lt;BR /&gt;if( (CAL2_Addr % SECTOR_SIZE) != 0)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;CAL2_Addr = CAL2_Addr - ( CAL2_Addr % &lt;SPAN style="background-color: #f6f6f6;"&gt;SECTOR_SIZE&lt;/SPAN&gt; );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;//Result:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt; 30720&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Aug 2019 12:14:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Write-Data-to-Internal-Flash-While-the-Code-is-Secured/m-p/946223#M54588</guid>
      <dc:creator>abdullah_cinar</dc:creator>
      <dc:date>2019-08-27T12:14:47Z</dc:date>
    </item>
  </channel>
</rss>

