How can I set flash security in kl82z mcu

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

How can I set flash security in kl82z mcu

2,951 Views
rysardsuboc
Contributor II

I need protected Flash memory from write/erase/read.

I tried in Keil uVision by wizard configuration in startup_MKL82Z7.s file, but secure status not changed.

0 Kudos
22 Replies

2,327 Views
Jonathan_Iglesias
NXP TechSupport
NXP TechSupport

Hello Rysard Suboc,

Please try to generate the .bin file and upload it to the MCU so we can discard that the problem comes from the IDE or is something in the code.

Hope you can share your project or more information about it.

have a great day.

BR

Jonathan

0 Kudos

2,327 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

    Maybe you mix the secure and the flash protect together.

  1.Flash protection,  protect the flash from program and erase operations. You can modify it in the flash configuration filed, address 0x408-0X40B, FPROT0-3. More details, please refer to the KL82 reference manual, chapter 34.5.1 Flash Protection.

  2. Chip secruity,  programmer interface are only allowed to launch mass erase operations and have no access to memory loction. Note, this is just for programmer interface, for example, SWD. If you want to secure the chip, you also can modify it in the flash configuration field, address 0X40C, FSEC. You can set the FSEC data to 0xff, then download the code, after reset, the chip is secured.

    After you moidfy the .s file, you can generate the hex file, and check the according flash address, whether it is correct as your demand.

Wish it helps you!

Have a great day,
Kerry

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

0 Kudos

2,327 Views
rysardsuboc
Contributor II

Hi Kerry,

when I modify FSEC register in Flash configuration in .s file, I set

security status secure (shown in first figure). In generated hex file, in

0x40C address I have 0xBF value (what I need).

But, when I download my code to flash, secure not changed. I checked it by

JLink with specific command (shown in second figure).

Why not saved security settings ?

2017-01-04 6:33 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/865282?commentID=865282&et=watches.email.thread#comment-865282>

0 Kudos

2,326 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

     I have test the FSEC byte modification in the KSDK2.0_FRDM-KL82 mdk project.

    1. modify 0X40C address data to 0XBF in the start file

pastedImage_2.png

2. Download the code to the board

3. use the JLINK Commander to check the data

pastedImage_1.png

pastedImage_3.png

You can find the 0X40C is 0XBF now.

You also can check it in our official ksdk2.0 sample code.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

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

0 Kudos

2,326 Views
rysardsuboc
Contributor II

Hello,

I modified 0X40C address data to 0XBF in the start file.

When downloaded the code to the board.

And checked the data (0x40C) with Jlink commander (selected device

MKL82Z128xxx7 Allow security), I got 0xBE, not 0xBF.

2017-01-05 8:51 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/865621?commentID=865621&et=watches.email.thread#comment-865621>

0 Kudos

2,326 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

   Please follow this step and try again.

     1. Do the mass erase  for your KL82 chip

     Open JLINK command, and input: unlock kinetis

    Wait it finished.

     Then check the 0X40C, it should be 0XFE.

    2. Download the KSDK2.0-FRDMKL82

Welcome to Kinetis Expert | Kinetis Expert

  Click Build an SDK, then choose FRDM-KL82 board, generated the code, and download the code.

   3.  Follow my last reply, modify the .s file. FSEC to 0xbf.

      build and download.

  and use the JLINK command to check it again.

 

If you still have problem, please give me some picture from your side.

I test it based on the FRDM-KL82 board, it works.

 

Have a great day,
Kerry

 

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

0 Kudos

2,326 Views
rysardsuboc
Contributor II

And I have one note. When I make other changes of FSEC register, for

example disable mass erase (0xAE), or disable backdoor key (0x7E), value in

0x40C address change.

But when I want set secure (0xBF), value in 0c40C address not changed.

2017-01-05 12:06 GMT+02:00 Rysardas . <rysardass@gmail.com>:

Hi Kerry,

I did by your steps, and what's I got shown i pictures.

>

2017-01-05 10:36 GMT+02:00 kerryzhou <admin@community.nxp.com>:

>> NXP Community

>> <https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

>> Re: How can I set flash security in kl82z mcu

>>

>> reply from Kerry Zhou

>> <https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

>> Microcontrollers* - View the full discussion

>> <https://community.nxp.com/message/865635?commentID=865635&et=watches.email.thread#comment-865635>

>>

0 Kudos

2,326 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

     That's really strange.

     What the board you are using? FRDM-KL82 or your own board with the external JLINK debugger?

    I don't know whether it is your JLINK debugger problem.

   Do you have the official FRDM-KL82 board?

   If you have it, please use the newest JLINK firmware which can be downloaded from this link:

SEGGER - The Embedded Experts - Downloads 

  Then try again.

  Let's use the same board , the same code and the same debugger firmware.


Have a great day,
Kerry

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

0 Kudos

2,326 Views
rysardsuboc
Contributor II

Hi, Kerry,

Yes I use the official board FRDM-82Z.

2017-01-09 4:08 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/866365?commentID=866365&et=watches.email.thread#comment-866365>

0 Kudos

2,327 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

   1. Download the newest JLINK driver and install it.

