Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SLEEP Mode with turned off RAM

Jackob2001

Newbie level 4
Newbie level 4
Joined
Nov 3, 2024
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
I've got a problem understanding how "SLEEP Mode with turned off RAM" works ... SORRY FOR SO MUCH TEXT, please read it, because I struggle with it for hours ....

There is an STM32 that my friend used in his project (still don't have it physically the board), and it had this option to use SLEEP mode without RAM.
I know how Sleep mode works. When wake up MCU from SLEEP Mode it starts from the place it entered the SLEEP mode.

Turning off RAM will not restart the whole program when MCU wakes up right ? How it works ?

STANDBY Mode also restarts the RAM but also must restart the whole program. I am confused then why.

That's why I am mixed. Here are specific questions :

- What happens when we wake up the MCU from SLEEP Mode with RAM disabled (it was cleared).
- What happens when we wake up the MCU from STOP Mode with RAM disabled (it was cleared).
- What happens in the Callback if RAM is cleared and in the Callback is variable, or when it exits the callback. Context is stored in RAM.
- Then if STANDBY clears the RAM and it still can do the function from where it stopped then why it Restarts ?
- How RAM and ROM works when it comes to executing next lines of code ?
- Why the code can still go on even though the RAM was cleared ? It still holds the variables value, stack (which was the code context when it interrupts, maybe even when it goes sleep mode).


ROM holds the instructions, MCU takes the next instructions and executes it, while RAM holds are data (variables, stack).
But I still don't get it.

Thank you and sorry for complicating it if I am a nuisance.

PS.

Here is an example code :


C:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
    str = "WakeUP from SLEEP by EXTI\r\n";
    HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen (str), HAL_MAX_DELAY);
    HAL_PWR_DisableSleepOnExit ();
}


int main ()
{
......
......
while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

      int x = 5;
      int y = 10;

      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 1);
      HAL_Delay(5000);

      HAL_SuspendTick();

      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 0);  // Just to indicate that the sleep mode is activated

      HAL_PWR_EnableSleepOnExit ();

//      Enter Sleep Mode , wake up is done once User push-button is pressed
      HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

//    What happens here, after we wake up SLEEP ? X and Y are cleared. And the context ?
       int s = x + y;

      HAL_ResumeTick();

      for (int i=0; i<20; i++)
      {
          HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
          HAL_Delay(100);
      }

  }
}

Here after we Enter SLEEP Mode with RAM disabled ... how it works ? We have the Callback from EXTI which wakes up the MCU, RAM is cleared so it can execute the function ? IF there was a variable how would it work when RAM was cleared ? How can he comeback to main program when RAM was cleared (stack) and there is no reference ? How it can continue the rest of the code when variables were cleared.

I understand I guess that functions are I guess stored in ROM not in RAM but variables value are in RAM, which ROM instructs where variable is stored in RAM.
But I am mixed ...
 
Hi,

There is an STM32 that
My recommendation:
When asking about a specific device or it´s features: always post a link to the datasheet.
Also we need to know the EXACT devicce type.
You need to read it in first place, but we need to read it, too.

****
In short: all your questions should be answered by the datsheet!!! .. or one of it´s additional documents (usually referred to in the datasheet)

So I did a quick internet search on STM32 sleep modes. I never found the information that on sleep modes [SRAM is powered OFF] and [SRAM contents are lost], still this might be true for a specific device. Thus it´s urgent to have a the datasheet.

What I found is, is that the DRIVERS to access the SRAM and the CLOCK to the SRAM is powered down to reduce current consumption.
And since the SRAM is not powered OFF, it´s contents are preserved. AGAIN: this might be true or not for your EXACT microcontroller type.

BUT preserving the SRAM contents on SLEEP only makes sense to me. After returning from SLEEP the microcontroller needs to go on (in opposite to a RESTART like RESET) and has to expect valid SRAM data.

****
You several times write "guess" .. but guessing is not a good way to design hardware or software. All related informations surely are given by the manufacturer documents. So before you reply, please be sure to have all documents by hand, and having read the related sections.
For detailed discussions always refer to the document (by clear name) and the according section/page.

Klaus
 
Here after we Enter SLEEP Mode with RAM disabled
According to which documentation? The assumption sounds just unsubstantiated. I'm not aware of other low power modes than STANDBY disabling RAM. If you think that any STM32 device behave differently, please tell device type and refer to respective doc.
 
My recommendation:
When asking about a specific device or it´s features: always post a link to the datasheet.
Also we need to know the EXACT devicce type.
You need to read it in first place, but we need to read it, too.

