cancel
Showing results for 
Search instead for 
Did you mean: 

ThreadX with stop mode 1 works fine after power reset, but fail on run and debug.

dhs
Senior

I have completed the code and uploaded it to the following GitHub repository: https://github.com/gamarrita/Nucleo-L452_Azure_RTOS/tree/master/01_stop_mode_1

In my code, I am using the RTC and its wakeup capability to control sleep time. I am only using one thread, which sleeps for 5 seconds and then wakes up to sleep again.

The code works fine if I turn the power off and on again, but the CPU keeps entering and exiting a very high frequency if I just press the run or debug button.

Why stop mode works fine in one situation and fails in others?

And more important, how I can figure out, debug technique, to find out what is making CPU wakeup?


_legacyfs_online_stmicro_images_0693W00000bhkp9QAA.png

void App_ThreadX_LowPower_Timer_Setup(ULONG count)
{
  /* USER CODE BEGIN  App_ThreadX_LowPower_Timer_Setup */
	// Wakeup Counter = 2048
	g_stop_ticks = count;
	HAL_RTCEx_SetWakeUpTimer_IT(&hrtc,
					(g_stop_ticks * 2048) / TX_TIMER_TICKS_PER_SECOND,
					RTC_WAKEUPCLOCK_RTCCLK_DIV16);
  /* USER CODE END  App_ThreadX_LowPower_Timer_Setup */
}
 
/**
  * @brief  App_ThreadX_LowPower_Enter
  * @param  None
  * @retval None
  */
void App_ThreadX_LowPower_Enter(void)
{
  /* USER CODE BEGIN  App_ThreadX_LowPower_Enter */
	HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET);
	HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
  /* USER CODE END  App_ThreadX_LowPower_Enter */
}
 
/**
  * @brief  App_ThreadX_LowPower_Exit
  * @param  None
  * @retval None
  */
void App_ThreadX_LowPower_Exit(void)
{
  /* USER CODE BEGIN  App_ThreadX_LowPower_Exit */
	HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
//	SystemClock_Config();
	HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_SET);
  /* USER CODE END  App_ThreadX_LowPower_Exit */
}
 
/**
  * @brief   App_ThreadX_LowPower_Timer_Adjust
  * @param  None
  * @retval Amount of time (in ticks)
  */
ULONG  App_ThreadX_LowPower_Timer_Adjust(void)
{
  /* USER CODE BEGIN   App_ThreadX_LowPower_Timer_Adjust */
  return g_stop_ticks;
  /* USER CODE END   App_ThreadX_LowPower_Timer_Adjust */
}
 
/* USER CODE BEGIN 1 */
VOID refresh_thread_entry(ULONG initial_input)
{
	while(1)
	{
		tx_thread_sleep(500);
	}
}

Daniel H Sagarra
10 REPLIES 10

I got it working here by simply ignore all attempts to sleep for 0 ticks and changing to 1000 ticks/sec.