cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to wake from Stop2 power mode with user button

JayDev
Senior II

I put my L4R5ZI chip into Stop2 mode but it doesn't seem to want to wake up from the user button, unfortunately. According to the datasheet, the wakeup sources include:

Reset pin, all I/Os

BOR, PVD, PVM

RTC, IWDG

COMPx (x=1..2)

I2C3(7)

LPUART1(6)

LPTIM1

I have setup the user button (PC13) as an external interrupt on the rising edge and have it entering low power mode using this same button. My code is shown below:

static void MX_GPIO_Init(void)
{
  /* Other GPIO setup here */
 
  /*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
 
   /* Other GPIO setup here */
}
 
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	if(GPIO_Pin == B1_Pin)
	{
		while(HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin) == GPIO_PIN_SET)
		{
 
		}
		if(lowpowermode == true)
		{
			lowpowermode = false;
			//ExitLowPowerMode();
		}
		else
		{
			lowpowermode = true;
			//EnterLowPowerMode();
			Run_Stop_Mode();
			//Enter_LowPower_Mode();
		}
		//HAL_GPIO_TogglePin(GPIOB, LD3_Pin);
	}
}
 
void EnterLowPowerMode()
{
	HAL_TIM_Base_Stop_IT(&htim2);
	HAL_ADC_Stop_DMA(&hadc1);
 
	HAL_SPI_DeInit(&hspi1);
	__HAL_RCC_SPI1_CLK_DISABLE();
 
	//__HAL_RCC_GPIOC_CLK_DISABLE();
	__HAL_RCC_GPIOH_CLK_DISABLE();
	__HAL_RCC_GPIOA_CLK_DISABLE();
	__HAL_RCC_GPIOB_CLK_DISABLE();
	__HAL_RCC_GPIOD_CLK_DISABLE();
	__HAL_RCC_GPIOG_CLK_DISABLE();
 
 
}
 
void ExitLowPowerMode()
{
	__HAL_RCC_GPIOC_CLK_ENABLE();
	__HAL_RCC_GPIOH_CLK_ENABLE();
	__HAL_RCC_GPIOA_CLK_ENABLE();
	__HAL_RCC_GPIOB_CLK_ENABLE();
	__HAL_RCC_GPIOD_CLK_ENABLE();
	__HAL_RCC_GPIOG_CLK_ENABLE();
 
	__HAL_RCC_SPI1_CLK_ENABLE();
	HAL_SPI_Init(&hspi1);
 
	HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_Value, 1);
	HAL_TIM_Base_Start_IT(&htim2);
}
 
void Run_Stop_Mode()
{
	EnterLowPowerMode();
 
	// Suspend the Ticks before entering the STOP mode or else this can wake the device up
	HAL_SuspendTick();
 
	// Enter Stop Mode
	HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
 
	SystemClock_Config();
	HAL_ResumeTick();
 
	ExitLowPowerMode();
}

Am I missing anything obvious? Do I need to setup that pin specifically to enable to interrupt? I've looked at a few other examples but haven't seen anything specifically setting that up. Maybe I'm looking in the wrong place?

I assume I'm probably pretty close but I clearly missed something. Any help you can give me would be appreciated. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
JayDev
Senior II

Ok, I found the problem (after getting another example to work, copying the clock settings, moving the clock settings to a NOW working example (there were errors with the example code, but I was able to fix it to get it working), etc).

After all that, it wasn't the clock, it was the button interrupt. Although I did have it setup as an interrupt, I hadn't enabled the NVIC for the button/GPIO pin . . . so stupid . . . anyway, it's working now. Not sure if anyone else runs into this issue but it appears that was the issue. Hopefully, this helps someone!

View solution in original post

2 REPLIES 2
JayDev
Senior II

I just returned to this after a break and decided to see if I can sort it out. I decided to remove the call to EnterLowPowerMode() in case it was disabling a GPIO clock or pin I might need so it's not getting woken up properly. Unfortunately, I haven't seen any changes with this.

I know the GPIO was setup correctly as it entered sleep mode when the button was pressed. If I'm not calling anything prior to the sleep mode, it looks like something isn't working to recognize it as a sleep wakeup event. As I mentioned above though, the IO pin should be enough to wake it (I even have this same sleep mode working on another board with a similar process).

Any ideas on what I'm missing? Is the STOP2 mode disabling a clock I need for a wake event or something to that effect?

Below is my clock setup:

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Configure the main internal regulator output voltage
  */
  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 2;
  RCC_OscInitStruct.PLL.PLLN = 20;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  {
    Error_Handler();
  }
}

I'm a bit confused as this seems to be a fairly straight forward process that I'm struggling with. If I setup a clock incorrectly, this would make sense but I haven't been able to figure it out just yet.

Any help would be appreciated. Thanks!

JayDev
Senior II

Ok, I found the problem (after getting another example to work, copying the clock settings, moving the clock settings to a NOW working example (there were errors with the example code, but I was able to fix it to get it working), etc).

After all that, it wasn't the clock, it was the button interrupt. Although I did have it setup as an interrupt, I hadn't enabled the NVIC for the button/GPIO pin . . . so stupid . . . anyway, it's working now. Not sure if anyone else runs into this issue but it appears that was the issue. Hopefully, this helps someone!