cancel
Showing results for 
Search instead for 
Did you mean: 

STMG0B1RET output pin does not pull down in Standby Mode

Kmax18
Senior II

I am using the STMG0B1RET on a custom, battery-powered board. During normal operation pin PC4 is used as UART1 (with an external pull-up resistor). In Standby Mode pin PC4 must be LOW in order to shut down the external device. For this I convert PC4 to GPIO and configure it for pull-down in Standby Mode to achieve the 0V at the output.

It is not working. When the HAL function HAL_PWR_EnterSTANDBYMode() is called the output goes HI.

I studied several posts and discussions about this issue, but no success yet.

The below is the latest code snipped. Wakeup pin 6 is used to exit Standby Mode (that works).
This line seems to pull the output to HI.  Why?

SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

What else can we try? Thank you!!

/* Convert UART1 IO to a GPIO */
GPIO_InitTypeDef GPIO_InitStruct = {0};
HAL_GPIO_WritePin(UART1_GPIO_Port, UART1_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin : UART1_Pin */
GPIO_InitStruct.Pin = UART1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(UART1_GPIO_Port, &GPIO_InitStruct);

PWR->PDCRC = PWR_PDCRC_PD4;   // Set pull-ups for standby modes
PWR->CR4 = PWR_CR4_WP6;       // Set wakeup pin 6 to low level
PWR->CR3 = PWR_CR3_APC | PWR_CR3_EWUP6; // Enable pin pull configurations and wakeup pins
PWR->SCR = PWR_SCR_CWUF; // Clear wakeup flags

// Configure MCU low-power mode for CPU deep sleep mode
PWR->CR1 |= PWR_LOWPOWERMODE_STANDBY;
(void)PWR->CR1; // Ensure that the previous PWR register operations have been completed

// Configure CPU core
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Enable CPU deep sleep mode

// Enter low-power mode
for (;;) {
    __DSB();
    __WFI();
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kmax18
Senior II

Solution:
The following code snippet shows how the output pin PC4 is pulled down (0V) in the low-power Standby Mode of the STM32G0 MCU. A NUCLEO-G071RB board was used for developing and testing the code, which is based on the ST example PWR/PWR_STANDBY. The ST example was modified and expanded. These are the main steps:

  • Determine if the MCU wakes up from Standby mode then resets the appropriate flags and registers.
  • Configure and set the test GPIO output pin to HIGH. (The output will later be pulled down for verification).
  • Use the PWR_PDCR register for controlling the GPIO output state (pull down to LOW) in Standby Mode.
  • Enter the low-power Standby mode.
  • Wake up from Standby Mode by pulling the WKUP pin2 HIGH.

The output voltage before and after entering Standby Mode was measured with a voltmeter (Figure 1).

Figure 1. Pinout of the NUCLEO board.

Kmax18_0-1743180013554.jpeg

Code snippet:

  /* Check if the system was resumed from Standby mode */ 
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
  {
    /* Clear Standby flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);

    /* Check and Clear the Wakeup flag */
    if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF2) != RESET)
    {
      __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    }

    /* Wait that user release the User push-button of the NUCLEO-G071RB */
    while ( HAL_GPIO_ReadPin(USER_BUTTON_GPIO_Port, USER_BUTTON_Pin) == GPIO_PIN_RESET )
    {}

    // Disable the pull-up bit
    HAL_PWREx_DisablePullUpPullDownConfig();
  }

  /* Set the GPIO test output pin to HIGH.
   * (Below it is pulled down to LOW before entering Standby Mode.)
  */
  HAL_GPIO_WritePin(PDCR_TEST_GPIO_Port, PDCR_TEST_Pin, GPIO_PIN_SET);

  /* Insert 5 seconds delay */
  HAL_Delay(5000);

  // Configure LOW GPIO output pin for Standby Mode
  HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4);

  // Apply the pull-up bit with APC bit 10
  HAL_PWREx_EnablePullUpPullDownConfig();

  /* The Following Wakeup sequence is highly recommended prior to Standby mode entry
     - Enable wakeup
     - Clear wake up pin flag depending in edge detection & pin level.
     - Enter the Standby mode.
  */

  /* Enable WakeUp Pin PWR_WAKEUP_PIN2 connected to PC.13 */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);

  /* Clear all related wakeup flags*/
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);

  /* Enter the Standby mode */
  HAL_PWR_EnterSTANDBYMode();

  /* This code will never be reached! */

 

