K64 FTFE Operations Across PFlash Blocks

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

K64 FTFE Operations Across PFlash Blocks

Jump to solution
2,518 Views
kyati
Contributor II

Hello all,

 

I am working on a project very similar toKinetis Bootloader , using KDS 3.0 with KSDK 1.3 to program a FRDM-K64F board. I have followed the SD Card Bootloader :how to using SD card to update existing firmware on CodeWarriror or KDS and KSDK 1.3 flash driver example to create a bootloader, which successfully loads a binary file from an SD card and then runs the application.

 

However, I am only able to erase and program to a location on a single block of PFlash (either the lower or upper block), as opposed to, for example, relegating 0x00000-0x10000 for the bootloader and the remaining 0x10000-0x100000 for the program. I encounter the "FTFx_ERR_PVIOL" error from FlashEraseSector() whenever I cross the 0x80000 boundary.

 

I also have a TWR-K60F120M, which did not have any of these issues when I ran the provided code from SD Card Bootloader :how to using SD card to update existing firmware on CodeWarriror or KDS . I have not been able to find anything in the K64 reference manual that describes this difference between the two processors. I am unsure if I am missing something from the provided examples or if it is not possible to perform flash operations across the PFlash blocks on the K64.

 

I have also tried this change, as shown in the code snippet below, in the "main.c" of "KSDK_1.3.0\examples\frdmk64f\demo_apps\flash_demo" of KSDK 1.3 and found the same issue at the 0x80000 point. If the flash operations are possible, can anyone provide correct method of doing the following erase procedure, where I have altered the beginning address to 0x10000 and end address to 0x100000?

 

    /************************************************************************/     /* Erase several sectors on upper pflash block where there is no code */     /************************************************************************/     destination = flashSSDConfig.PFlashBase + 0x10000; // Base address to erase set to 0x10000     end = destination + 0xE0000;    /* erase and program two sectors */ //End address for erase set to 0x100000     while ((destination + (FTFx_PSECTOR_SIZE)) < end)     {         size = FTFx_PSECTOR_SIZE;         ret = FlashEraseSector(&flashSSDConfig, destination, size, g_FlashLaunchCommand);         if (FTFx_OK != ret)         {             ErrorTrap(ret);         }           /* Verify section for several sector of PFLASH */         number = FTFx_PSECTOR_SIZE/FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT;         for(margin_read_level = 0; margin_read_level < 0x2; margin_read_level++)         {             ret = FlashVerifySection(&flashSSDConfig, destination, number, margin_read_level, g_FlashLaunchCommand);             if (FTFx_OK != ret)             {                 ErrorTrap(ret); //0x10,FTFx_ERR_PVIOL, being returned when trying to erase 0x7e000-0x80000             }         }           /* print message for user */         PRINTF("\r\n\tDemo:  Successfully Erased Sector 0x%x -> 0x%x", (unsigned int)destination, (unsigned int)(destination+size));           destination += (size);     }

 

 

Thanks,

 

Jared

Labels (1)
1 Solution
1,557 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Jared Evans:

I think I replicated your issue, but actually I am guessing you see the problem when trying to program at address 0x7E000 and not from 0x80000.

That flash example code demonstrates the use of the SWAP feature in K64 device. It initializes the swap system and places the SWAP Indicator at offset 0x7E000:

pastedImage_1.png

Once the SWAP system is initialized the corresponding sector which contains the swap indicator is protected, so it cannot be erased, unless following the sequence of the SWAP system state machine. This is why your code fails when reaching that address, before even crossing the PFlash block boundary.

To recover from this situation you need 2 steps:

1) Mass erase the device, which resets the SWAP system.

If your FRDM-K64F has the P&E Micro debug interface, then a Mass Erase is automatically issued when launching the Debug Session in KDSv3.0.0. The P&E Micro interface binary can be downloaded from this link: Summary of FRDM-K64F open source debug interface

2) Comment out or remove the swap code from the example and build the project, to avoid getting in the same situation again.

I hope this helps.

PS. In case you are interested about SWAP system, you can read application note AN4533.

Regards!,

Jorge Gonzalez

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

View solution in original post

0 Kudos
8 Replies
1,557 Views
Angelillo
Contributor III

Hi Jorge,

Thank you very much for your fast reply.

According to your proposal, I have tested the flash driver example for K64. In this example, one sector which belongs to the upper P-flash block is erased and programmed. In order to test, I have modified this example application to erase and program one sector which belongs to the lower P-flash block. With this modification, the driver example application can erase and program the sector correctly.

