cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to disable the debug module during Sleep mode for the STM32f0?

Taylor Welsh
Associate II

I am getting suspiciously high current draw (10mA) after I call

HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);

and I'm trying to track down the culprit, I'm suspending the systick but it makes no change.

In stm32f0xx_hal.c it lists enabling/disabling debug during sleep (I am assuming to save power) as one of the included functions but only functions for stop mode and standby mode are included.

 ===============================================================================
                      ##### HAL Control functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Provide a tick value in millisecond
      (+) Provide a blocking delay in millisecond
      (+) Suspend the time base source interrupt
      (+) Resume the time base source interrupt
      (+) Get the HAL API driver version
      (+) Get the device identifier
      (+) Get the device revision identifier
      (+) Enable/Disable Debug module during Sleep mode
      (+) Enable/Disable Debug module during STOP mode
      (+) Enable/Disable Debug module during STANDBY mode

only these functions are listed

/**
  * @brief  Enable the Debug Module during STOP mode       
  * @retval None
  */
void HAL_DBGMCU_EnableDBGStopMode(void)
{
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
}
 
/**
  * @brief  Disable the Debug Module during STOP mode       
  * @retval None
  */
void HAL_DBGMCU_DisableDBGStopMode(void)
{
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
}
 
/**
  * @brief  Enable the Debug Module during STANDBY mode       
  * @retval None
  */
void HAL_DBGMCU_EnableDBGStandbyMode(void)
{
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
}
 
/**
  * @brief  Disable the Debug Module during STANDBY mode       
  * @retval None
  */
void HAL_DBGMCU_DisableDBGStandbyMode(void)
{
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
}

There is nothing listed in the bit definitions for this device (stm32f091xc.h) either. Is this just an omision by ST or is it not supported by the hardware?

5 REPLIES 5

I think the comment is a hold-over from other STM32 families. The L0 supports a debug module SLEEP mode, whereas the F0 only has this for the deep sleep modes STOP/STANDBY, where everything is otherwise turned off.

Is your system physically disconnected from the debug pod during these tests?

Are there any interrupts occurring with high regularity?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

If a debugger had been attached, make sure if doesn't have anything enabled in the DBGMCU_APBx_FZ registers that would keep things ticking.

I'd probably look for external connectivity drawing current.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Taylor Welsh
Associate II

I get the 10mA current draw without the debugger attached.

I guess the assumption is that if you are using the sleep mode rather than the stop or standby you want the peripherals enabled but it would be nice to limit this to only the peripherals you actually need. I can DeInit the rest but as far as I can tell there is no DeInit for the debug module in the hal.

I'm using the ADC in DMA mode with a timer as a external trigger during sleep. Ideally the MCU should wake only on the analog watchdog interrupt but there is a chance that I have missed an interrupt elsewhere that could be waking the cpu, will take a closer look.

This was a similar L0 related post

https://community.st.com/s/question/0D50X00009XkeECSAZ/question-regarding-hardware-state-and-debug-in-stop-mode

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

There is a DBGMCUEN clock enable in RCC_APB2ENR, I'd expect that it is off by default

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..