<?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: MKE16 Hardfault With FlashWrite  and interrupts in Other NXP Products</title>
    <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360705#M12419</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The s_buffer size is not a sector.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nxf56274_0-1635150129205.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/160009i8E227F432CDF6154/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nxf56274_0-1635150129205.png" alt="nxf56274_0-1635150129205.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Oct 2021 08:23:40 GMT</pubDate>
    <dc:creator>nxf56274</dc:creator>
    <dc:date>2021-10-25T08:23:40Z</dc:date>
    <item>
      <title>MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360521#M12406</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I have been trying to implement Flash Driver Example(&lt;EM&gt;....\boards\frdmke16z\driver_examples\flash&lt;/EM&gt;) from &lt;STRONG&gt;SDK_2_10_0_FRDM-KE16Z &lt;/STRONG&gt;for&amp;nbsp; &lt;SPAN class=""&gt;MKE16Z64VLD4&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Micro controller . &lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When I checked without any interrupts code, it was working well. When I included&amp;nbsp; SysTick&amp;nbsp; interrupt, During &lt;STRONG&gt;FlashWrite&lt;/STRONG&gt; Operation&amp;nbsp; , HardFault occurs .&amp;nbsp;&lt;/P&gt;&lt;P&gt;By assuming ISR is causing the HardFault&amp;nbsp; , I disabled the Systick interrupt using the following before FlashWrite&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;SysTick-&amp;gt;CTRL  = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also Enabled Systick interrupt after FlashWrite&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;SysTick-&amp;gt;CTRL  = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk |            SysTick_CTRL_ENABLE_Msk;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still it causes Hardfault.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 05:24:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360521#M12406</guid>
      <dc:creator>amalmathewtech</dc:creator>
      <dc:date>2021-10-25T05:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360593#M12411</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;Please try to disable the global interrupt before flash operation.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nxf56274_0-1635143831943.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/159986i98439C7DB9C1E825/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nxf56274_0-1635143831943.png" alt="nxf56274_0-1635143831943.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 06:37:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360593#M12411</guid>
      <dc:creator>nxf56274</dc:creator>
      <dc:date>2021-10-25T06:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360644#M12416</link>
      <description>&lt;P&gt;I have disabled global interrupt before flash operation. After this Flash Write is happening successfully.&lt;/P&gt;&lt;P&gt;and once Flash Operation is completed I have enabled global interrupts (&lt;EM&gt;EnableGlobalIRQ&lt;/EM&gt;) back. But the ISR (SysTick ISR - In my case) is not running now.&lt;/P&gt;&lt;P&gt;Am I missing something ?&lt;/P&gt;&lt;P&gt;I am adding&amp;nbsp; a code snippet for your reference.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;volatile uint32_t msTicks = 0;
/*-----------------------------------------------------------------------------*
  SysTick_Handler
*-----------------------------------------------------------------------------*/

void SysTick_Handler(void) {
	msTicks++;
}

int main(void)
{
	SystemCoreClockUpdate();
	SysTick_Config(SystemCoreClock/2000);
	NVIC_SetPriority(SysTick_IRQn, 2);
	flash_init();       // Function made from frdmke16z library 
	FlashBuffer[0] = 9; // Test variable to be written
	uint32_t  var = DisableGlobalIRQ();
        flash_write(FlashBuffer,1);  // Function made from  frdmke16z          library 
	EnableGlobalIRQ(var);
	flash_read();
	for(;;){

	}
    return 0;
}



&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 07:44:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360644#M12416</guid>
      <dc:creator>amalmathewtech</dc:creator>
      <dc:date>2021-10-25T07:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360659#M12417</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Before you write into the flash, is the flash empty? You can try to erase firstly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your flash operation based on sector operation? Do you sure that you write the data into flash successfully?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 07:53:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360659#M12417</guid>
      <dc:creator>nxf56274</dc:creator>
      <dc:date>2021-10-25T07:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360696#M12418</link>
      <description>&lt;P&gt;yes ,Before I write into the flash, I am&amp;nbsp; erasing it firstly.&lt;/P&gt;&lt;P&gt;with Following Function&lt;/P&gt;&lt;LI-CODE lang="c"&gt;FLASH_Erase(&amp;amp;s_flashDriver, destAddr, pflashSectorSize, kFTFx_ApiEraseKey);&lt;/LI-CODE&gt;&lt;P&gt;My&amp;nbsp;flash operation is&amp;nbsp; based on sector operation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Your Reference I am adding each of the function definition that I am using&lt;/P&gt;&lt;LI-CODE lang="c"&gt;uint32_t value = 0;     // Variable to read flash - To Debug
