<?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 FLASH_Program not working but not crashing in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2006977#M67052</link>
    <description>&lt;P&gt;Hello I have two question regarding the &lt;SPAN&gt;FLASH_Program from the fsl_flash files. When the memory is 0xFFFFFFFF (empty) the&amp;nbsp;FLASH_Program is able to write it and&amp;nbsp; then as the firmware tries to program it again, it fails. And the function&amp;nbsp;FLASH_Program does not crash and the result is&amp;nbsp;&amp;nbsp;kStatus_Success. Why?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="carlesls_0-1733310348321.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/314052i5ADFD9964F0DEAA3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="carlesls_0-1733310348321.png" alt="carlesls_0-1733310348321.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Dec 2024 11:06:10 GMT</pubDate>
    <dc:creator>carlesls</dc:creator>
    <dc:date>2024-12-04T11:06:10Z</dc:date>
    <item>
      <title>FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2006977#M67052</link>
      <description>&lt;P&gt;Hello I have two question regarding the &lt;SPAN&gt;FLASH_Program from the fsl_flash files. When the memory is 0xFFFFFFFF (empty) the&amp;nbsp;FLASH_Program is able to write it and&amp;nbsp; then as the firmware tries to program it again, it fails. And the function&amp;nbsp;FLASH_Program does not crash and the result is&amp;nbsp;&amp;nbsp;kStatus_Success. Why?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="carlesls_0-1733310348321.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/314052i5ADFD9964F0DEAA3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="carlesls_0-1733310348321.png" alt="carlesls_0-1733310348321.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 11:06:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2006977#M67052</guid>
      <dc:creator>carlesls</dc:creator>
      <dc:date>2024-12-04T11:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007624#M67053</link>
      <description>&lt;P&gt;Hello, my name is Pavel, and I will be supporting your case, could you let me know about the number of your MCU? and What kind of example are you using? is the flash iap?&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Pavel&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 00:42:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007624#M67053</guid>
      <dc:creator>Pavel_Hernandez</dc:creator>
      <dc:date>2024-12-05T00:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007827#M67054</link>
      <description>&lt;P&gt;Thanks, Pavel.&lt;/P&gt;&lt;P&gt;I am using the&amp;nbsp;mke04z8vtg4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using no examples... I am merely using the FLASH_Program function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 06:27:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007827#M67054</guid>
      <dc:creator>carlesls</dc:creator>
      <dc:date>2024-12-05T06:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007837#M67056</link>
      <description>&lt;P&gt;I added the code I use.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 06:49:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007837#M67056</guid>
      <dc:creator>carlesls</dc:creator>
      <dc:date>2024-12-05T06:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007946#M67057</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="carlesls_0-1733386275613.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/314251i133F43F5F2C9A460/image-size/medium?v=v2&amp;amp;px=400" role="button" title="carlesls_0-1733386275613.png" alt="carlesls_0-1733386275613.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to write a 64-bit each time but I am not able to do it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 08:28:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007946#M67057</guid>
      <dc:creator>carlesls</dc:creator>
      <dc:date>2024-12-05T08:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007952#M67058</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="carlesls_1-1733387342866.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/314263iEE838D75447B7173/image-size/medium?v=v2&amp;amp;px=400" role="button" title="carlesls_1-1733387342866.png" alt="carlesls_1-1733387342866.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I try to increase a value on the memory but to no avail... it writes a '0' instead of a '2'...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 08:30:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2007952#M67058</guid>
      <dc:creator>carlesls</dc:creator>
      <dc:date>2024-12-05T08:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2008081#M67059</link>
      <description>&lt;P&gt;However I am able to erase sectors at the very begining of the application firmware.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 10:00:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2008081#M67059</guid>
      <dc:creator>carlesls</dc:creator>
      <dc:date>2024-12-05T10:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: FLASH_Program not working but not crashing</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2008613#M67060</link>
      <description>&lt;P&gt;Hello, maybe this example could work for your app.&lt;/P&gt;
&lt;LI-SPOILER&gt;&lt;LI-CODE lang="c"&gt;/*
 * Copyright (c) 2016, Freescale Semiconductor, Inc.
 * Copyright 2016-2017 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_flash.h"

#include "fsl_common.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/


#define BUFFER_LEN 4

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

void error_trap(void);
void app_finalize(void);

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*! @brief Flash driver Structure */
static flash_config_t s_flashDriver;
/*! @brief Buffer for program */
static uint32_t s_buffer[BUFFER_LEN];
/*! @brief Buffer for readback */
static uint32_t s_buffer_rbc[BUFFER_LEN];

/*******************************************************************************
 * Code
 ******************************************************************************/

/*
 * @brief Gets called when an error occurs.
 *
 * @details Print error message and trap forever.
 */
void error_trap(void)
{
    PRINTF("\r\n\r\n\r\n\t---- HALTED DUE TO FLASH ERROR! ----");
    while (1)
    {
    }
}

