Jackob2001
Newbie level 4
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 :
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 ...
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 ...