View solution in original post

4 REPLIES 4
Kmax18
Senior II

JosueWilliams (Visitor II) posted a new reply in STM32 MCUs Products on 2025-03-20 8:08 AM:

"If the STMG0B1RET output pin isn’t pulling down in Standby Mode, check if the GPIO is properly configured as an output and if it retains state in low-power mode. Also, verify if any alternate functions or pull-up resistors are affecting it. Have you tried testing it in a different low-power state?"

Sarra.S
ST Employee

Hello @Kmax18, have you been able to solve this issue? 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @Sarra.S, thanks for asking. Yes I solved the issue using a NUCLEO-G071RB board and a modified and expanded version of the code example PWR/PWR_STANDBY. The code controls a GPIO output with the PWR_PDCR and PWR_PUCR registers and the associated HAL library functions. How can a post an article about this for the ST Community?

Kmax18
Senior II

Solution:
The following code snippet shows how the output pin PC4 is pulled down (0V) in the low-power Standby Mode of the STM32G0 MCU. A NUCLEO-G071RB board was used for developing and testing the code, which is based on the ST example PWR/PWR_STANDBY. The ST example was modified and expanded. These are the main steps:

  • Determine if the MCU wakes up from Standby mode then resets the appropriate flags and registers.
  • Configure and set the test GPIO output pin to HIGH. (The output will later be pulled down for verification).
  • Use the PWR_PDCR register for controlling the GPIO output state (pull down to LOW) in Standby Mode.
  • Enter the low-power Standby mode.
  • Wake up from Standby Mode by pulling the WKUP pin2 HIGH.

The output voltage before and after entering Standby Mode was measured with a voltmeter (Figure 1).

Figure 1. Pinout of the NUCLEO board.

Kmax18_0-1743180013554.jpeg

Code snippet:

  /* Check if the system was resumed from Standby mode */ 
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
  {
    /* Clear Standby flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);

    /* Check and Clear the Wakeup flag */
    if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF2) != RESET)
    {
      __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    }

    /* Wait that user release the User push-button of the NUCLEO-G071RB */
    while ( HAL_GPIO_ReadPin(USER_BUTTON_GPIO_Port, USER_BUTTON_Pin) == GPIO_PIN_RESET )
    {}

    // Disable the pull-up bit
    HAL_PWREx_DisablePullUpPullDownConfig();
  }

  /* Set the GPIO test output pin to HIGH.
   * (Below it is pulled down to LOW before entering Standby Mode.)
  */
  HAL_GPIO_WritePin(PDCR_TEST_GPIO_Port, PDCR_TEST_Pin, GPIO_PIN_SET);

  /* Insert 5 seconds delay */
  HAL_Delay(5000);

  // Configure LOW GPIO output pin for Standby Mode
  HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4);

  // Apply the pull-up bit with APC bit 10
  HAL_PWREx_EnablePullUpPullDownConfig();

  /* The Following Wakeup sequence is highly recommended prior to Standby mode entry
     - Enable wakeup
     - Clear wake up pin flag depending in edge detection & pin level.
     - Enter the Standby mode.
  */

  /* Enable WakeUp Pin PWR_WAKEUP_PIN2 connected to PC.13 */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);

  /* Clear all related wakeup flags*/
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);

  /* Enter the Standby mode */
  HAL_PWR_EnterSTANDBYMode();

  /* This code will never be reached! */