K66 Flash Swap

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

K66 Flash Swap

2,482 Views
matyb
Contributor II

Good morning, I keep having a Flash Access Error Flag whenever I attempt to write to the Flash Status Register. I am attempting to use the Freescale libraries that were provided to initialize the Flash Swap function on a K66. The function that I am attempting to execute is called FLASH_SwapControl.

Inside the flash swap control, one of the steps attempts to reset the CCIF bit in the flash status register, by setting it to a 1. However, as soon as it tries to do this, the access error flag (in the same register) gets set and then everything goes downhill. All of this is being executed internally in the Freescale library, so I not 100% sure of what each step does. Here are libraries. Can anyone point me to the right direction as to why this is happening? Any help is very appreciated. Thank you.

Labels (1)
Tags (2)
0 Kudos
4 Replies

1,240 Views
knovinger
Contributor III

Not sure if it's relevant, and unfortunately it's not an immediate solution, but it may provide some guidance.  I've been experiencing a similar issue with K64 and receiving, what I believe to be, the same error.  However, with my issue, the error only occurs on the 2nd attempt to swap.

Also, my original was seen with SDK2.4.2 for K64 which included v3.0.0 of the FSL_FLASH_DRIVER.  My interim solution was to revert back to an older flash driver version (v2.1.0).

Here is the original thread...

SWAP does not work from UPPER on SDK 2.4.1 flash driver?

0 Kudos

1,240 Views
matyb
Contributor II

Does anyone have any suggestions? I'm completely lost as to what is happening.

This is the line that it is giving me an access error flag.

fsl_flash.h

#define FTFx_REG8_ACCESS_TYPE volatile uint8_t *

/*! @brief A function pointer used to point to relocated flash_run_command() */
static void (*callFlashRunCommand)(FTFx_REG8_ACCESS_TYPE ftfx_fstat);

fsl_flash.c

/*!
* @brief Flash Command Sequence
*
* This function is used to perform the command write sequence to the flash.
*
* @param driver Pointer to storage for the driver runtime state.
* @return An error code or kStatus_FLASH_Success
*/
static status_t flash_command_sequence(flash_config_t *config)
{
uint8_t registerValue;

#if FLASH_DRIVER_IS_FLASH_RESIDENT


/* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */
FTFx->FSTAT = FTFx_FSTAT_RDCOLERR_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_FPVIOL_MASK;

status_t returnCode = flash_check_execute_in_ram_function_info(config);
if (kStatus_FLASH_Success != returnCode)
{
return returnCode;
}

/* We pass the ftfx_fstat address as a parameter to flash_run_comamnd() instead of using
* pre-processed MICRO sentences or operating global variable in flash_run_comamnd()
* to make sure that flash_run_command() will be compiled into position-independent code (PIC). */
callFlashRunCommand((FTFx_REG8_ACCESS_TYPE)(&FTFx->FSTAT));


#else
...
#endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */

/* Check error bits */
/* Get flash status register value */
registerValue = FTFx->FSTAT;

/* checking access error */
if (registerValue & FTFx_FSTAT_ACCERR_MASK)
{
return kStatus_FLASH_AccessError;
}
/* checking protection error */
else if (registerValue & FTFx_FSTAT_FPVIOL_MASK)
{
return kStatus_FLASH_ProtectionViolation;
}
/* checking MGSTAT0 non-correctable error */
else if (registerValue & FTFx_FSTAT_MGSTAT0_MASK)
{
return kStatus_FLASH_CommandFailure;
}
else
{
return kStatus_FLASH_Success;
}
}

0 Kudos

1,240 Views
mjbcswitzerland
Specialist V

Hi


Remember that flash operations are not possible in HSRUN mode - check that you are not running at > 120MHz.

https://community.nxp.com/thread/431864 

Regards

Mark

Swap operation: https://community.nxp.com/message/587699?commentID=587699#comment-587699 

uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
uTasker - for more performance and faster, cheaper product development

0 Kudos

1,240 Views
matyb
Contributor II

Thanks for the response. I can confirm that I am running at 60 MHz. I am able to write and erase to flash, just not the swap initialization. 

0 Kudos