Preventing stored variables in flash from being erased when reprogramming?

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

Preventing stored variables in flash from being erased when reprogramming?

Jump to solution
1,005 Views
brettutesch
Contributor II

I'm using a KL16 with MCUXpresso 10.2 and I'm able to store/write/read my variables to flash (in the last 2KB of the 64KB using Flash_Program(...)).  Is there a setting to block MCUXpresso or the debugger from erasing these variables when reprogramming new firmware?

I've tried to create a new flash region in the last 2KB using the Memory Configuration Editor but my variables get erased.

0 Kudos
1 Solution
835 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Brett,

Yes, you can use "Non-Volatile Memory Preservation" :

If you want protect 0xF800- 0xFFFF , you can configure as below:

pastedImage_1.png


Have a great day,
TIC

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

View solution in original post

0 Kudos
3 Replies
835 Views
brettutesch
Contributor II

Sorry, I'm using a PE Multilink Universal FX.  I've defined the two sections:

Name                        Location      Size

Program_Flash         0x0            0xF800

Variable_Flash         0xF800      0x800

You mentioned I have to ensure the flash operation does not use mass erase.  Is this through the "Edit Configuration" of the ....PE Debug.launch (under the doc folder in the Project Explorer)? 

I see there is a "Non-Volatile Memory Preservation" under Debugger, Advanced Options.

0 Kudos
836 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Brett,

Yes, you can use "Non-Volatile Memory Preservation" :

If you want protect 0xF800- 0xFFFF , you can configure as below:

pastedImage_1.png


Have a great day,
TIC

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

0 Kudos
835 Views
lpcxpresso_supp
NXP Employee
NXP Employee

You didn't mention which debugger you're using, but the same principles apply. The K16 sector size is 1 KB. A sector is typically the smallest programmable/erasable block of memory. In order to get this to work, you need to redefine the flash memory into two flash blocks. It sounds like you've already done this.

The memory range of the first block is now 0x00000000-0x00007FFF. The memory range of the second block is 0x00008000-0x0000FFFF.

You have to ensure the flash operation does not use mass erase. Most debuggers (e.g. MCUXpresso) allow you to erase by sector.

Thanks and regards,

MCUXpresso Support

EDIT: Sorry, you said 2 KB persistent storage. In this case, the memory range of the first flash block is 0x00000000-0x0000F7FF, and the second is 0x0000F800-0x0000FFFF.

0 Kudos