cancel
Showing results for 
Search instead for 
Did you mean: 

IT based DTS on STM32H5 gets stuck in HAL_DTS_STATE_BUSY

luc1
Associate

Hi,

I am trying to use the DTS on the STM32H5, but after i call HAL_DTS_Start_IT(&hdts), the state of the handle is stuck in HAL_DTS_STATE_BUSY, resulting in a HAL_BUSY when i am trying to get the temperature via HAL_DTS_GetTemperature(&hdts, &temperature) in the HAL_DTS_EndCallback(DTS_HandleTypeDef *hdts)

I debugged through my code and the HAL library and found out that during the execution of the HAL_DTS_Start_IT(&hdts) code (see below)  it jumps directly into the HAL_DTS_EndCallback(DTS_HandleTypeDef *hdts) after Line 47 and therefore never reaches Line 50, where the handle state would be set back to HAL_DTS_STATE_READY

I "fixed" this problem for now by either setting the state manually back to HAL_DTS_STATE_READY at the beginning of the HAL_DTS_EndCallback(DTS_HandleTypeDef *hdts) or commenting out the HAL_Delay(TS_TIMEOUT_MS) call in Line 47. 

 

My DTS_HandleTypeDef configuration is: 

 

DTS_HandleTypeDef   hdts = {.Instance = DTS,
                            .Init     = {.QuickMeasure  = DTS_QUICKMEAS_DISABLE,
                                         .RefClock      = DTS_REFCLKSEL_PCLK,
                                         .TriggerInput  = DTS_TRIGGER_HW_NONE,
                                         .SamplingTime  = DTS_SMP_TIME_15_CYCLE,
                                         .Divider       = 250,
                                         .HighThreshold = 100,
                                         .LowThreshold  = 0}};

 

 

and the frequency of my clock is 250MHz. 

 

Does anybody have another "cleaner" solution for this? or might this be a bug of the HAL-Library itself? 

 

Thanks in advance. 

 

 

HAL_StatusTypeDef HAL_DTS_Start_IT(DTS_HandleTypeDef *hdts)
{
  uint32_t Ref_Time;

  /* Check the DTS handle allocation */
  if (hdts == NULL)
  {
    return HAL_ERROR;
  }

  if (hdts->State == HAL_DTS_STATE_READY)
  {
    hdts->State = HAL_DTS_STATE_BUSY;

    /* On Asynchronous mode enable the asynchronous IT */
    if (hdts->Init.RefClock == DTS_REFCLKSEL_LSE)
    {
      __HAL_DTS_ENABLE_IT(hdts, DTS_IT_TS1_AITE | DTS_IT_TS1_AITL | DTS_IT_TS1_AITH);
    }
    else
    {
      /* Enable the IT(s) */
      __HAL_DTS_ENABLE_IT(hdts, DTS_IT_TS1_ITE | DTS_IT_TS1_ITL | DTS_IT_TS1_ITH);
    }

    /* Enable the selected DTS sensor */
    __HAL_DTS_ENABLE(hdts);

    /* Get Start Tick*/
    Ref_Time = HAL_GetTick();

    /* Wait till TS1_RDY flag is set */
    while (__HAL_DTS_GET_FLAG(hdts, DTS_FLAG_TS1_RDY) == RESET)
    {
      if ((HAL_GetTick() - Ref_Time) > DTS_DELAY_STARTUP)
      {
        return HAL_TIMEOUT;
      }
    }

    if (__HAL_DTS_GET_TRIGGER(hdts) == DTS_TRIGGER_HW_NONE)
    {
      /* Start continuous measures */
      SET_BIT(hdts->Instance->CFGR1, DTS_CFGR1_TS1_START);

      /* Ensure start is taken into account */
      HAL_Delay(TS_TIMEOUT_MS);
    }

    hdts->State = HAL_DTS_STATE_READY;
  }
  else
  {
    return HAL_BUSY;
  }

  return HAL_OK;
}

 

 

1 REPLY 1
Amel NASRI
ST Employee

Hi @luc1 ,

Unfortunately the example provided in STM32CubeH5 firmware package is based on polling mode not interrupt mode.

My recommendations in your case:

  • Check the flags set in DTS_SR register.
  • Check that the interrupt handler for the DTS is correctly implemented and that it clears the interrupt flags properly. Failure to clear the flags can cause the DTS to remain in the busy state.
  •  Does increasing TS_TIMEOUT_MS fix the issue?

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.