/*
 * @brief Gets called when the app is complete.
 *
 * @details Print finshed message and trap forever.
 */
void app_finalize(void)
{
    /* Print finished message. */
    PRINTF("\r\n End of PFlash Example \r\n");
    while (1)
    {
    }
}

/*!
 * @brief Use Standard Software Drivers (SSD) to modify pflash.
 *
 * @details This function uses SSD to demonstrate flash mode:
 *            + Check pflash information.
 *            + Erase a sector and verify.
 *            + Program a sector and verify.
 */
int main(void)
{
    status_t result;    /* Return code from each flash driver function */
    uint32_t destAdrss; /* Address of the target location */
    uint32_t i;

    uint32_t pflashBlockBase  = 0;
    uint32_t pflashTotalSize  = 0;
    uint32_t pflashSectorSize = 0;

    /* Init hardware */
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitDebugConsole();

    /* Clean up Flash driver Structure*/
    memset(&amp;amp;s_flashDriver, 0, sizeof(flash_config_t));

    FLASH_SetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyFlashClockFrequency, 20000000U);
    /* Setup flash driver structure for device and initialize variables. */
    result = FLASH_Init(&amp;amp;s_flashDriver);
    if (kStatus_FLASH_Success != result)
    {
        error_trap();
    }
    /* Get flash properties*/
    pflashBlockBase  = s_flashDriver.PFlashBlockBase;
    pflashTotalSize  = s_flashDriver.PFlashTotalSize;
    pflashSectorSize = s_flashDriver.PFlashSectorSize;

    /* print welcome message */
    PRINTF("\r\n PFlash Example Start \r\n");
    /* Print flash information - PFlash. */
    PRINTF("\r\n PFlash Information: ");
    PRINTF("\r\n Total Program Flash Size:\t%d KB, Hex: (0x%x)", (pflashTotalSize / 1024), pflashTotalSize);
    PRINTF("\r\n Program Flash Sector Size:\t%d B, Hex: (0x%x) ", pflashSectorSize, pflashSectorSize);

    /* Debug message for user. */
    /* Erase several sectors on upper pflash block where there is no code */
    PRINTF("\r\n Erase a sector of flash");

/* In case of the protected sectors at the end of the pFlash just select
the block from the end of pFlash to be used for operations
SECTOR_INDEX_FROM_END = 1 means the last sector,
SECTOR_INDEX_FROM_END = 2 means (the last sector - 1) ...
in case of FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP it is
SECTOR_INDEX_FROM_END = 1 means the last 2 sectors with width of 2 sectors,
SECTOR_INDEX_FROM_END = 2 means the last 4 sectors back
with width of 2 sectors ...
*/
#ifndef SECTOR_INDEX_FROM_END
#define SECTOR_INDEX_FROM_END 1U
#endif

/* Erase a sector from destAdrss. */
#if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) &amp;amp;&amp;amp; FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
    /* Note: we should make sure that the sector shouldn't be swap indicator sector*/
    destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize * 2));
#else
    destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
#endif

    result = FLASH_Erase(&amp;amp;s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);
    if (kStatus_FLASH_Success != result)
    {
        error_trap();
    }

    /* Print message for user. */
    PRINTF("\r\n Program a buffer to a sector of flash ");

    /* Prepare user buffer. */
    for (i = 0; i &amp;lt; BUFFER_LEN; i++)
    {
        s_buffer[i] = i;
    }
    /* Program user buffer into flash*/
    result = FLASH_Program(&amp;amp;s_flashDriver, destAdrss, s_buffer, sizeof(s_buffer));
    if (kStatus_FLASH_Success != result)
    {
        error_trap();
    }

#if defined(__DCACHE_PRESENT) &amp;amp;&amp;amp; __DCACHE_PRESENT
    /* Clean the D-Cache before reading the flash data*/
    SCB_CleanInvalidateDCache();
#endif
    /* Verify programming by reading back from flash directly*/
    for (i = 0; i &amp;lt; BUFFER_LEN; i++)
    {
        s_buffer_rbc[i] = *(volatile uint32_t *)(destAdrss + i * 4);
        if (s_buffer_rbc[i] != s_buffer[i])
        {
            error_trap();
        }
    }
    PRINTF("\r\n Successfully Programmed and Verified Location 0x%x -&amp;gt; 0x%x \r\n", destAdrss,
           (destAdrss + sizeof(s_buffer)));

    FLASH_Erase(&amp;amp;s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);
    app_finalize();

    return 0;
}
&lt;/LI-CODE&gt;&lt;/LI-SPOILER&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Pavel&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 00:53:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FLASH-Program-not-working-but-not-crashing/m-p/2008613#M67060</guid>
      <dc:creator>Pavel_Hernandez</dc:creator>
      <dc:date>2024-12-06T00:53:42Z</dc:date>
    </item>
  </channel>
</rss>