SEGGER - The Embedded Experts - Downloads 

   2 Please change your board's debugger firmware with the newest JLINK firmware.

     (1) unplug the board

     (2) press the RESET button, hold on it, then plug the board to your PC, you will find your board is a device named as "BOOTLOADER", release the button.

    (3) Send the newest JLINK firmware .bin file to your board:

SEGGER - The Embedded Experts - Downloads 

  (4) unplug the board, then plug it again, your board will be a device named as "FRDM=KL82ZJ"

3. Use MDK project, modify FSEC to 0xbf in the startup_mkl82z7.s

   Before you download the code, please generate the hex file

pastedImage_2.png

  Then build it, open the hex file from folder:SDK_2.0_FRDM-KL82Z\boards\frdmkl82z\demo_apps\hello_world\mdk\debug

Check 0X40C address:

pastedImage_3.png

Whether it is 0XBF?

Please also tell me your MDK IDE reversion.

Please try it again on your side, any test result, please let me know!

Have a great day,
Kerry

 

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

0 Kudos

2,327 Views
rysardsuboc
Contributor II

Hi Kerry and Jonathan,

I was away a few days.

I tried update segger JLink and upload bootloader to the board. In my

generated hex file I got 0xBF, but when I checked it with JLink.exe and I

got 0xBE.

And MDK not upload code to the board, because I get message that contents

mismatch at 0x40C (Flash=BEH Required=BF).

My MDK version: MDK-ARM Plus Version: 5.21a.

Witch project file need to you to checking what is wrong?

2017-01-10 4:10 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/866782?commentID=866782&et=watches.email.thread#comment-866782>

0 Kudos

2,327 Views
kerryzhou
NXP TechSupport
NXP TechSupport

You can attached your project, I will test it on my side directly!


Have a great day,
Kerry

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

0 Kudos

2,327 Views
rysardsuboc
Contributor II

OK.

2017-01-16 10:09 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/868563?commentID=868563&et=watches.email.thread#comment-868563>

0 Kudos

2,327 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

    You just add the project, no source file.

    But it doesn't matter, because you hex file is correct, I think it should caused by the download configuration in the IDE.

   Please check the following picture:

pastedImage_1.png

Choose erase sectors instead of erase full chip.

Please try it again on your side.

Wish it helps you!

Any test result, please let me know!


Have a great day,
Kerry

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

0 Kudos

2,327 Views
rysardsuboc
Contributor II

Hi Kerry,

This help for me. It secured the MCU. But after JLink connection to the

MCU, all flash erased, but I don't know why. Maybe it is JLink settings..?

And when set secure MDK say:

  • JLink Info: BL reset: Timeout while waiting for CPU to halt after reset.

Manually halting CPU.

**JLink Warning: CPU could not be halted

***JLink Error: CPU is not halted

2017-01-17 11:05 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/869080?commentID=869080&et=watches.email.thread#comment-869080>

0 Kudos

2,327 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

  Another way to check your flash address 0x40c, you can add the printf 0x40c code in your helloworld like this:

int main(void)
{
    char ch;

    /* Init board hardware. */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    PRINTF("hello world.\r\n");
   PRINTF("0x40c data = %x.\r\n", *(uint8_t *)(0x40c));

    while (1)
    {
        ch = GETCHAR();
        PUTCHAR(ch);
    }
}

Then you will get the uart data in the PC after reset:

35.jpg

You can find the 0X40C data is 0xbf.

After the chip is secured, the SWD port cannot access the memory resources of the MCU.

So, after power off the board, then power on the board again, and connect with the jlink command,  I think the JLINK demand can't acces the memory, so it do the mass erase function automatically.

 

Wish it helps you!

Have a great day,
Kerry

 

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

0 Kudos

2,327 Views
rysardsuboc
Contributor II

Hi, Kerry,

Thank You for your answers and assistance for these issues.

A whole discussion was very useful.

2017-01-18 4:34 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/869308?commentID=869308&et=watches.email.thread#comment-869308>

0 Kudos

2,327 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Rysard Suboc,

  If you still have question, please let me know!

 If your question is solved, please help me to mark the correct answer,  just to close this case, thank you!


Have a great day,
Kerry

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

0 Kudos

2,327 Views
rysardsuboc
Contributor II

This question is solved, and answers can be formulated as follows:

First: change FSEC value in startup file.

Second: In debugger settings choose "erase sections" not "erase full chip".

Third: If not working, change device name in JLinkSettings.ini file

to "MKL82Z128XXX7 (ALLOW SECURITY)".

Maybe this is correct answer... You can add your own sightings.

2017-01-18 9:56 GMT+02:00 kerryzhou <admin@community.nxp.com>:

NXP Community

<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: How can I set flash security in kl82z mcu

reply from Kerry Zhou

<https://community.nxp.com/people/kerryzhou?et=watches.email.thread> in *Kinetis

Microcontrollers* - View the full discussion

<https://community.nxp.com/message/869485?commentID=869485&et=watches.email.thread#comment-869485>

0 Kudos

2,327 Views
kerryzhou
NXP TechSupport
NXP TechSupport

 Hi Rysard Suboc,

Yes, the summary is correct, but it is for MDK IDE. IAR is not the same.


Have a great day,
Kerry

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

0 Kudos