I have got a Cerb40 - Board an i want to save counter values in the battery backed ram. Do anyone have a sample program for this?
Thanks Andreas
I have got a Cerb40 - Board an i want to save counter values in the battery backed ram. Do anyone have a sample program for this?
Thanks Andreas
I do not remember if there is battery ram on the micro but the way is by using Register class to access it directly.
Welcome to the community.
I thing there is a backup SRAM on the micro. The image shows a part of STM32F40x block diagram.
I wrote a little test program to store some values into backup SRAM.
If I switch on the power supply the values are still inside the micro.
public class Program
{
// PWR
const uint PWR_BASE = 0x40007000;
// Offsets
const uint CR_OFFSET = 0x00;
const uint CSR_OFFSET = 0x04;
// RCC
const uint RCC_BASE = 0x40023800;
// Offsets
const uint AHB1ENR_OFFSET = 0x30;
const uint APB1ENR_OFFSET = 0x40;
// BKSRAM
const uint BKSRAM_BASE = 0x40024000;
// Register
static Register PWR_CR = new Register(PWR_BASE + CR_OFFSET);
static Register PWR_CSR = new Register(PWR_BASE + CSR_OFFSET);
static Register RCC_AHB1ENR = new Register(RCC_BASE + AHB1ENR_OFFSET);
static Register RCC_APB1ENR = new Register(RCC_BASE + APB1ENR_OFFSET);
static Register BKSRAM = new Register(BKSRAM_BASE);
public static void Main()
{
//Bit 28 PWREN: Power interface clock enable
RCC_APB1ENR.SetBits(1 << 28);
//Bit 8 DBP: Disable backup domain write protection
PWR_CR.SetBits(1 << 8);
//Bit 9 BRE: Backup regulator enable
PWR_CSR.SetBits(1 << 9);
//Bit 18 BKPSRAMEN: Backup SRAM interface clock enable
RCC_AHB1ENR.SetBits(1 << 18);
//Write_BKSRAM(0, 4711);
//Write_BKSRAM(4, 777);
//Write_BKSRAM(8, 0);
//Write_BKSRAM(12, 0);
//Write_BKSRAM(16, 0);
while (true)
{
Debug.Print(Read_BKSRAM(0).ToString());
Debug.Print(Read_BKSRAM(4).ToString());
Debug.Print(Read_BKSRAM(8).ToString());
Debug.Print(Read_BKSRAM(12).ToString());
Debug.Print(Read_BKSRAM(16).ToString());
Thread.Sleep(100);
}
}
static void Write_BKSRAM(uint offset, uint value)
{
Register BKSRAMx = new Register(BKSRAM_BASE + offset);
BKSRAMx.Write(value);
}
static uint Read_BKSRAM(uint offset)
{
Register BKSRAMx = new Register(BKSRAM_BASE + offset);
return BKSRAMx.Read();
}
}
Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the
tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)
I thing there is a backup SRAM on the micro. The image shows a part of STM32F40x block diagram.
I wrote a little test program to store some values into backup SRAM.
If I switch on the power supply the values are still inside the micro.
public class Program
{
// PWR
const uint PWR_BASE = 0x40007000;
// Offsets
const uint CR_OFFSET = 0x00;
const uint CSR_OFFSET = 0x04;
// RCC
const uint RCC_BASE = 0x40023800;
// Offsets
const uint AHB1ENR_OFFSET = 0x30;
const uint APB1ENR_OFFSET = 0x40;
// BKSRAM
const uint BKSRAM_BASE = 0x40024000;
// Register
static Register PWR_CR = new Register(PWR_BASE + CR_OFFSET);
static Register PWR_CSR = new Register(PWR_BASE + CSR_OFFSET);
static Register RCC_AHB1ENR = new Register(RCC_BASE + AHB1ENR_OFFSET);
static Register RCC_APB1ENR = new Register(RCC_BASE + APB1ENR_OFFSET);
static Register BKSRAM = new Register(BKSRAM_BASE);
public static void Main()
{
//Bit 28 PWREN: Power interface clock enable
RCC_APB1ENR.SetBits(1 << 28);
//Bit 8 DBP: Disable backup domain write protection
PWR_CR.SetBits(1 << 8);
//Bit 9 BRE: Backup regulator enable
PWR_CSR.SetBits(1 << 9);
//Bit 18 BKPSRAMEN: Backup SRAM interface clock enable
RCC_AHB1ENR.SetBits(1 << 18);
//Write_BKSRAM(0, 4711);
//Write_BKSRAM(4, 777);
//Write_BKSRAM(8, 0);
//Write_BKSRAM(12, 0);
//Write_BKSRAM(16, 0);
while (true)
{
Debug.Print(Read_BKSRAM(0).ToString());
Debug.Print(Read_BKSRAM(4).ToString());
Debug.Print(Read_BKSRAM(8).ToString());
Debug.Print(Read_BKSRAM(12).ToString());
Debug.Print(Read_BKSRAM(16).ToString());
Thread.Sleep(100);
}
}
static void Write_BKSRAM(uint offset, uint value)
{
Register BKSRAMx = new Register(BKSRAM_BASE + offset);
BKSRAMx.Write(value);
}
static uint Read_BKSRAM(uint offset)
{
Register BKSRAMx = new Register(BKSRAM_BASE + offset);
return BKSRAMx.Read();
}
}
Thanks for sharing. This is best posted on codeshare for others to benefit from if you like.
You ought to write up the native code for it and get it into the GCC build.
No need as this is very low speed. Easier to use register access then be able to tweak as needed.
How about including it in the OSHW library as-is, then?
I thought about it but the library is not made for a specific device. Standard methods should make sense for all devices. We will have to think about this for current offers and future ones.
Panda II has a class for interacting with its battery ram, correct? It shouldn’t be much different…
You said it, 4.1 did but not 4.2. It may come back in future.
Is that because the LPC17xx (G120) has no battery ram?
Gus, the processors you’ve chosen for your OSHW products (especially the Cerberus line) are extremely powerful pieces of hardware. It would be a shame to suppress features in those boards in order to promote your premium products.
Especially when the community already wrote the feature.
You keep saying “the community can contribute xxx feature”, and now they have, and you’re not interested in including it.
The good thing is that you can add these features yourself if you really need them. Several people here build their own firmware and shared detailed how-tos.
It’s not necessary to build custom firmware to include a single managed class.
I simply find it frustrating that Gus suggests that the community build out new features for the firmware, and then declines to include the community’s contributions in the firmware.
I think it was a specific small list of features when that request was made. Doesn’t really include every other possible feature will be included. Oh well, may be I am wrong.
That is why we have codeshare. Please let GHI decide what fits it’s products best. Please let GHI decide what works best for this community and also for its commercial customers that may or may not be part of the community. No need to be frustrated. We are trying our best.
GHI obviously USED to think that firmware-provided access to battery ram worked best for the community and customers. I can see no reason that GHI has changed their mind, other than that the new flagship product does not support battery ram in hardware. If there’s another reason, please share.
Gus, Architect, really, I didn’t want to argue. I won’t be replying to any more posts in this thread.
The natural evolution of many OSHW products in this situation is to simply have the community start it’s own firmware project. A device I own that comes to mind is my DSO pocket scope. I think it would be good for everyone if the community came up with their own firmware release for the Cerb.
We have a lot of people who make living working at GHI. please let us try to make the best decisions for our business while still caring for this community, that we adore, as much as possible.
Ian’s idea is perfect. A community firmware is most welcome.