BatteryRam in 4.2

Hello everyone, i am moving my project to 4.2 SDK and I can’t find the BatteryRam class in this release. I can’t use EWR for these data due to number or writes limitations. Therefore how to proceed?

Regards

You can still access that ram using the Register classed address space. You just need to know the battery ram location from the processor datasheet.

Hi Gus

Cool, I will retry moving from 4.1 to 4.2 soon. Still have to ensure if one wire will work properly and how to manage cdc and debug and I will be ready. Do you know if I can expect runtime improvement by upgrading the SDK?

Best regards

You will have boot time improvements, couple seconds maybe.

Good to know for the boot, but the major problem for us actually is the runtime due to Hashtable usage and a lot of boxing unboxing.

That can’t be solved, except by implementing your own Hashtable with a specific storage type, instead of using object.

1 Like

@ Gus - I have read several time the LPC2478 datasheet and can’t find the address for the BatteryRam location. Page 30 and 31 does not give this information. Does any one know where to write and how to use the register class to do the same as Battery Ram did?

You need the user manual.

Thanks Gus,Let’s go for a deep reading of it… 792 pages!!! See U on the forum in July :slight_smile:

Fortunately, I found other posts on the forum: Battery Ram starts at 0xE0084000 and stops at 0xE00847FF

Just need now to rebuild a kind of BatteryRam class to have the same capabilities than in 4.1 sdk…

I think the team here is adding the code if you want to wait few days.

Wow!!!

No need to work anymore!!! Just talk here about what you need and GHI does it !!! I like that :slight_smile:

I’m kidding… I can wait few days (not too much…) and be focused on other changes needed by the 4.2 sdk…

Thanks Gus and thank to the team

Plz let me know when it will be available

Regards

This is a quick sample code to show one of the quickest/easiest methods to access/utilize the Battery backed RAM associated with the RTC on EMX (FEZ Spider)

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using GHI.Premium.Hardware.LowLevel;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

// deploy and run, then unpower/reset board and run again to see values were 
// stored, saved, recalled across power-down/reset
// WARNING THIS IS ONLY FOR EMX BASED DEVICES
namespace GadgeteerApp1
{
    public partial class Program
    {
        static Register BatteryRam;
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            if (   ReadBatteryRam(0) != (uint)0
                || ReadBatteryRam(1) != (uint)1
                || ReadBatteryRam(2) != (uint)2
                || ReadBatteryRam(3) != (uint)3
                )
            {
                Debug.Print("Initializing 0,1,2,3 battery ram");
                WriteBatteryRam(0, 0);
                WriteBatteryRam(1, 1);
                WriteBatteryRam(2, 2);
                WriteBatteryRam(3, 3);
            }
            else
            {
                Debug.Print("Ram is already at 0,1,2,3");
            }
        }

        // write a 32 bit value into virtual uint[512] array mapped over RTC battery RAM
        // offset is the index into the array.
        void WriteBatteryRam(uint offset, uint a_value)
        {
            // todo: if offset > 511 throw illegal arg exception
            BatteryRam = new Register(0xE0084000 + (offset << 2));
            BatteryRam.Write(a_value);
        }

        // read a 32 bit value from virtual uint[512] array mapped over RTC battery RAM
        // offset is index into array
        uint ReadBatteryRam(uint offset)
        {
            // todo: if offset > 511 throw illegal arg exception
            BatteryRam = new Register(0xE0084000 + (offset << 2));
            return BatteryRam.Read();
        }

    } 
}

…follow up note on my example… in case folks try to emulate this with GHI.Premium.Hardware.LowLevel.AddressSpace class, the datasheet for the processor says that the RAM is [em]only[/em] accessible in 32 bit words, i.e. not byte-wise accessible. AddressSpace uses byte-wise access.

1 Like

Thanks boss :slight_smile:

is there a clever way to store and retrieve a float from register class?