Use the internal flash to save data at runtime with MCUXpresso

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

Use the internal flash to save data at runtime with MCUXpresso

Jump to solution
2,346 Views
AndreVB
Contributor III

Hi NXP Team,

I have an KINETIS-based application being developed with MCUXpresso (MCU-Link debug probe). Of 64k FLASH I use 4k to save data. FLASH_LOWER for the code and FLASH_HIGHER to save data (see next image). Two questions:

1. Whenever I debug the whole Flash is erase. But I want to preseve FLASH_UPPER (my data) during the debbuging process. How can I do that? 

AndreVB_0-1642355149541.png

2.  In the final product, I want to protect my code (FLASH_LOWER). Don' t care about FLASH_LOWER (my data). How do I do that?

I have read these articles:

17.8.2 Kinetis MCUs – Flash Config Blocks

https://community.nxp.com/t5/Kinetis-Design-Studio-Knowledge/Relocating-Code-and-Data-Using-the-MCUX...

https://mcuoneclipse.com/2014/05/31/configuration-data-using-the-internal-flash-instead-of-an-extern...

I’ve looked through the documentation but I haven’t understood how I could use the MCUXpresso IDE to configure the flash accordingly. Any help is very welcome.

Thank you, Andre.

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Reply
1 Solution
2,329 Views
ErichStyger
Specialist I

Hi @AndreVB ,

About 1): I don't see (at least with my IDE 11.4.1) the the LinkServer connection is erasing first all memory. I do have in many projects reserved a region at the end of the flash. But I simply reduce the flash size in the MCU settings:

ErichS_0-1642419844457.png

I can confirm that way for all debug connections I use (Segger J-Link, LinkServer McuLink & P&E Multilink) the FLASH that way does not get touched, showing with MinINI and McuFlash below (from https://mcuoneclipse.com/2021/12/19/key-value-pairs-in-flash-memory-file-system-less-minini/ )

ErichS_1-1642419986116.png

Maybe the thing you see is because you are using an older IDE? I remember (I think it was starting with 11.4) the LinkServer flashing has been optimized, not programming untouched sectors by default (something what J-Link always did, and P&E does now too, at least when I last checked). You could verify the flash operations in the Console view:

ErichS_2-1642420220729.png

 

About 2): on the KL25Z there are the FPROTx registers which can be used to protect each of the 32 regions of the flash memory (see chapter 27.4.1 Flash Protection) in the KL25Z reference manual.

 

I hope this helps,

Erich

View solution in original post

0 Kudos
Reply
4 Replies
2,330 Views
ErichStyger
Specialist I

Hi @AndreVB ,

About 1): I don't see (at least with my IDE 11.4.1) the the LinkServer connection is erasing first all memory. I do have in many projects reserved a region at the end of the flash. But I simply reduce the flash size in the MCU settings:

ErichS_0-1642419844457.png

I can confirm that way for all debug connections I use (Segger J-Link, LinkServer McuLink & P&E Multilink) the FLASH that way does not get touched, showing with MinINI and McuFlash below (from https://mcuoneclipse.com/2021/12/19/key-value-pairs-in-flash-memory-file-system-less-minini/ )

ErichS_1-1642419986116.png

Maybe the thing you see is because you are using an older IDE? I remember (I think it was starting with 11.4) the LinkServer flashing has been optimized, not programming untouched sectors by default (something what J-Link always did, and P&E does now too, at least when I last checked). You could verify the flash operations in the Console view:

ErichS_2-1642420220729.png

 

About 2): on the KL25Z there are the FPROTx registers which can be used to protect each of the 32 regions of the flash memory (see chapter 27.4.1 Flash Protection) in the KL25Z reference manual.

 

I hope this helps,

Erich

0 Kudos
Reply
2,314 Views
AndreVB
Contributor III

Hi Erich,

That´s works fine. Simpler than I thought. I was using IDE 11.4.1 and jut moved to IDE 11.5.0. Both working fine. For some reason using IDE 11.4.1, if I do not reduce the Flash size the appliction was mass erasing the memory prior debugging. With IDE 11.5.0, either reducing the flash size or keep it untouched the last sectors are preserved from one debug session to another.

Thank you,

AndreVB

Tags (1)
0 Kudos
Reply
2,335 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @AndreVB ,

The MCUXpresso IDE will only erase erase affected sector when downloading code by default. You data will not be erased if the last sector is not overlapped by code. If you want to erase everything when programming, you can set in GUI Flash Tool.

jingpan_0-1642414699180.png

 

 

Regards,

Jing

0 Kudos
Reply
2,328 Views
ErichStyger
Specialist I

Hi @jingpan ,

If I'm not wrong: the settings you show are not used for the download/programming/debugging operation. They are only used if you press that 'Run' button in that dialog, otherwise I think these settings are ignored.

Let me know if I have that wrong?

Erich

0 Kudos
Reply