problem erasing MK02FN128VLF10 flash with program calls to flash driver

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem erasing MK02FN128VLF10 flash with program calls to flash driver

1,171 Views
Ed_McM
Contributor I
Hello,
I’m having a problem erasing MK02FN128VLF10 flash, using Flash driver calls from within our program .  Our board design is loosely based on the FRDM K22 board.  The part on our board is clocked with internal IRC48M clock.  The SDK used for the starting point of our software was built with NXP SDK builder configured for MK02FN128xxx10. 
The design works fine overall,  wejust ran into a problem when trying to use Flash to save “user setting”, between power downs.  I started the Flash access effort,  using the example in the SDK “flash_erase_program_verify”. (see attached C file)
The MK02 has 128M of Flash, in 1 block with 2K sectors.  Given the fact that Flash is one block, the section of code that sends flash command and waits for completion, has to be run from ram.  
I have verified that the correct section of Flash code is copied into the correct section of Ram.  Using the debugger, I am able to verify that the code runs as expected from Ram.  I can verify that the last sector in Flash is erased, and then that it is written with the correct 4 bytes. 
The problem is that I can only get the code to run successfully if I put a single breakpoint in the ram code, between the code to send the command and the code to wait for it to complete.  I place the breakpoint there and run the the erase command.  Then I remove it for all the other Read / Write commands.  It works fine and I can verify such in memory view.
When Running it without the break point there, and just letting it run, it doesn’t work.  I get a reset once the code is sent.  I’m not sure of the actual error that causes reset.
Any thoughts on what the problem may be or where I should look for hints?
Thanks,
Ed
Miscellaneous info:
a: flash_driver.c  see function call to erase flash sector
result = FLASH_Erase(&flashDriver, destAdrss, pflashSectorSize, kFLASH_apiEraseKey);
b: fsl_flash.c  see function call to run command in ram
callFlashRunCommand((FTFx_REG_ACCESS_TYPE)(&FTFx->FSTAT));
c: I have checked commnd registers, it looks like the flash commands are good.
d: Flash Code placed in Ram
 /* This function should be copied to RAM for execution to make sure that code works properly even flash cache is disabled.
    It is for flash-resident bootloader only, not technically required for ROM or flashloader (RAM-resident bootloader).  */
void flash_run_command(FTFx_REG_ACCESS_TYPE ftfx_fstat)
{
    volatile int i_ram; // mcmurray
    /* clear CCIF bit */
    *ftfx_fstat = FTFx_FSTAT_CCIF_MASK;
   // Breakpoint placed here
    /* Check CCIF bit of the flash status register, wait till it is set.  IP team indicates that this loop will always complete. */
   while (!((*ftfx_fstat) & FTFx_FSTAT_CCIF_MASK)){ }
}

 

Original Attachment has been moved to: flashTest.zip

0 Kudos
Reply
2 Replies

683 Views
Ed_McM
Contributor I

A little more information about the command sequence of code, being run from ram.

1: I am using assembly code breakpoints.  If I place (1) BP anywhere in the while loop assembly code, ONLY required before the sector erase command,  and then let it run freely to write and read.  It works.  That is the only way it works at this point

void flash_run_command(FTFx_REG_ACCESS_TYPE ftfx_fstat)
{
    /* clear CCIF bit */
    *ftfx_fstat = FTFx_FSTAT_CCIF_MASK;
    /* Check CCIF bit of the flash status register, wait till it is set.   I PLACE BP anywhere is this section of Assy code*/
   while (!((*ftfx_fstat) & FTFx_FSTAT_CCIF_MASK)){ }
}
Note:  
1: WDOGEN is 0, watchdog is disabled.
2: I have tried various sectors throughout free flash where program does not reside.
0 Kudos
Reply

683 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

Could you provide the K02 RCM_SRS0 & RCM_SRS1 register value?

We want to know what kind of reset during the Flash operation. Thanks.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply