K66 locks when flashing image

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

K66 locks when flashing image

1,673 Views
panpwr
Contributor IV

Hi all,

We have some data we need to read from the program once registers.

We are able to read and write the data when we use the JLink commander.

When we try to read from the application the process fails.

I noticed that after the application is stopped and I try reading the program once registers with the JLink commander, it fails until I issue the command unlock kinetis.

Only after I do that I can read the registers again. I assume that this happens, because the flash gets protected somehow and the writing of the FCCOB fails and with that the read fails.

The question is, why does the flashing of an application gets th@e flash protected?

Here is the code we use to read the program once registers:

   FTFE_FCCOB0 = 0x41; //Program Once read command

   FTFE_FCCOB1 = 0x00; //Program Once index 0

   FTFE_FSTAT = 0x80;

  

   while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK)); //Wait for the read operation to complete

  

   address[0] = FTFE_FCCOB4;

   address[1] = FTFE_FCCOB5;

   address[2] = FTFE_FCCOB6;

   address[3] = FTFE_FCCOB7;  

   address[4] = FTFE_FCCOB8;

   address[5] = FTFE_FCCOB9;

Thanks,

Lior.

ohadbenjamin

Labels (1)
Tags (1)
0 Kudos
7 Replies

1,096 Views
ERussell
Contributor IV

I realize it has been a while but I was wondering if you ever figured out the problem? I seem to be having the same problem on a k65. Whenever I try using any of the flash commands, I get the FTFE_FSTAT_ACCERR_MASK error. The chip is in an unsecured state and the code issuing the flash commands is running out of RAM. The code worked fine on a k64. It doesn't seem to be a problem for either the Segger JLINK routines or the IAR flash loader so it wouldn't be an inherent problem with the chip itself. Any help would be greatly appreciated!

Thanks,

Elizabeth

0 Kudos

1,096 Views
RichardR
Contributor IV

Wish I could help, we are running into a similar issue with the K65.  Ported code that was working fine on a K60 to the K65, and suddenly flash erases and writes generate the ACCERR.

0 Kudos

1,096 Views
mjbcswitzerland
Specialist V

Hi All

If you are using the K65/K66 at > 120MHz in HSRUN mode it is not possible to erase/program Flash:

Flash driver fails when configuring swap at 180MHz 

Regards

Mark

Kinetis for professionals: http://http://www.utasker.com/kinetis.html
K65/K66: http://www.utasker.com/kinetis/TWR-K65F180M.html

0 Kudos

1,096 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello panpwr:

The security or protection states do not prevent the application from using the Read Once command, but security could indeed prohibit the JLink from accessing those registers. Security depends on the value of the flash security byte (FSEC) loaded at flash address 0x040C, in particular the 2 least significant bits:

FSEC.png

So you need to check your application or the binary to confirm what value is loaded to the address 0x040C in flash.

About the code:

- Make sure that the command is launched from RAM or from a different flash block other than 0, where the Program Once field is.

- Also your code does not seem to check if previous commands are finished (by checking CCIF flag) and clearing previous error flags (by writing 0x30 to FSTAT).


Regards!,
Jorge Gonzalez

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

0 Kudos

1,096 Views
ohadbenjamin
Contributor III

I tried moving the function to RAM and this still doesn't work.

The error I am getting is FTFE_FSTAT_ACCERR_MASK.

Has anyone any idea about this problem?

Can someone from Freescale run my code and comment about this?

0 Kudos

1,096 Views
ohadbenjamin
Contributor III

Hi,

Thanks for replying.

I modified the code with your suggestions as follows.

It still does not work.

Our bootloader is able to read the program once registers and the code is at address 0x1CE8.

The function that is not able to read the program once registers is in run from an MQX task which is in address 0x6860.

This is the code:

void Main_task(uint32_t initial_data)

{

   printf("\n Hello World \n");

 

   printf ("\n-------------- Program Once Read --------------\n\n");

 

   FTFE_FSTAT = 0x30;

   while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK)); //Wait for the read operation to complete

 

   FTFE_FCCOB0 = 0x41; //Program Once read command

   FTFE_FCCOB1 = 0x00; //Program Once index 0

   FTFE_FSTAT = 0x80;

 

   while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK)); //Wait for the read operation to complete

 

   if (FTFE_FSTAT & FTFE_FSTAT_ACCERR_MASK)

   {

       /* clear error flag */

       FTFE_FSTAT |= FTFE_FSTAT_ACCERR_MASK;

       /* update return value*/

       printf("Error ACCERR FSEC=0x%02x\n", FTFE_FSEC);

   }

   /* checking protection error */

   else if (FTFE_FSTAT & FTFE_FSTAT_FPVIOL_MASK)

   {

       /* clear error flag */

       FTFE_FSTAT |= FTFE_FSTAT_FPVIOL_MASK;

       /* update return value*/

       printf("Error FPVIOL\n");

   }

   else if (FTFE_FSTAT & FTFE_FSTAT_RDCOLERR_MASK)

   {

       /* clear error flag */

       FTFE_FSTAT |= FTFE_FSTAT_RDCOLERR_MASK;

       /* update return value*/

       printf("Error RDCOLERR\n");

   }

   /* checking MGSTAT0 non-correctable error */

   else if (FTFE_FSTAT & FTFE_FSTAT_MGSTAT0_MASK)

   {

       printf("Error MGSTAT0\n");

   }

 

   printf("%02X %02X %02X %02X %02X %02X\n", FTFE_FCCOB4, FTFE_FCCOB5, FTFE_FCCOB6, FTFE_FCCOB7, FTFE_FCCOB8, FTFE_FCCOB9);

 

   _mqx_exit(0);

}

0 Kudos

1,096 Views
ohadbenjamin
Contributor III

How come no one is trying to answer this?

0 Kudos