cancel
Showing results for 
Search instead for 
Did you mean: 

ST-LINK debugger shows me not expected values

tjaekel
Senior III

I try to debug how to set AZURE RTOS for 1ms tick timer. I debug this function:

HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) in file "stm32u5xx_hal_timebase_tim.c":

 

HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
  RCC_ClkInitTypeDef    clkconfig;
  uint32_t              uwTimclock = 0;
  uint32_t              uwPrescalerValue = 0;
  uint32_t              pFLatency;
  HAL_StatusTypeDef     status;

  /* Enable TIM6 clock */
  __HAL_RCC_TIM6_CLK_ENABLE();

  /* Get clock configuration */
  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);

  /* Compute TIM6 clock */
  uwTimclock = HAL_RCC_GetPCLK1Freq();

  /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
  uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);

  /* Initialize TIM6 */
  htim6.Instance = TIM6;

  /* Initialize TIMx peripheral as follow:

  + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
  + ClockDivision = 0
  + Counter direction = Up
  */
  htim6.Init.Period = (1000000U / 1000U) - 1U;	//XXXX
  htim6.Init.Prescaler = uwPrescalerValue;	//__HAL_TIM_CALC_PSC(160000000, 1000); //XXXX

 

Strange is:

  • I set breakpoint on line 16 and I get as variable value for uwTimclock a 4
  • actually, doing this calculation in line 19, with 4 / 1000000 should result in 0, so that uwPrescalerValue should be 0
  • But it is not 0: I get 159 - which makes sense (160 MHz clock, divide by 1000000 and minus 1 = 159) - it looks correct for line 32

Just curious why I get a 4 and later a correct 159?

The 4 makes a bit sense: it comes from a table "APBPresTable" which has the 4 as an entry (but it is a prescaler value).
But it does not make sense to see the 4 as result in a variable, divide it by 1000000 and get 160 (minus 1).

What is going on here?

BTW: I see also immediately during stepping through the code that the variable is "opt out". Why?

How to understand with debugger? The code works fine, but with debugger and tracing what is done - it does not make sense to me.

2 REPLIES 2
nouirakh
ST Employee

Hello  @tjaekel 

I have conducted some tests and I get as variable value for uwTimclock 4000000. For uwPrescalerValue, I calculated 3 by dividing 4000000 by 1000000 and subtracting 1.
Could you please share the code that was used to reproduce the issue in order to allow a better analysis of the problem?

Andrew Neil
Evangelist III

@tjaekel wrote:

BTW: I see also immediately during stepping through the code that the variable is "opt out". Why?


What variable?

Do you mean, "optimised out" ?

Perhaps show a screenshot ...