Read/write non volatile variable

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Read/write non volatile variable

ソリューションへジャンプ
1,533件の閲覧回数
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 件の賞賛
1 解決策
1,497件の閲覧回数
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 件の賞賛
4 返答(返信)
1,498件の閲覧回数
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 件の賞賛
1,527件の閲覧回数
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 件の賞賛
1,515件の閲覧回数
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:

スポイラ
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 件の賞賛
1,524件の閲覧回数
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 件の賞賛