K21 Flex Memory Setup

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

K21 Flex Memory Setup

1,079 Views
al1
Contributor II

I reviewed couple of posts regarding setting flex memory on Kinetis devices and so far I am still facing issues with setting the Flex memory on the MK21FX512VLQ12.

First I am using the PE to set peripherals, using the Cpu_SetFlexNVMPartition() causes the core to lockup and reset (lockup bit in RCM_SRS1 is set) so I gave up on using this function.

I tried the following code:

if (FTFE_FSTAT & FTFE_FSTAT_ACCERR_MASK)

            FTFE_FSTAT = FTFE_FSTAT_ACCERR_MASK;

        /* Write the FCCOB registers */

          FTFE_FCCOB0 = FTFE_FCCOB0_CCOBn(0x80); // Selects the PGMPART command

          FTFE_FCCOB1 = 0x00;

          FTFE_FCCOB2 = 0x00;

          FTFE_FCCOB3 = 0x00;

          /* FCCOB4 is written with the code for the subsystem sizes (eeprom_size define) */

          FTFE_FCCOB4 = 0x18; //64bytes

          /* FFCOB5 is written with the code for the Dflash size (dflash_size define) */

          FTFE_FCCOB5 = 0x0B; //32KB for data and 96KB for EE Backup

          /* All required FCCOBx registers are written, so launch the command */

          while (!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK)){};

          FTFE_FSTAT = FTFE_FSTAT_CCIF_MASK;  // step in line by line after this line

          /* Wait for the command to complete */

          while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK)){}; // this is the while loop where it resets

Using the debugger and going line by line starting at the command setting the CCIF bit in the FSTAT I was able to set the flex memory the way I wanted.

Now if the debugger was not stepping line by line at the last while loop the program will Lockup again and the core resets.

Anyone has any thoughts about this issue ?

Thanks.

Labels (1)
4 Replies

717 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello al1:

The part of code for launching the program partition and waiting for it to complete should be placed in RAM space. With the debugger it works because the core does not try to read the next instruction from flash right away, giving the command enough time to finish. Below is an extract from the reference manual:

pastedImage_1.png

The syntax to locate code in RAM is compiler dependent.

Regards!,
Jorge Gonzalez

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

717 Views
al1
Contributor II

Hello Jorge,

I am revisiting this issue and at this moment I am looking for the best way to set up the Flex memory.

If during operation I understand the code section related to lunching the flash command need to be executed from RAM. What is the best way to do this knowing that I am using the latest KDS 3.0.0.

Is it possible to completely ignore setting up the flash from within the code and just do it while flashing the device on production line?

Thanks,

0 Kudos

717 Views
al1
Contributor II

Replying to my second question in the previous reply, I found where the partition settings can be programmed initially inside KDS without the need to worry about configuring it while code is running.

under the debugger tab the advanced tab will show this window:

pastedImage_1.png

In red is where I set up the partition I want during the programming process.

My first question still out, is there a simple example on how to relocate into RAM let's say the line FTFE_FSTAT = FTFE_FSTAT_CCIF_MASK which will quick start the partitioning of the internal memory?

Thanks,

0 Kudos

717 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello al1:

You may give a check to this document:

Relocating Code and Data Using the KDS GCC Linker File for Kinetis

You may also check the C90TFS flash driver package, which shows a different approach without modifying the linker file, by copying the code to a buffer stored in RAM and then executing from there. This driver also supports the partition command.

Regards!

Jorge Gonzalez