uint32_t FlashBuffer[16];

/*******************************************************************************
 * Definitions
 ******************************************************************************/
#define FSL_SUPPORT_ERASE_SECTOR_NON_BLOCKING 1U
#define BUFFER_LEN                            6

/*******************************************************************************
 * Prototypes
 ******************************************************************************/
void error_trap(void);
void flash_init(void);
void flash_write(uint32_t *DataArray, int DataCount);
void flash_read(void);

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*! @brief Flash driver Structure */
static flash_config_t s_flashDriver;
/*! @brief Flash cache driver Structure */
static ftfx_cache_config_t s_cacheDriver;
/*! @brief Buffer for program */
static uint32_t s_buffer[BUFFER_LEN];
/*! @brief Buffer for readback */
static uint32_t s_buffer_rbc[BUFFER_LEN];


/*  flash related variables  */
ftfx_security_state_t securityStatus = kFTFx_SecurityStateNotSecure; /* Return protection status */
status_t result;   /* Return code from each flash driver function */
uint32_t destAddr; /* Address of the target location */
uint32_t i, failAddr, failDat;

uint32_t pflashBlockBase  = 0;
uint32_t pflashTotalSize  = 0;
uint32_t pflashSectorSize = 0;

void flash_init(void){
	/* Clean up Flash, Cache driver Structure*/
	memset(&amp;amp;s_flashDriver, 0, sizeof(flash_config_t));
	memset(&amp;amp;s_cacheDriver, 0, sizeof(ftfx_cache_config_t));

	/* Setup flash driver structure for device and initialize variables. */
	FLASH_Init(&amp;amp;s_flashDriver);
	/* Setup flash cache driver structure for device and initialize variables. */
	FTFx_CACHE_Init(&amp;amp;s_cacheDriver);

	/* Get flash properties*/
	FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflash0BlockBaseAddr, &amp;amp;pflashBlockBase);
	FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflash0TotalSize, &amp;amp;pflashTotalSize);
	FLASH_GetProperty(&amp;amp;s_flashDriver, kFLASH_PropertyPflash0SectorSize, &amp;amp;pflashSectorSize);

	/* Check security status. */
	FLASH_GetSecurityState(&amp;amp;s_flashDriver, &amp;amp;securityStatus);
}


void flash_write(uint32_t *DataArray, int DataCount){

	/*erase before writing into flash***/
	FLASH_Erase(&amp;amp;s_flashDriver, destAddr, pflashSectorSize, kFTFx_ApiEraseKey);
	
	/* Test pflash basic opeation only if flash is unsecure. */
	if (kFTFx_SecurityStateNotSecure == securityStatus)
	{
		/* Pre-preparation work about flash Cache/Prefetch/Speculation. */
		FTFx_CACHE_ClearCachePrefetchSpeculation(&amp;amp;s_cacheDriver, true);
		
		#ifndef SECTOR_INDEX_FROM_END
		#define SECTOR_INDEX_FROM_END 1U
		#endif

		#ifdef TEST_TARGET_ADDRESS
			destAddr = TEST_TARGET_ADDRESS;
		#else
		/* Erase a sector from destAddr. */
		#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*/
		destAddr = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize * 2));
		#else
		destAddr = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
		#endif
		#endif // TEST_TARGET_ADDRESS
		/* Print message for user. */
		for (uint32_t i = 0; i &amp;lt; DataCount; i++)
		{
			s_buffer[i] = DataArray[i];
		}

		#if defined(FSL_SUPPORT_ERASE_SECTOR_NON_BLOCKING) &amp;amp;&amp;amp; FSL_SUPPORT_ERASE_SECTOR_NON_BLOCKING
		FLASH_EraseSectorNonBlocking(&amp;amp;s_flashDriver, destAddr, kFTFx_ApiEraseKey);

		/* Before programming the flash, check whether the erase sector command is completed,*/
		/* and get the flash status. */
		FLASH_GetCommandState();
		#else
		FLASH_Erase(&amp;amp;s_flashDriver, destAddr, pflashSectorSize, kFTFx_ApiEraseKey);
			
		#endif
		/* Verify sector if it's been erased. */
		FLASH_VerifyErase(&amp;amp;s_flashDriver, destAddr, pflashSectorSize, kFTFx_MarginValueUser);
		/* Program user buffer into flash*/
		FLASH_Program(&amp;amp;s_flashDriver, destAddr, (uint8_t *)s_buffer, sizeof(s_buffer));
		/* Verify programming by Program Check command with user margin levels */
		FLASH_VerifyProgram(&amp;amp;s_flashDriver, destAddr, sizeof(s_buffer), (const uint8_t *)s_buffer,
			    	        kFTFx_MarginValueUser, &amp;amp;failAddr, &amp;amp;failDat);
			    	
		/* Post-preparation work about flash Cache/Prefetch/Speculation. */
		FTFx_CACHE_ClearCachePrefetchSpeculation(&amp;amp;s_cacheDriver, false);
	}

}

