cancel
Showing results for 
Search instead for 
Did you mean: 

Wakeup from sleep HAL_TIM_PeriodElapsedCallback interupt on a STM32L031 commenting out HAL_PWR_EnableSleepOnExit (); and HAL_SuspendTick(); the LED flashes

PGood.1
Associate II

Im trying to reduce power by putting the a STM32l031 to sleep between timer interupts. It goes to sleep but never wakes up

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim) {

  if (htim -> Instance == TIM21) {

 Strobe++;

 if (Strobe==8352){

Strobe=0;

HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);

   }

}

HAL_PWR_EnableSleepOnExit ();

    HAL_SuspendTick();

}

static void MX_TIM21_Init(void)

{

 /* USER CODE BEGIN TIM21_Init 0 */

 /* USER CODE END TIM21_Init 0 */

 TIM_ClockConfigTypeDef sClockSourceConfig = {0};

 TIM_MasterConfigTypeDef sMasterConfig = {0};

 /* USER CODE BEGIN TIM21_Init 1 */

 /*

  * htim21.Init.Prescaler = 320;

  * htim21.Init.Period = 248;

  */

 /* USER CODE END TIM21_Init 1 */

 htim21.Instance = TIM21;

 htim21.Init.Prescaler = 0;

 htim21.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim21.Init.Period = 3333;

 htim21.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim21.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_Base_Init(&htim21) != HAL_OK)

 {

  Error_Handler();

 }

 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

 if (HAL_TIM_ConfigClockSource(&htim21, &sClockSourceConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

 if (HAL_TIMEx_MasterConfigSynchronization(&htim21, &sMasterConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN TIM21_Init 2 */

 /* USER CODE END TIM21_Init 2 */

}

0 REPLIES 0