COPCTL loading problem at start from flash

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

COPCTL loading problem at start from flash

Jump to solution
1,298 Views
xak
Contributor I

I use the microcontroller S12XET256 with codewarrior 5.0.

My application run in a noised environment so I must enable the COP at start by loading the COPCTL from flash at reset.

As recommended, I use this 4 instructions to program flash NV registers:

 

const byte NVFPROT_INIT @0x0000FF0C = 0x7F; //FULL PFLASH SECURED

const byte NVEPROT_INIT @0x0000FF0D = 0xFF;

const byte NVFOPT_INIT @0x0000FF0E   = 0xF9; //COP CR[2:0]=6

const byte NVFSEC_INIT @0x0000FF0F   = 0x7D //SECURED, KEY DISABLED

 

But after start I read this by respective register and the COP, obviously, don't run:

FPROT=0x7F  (OK)

EPROT=0x7F  (wrong, should be 0x7F)

FOPT=0xFF    (wrong, should be 0xF9)

FSEC=0xFF    (wrong, should be 0x7D)

 

I try also with this settings:

 

const byte NVFPROT_INIT @0x0000FF0C = 0xFF;

const byte NVEPROT_INIT @0x0000FF0D = 0xFF;

const byte NVFOPT_INIT @0x0000FF0E   = 0xF9;

const byte NVFSEC_INIT @0x0000FF0F   = 0xFF

 

And I read this:

FPROT=0xFF (OK)

EPROT=0xFF (OK)

FOPT=0xFE  (wrong, should be 0xF9)

FSEC=0xFE  (wrong, should be 0xFF)

 

I use this funcion for another microcontroller (S12P128) without problems.

I wondering if someone has used this function with success or know the cause of problem.


Thanks in advance and best regards

Labels (1)
0 Kudos
Reply
1 Solution
1,033 Views
kef
Specialist I

By default codewarrior debugger reprograms NVSEC with 0xFE before loading your code. This worked for older S12(X), but failes for newer parts with ECC flash. You need to following command to your ???preload.cmd file:

FLASH NOUNSECURE

Are you sure your S12P project doesn't contain this command in preload.cmd?

Also, since you are enabling security, how do you read and verify  FOPT, FSEC values? It should be not possible using debugger.

View solution in original post

0 Kudos
Reply
3 Replies
1,034 Views
kef
Specialist I

By default codewarrior debugger reprograms NVSEC with 0xFE before loading your code. This worked for older S12(X), but failes for newer parts with ECC flash. You need to following command to your ???preload.cmd file:

FLASH NOUNSECURE

Are you sure your S12P project doesn't contain this command in preload.cmd?

Also, since you are enabling security, how do you read and verify  FOPT, FSEC values? It should be not possible using debugger.

0 Kudos
Reply
1,033 Views
xak
Contributor I

Thank you very much for the answer, it solves the problem.

I add the "FLASH NOUNSECURE" command and now the values are correct and the COP work correctly. :-)

In the first case I was able to read the registers because my application has a display and I was able to print them on it.

0 Kudos
Reply
1,031 Views
RadekS
NXP Employee
NXP Employee

Yes, Eduard has true.

Obviously ECC algorithm tries fixing corrupted data by one bit changing.

For example I will take second case:

Prior your write was data 0xFF, 0xFF, 0xFF, 0xFE (MCU unsecured)

You write 0xFF, 0xFF, 0xF9, 0xFF

In flash is after that 0xFF, 0xFF, 0xF9, 0xFE, but there ECC checksum didn’t fits and when you read data, ECC algorithm try fixing 1bit error and you get: 0xFF, 0xFF, 0xFE, 0xFE.

Problem is caused by cumulative write to the same phrase.

In attachment you can find short description of security feature at S12(X) devices.

Result behaviour depends on checksum value (of whole phrase) and therefore it is heavy predictable (sometimes it can work).

Anyway cumulative write to flash is not allowed. You should use FLASH NOUNSECURE command in preload file when you using loading code by CW.