<?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: Can't get C90TFS routines to write flash in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Can-t-get-C90TFS-routines-to-write-flash/m-p/676628#M41622</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kerry: Thanks.&lt;/P&gt;&lt;P&gt;I've brought in the DSDK 2.2 flash driver as well as copied some of the start up code from the demo examples. I get identical results to the 1.3, i.e., the routines complete with successful return status, but the flash never changes.&lt;BR /&gt;I'm beginning to suspect the problem my be in the 1.3 header files, such as fsl_device_registers.h, but I can't bring in the 2.2 version since all of my other code relies on 1.3.&lt;/P&gt;&lt;P&gt;Really bizarre such a simple piece of code can't work. Please have a look and see if I've done anything really stupid that keeps this from working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Here's output from the version using the 2.2 driver:&lt;/P&gt;&lt;P&gt;@fffffffffffffffffffffffffe1affff&lt;BR /&gt;FLASH_Init(): rc = 0x00&lt;/P&gt;&lt;P&gt;PFlash Example Start&lt;/P&gt;&lt;P&gt;PFlash Information: &lt;BR /&gt; Flash block base address: 0x0&lt;BR /&gt; Total Program Flash Size: 32 KB, Hex: (0x8000)&lt;BR /&gt; Program Flash Sector Size: 1 KB, Hex: (0x400)&lt;/P&gt;&lt;P&gt;FLASH_Erase(): rc = 0x00&lt;/P&gt;&lt;P&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe&lt;BR /&gt;fffffffffffffffffffffffffe1affff&lt;BR /&gt;FLASH_VerifyErase(): rc = 0x00&lt;/P&gt;&lt;P&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe&lt;/P&gt;&lt;P&gt;FLASH_Program(): rc = 0x00&lt;/P&gt;&lt;P&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe&lt;BR /&gt;fffffffffffffffffffffffffe1affff&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And the code (sorry the paste doesn't preserve indentation)&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;/* ----------------------------------------------------------------------------&lt;BR /&gt; Copyright (c) 2017, ZOS, Inc.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Author(s): Bill Fox &amp;lt;&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:billfox@bct.com"&gt;billfox@bct.com&lt;/A&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Target(s): ISO/IEC 9899:1999 (C99)&lt;BR /&gt; ------------------------------------------------------------------------- */&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdint.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;/P&gt;&lt;P&gt;#include "fsl_flash.h"&lt;/P&gt;&lt;P&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "constants.h"&lt;BR /&gt;#include "delay.h"&lt;/P&gt;&lt;P&gt;#define FLASH_LOGGING_ENABLE 1&lt;/P&gt;&lt;P&gt;#if (FLASH_LOGGING_ENABLE == 1)&lt;BR /&gt;#define FLASH_LOG(...) debug_printf(__VA_ARGS__)&lt;BR /&gt;#else&lt;BR /&gt;#define FLASH_LOG(...)&lt;BR /&gt;#endif&lt;BR /&gt; &lt;BR /&gt;#define FTFA_FSEC_ADDR 0x040c&lt;BR /&gt;#define FTFA_FOPT_ADDR 0x040d&lt;BR /&gt;uint8_t const *pFTFA_FSEC = (uint8_t *)FTFA_FSEC_ADDR;&lt;BR /&gt;uint8_t const *pFTFA_FOPT = (uint8_t *)FTFA_FOPT_ADDR;&lt;/P&gt;&lt;P&gt;static flash_config_t s_flashDriver;&lt;/P&gt;&lt;P&gt;static void printFLASH( uint32_t addr, size_t size ){&lt;BR /&gt; for(;size;size--){&lt;BR /&gt; FLASH_LOG("%02x", *(uint8_t*)addr++);&lt;BR /&gt; }&lt;BR /&gt; FLASH_LOG("\n");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void&lt;BR /&gt;flash_protection(void){&lt;/P&gt;&lt;P&gt;uint8_t config_FSEC = *pFTFA_FSEC;&lt;BR /&gt; uint8_t config_FOPT = *pFTFA_FOPT;&lt;BR /&gt; uint32_t buf = (config_FOPT &amp;lt;&amp;lt; 8) | config_FSEC;&lt;/P&gt;&lt;P&gt;uint32_t rc = 0;&lt;/P&gt;&lt;P&gt;uint32_t pflashBlockBase = 0;&lt;BR /&gt; uint32_t pflashTotalSize = 0;&lt;BR /&gt; uint32_t pflashSectorSize = 0;&lt;/P&gt;&lt;P&gt;printFLASH( 0x400, 16 );&lt;/P&gt;&lt;P&gt;memset(&amp;amp;s_flashDriver, 0, sizeof(flash_config_t));&lt;BR /&gt; rc = FLASH_Init(&amp;amp;s_flashDriver);&lt;BR /&gt; FLASH_LOG("FLASH_Init(): rc = 0x%02x\n", rc );&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &amp;amp;pflashBlockBase);&lt;BR /&gt; FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflashTotalSize, &amp;amp;pflashTotalSize);&lt;BR /&gt; FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflashSectorSize, &amp;amp;pflashSectorSize);&lt;/P&gt;&lt;P&gt;/* print welcome message */&lt;BR /&gt; debug_printf("\r\n PFlash Example Start \r\n");&lt;BR /&gt; /* Print flash information - PFlash. */&lt;BR /&gt; debug_printf("\r\n PFlash Information: ");&lt;BR /&gt; debug_printf("\r\n Flash block base address:\t0x%0x", pflashBlockBase);&lt;BR /&gt; debug_printf("\r\n Total Program Flash Size:\t%d KB, Hex: (0x%x)", (pflashTotalSize / 1024), pflashTotalSize);&lt;BR /&gt; debug_printf("\r\n Program Flash Sector Size:\t%d KB, Hex: (0x%x)\n\n", (pflashSectorSize / 1024), pflashSectorSize);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rc = FLASH_Erase(&amp;amp;s_flashDriver, 0x400, 1024, kFLASH_ApiEraseKey);&lt;BR /&gt; FLASH_LOG("FLASH_Erase(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf );&lt;/P&gt;&lt;P&gt;printFLASH( 0x400, 16 );&lt;/P&gt;&lt;P&gt;rc = FLASH_VerifyErase(&amp;amp;s_flashDriver, 0x400, 1024, kFLASH_MarginValueUser);&lt;BR /&gt; FLASH_LOG("FLASH_VerifyErase(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf );&lt;/P&gt;&lt;P&gt;rc = FLASH_Program(&amp;amp;s_flashDriver, FTFA_FSEC_ADDR, &amp;amp;buf, 4 );&lt;BR /&gt; FLASH_LOG("\nFLASH_Program(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf );&lt;/P&gt;&lt;P&gt;printFLASH( 0x400, 16 );&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Jul 2017 02:38:28 GMT</pubDate>
    <dc:creator>ee4hire</dc:creator>
    <dc:date>2017-07-21T02:38:28Z</dc:date>
    <item>
      <title>Can't get C90TFS routines to write flash</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Can-t-get-C90TFS-routines-to-write-flash/m-p/676626#M41620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How to get the C90TFS driver to write flash in a KL03Z4 MCU. I simply copied each file for each command I wanted to execute into my project. Compiles and seems to execute fine. All commands complete with success return code, but as far as I can see, the flash never gets erased or written.&lt;/P&gt;&lt;P&gt;Here is the code I'm using:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdint.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;/P&gt;&lt;P&gt;#include "SSD_FTFx.h"&lt;/P&gt;&lt;P&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "constants.h"&lt;/P&gt;&lt;P&gt;#define FLASH_LOGGING_ENABLE 1&lt;/P&gt;&lt;P&gt;#if (FLASH_LOGGING_ENABLE == 1)&lt;BR /&gt;#define FLASH_LOG(...) debug_printf(__VA_ARGS__)&lt;BR /&gt;#else&lt;BR /&gt;#define FLASH_LOG(...)&lt;BR /&gt;#endif&lt;BR /&gt; &lt;BR /&gt;#define FTFA_FSEC_ADDR 0x040c&lt;BR /&gt;#define FTFA_FOPT_ADDR 0x040d&lt;BR /&gt;uint8_t const *pFTFA_FSEC = (uint8_t *)FTFA_FSEC_ADDR;&lt;BR /&gt;uint8_t const *pFTFA_FOPT = (uint8_t *)FTFA_FOPT_ADDR;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void&lt;BR /&gt;flash_protection(void){&lt;/P&gt;&lt;P&gt;uint8_t config_FSEC = *pFTFA_FSEC;&lt;BR /&gt; uint8_t config_FOPT = *pFTFA_FOPT;&lt;BR /&gt; uint8_t buf[4] = { config_FSEC, config_FOPT, 0xff, 0xff };&lt;/P&gt;&lt;P&gt;uint32_t rc = 0;&lt;/P&gt;&lt;P&gt;FLASH_SSD_CONFIG flash_ssd_config = {&lt;BR /&gt; .ftfxRegBase = FTFA_BASE,&lt;BR /&gt; .PFlashBase = 0u,&lt;BR /&gt; .PFlashSize = 0x8000u,&lt;BR /&gt; .DebugEnable = true,&lt;BR /&gt; .CallBack = NULL,&lt;BR /&gt; };&lt;/P&gt;&lt;P&gt;debug_printf("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%02x, 0x%02x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf[0], buf[1] );&lt;/P&gt;&lt;P&gt;rc = FlashInit(&amp;amp;flash_ssd_config);&lt;BR /&gt; FLASH_LOG("FlashInit(): rc = 0x%02x\n", rc );&lt;/P&gt;&lt;P&gt;uint32_t protectStatus = 0;&lt;BR /&gt; rc = PFlashGetProtection(&amp;amp;flash_ssd_config, &amp;amp;protectStatus );&lt;BR /&gt; FLASH_LOG("\nPFlashGetProtection(): rc = 0x%02x, protectStatus = 0x%08x\n", rc, protectStatus );&lt;/P&gt;&lt;P&gt;uint8_t securityState;&lt;BR /&gt; rc = FlashGetSecurityState(&amp;amp;flash_ssd_config, &amp;amp;securityState);&lt;BR /&gt; FLASH_LOG("\nFlashGetSecurityState(): rc = 0x%02x, securityState = 0x%02x\n", rc, securityState );&lt;/P&gt;&lt;P&gt;rc = FlashEraseSector(&amp;amp;flash_ssd_config, 0x400, 1024, FlashCommandSequence );&lt;BR /&gt; FLASH_LOG("\nFlashEraseSector(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("FSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%02x, 0x%02x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf[0], buf[1] );&lt;/P&gt;&lt;P&gt;buf[0] |= 1;&lt;/P&gt;&lt;P&gt;rc = FlashProgram(&amp;amp;flash_ssd_config, FTFA_FSEC_ADDR, 4, buf, FlashCommandSequence );&lt;BR /&gt; FLASH_LOG("\nFlashProgramFlash(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("FSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%02x, 0x%02x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf[0], buf[1] );&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;and the results of its execution:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0xfe, 0x1a&lt;BR /&gt;FlashInit(): rc = 0x00&lt;/P&gt;&lt;P&gt;PFlashGetProtection(): rc = 0x00, protectStatus = 0xffffffff&lt;/P&gt;&lt;P&gt;FlashGetSecurityState(): rc = 0x00, securityState = 0x01&lt;/P&gt;&lt;P&gt;FlashEraseSector(): rc = 0x00&lt;BR /&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0xfe, 0x1a&lt;/P&gt;&lt;P&gt;FlashProgramFlash(): rc = 0x00&lt;BR /&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0xff, 0x1a&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Any suggestions as to why this doesn't write the flash would be much appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jul 2017 20:46:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Can-t-get-C90TFS-routines-to-write-flash/m-p/676626#M41620</guid>
      <dc:creator>ee4hire</dc:creator>
      <dc:date>2017-07-19T20:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get C90TFS routines to write flash</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Can-t-get-C90TFS-routines-to-write-flash/m-p/676627#M41621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello William Fox,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Actually, you can use our SDK_2.2_FRDM-KL03Z flash code directly, this code already be test, and it works OK on the FRDM-KL03 board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I think you can try the official code at first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Please download the KSDK code from this link:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://mcuxpresso.nxp.com/en/welcome" title="https://mcuxpresso.nxp.com/en/welcome"&gt;Welcome to MCUXpresso | MCUXpresso Config Tools&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SDK Builder, choose the board as FRDM-KL03, generate the code and download it, you can find the flash code in folder:&lt;/P&gt;&lt;P&gt;SDK_2.2_FRDM-KL03Z\boards\frdmkl03z\driver_examples\flash\pflash&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please try it at first, if you still have question, please let me know!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Kerry&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>Thu, 20 Jul 2017 08:20:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Can-t-get-C90TFS-routines-to-write-flash/m-p/676627#M41621</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2017-07-20T08:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get C90TFS routines to write flash</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Can-t-get-C90TFS-routines-to-write-flash/m-p/676628#M41622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kerry: Thanks.&lt;/P&gt;&lt;P&gt;I've brought in the DSDK 2.2 flash driver as well as copied some of the start up code from the demo examples. I get identical results to the 1.3, i.e., the routines complete with successful return status, but the flash never changes.&lt;BR /&gt;I'm beginning to suspect the problem my be in the 1.3 header files, such as fsl_device_registers.h, but I can't bring in the 2.2 version since all of my other code relies on 1.3.&lt;/P&gt;&lt;P&gt;Really bizarre such a simple piece of code can't work. Please have a look and see if I've done anything really stupid that keeps this from working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Here's output from the version using the 2.2 driver:&lt;/P&gt;&lt;P&gt;@fffffffffffffffffffffffffe1affff&lt;BR /&gt;FLASH_Init(): rc = 0x00&lt;/P&gt;&lt;P&gt;PFlash Example Start&lt;/P&gt;&lt;P&gt;PFlash Information: &lt;BR /&gt; Flash block base address: 0x0&lt;BR /&gt; Total Program Flash Size: 32 KB, Hex: (0x8000)&lt;BR /&gt; Program Flash Sector Size: 1 KB, Hex: (0x400)&lt;/P&gt;&lt;P&gt;FLASH_Erase(): rc = 0x00&lt;/P&gt;&lt;P&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe&lt;BR /&gt;fffffffffffffffffffffffffe1affff&lt;BR /&gt;FLASH_VerifyErase(): rc = 0x00&lt;/P&gt;&lt;P&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe&lt;/P&gt;&lt;P&gt;FLASH_Program(): rc = 0x00&lt;/P&gt;&lt;P&gt;FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe&lt;BR /&gt;fffffffffffffffffffffffffe1affff&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And the code (sorry the paste doesn't preserve indentation)&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;/* ----------------------------------------------------------------------------&lt;BR /&gt; Copyright (c) 2017, ZOS, Inc.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Author(s): Bill Fox &amp;lt;&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:billfox@bct.com"&gt;billfox@bct.com&lt;/A&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Target(s): ISO/IEC 9899:1999 (C99)&lt;BR /&gt; ------------------------------------------------------------------------- */&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdint.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;/P&gt;&lt;P&gt;#include "fsl_flash.h"&lt;/P&gt;&lt;P&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "constants.h"&lt;BR /&gt;#include "delay.h"&lt;/P&gt;&lt;P&gt;#define FLASH_LOGGING_ENABLE 1&lt;/P&gt;&lt;P&gt;#if (FLASH_LOGGING_ENABLE == 1)&lt;BR /&gt;#define FLASH_LOG(...) debug_printf(__VA_ARGS__)&lt;BR /&gt;#else&lt;BR /&gt;#define FLASH_LOG(...)&lt;BR /&gt;#endif&lt;BR /&gt; &lt;BR /&gt;#define FTFA_FSEC_ADDR 0x040c&lt;BR /&gt;#define FTFA_FOPT_ADDR 0x040d&lt;BR /&gt;uint8_t const *pFTFA_FSEC = (uint8_t *)FTFA_FSEC_ADDR;&lt;BR /&gt;uint8_t const *pFTFA_FOPT = (uint8_t *)FTFA_FOPT_ADDR;&lt;/P&gt;&lt;P&gt;static flash_config_t s_flashDriver;&lt;/P&gt;&lt;P&gt;static void printFLASH( uint32_t addr, size_t size ){&lt;BR /&gt; for(;size;size--){&lt;BR /&gt; FLASH_LOG("%02x", *(uint8_t*)addr++);&lt;BR /&gt; }&lt;BR /&gt; FLASH_LOG("\n");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void&lt;BR /&gt;flash_protection(void){&lt;/P&gt;&lt;P&gt;uint8_t config_FSEC = *pFTFA_FSEC;&lt;BR /&gt; uint8_t config_FOPT = *pFTFA_FOPT;&lt;BR /&gt; uint32_t buf = (config_FOPT &amp;lt;&amp;lt; 8) | config_FSEC;&lt;/P&gt;&lt;P&gt;uint32_t rc = 0;&lt;/P&gt;&lt;P&gt;uint32_t pflashBlockBase = 0;&lt;BR /&gt; uint32_t pflashTotalSize = 0;&lt;BR /&gt; uint32_t pflashSectorSize = 0;&lt;/P&gt;&lt;P&gt;printFLASH( 0x400, 16 );&lt;/P&gt;&lt;P&gt;memset(&amp;amp;s_flashDriver, 0, sizeof(flash_config_t));&lt;BR /&gt; rc = FLASH_Init(&amp;amp;s_flashDriver);&lt;BR /&gt; FLASH_LOG("FLASH_Init(): rc = 0x%02x\n", rc );&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &amp;amp;pflashBlockBase);&lt;BR /&gt; FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflashTotalSize, &amp;amp;pflashTotalSize);&lt;BR /&gt; FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflashSectorSize, &amp;amp;pflashSectorSize);&lt;/P&gt;&lt;P&gt;/* print welcome message */&lt;BR /&gt; debug_printf("\r\n PFlash Example Start \r\n");&lt;BR /&gt; /* Print flash information - PFlash. */&lt;BR /&gt; debug_printf("\r\n PFlash Information: ");&lt;BR /&gt; debug_printf("\r\n Flash block base address:\t0x%0x", pflashBlockBase);&lt;BR /&gt; debug_printf("\r\n Total Program Flash Size:\t%d KB, Hex: (0x%x)", (pflashTotalSize / 1024), pflashTotalSize);&lt;BR /&gt; debug_printf("\r\n Program Flash Sector Size:\t%d KB, Hex: (0x%x)\n\n", (pflashSectorSize / 1024), pflashSectorSize);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rc = FLASH_Erase(&amp;amp;s_flashDriver, 0x400, 1024, kFLASH_ApiEraseKey);&lt;BR /&gt; FLASH_LOG("FLASH_Erase(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf );&lt;/P&gt;&lt;P&gt;printFLASH( 0x400, 16 );&lt;/P&gt;&lt;P&gt;rc = FLASH_VerifyErase(&amp;amp;s_flashDriver, 0x400, 1024, kFLASH_MarginValueUser);&lt;BR /&gt; FLASH_LOG("FLASH_VerifyErase(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf );&lt;/P&gt;&lt;P&gt;rc = FLASH_Program(&amp;amp;s_flashDriver, FTFA_FSEC_ADDR, &amp;amp;buf, 4 );&lt;BR /&gt; FLASH_LOG("\nFLASH_Program(): rc = 0x%02x\n", rc );&lt;BR /&gt; FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n", &lt;BR /&gt; *pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",&lt;BR /&gt; buf );&lt;/P&gt;&lt;P&gt;printFLASH( 0x400, 16 );&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2017 02:38:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Can-t-get-C90TFS-routines-to-write-flash/m-p/676628#M41622</guid>
      <dc:creator>ee4hire</dc:creator>
      <dc:date>2017-07-21T02:38:28Z</dc:date>
    </item>
  </channel>
</rss>

