cancel
Showing results for 
Search instead for 
Did you mean: 

Hi Team, I'm using a STM32L4R5 and am wanting to store variables in SRAM2 as static variables so that they hold their value while the micro is in standby mode with SRAM2 retention enabled. What am I missing?

PLeij.1
Associate II

I've followed every tutorial/thread that i've been able to find but cannot get this to work. I've set:

 RAM2 (xrw) : ORIGIN = 0x20030000,  LENGTH = 64K

and

 .ram2_bss :

 {

 . = ALIGN(4);

 *(.ram2_bss)

 *(.ram2_bss*)

 } >RAM2

In STM32L4R5ZITX_FLASH.ld and defined the variable as

static int __attribute__((section(".ram2_bss"))) nrOfWakeUps = 0;

In main.c. The nrOfWakeUps is incremented each time the micro wakes up and an IO line is toggled to reflect this as per:

 while (1)

 {

 nrOfWakeUps++;

 for(int i=0; i<nrOfWakeUps; i++){

 GPIOA->BSRR = 0x00001111;

 HAL_Delay(1);

 GPIOA->BSRR = 0x11110000;

 HAL_Delay(1);

 }

 if(nrOfWakeUps>5)

 nrOfWakeUps=0;

 SysTick->CTRL = 0;  //Disable Systick

 asm("WFI");

 }

but i only ever get one pulse on the IO lines. What am i doing wrong?

Thanks in Advance!

Regards,

Peter

5 REPLIES 5
KnarfB
Principal III

[Edited] Sorry, was decaffeinated, cannot delete.

Piranha
Chief II
 SysTick->CTRL = 0;  //Disable Systick
 asm("WFI");

This is not entering a standby mode, but a simple sleep mode without any possibility to ever wake up. Read the reference manual and look at examples how standby mode is entered. And for keeping SRAM2 powered, RRS bits in PWR_CR3 must be set accordingly.

Hi Piranha,

I didn't include any of the configuration code, the full main() is

int main(void)
{
 HAL_Init();
 MX_GPIO_Init();
 
 SCB->SCR |= 0x0004;	// setting SLEEPDEEP bit in System Control Register
 PWR->CR1 |= 0x4403;	// LPR = 1, standby mode
 PWR->CR3 |= 0x100;	// full SRAM2 retention
 PWR->CR3 |= 0x001;	// enable wakeup
 PWR->CR4 &= ~0x01F;	// setup rising edge wakeup
 PWR->SCR |= 0x1F;		// clearing WUFx bits in PWR_SR1
 
 GPIOA->MODER = 0xabFFFD54; //mode register all outputs general purpose output 0b01
 GPIOA->OTYPER = 0x00000000; // all output push pull
 
 nrOfWakeUps = 0;
 
 while (1)
 {
	 nrOfWakeUps++;
	 for(int i=0; i<nrOfWakeUps; i++){
		 GPIOA->BSRR = 0x00001111;
		 HAL_Delay(1);
		 GPIOA->BSRR = 0x11110000;
		 HAL_Delay(1);
	 }
	 if(nrOfWakeUps>5)
		 nrOfWakeUps=0;
	 SysTick->CTRL = 0;  //Disable Systick
	 asm("WFI");
 }
}

I had double checked that it was actually in standby mode with ram retention by looking at the current draw with no input on the WKUP pin (562nA) which is within spec of the datasheet. A second thought I had last night was that it may be rebooting completely so I'll check that this morning.

Thanks for your reply,

Peter

Confirmed that the Micro is rebooting from the start of main() and setting nrOfWakeUps=0;. removing this line and it works as expected. However I'd like to avoid doing all the configuration stuff every cycle if that can be avoided.

I guess I have some more work to do...

Yes, that is exactly what standby mode does - almost a complete reset. Read the reference manual RM0432 section 5.3.9 Standby mode.