cancel
Showing results for 
Search instead for 
Did you mean: 

Low power mode with ThreadX

jampino
Associate II

Hello all,

I am testing low power mode 2 using ThreadX but having a bit of a problem when waking up. I have generated a simple test, there is one task running blinking a led every second for 10 secs and then sending the MCU to low power mode 2, until this point all works okay.

I have got a button that will wake up the MCU by an interrupt when it is pressed and the unit should go and start blinking the LED every 1 sec for another 10 secs.

The MCU comes out of mode 2 when the the button is pressed but I am having a problem with the clock configuration when waking up, the led flashes at around 6 secs after waking up instead of every 1 sec.

Main routine:

VOID LED1_thread_entry(ULONG initial_input)
{
   uint8_t counter = 0;
   while(1)
   {
      HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
      tx_thread_sleep(1000);
      counter++;
      if(counter == 10)
      {
         counter = 0;
         Enter_LowPower_Mode();
       }
   }
}

This is my routine that put the MCU into low power mode 2:

 

 

void Enter_LowPower_Mode(void)
{
   HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
   __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
   HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}

 

 


This is the routine exiting the lo power mode2:

 

 

void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
{
   if(GPIO_Pin == Button_Pin)
   {
      Exit_LowPower_Mode();
   }
}

 

 

 

 

 

void Exit_LowPower_Mode(void)
{
   SystemClock_Config();
}

 

 

 

The clock configuration that I am using is:

 

 

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_SCALE2) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
  RCC_OscInitStruct.PLL.PLLM = 1;
  RCC_OscInitStruct.PLL.PLLN = 13;
  RCC_OscInitStruct.PLL.PLLP = 2;
  RCC_OscInitStruct.PLL.PLLQ = 2;
  RCC_OscInitStruct.PLL.PLLR = 2;
  RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
  RCC_OscInitStruct.PLL.PLLFRACN = 4096;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
                              |RCC_CLOCKTYPE_PCLK3;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  {
    Error_Handler();
  }
}

 

 

 

Any idea what the problem could be?

Thank you 

0 REPLIES 0