The device is : STM32L031G6 (I don't have it yet)

In the STM website it is written : https://www.st.com/en/microcontrollers-microprocessors/stm32l031g6.html

1730635301105.png


I interpreted this information as so that Stop mode with 0.38uA has disabled RTC and RAM.
In the RM - Reference Manual
1730635686031.png


It is said it doesn't have the ability to turn off RAM retention. So I am puzzled.
It also says something about SLEEP mode and the RAM

1730639165715.png



There is also some info about Running on RAM which I can't imagine how it works.
1730639219978.png



What I found is, is that the DRIVERS to access the SRAM and the CLOCK to the SRAM is powered down to reduce current consumption.
And since the SRAM is not powered OFF, it´s contents are preserved. AGAIN: this might be true or not for your EXACT microcontroller type.

This is interesting as well as Running code from RAM instead of ROM.
But here what you've said there can be a device that drivers or clock to SRAM are down but the data in SRAM is still preserved so RAM is still ON.

But am I right that it has no sense for SLEEP and STOP mode to have the ability to turn off RAM ? Because all data is gone and when it comes back to execute the code all data is gone.
 
Still not clear what you are asking about. Standby mode is the only low power mode with RAM turned off. It can be only exited by going through a reset sequence.
 
Hi,

in other words: STOP mode is not the same as a SLEEP mode.
* In post#1 you talked about SLEEP mode ... with a SLEEP command ... and the microcontroller RESUMES operation after SLEEP.
* In post#4 you talk about STOP mode... not meant to resume operation ... but it needs a RESTART.

Klaus

added:
I see you mentioned both modes. But I can´t see how you distinguish in your code between the different power saving modes.
You use the HAL library ... I expec the HAL documentation to tell you how to enter, and how to resume form SLEEP.
Also when and how the callback should be used.

For sure this is a lot of documentation reading ... I don´t have the time for..

Klaus
 
Last edited:
Hi,

in other words: STOP mode is not the same as a SLEEP mode.
* In post#1 you talked about SLEEP mode ... with a SLEEP command ... and the microcontroller RESUMES operation after SLEEP.
* In post#4 you talk about STOP mode... not meant to resume operation ... but it needs a RESTART.

Klaus

I was just puzzled by the information that 0.38uA current is drawn from supply in STOP mode with disabled RTC and RAM retention (that's what I interpreted when I read 0.68uA with RTC and RAM retention).

In the end STOP mode has nothing about it if I read correctly second picture in post#4. Sleep mode can disable RAM and Flash clock, but RAM memory is still preserved if I correctly understand it.

I do have two questions though :
RAM and ROM I will create another post because I lack the basics even though I read some on the websites I want confirmations or clarifications.

- If SLEEP mode or STOP mode did indeed cleared that RAM what would happen if they were woken up ? MCU still can read instructions what to do next in the code but the variables etc are cleared from RAM so ERROR ?

- Same goes with Callback, it will turn on Callback function will try to execute it but can't go back because RAM was cleared ?

Thank you for your support/help. Although this part you could skip :

For sure this is a lot of documentation reading ... I don´t have the time for..

Sounds like "google it" and not as a really help ;)
That's why I ask here and send pictures because either I read it incorrectly or I can't find it. HAL functions do not have I guess these function to turn off RAM clock in Sleep mode as an addition. So I wondered how to do it without HAL (I only use HAL and have zero experience with LL if this is how it is called).
 
Last edited:
- If SLEEP mode or STOP mode did indeed cleared that RAM what would happen if they were woken up ? MCU still can read instructions what to do next in the code but the variables etc are cleared from RAM so ERROR ?
Problem is that you don't believe clear and simple datasheet facts and ask about unsubstantiated guesses instead.
 
Problem is that you don't believe clear and simple datasheet facts and ask about unsubstantiated guesses instead.

I did not deny datasheet. The website said something else and datasheet something else, but I believe more in datasheet.

Also I asked these 2 questions just out of curiosity. These are not quesses, just questions, and I believe I can ask them, because I am interested if something like that was possible then what could happen.
 
Yes, sure. Both questions have been essentially answered in post #5. Standby mode is the only way to turn off RAM. There's no problem of resuming code execution because standby is exited through reset only.
 
Sounds like "google it" and not as a really help
For sure you are free to see it this way. I see it a bit differently.

From forum experience ... there are some people (not saying you do it this way) who just try to avoid to read the documentation by themselves. They want others to read the documentation.
**********

HAL:
You used HAL in your code. And HAL library comes with documentation. It is improtant for you in first place to read the documentation.
You should not have to do a google search .... since you already shold have the documentation by hand.

I - on the other hand - needed to google for it. And since you did not provide section number or page number .. I needed to spend time to work through this documentation.

So before you reply, please be sure to have all documents by hand, and having read the related sections.
For detailed discussions always refer to the document (by clear name) and the according section/page.
To ease the process for all of us trying to help you ... I wrote this sentence above.
But I´m not sure:
* do you have the ALL documentation by hand (including HAL)
* did you provide a link to the documentation for us ... or at least a clear documentation name so we don´t need to spend time tor finding the same document you use
* did you provide chapter / page?

I noticed you posted a link ... and you posted the section "6.3.9 Stop Mode".
But the link is not to a datasheet, but a link to an internet site. Ok .. so I downloaded the datasheet by using the link on that site. ... and guess what
--> it shows section "6.3.9 Memory characteristics".
See: datasheet

So - a bit disappointed - I wondered which document your "6.3.9 Stop mode" is from...
I looked for a clear name (as I requested) ... no avail
I looked for a link to the document (as I requested) .. no avail

So am I wrong .. when I have to assume you did not take my post#2/recommendations seriously?
At least: Objectively one can not deny that you did not provide a link to the document you referred to, nor did you provide a clear document name.
I´m not angry. But I´m just not motivated enough to spend more time.
Usually one says: live is "give and take". But in a forum we know it is differently. There are people who GIVE only, and others who TAKE only.
And I - as the one who GIVEs only ... just ask for being taken seriously, a "thank you", a "please", and clear informations that I can SPEND time on HELPING instead of wasting time on SEARCHING and GUESSING. Just a little respect for the time we spend (for free) to keep us motivated. We are no servants. We are professionals ... used to work efficiently.
It´s just not efficient - when you already have the document - but hide it from us. So every single one of us, who wants to assist you ... needs to spend time for the search.
So 10 people = 10 times "search time" .. with the risk of finding a wrong document.

So luckily there are different people here to assist you. So you don´t have to rely on me .. you don´t have to spend time and effort on me.
There are others to help you.
So neither me nor you have to be angry ... when I now quit this thread.

Klaus
 
I noticed you posted a link ... and you posted the section "6.3.9 Stop Mode".
But the link is not to a datasheet, but a link to an internet site. Ok .. so I downloaded the datasheet by using the link on that site. ... and guess what
--> it shows section "6.3.9 Memory characteristics".
See: datasheet

The name is provided above the picture :

In the RM - Reference Manual

Indeed I did forget to say from where I took the info from last picture which is on me. And indeed I did forget to to say where on the website is the button to click to find pdf files for this device.

I will next time send all important information using pdf files. If it's possible here of course.

* do you have the ALL documentation by hand (including HAL)

I did not have. I do not know which documentation has it. I used to find these functions in the app CubeIDE and with tutorials how to Start with Low power modes.
They had only two modes for sleep which is Mainpoweron and Lowpoweron. I don:t know what they exactly turn off so I thought maybe I don't have to do low level.

So luckily there are different people here to assist you. So you don´t have to rely on me .. you don´t have to spend time and effort on me.
There are others to help you.
So neither me nor you have to be angry ... when I now quit this thread.

Ok, thank you.

Yes, sure. Both questions have been essentially answered in post #5. Standby mode is the only way to turn off RAM. There's no problem of resuming code execution because standby is exited through reset only

I do understand that SLEEP and STOP mode do not clear RAM memory in this device and maybe In any device.

I do understand that STANDBY mode is the only mode that clears RAM and has to be restarted when it wakes up.

Ok I do have two questions after this I will end the topic :

- in post#3 picture nr.2 paragraph 2 from Datasheet - Reference Manual. I am confused what is says.
It says for lowest consumption it turns Lowe power mode in internal Flash. In next sentence it says when Flash is in power down mode. Power down is turning off Flash. So which mode ?

- IF STOP mode could turn off Flash. Then how does the MCU know how to wake up and what to turn on like flash ? Why it does not require to reset the whole MCU like in standby mode ? Or where to start in that restarted ROM ?

This IF is to know what could happen. Pure curiosity.
 
Last edited:
- IF STOP mode could turn off Flash. Then how does the MCU know how to wake up and what to turn on like flash ? Why it does not require to reset the whole MCU like in standby mode ? Or where to start in that restarted ROM ?
PC (program counter) holds address of next instruction. Power control logic will first restart clock and then resume program execution.
 
PC (program counter) holds address of next instruction. Power control logic will first restart clock and then resume program execution.

PC holds the address of the next instruction but in order to take the next instruction Flash must be turned on but it was in stop mode and it was turned off.

Is it that when it wakes up it first turn on ROM the clock and the resume program execution? It has some kind of mechanizm that wakes up ROM, clocks etc without the need of executing the program ?

I had to read something about PC but it was helpful thank you.
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top