Read/write non volatile variable

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

Read/write non volatile variable

Jump to solution
1,509 Views
Ekaitz
Contributor II

Hello,

I'm doin a proyect whit the micro MPC 5744P with GNU toolchain.

I'm triyin to define a variable that can write and read but not initialize in all the power on of.

I'm tray to define a variable in liker scrip but I dont get the espected results

My example is this:

Linker script

MEMORY
{
flash_rchw : org = 0x00F98000, len = 4
cpu0_reset_vec : org = 0x00F98004, len = 4

m_my_flash : org = 0x01000000, len = 4
m_text : org = 0x01000004, len = 2048K - 4

m_my_ram : org = 0x40000000, len = 4
m_data : org = 0x40000004, len = 384K - 4

local_dmem :org = 0x50800000, len = 64K
}

SECTIONS
{
...............
.startup_state_sect ORIGIN(m_my_ram) :
{
KEEP (*(.startup_state_sect))
} > m_my_ram AT > m_my_flash
......................
}

Code:

uint32_t __attribute__((__section__(".startup_state_sect"))) startup_state;

0 Kudos
1 Solution
1,473 Views
jamesmurray
Contributor V

In my previous message I wrote about using flash memory for storage. Actually, that's not a good idea to do this on the flash within the device for two reasons:
1. The flash has a limited number of write cycles and constant use will wear it out.
2. If the "system can be power off anytime" your flash write could be interrupted and left in an unknown state.

If you really need this, then perhaps battery backed-up RAM is a better idea. I looked and it seems that the 5744P does not have standby RAM. (The 5746R does.)
So maybe some external RAM with battery backup. You would need to use two regions and alternate between them. Otherwise if power is lost at the time you are writing you will get unknown behaviour.

James

View solution in original post

0 Kudos
4 Replies
1,474 Views
jamesmurray
Contributor V

In my previous message I wrote about using flash memory for storage. Actually, that's not a good idea to do this on the flash within the device for two reasons:
1. The flash has a limited number of write cycles and constant use will wear it out.
2. If the "system can be power off anytime" your flash write could be interrupted and left in an unknown state.

If you really need this, then perhaps battery backed-up RAM is a better idea. I looked and it seems that the 5744P does not have standby RAM. (The 5746R does.)
So maybe some external RAM with battery backup. You would need to use two regions and alternate between them. Otherwise if power is lost at the time you are writing you will get unknown behaviour.

James

0 Kudos
1,503 Views
jamesmurray
Contributor V

 I am not sure I fully understand your question, but I will try.

How is this variable going to be non-volatile? Your linker script is creating a variable that operates from RAM but gets initialised by startup code to an initial value from flash.
The conventional approaches I can think of.

1. semi non volatile - store it in a standby RAM section (if available on 5744P)

2. Permanent copy of data lives in flash, but gets loaded to RAM on boot.
Software uses and modifies the RAM version.
Changes get written back to flash under software control.

James

0 Kudos
1,491 Views
Ekaitz
Contributor II

Thanks for the answer,

I'm trying to define a variable wich I can modify by the main program and the changes of this variable save in all power on - off process or reset. 

But I don't get this result. I have this try program to function like a toogle the variable but when I reset the hardware I don't see the expected process.

if (startup_state != 0xAA)
{
startup_state = 0xAA;
..............
}
else
{
 startup_state = 0x00;
...............................
}

When you say:

Spoiler
Permanent copy of data lives in flash, but gets loaded to RAM on boot.
Software uses and modifies the RAM version.
Changes get written back to flash under software control.

This mean that I need to save the value before the sistem reset?

I need this variable with the last value all time, because the system can be power off anytime

 

0 Kudos
1,500 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

It is typical to define non-volatile data as const storage class. It can be changed by flash reprogramming.

0 Kudos