void flash_read(void){
	/* test code */
	/* address starts from 0xFC00*/
	uint32_t* fl = (uint32_t*)0xFC00;
	value = *fl;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 08:17:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360696#M12418</guid>
      <dc:creator>amalmathewtech</dc:creator>
      <dc:date>2021-10-25T08:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360705#M12419</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The s_buffer size is not a sector.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nxf56274_0-1635150129205.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/160009i8E227F432CDF6154/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nxf56274_0-1635150129205.png" alt="nxf56274_0-1635150129205.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 08:23:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360705#M12419</guid>
      <dc:creator>nxf56274</dc:creator>
      <dc:date>2021-10-25T08:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360711#M12420</link>
      <description>&lt;P&gt;Okay , But why interrupt handler&amp;nbsp; stopped working, Can you help me on this .&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 08:32:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360711#M12420</guid>
      <dc:creator>amalmathewtech</dc:creator>
      <dc:date>2021-10-25T08:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360717#M12421</link>
      <description>&lt;P&gt;I am doubting the wrong flash operation causing the problems. After the flash writing, do you check if the the data is written into flash? Although you use the Flash_VerifyProgram, but you don't check the return value.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 08:39:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360717#M12421</guid>
      <dc:creator>nxf56274</dc:creator>
      <dc:date>2021-10-25T08:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360726#M12423</link>
      <description>&lt;P&gt;I am attaching driver example folder provided on the SDK for MCUXpresso.&lt;/P&gt;&lt;P&gt;On the given sample code all flash related functions are working fine. When Interrupts are included on the code during flash Write operation it was causing HardFault.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As per your suggestion I have disabled global interrupt before flash write and enabled back once flash write is completed. After this Flash Related Functions are working , But Interrupt handler stopped working.&lt;/P&gt;&lt;P&gt;Any suggestion on this.&amp;nbsp;&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>Mon, 25 Oct 2021 08:47:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1360726#M12423</guid>
      <dc:creator>amalmathewtech</dc:creator>
      <dc:date>2021-10-25T08:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1361171#M12427</link>
      <description>&lt;P&gt;I have modified the sample to run the systick. Please refer the attachment. I use '&amp;nbsp; &amp;nbsp;//*******&amp;nbsp; &amp;nbsp;'&amp;nbsp; &amp;nbsp;to tell you where I modify&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 02:52:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1361171#M12427</guid>
      <dc:creator>nxf56274</dc:creator>
      <dc:date>2021-10-26T02:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: MKE16 Hardfault With FlashWrite  and interrupts</title>
      <link>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1361263#M12428</link>
      <description>&lt;P&gt;Thank you Very much&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/71004"&gt;@nxf56274&lt;/a&gt;&amp;nbsp; , It worked.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 05:21:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Other-NXP-Products/MKE16-Hardfault-With-FlashWrite-and-interrupts/m-p/1361263#M12428</guid>
      <dc:creator>amalmathewtech</dc:creator>
      <dc:date>2021-10-26T05:21:19Z</dc:date>
    </item>
  </channel>
</rss>

