Snippet - Cerberus InternalFlashStorage

This does not seem to work for me ???
I have the following code


byte[] buffer = new byte[1];
byte count
{
    get
    {
        return buffer[0];
    }
    set
    {
        buffer[0] = value;
    }
}
void ProgramStarted()
{
    Thread.Sleep(1000);
    Debug.Print("Program Started");
    ReadCount();
    PrintCount();
    joystick.JoystickPressed += joystick_JoystickPressed;
}

private void ReadCount()
{
    InternalStorage.Read(buffer, 0, 0, 1);
}

private void WriteCount()
{
    InternalStorage.Write(buffer, 0, 0, 1);
}

private void PrintCount()
{
    Debug.Print("Count: " + count.ToString());
}

void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
{
    Debug.Print("JoystickPressed");
    count++;
    PrintCount();
    WriteCount();
    ReadCount();
    PrintCount();
}

When the program starts it reads 255.
When i press the button the first time this changes to 0 and 0 after write.
Any button press after that changes it to 1 then to 0 again after the read.
Output:

I have tried the version on code share i have also tried to apply the bug fix for the write method posted here on page 3 but it doesnā€™t change any thing.
I have also tried to run this code without the debugger and outputting the information to a N18 display same result!

So no matter what I save when I read it I get 0.

@ Petoj - I was able to make it work well. Let me see if I made any substantial changes. I use it for settings, logging, and data storage.

@ Petoj - Here is my version: https://www.ghielectronics.com/community/codeshare/entry/885

Hi Petoj,
Did you try with Address range more than 15360.
Because the config bits are stored in first 15KBā€™s. Must use the Last 1KB.

I am never calling EraseBlock could that be it?
and if i need to call it how do i determine when to call it? i guess i should call it the first time it boots after a flash?

I donā€™t think so for.
Still if you want to call EraseBlock, Then call it first after that you will try to write in flash.

Does any one have a 4.3.4.0 compatible version of this the method the register class does not seem to have write and read methods any moreā€¦

Also my guess is that GHI.OSHW.Hardware was replaced with GHI.Hardware if that is incorrect then im missing GHI.OSHW.Hardware.

Just use equals now.

Register Reg1 = new Register(0x12345678);
uint value;
Reg1 = value;
value = Reg1; 

Thanks one question The Read function returned a uint value while the implicit operator is for type int not uint will this cause any errors?

Also DeviceInfo and DeviceID seem to be gone where did those go?

This does not work as i get ā€œCannot implicitly convert type ā€˜uintā€™ to ā€˜GHI.Processor.Registerā€™ā€.

So tried to use register.Value but that doesnā€™t seem to work as the value that is saved seems to be randomā€¦

If i try to call EraseBlock i get
Exception was thrown: System.Exception
GHI.Processor.Register::set_Value
STM32F4.IO.InternalStorage::EraseBlock
Counter.Program::timer_Tick
Gadgeteer.Timer::dt_Tick
Microsoft.SPOT.DispatcherTimer::FireTick
Microsoft.SPOT.Dispatcher::PushFrameImpl
Microsoft.SPOT.Dispatcher::PushFrame
Microsoft.SPOT.Dispatcher::Run
Gadgeteer.Program::Run
Counter.Program::Main

I guess some thing is broken in the flashā€¦

Iā€™ll check tomorrow unless someone else can help first.

Register Reg1 = new Register(0x12345678);
uint value;
Reg1.Value = value;
value = Reg1.Value; 

[/quote]

[/quote]

Yes thats what i used but I still get a error when I try to execute erase blocksā€¦

Register uses int32 and uint32 - maybe you should change your variables to 32bit.

@ Lurch - What do you mean? both uint and int are 32 bit?