I have replicated this source code but using the methods of the flash_fsl bean (I'm using Processor Expert). Apparently, I don't see any difference between the flash driver example and my application.

Lastly, in your last post, you suggest me to relocate the Flash Command Sequence function in RAM like is done in the flash driver example. I have done the same using the RelocateFunction method of the flash_fsl bean but the result is still unsuccessful. Moreover, I have modified the main.c of the example flash driver in order to test whether it is possible to erase and program the sector without relocating the Flash Command Sequence function in RAM. And the result also has been successful. This way, I have discarded that this is my problem.

I think that the only difference is that my application use Processor Expert and the flash driver example doesn't use Processor Expert. I attach both main.c files so that you can compare both files. Also, I attach a document comparing my flas_fsl bean configuration with the init structure used in the flash driver example. Have you got any idea why is not possible erase and program a sector of the lower P-flash block using Processor Expert?

Thank you very much in advance for your support!

Regards,

Ángel G.

0 Kudos
1,556 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Angel:

I think I can see your problem now. You have USB, and an interrupt must be triggering while trying to erase/program flash. The interrupt handler is most probably in Flash block 1 and you have a "Read while Write error".

Try disabling all interrupts before calling a flash function, and enable them afterwards, like next:

INT_SYS_DisableIRQGlobal();

result = FlashEraseSector(&flash1_InitConfig0, 0x60000, FTFx_PSECTOR_SIZE, g_FlashLaunchCommand);

INT_SYS_EnableIRQGlobal();

I hope this helps.

Regards!
Jorge Gonzalez

1,556 Views
Angelillo
Contributor III

Hi Jorge,

Thank you for your useful support. You are right completely. Now, I disable all interruptions before to erase and program a sector which belongs to the P-flash lower block and I'm able to erase and program this sector perfectly. After erasing and programming this sector, I enable all interruptions again.

You have solved my issue.

Thank you very much again for your useful support.

Best Regards,

Ángel G.

1,556 Views
Angelillo
Contributor III

Hi Jared,

How have you disabled SWAP functionality in your project?

What is the configuration file that allows you to disable SWAP functionality?

Thank you very much for your support.

Regards,

Ángel G.

0 Kudos
1,556 Views
Angelillo
Contributor III

Hi Jorge / Jared,

Like Jared, I'm also developing a customized Bootloader over K64 (with 1MB of internal flash memory). I have the same issue with SWAP functionality. But in my case, I'm using KDS 3.0.0, KSDK 1.3.0 and Processor Expert. By default, I think SWAP functionality is enabled but I need disable this SWAP funcionality due to I need to erase a range of addresses from 0x15000 address (which belongs to PFlash lower block) to 0x100000 address (which belongs to PFlash upper block) in order to flash a new application from Bootloader. I have the following memory map:

- Bootloader: Addresses 0x00000000 --> 0x00015000   (aprox)

- Application: Addresses 0x00015000 --> 0x00100000    (aprox)

Now, I can just erase the addresses of PFlash upper block  (0x00080000 - 0x00100000) but I can't erase the addresses of PFlash lower block (0x00015000 - 0x00080000).

My question is: How can I disable the SWAP functionality on K64 using Processor Expert (fsl_flash bean) and KDSK? Is it possible to disable SWAP functionality using either PFlashSwap or PFlashSwapCtl methods? Or,  Is it possible to disable swap functionality in CPU bean directly?

Thank you very much in advance for your support.

Best Regards,

Ángel G.

0 Kudos
1,557 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Angel Gutierrez:

The SWAP feature cannot be enabled/disabled, so this is not a setting. The SWAP System is like a state machine, which by default is in UNINITIALIZED state, so it needs to be initialized in the code if you want to use it, by calling the Swap Control Command.

Once initialized, the FLASH_INDICATOR address is protected and it could cause issues if you don't follow the state machine rules as stated in AN4533.

- To reset the SWAP system a Mass erase is required.

- In your case you mention that only spaces in the upper block can be erased, but not the lower block. This sounds like you have not copied the flash command function to RAM. Please try the demo and example projects in KSDK installation and compare it to your own code:

C:\Freescale\KSDK_1.3.0\examples\frdmk64f\demo_apps\flash_demo\kds

C:\Freescale\KSDK_1.3.0\examples\frdmk64f\driver_examples\flash\kds

Regards!

Jorge Gonzalez

0 Kudos
1,558 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Jared Evans:

I think I replicated your issue, but actually I am guessing you see the problem when trying to program at address 0x7E000 and not from 0x80000.

That flash example code demonstrates the use of the SWAP feature in K64 device. It initializes the swap system and places the SWAP Indicator at offset 0x7E000:

pastedImage_1.png

Once the SWAP system is initialized the corresponding sector which contains the swap indicator is protected, so it cannot be erased, unless following the sequence of the SWAP system state machine. This is why your code fails when reaching that address, before even crossing the PFlash block boundary.

To recover from this situation you need 2 steps:

1) Mass erase the device, which resets the SWAP system.

If your FRDM-K64F has the P&E Micro debug interface, then a Mass Erase is automatically issued when launching the Debug Session in KDSv3.0.0. The P&E Micro interface binary can be downloaded from this link: Summary of FRDM-K64F open source debug interface

2) Comment out or remove the swap code from the example and build the project, to avoid getting in the same situation again.

I hope this helps.

PS. In case you are interested about SWAP system, you can read application note AN4533.

Regards!,

Jorge Gonzalez

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

0 Kudos
1,557 Views
kyati
Contributor II

Hi Jorge,

I appreciate the assistance. I was not aware of the SWAP system, as I had not implicitly implemented it in my main project, and did not know that it was on by default in the configuration files. I disabled the feature in my main project and the bootloader now works as expected.

Thanks,

Jared

0 Kudos