Flash Swap - Swap Control Command

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

Flash Swap - Swap Control Command

Jump to solution
1,677 Views
jasonphilippi
Contributor III

Hello Everybody,

I am trying to use the Swap Control Command as used in AN4533 from an Uninitialized State.

In PFlashSwap.c:

/* Report current swap state */
 ret = PFlashSwapCtl(pSSDConfig,addr,FTFx_SWAP_REPORT_STATUS,&currentSwapMode, \
 &currentSwapBlockStatus, &nextSwapBlockStatus ,pFlashCommandSequence);‍‍‍‍‍‍

I get

ret = FTFx_OK

currentSwapMode = 0x00 (Uninitialized)

currentSwapBlockStatus = 0x00 (Block 0 at 0x0_0000)

nextSwapBlockStatus = 0x00 (Block 0 at 0x0_0000)

Which that is all fine with me.

Next I go into this in PFlashSwap.c:

/* If current swap mode is Uninitialized */
 if (FTFx_SWAP_UNINIT == currentSwapMode)
 {
 /* Initialize Swap to Initialized/READY state */
 ret = PFlashSwapCtl(pSSDConfig, addr, FTFx_SWAP_SET_INDICATOR_ADDR,&currentSwapMode, \
 &currentSwapBlockStatus, &nextSwapBlockStatus , pFlashCommandSequence);
 }‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This time I am Initializing the Swap System to UPDATE-ERASED, but this where I run into problems.

I get back

ret = FTFx_ERR_ACCERR

Based on the FTFE Chapter in my manual, there are 4 errors I could be having.

  1. Command not available in current mode/security
  2. Flash Address is not in the lower half of program flash memory
  3. Flash address is in the Flash Configuration Field
  4. Flash address is not 128-bit aligned

I'm not sure what my problem is, but I'll throw in some snippets of information that might help.

Memory Segments in my linker file

MEMORY {
 m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
 m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
 m_interrupts_ram (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00000400
 m_text (RX) : ORIGIN = 0x00002000, LENGTH = 0x0007E000
 m_data (RW) : ORIGIN = 0x1FFF0400, LENGTH = 0x0000FC00
 m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00030000
 m_swap (RX) : ORIGIN = 0x00001000, LENGTH = 0x00001000
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I added a separate section called m_swap to hold my SWAP_INDICATOR.

That block is 128 bit or double phrase aligned.

#define FLASH_SWAP_INDICATOR_ADDR 0x1000 //!<Address for the Flash Swap Indicator
#define LAUNCH_CMD_SIZE 0x600
#define CALLBACK_SIZE 0x100‍‍‍‍‍‍

Also, I have defined the address for the swap indicator address.

I went a little overboard on the Ram size for the Launch Command Size, but I checked my map file and found out I needed more room.

flash1_InitConfig0.CallBack = (PCALLBACK)RelocateFunction((uint32_t)ramForCallback , CALLBACK_SIZE , (uint32_t)flash_callback);
 flashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)ramFunctions, LAUNCH_CMD_SIZE, (uint32_t)FlashCommandSequence);
‍‍‍‍‍

Putting the functions into RAM.

I manually removed program flash protection in debug and I still error out.

I think I am having trouble with either 1 or 3.

I am using KSDK 1.3.0 and FreeRTOS on a K24.

Any ideas would be appreciated.

Thank you,

Jason Philippi

Labels (1)
0 Kudos
Reply
1 Solution
1,158 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

The AN4533 provides below info about where to locate the flash swap indicators:

Where to locate the flash swap indicators?
The system programmer specifies where the flash swap indicators are to be located when initializing the flash swap system. Any flash sector can be used except the first two sectors which contain the vectors and flash configuration fields. Depending on the device, the swap indicator must be 32-bit, 64-bit, or 128-bit aligned.

It is recommended to place the flash swap indicators in the last sector of the p-flash block. This will allow the largest contiguous flash area for the application code.

Customer need to erase the Swap Indicator located Flash sector before using PFlashSwapCtl on a UNINITIALIZED system.


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
3 Replies
1,158 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

If customer run the Flash swap operation with TWR-K24F120M board?

For the TWR-K24F120M board is using MK24FN256VDC12 chip, which only has one program Flash block and doesn't support SWAP operation.

If customer is using MK24FN1M0VDC12R product or other K24 with internal 1MB flash product board, which could support SWAP operation.

Customer could refer KSDK V1.3 flash_demo, which provides Flash SWAP operation demo and related code.

The flash_demo located at default path:

C:\Freescale\KSDK_1.3.0\examples\twrk24f120m\demo_apps\flash_demo


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,158 Views
jasonphilippi
Contributor III

I am using a MK24 with 1 MB flash on a custom board. 

The flash demo has been very helpful. I see conflicting suggestions about where to place the indicator address, but as I see it, you have to dedicate one whole sector (4k) for the indicator.

Is there something wrong with my swap indicator address?

Do I need to erase the Swap Indicator before using PFlashSwapCtl on a UNINITIALIZED system?

0x01 (Initialize Swap System to UPDATE-ERASED State) - After verifying that the
current swap state is UNINITIALIZED, and that both phrases which will contain the
swap indicators (located in each half of the Program flash memory within the relative
double-phrase flash address provided) are erased, and that the flash address provided
is in the lower half of Program flash memory but not in the Flash Configuration
Field, the flash address provided (shifted with bits[3:0] removed) will be
programmed into the IFR Swap Field found in the program flash swap IFR. After the
swap indicator address has been programmed into the IFR Swap Field, the swap
enable word will be programmed to 0x0000. After the swap enable word has been
programmed, the swap indicator located in the lower half of the Program flash
memory will be programmed to 0xFF00.

It seems like I need to check what state the swap is in. If it is UNINITIALIZED, then I should erase both sectors in each swap block. I didn't see a protection error, but I know that in order to program. the sector must first be erased. I thought maybe the command would have handled that. I will check that soon. Unfortunately, I can not use the callback function after finding out it is UNINITIALIZED to erase it before it tries to update it to UPDATE-ERASED.

I'll give this a try. 

0 Kudos
Reply
1,159 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

The AN4533 provides below info about where to locate the flash swap indicators:

Where to locate the flash swap indicators?
The system programmer specifies where the flash swap indicators are to be located when initializing the flash swap system. Any flash sector can be used except the first two sectors which contain the vectors and flash configuration fields. Depending on the device, the swap indicator must be 32-bit, 64-bit, or 128-bit aligned.

It is recommended to place the flash swap indicators in the last sector of the p-flash block. This will allow the largest contiguous flash area for the application code.

Customer need to erase the Swap Indicator located Flash sector before using PFlashSwapCtl on a UNINITIALIZED system.


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply