Skip to main content
Evan .1
Associate III
Apr 29, 2020 12:20 PM UTC
Question

low lever driver backup sram example

Is there an LL example to enable the backup ram.

This doesn't work:

   // Enable PWR clock

   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);

   // Enable Backup ram clock

   LL_APB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_BKPSRAM);

   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);

   // Enable backup ram regulator

   LL_PWR_EnableBkUpAccess();

   LL_PWR_EnableBkUpRegulator();

   while (LL_PWR_IsActiveFlag_BRR() == 0);

   *(__IO uint32_t *) (BKPSRAM_BASE ) = 0x5A5A5A5A;

I can't find in the documentation what I forgot.

Thanks.

This topic has been closed for replies.

26 replies

Evan .1
Evan .1Author
Associate III
May 1, 2020 9:42 AM UTC

Nucleo-F767ZI

#define BKPSRAM_BASE          0x40024000UL /*!< Base address of : Backup SRAM(4 KB)                                                    */

from stm32f767xx.h

Evan .1
Evan .1Author
Associate III
May 1, 2020 9:54 AM UTC

Write backup ram

reset.

Breakpoint after enables breakup sram clock

0693W000000WmXCQA0.png

Power cycle.

Again breakpoint after enabling breakup sram clock

0693W000000WmXHQA0.png

waclawek.jan
Super User
May 2, 2020 10:22 PM UTC

Humm, and PWR_CSR1 content at both of these situations?

Also, RTC runs uninterrupted during the power outage, i.e. if it's say a minute long, the RTC time is not delayed?

JW

Evan .1
Evan .1Author
Associate III
May 4, 2020 6:00 AM UTC

PWR_CSR1 is in both situation 0x34000.

I don't use the RTC. I only need the backup ram.

Adam Santamaria
Visitor II
May 4, 2020 6:34 AM UTC

Hello,

So it seems that there is a problem with this part of your code:

LL_PWR_EnableBkUpRegulator();

while (LL_PWR_IsActiveFlag_BRR() == 0);

Because bit 9 (BRE Backup regulator enable) of PWR_CSR1 is not setif its value is 0x34000.

PWR-CR1 should be 0x34200 even after a power cycle

Could you try to set it manually with PWR->CSR1 = 0x00034200,

And check that bit 9 has not been reset after power cycle ?

Evan .1
Evan .1Author
Associate III
May 4, 2020 7:10 AM UTC

   PWR->CSR1 = 0x00034200;

don't change the value of CR1 after this the value is still 0x34000

I also tried this:

   LL_PWR_EnableBkUpAccess();

   PWR->CSR1 = 0x00034200;

Still the CR1 is not updated.

Adam Santamaria
Visitor II
May 4, 2020 8:07 AM UTC

The following code works for me (i used the f746 discovery board but the register mapping is the same for f76x products).

PWR->CR1 is well updated after the while (test is a global variable).

RCC->APB1ENR |= 0x10000000;

 PWR->CR1 |= 0x00000100;

 RCC->AHB1ENR |= 0x00040000;

  

 test = PWR->CSR1;

  

 PWR->CSR1 |= 0x00000200;

  

 while( (PWR->CSR1 & 0x00000008) != 0x00000008) ;

  

 test = PWR->CSR1;

Evan .1
Evan .1Author
Associate III
May 4, 2020 9:14 AM UTC

I changed my code to this:

void CPU_config_backupram(void)

{

   volatile uint32_t test;

   RCC->APB1ENR |= 0x10000000;

   PWR->CR1 |= 0x00000100;

   RCC->AHB1ENR |= 0x00040000;

   test = PWR->CSR1;

   PWR->CSR1 |= 0x00000200;

   while( (PWR->CSR1 & 0x00000008) != 0x00000008) ;

   test = PWR->CSR1;

}

PWR->CSR1 is still 0x34000.

So are there any other requirements?

Reading variable: test gives me the following error message:

Multiple errors reported.

1) Failed to execute MI command:

-var-create - * test

Error message from debugger back end:

-var-create: unable to create variable object

2) Unable to create variable object

3) Failed to execute MI command:

-data-evaluate-expression test

Error message from debugger back end:

No symbol "test" in current context.

4) Failed to execute MI command:

-var-create - * test

Error message from debugger back end:

-var-create: unable to create variable object

Evan .1
Evan .1Author
Associate III
May 4, 2020 9:28 AM UTC

RCC->APB1ENR |= 0x10000000;

 PWR->CR1 |= 0x00000100;

 RCC->AHB1ENR |= 0x00040000;

  

 test = PWR->CSR1;

  

 PWR->CSR1 |= 0x00000200;

  

 while( (PWR->CSR1 & 0x00000008) != 0x00000008) ;

  

 test = PWR->CSR1;

This solved the problem. Somehow the debug environment uses an other image with the new source code?

Evan .1
Evan .1Author
Associate III
May 4, 2020 10:07 AM UTC

This seems the correct low level driver code for configure the backup ram:

void CPU_config_backupram(void)

{

// Enable PWR clock

   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);

   // Enable Backup ram clock

   LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_BKPSRAM);

   // Enable backup ram regulator

   LL_PWR_EnableBkUpAccess();

   LL_PWR_EnableBkUpRegulator();

   while (LL_PWR_IsActiveFlag_BRR() == 0);

}