cancel
Showing results for 
Search instead for 
Did you mean: 

Question regarding hardware state and debug in stop mode

Vu.Andy
Associate III
Posted on July 11, 2018 at 01:56

Hi,

I am currently writing a program for the part STM32L031F6.  I am using StopMode to put the uController to sleep.

I have a couple of questions I was wonder if you could help.

1. When waking up from stop mode, do I need to initialize any hardware or clock?  I assume that after waking up, the program will continue to execute where the stop mode was entered, correct?  In my codes, I would reinitialize the clock again SystemClock_Config();  Are there anything else I need to initialize?  Like my ADC, Timer, and so on?

2. In order to debug in stop mode, all I have to do is to program this line?

        SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);

   By the way, I am using KEIL.  Does the debugger would start running again after waking up?  I am just curious as to

  how would the debugger work in stop mode?  I guess the debugger would just stop when stop mode is entered, then run   

  again to the next break point after the uController has waken up?

Thanks in advance.

Here are the my codes to enter stop mode:

    /* Enable Power Clock*/

  __HAL_RCC_PWR_CLK_ENABLE();        

  /* Allow access to Backup */

  HAL_PWR_EnableBkUpAccess();    

    

    HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

  

    

    HAL_SuspendTick();

    

    //enable debug in sleep mode

//    SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);

    

    //enable debug in stop mode

    SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);

    

    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

    

    SystemClock_Config();

    HAL_ResumeTick();
2 REPLIES 2
Szymon PANECKI
Senior III
Posted on July 11, 2018 at 09:27

Hello Andy,

Let me provide you some feedback regarding your questions.

1. When waking up from stop mode, do I need to initialize any hardware or clock?  I assume that after waking up, the program will continue to execute where the stop mode was entered, correct?

This is correct that when STM32L0 wakes up from STOP mode, it resumes executing the code from the place, where it finished just before entering STOP mode.

In my codes, I would reinitialize the clock again SystemClock_Config();

Regarding calling SystemClock_Config() after waking up from STOP mode: it is needed only when either HSE or PLL is used, because MCU can wake up either with MSI or HSI clock. If you use MSI/HSI clock directly to feed system clock, no reconfiguration is needed. If you use PLL/HSE, then you need to call SystemClock_Config() to restore them.

Are there anything else I need to initialize?  Like my ADC, Timer, and so on?

It is not mandatory to switch off peripherals before entering STOP mode. But it can be a good practice to switch of at least some of them. For example if you swtich off ADC, you will avoid a risk that conversion is ongoing when MCU enters STOP mode. Additionally if you disable voltage regulator for ADC, MCU will reduce a bit current consumption.

2. In order to debug in stop mode, all I have to do is to program this line?

        SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);

Yes. As you use HAL in your code, you can use this function instead: HAL_DBGMCU_EnableDBGStopMode();

Just one more comment regarding code, which you shared. In STOP mode systick timer is stopped. So there is no need to call HAL_SuspendTick() before entering STOP mode and  HAL_ResumeTick() after waking up from STOP mode.

Regards

Szymon
Posted on July 11, 2018 at 23:19

Regarding calling SystemClock_Config() after waking up from STOP mode: it is needed only when either HSE or PLL is used, because MCU can wake up either with MSI or HSI clock. If you use MSI/HSI clock directly to feed system clock, no reconfiguration is needed. If you use PLL/HSE, then you need to call SystemClock_Config() to restore them.

Thanks for the very detail reply.  As for initialize the clock after woken up, although I do not use the  HSE clock, I use the HSI clock but I also use the PLL to reduce the frequency from 16MHz to 8MHz (through a combination of requency multiply and division) to save power.  Does it mean I need to re-initialize the clock since the PLL is being used?

Thanks.