cancel
Showing results for 
Search instead for 
Did you mean: 

LPTIM4 init stuck at REPOK on NUCLEO-U575ZI-Q

NNir
Associate II

Hello together,

Aim:

  • Learn how to use the LPTIM on STM32CubeU5 low level device drivers, such that it consumes least possible energy.
  • Write a program that blinks the on board red LED every 1 s (forground loop) using the interrupt mechanism of the LPTIM, while blinking the blue LED in the background every 250 ms in the main() loop.

Given:

Platform:     NUCLEO-U575ZI-Q

MCU:        STM32U575ZIT6Q

Peripheral:    LPTIM4

Peripheral clock: 32kHz LSI or 32.768 kHz LSE

Peripheral bus:  APB3

APB3 clock:    160 MHz PCLK3 - HCLK - MSIS - HSI RC 16 MHz

STM32Cube tool: STM32CubeMX and the LL STM32CubeU5

Procedure:

  1. Successfully configure the peripherals in STM32CubeMX.
  2. Successfully configure the clock in the STM32CubeMX.
  3. Select the low level device driver in the advanced project settings for everything.
  4. Generate code without TrustZone, without ICACHE, etc.
  5. Please find attached the .ioc file that I used to generate the CubeMX project.

Problem:

  • The control is stuck in the generated function `MX_LPTIM4_Init(void)`.
  • Specifically in the function `LL_LPTIM_IsActiveFlag_REPOK(LPTIM4)`.
  • The hardware does not reset the REPOK flag located in the LPTIM_ISR register, which detects that the synchronization of the LPTIM_RCR register content is finished.
  • The control is stuck in the `while(!LL_LPTIM_IsActiveFlag_REPOK(LPTIM4));`.
  • I have tried both LSE and LSI clock source with no success.

Code:

main.c

static void MX_LPTIM4_Init(void)
 
{
 
 
  /* USER CODE BEGIN LPTIM4_Init 0 */
 
//  LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM34_CLKSOURCE_LSI);
 
 
  /* USER CODE END LPTIM4_Init 0 */
 
 
  LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
 
 
  /* Peripheral clock enable */
 
  LL_APB3_GRP1_EnableClock(LL_APB3_GRP1_PERIPH_LPTIM4);
 
 
  LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF);
 
  /**LPTIM4 GPIO Configuration
 
  PF11   ------> LPTIM4_IN1
 
  */
 
  GPIO_InitStruct.Pin = LL_GPIO_PIN_11;
 
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
 
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
 
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
 
  GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
 
  GPIO_InitStruct.Alternate = LL_GPIO_AF_13;
 
  LL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
 
  /* LPTIM4 interrupt Init */
 
  NVIC_SetPriority(LPTIM4_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
 
  NVIC_EnableIRQ(LPTIM4_IRQn);
 
 
  /* USER CODE BEGIN LPTIM4_Init 1 */
 
 
  /* USER CODE END LPTIM4_Init 1 */
 
  LL_LPTIM_Enable(LPTIM4);
 
  LL_LPTIM_ClearFlag_REPOK(LPTIM4);
 
  LL_LPTIM_SetRepetition(LPTIM4, 0);
 
 
   /* Wait till REPOK Flag is ready */
 
  while(!LL_LPTIM_IsActiveFlag_REPOK(LPTIM4))
 
  {
 
  }
 
  LL_LPTIM_ClearFlag_ARROK(LPTIM4);
 
  LL_LPTIM_SetAutoReload(LPTIM4, 32768);
 
 
   /* Wait till ARROK Flag is ready */
 
  while(!LL_LPTIM_IsActiveFlag_ARROK(LPTIM4))
 
  {
 
  }
 
  LL_LPTIM_Disable(LPTIM4);
 
  LL_LPTIM_SetClockSource(LPTIM4, LL_LPTIM_CLK_SOURCE_INTERNAL);
 
  LL_LPTIM_SetPrescaler(LPTIM4, LL_LPTIM_PRESCALER_DIV1);
 
  LL_LPTIM_SetUpdateMode(LPTIM4, LL_LPTIM_UPDATE_MODE_IMMEDIATE);
 
  LL_LPTIM_SetCounterMode(LPTIM4, LL_LPTIM_COUNTER_MODE_EXTERNAL);
 
  LL_LPTIM_ConfigClock(LPTIM4, LL_LPTIM_CLK_FILTER_NONE, LL_LPTIM_CLK_POLARITY_RISING);
 
  LL_LPTIM_TrigSw(LPTIM4);
 
  LL_LPTIM_SetInput1Src(LPTIM4, LL_LPTIM_INPUT1_SRC_GPIO);
 
  /* USER CODE BEGIN LPTIM4_Init 2 */
 
 
  /* USER CODE END LPTIM4_Init 2 */
 
 
}

stm32u5xx_ll_lptim.h

/**
 
  * @brief  Informs application whether the APB bus write operation to the LPTIMx_RCR register has been successfully
 
            completed; If so, a new one can be initiated.
 
  * @rmtoll ISR          REPOK         LL_LPTIM_IsActiveFlag_REPOK
 
  * @param  LPTIMx Low-Power Timer instance
 
  * @retval State of bit (1 or 0).
 
  */
 
__STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_REPOK(const LPTIM_TypeDef *const LPTIMx)
 
{
 
  return ((READ_BIT(LPTIMx->ISR, LPTIM_ISR_REPOK) == (LPTIM_ISR_REPOK)) ? 1UL : 0UL);
 
}

9 REPLIES 9
Amel NASRI
ST Employee

Hi @NNir​ ,

First of all I would like to thank you for the detailed description of the issue you are facing.

I'll try to reproduce it on my side and let you know my findings.

Meanwhile, could you please check if a similar issue is faced with HAL generated code (instead of LL)?

-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.

NNir
Associate II

Greetings Amel,

thank you for probing further. I can affirm the functionlity LPTIM4 using the HAL in CubeMX. HAL works fine. The problem persists in LPTIM3 and LPTIM4 on LL.

Thanks and regards

Nirav Nirmal

Hi @NNir​ ,

It seems that I need your ioc file to reproduce the issue. I tried several configurations and no stuck on my side.

Could you please share it?

Thanks.

-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.

NNir
Associate II

Greetings Amel,

the .ioc is attached with this ticket. :)

Thanks and regards

Nirav Nirmal

Hi @NNir​ ,

Sorry to come back late to this discussion.

I made the test as soon as I received the file you shared but there is no issue faced.

What I did:

  • generate code based on the file you shared (using STM32CubeIDE 1.9.0)
  • connect my NUCLEO-U575ZI-Q and debug downloaded code ==> no stuck at LL_LPTIM_IsActiveFlag_REPOK(LPTIM4)

==> Is there any thing I'm missing?

-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.

NNir
Associate II

Hello Amel, :grinning_face:

Sorry for the confusion. :expressionless_face: I have supplied you with the wrong file. Please change the clock source for LPTIM4 to LSE instead of LSI under the Clock Configuration in the same .ioc file and then check again.

Thanks and regards :folded_hands:

NIrav Nirmal

Hi @NNir​ ,

To update you on the current status on my side and to make sure that we have the same behavior:

  • execution stuck at LL_LPTIM_IsActiveFlag_REPOK(LPTIM4) for both LSE & LSI if RCC code is based on LL
  • no such issue if RCC code is based on HAL driver

If I generate HAL code for LPTIM, I get a similar behavior (HAL_TIMEOUT with LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK)) when LL code is generated for RCC.

Is that what you have on your side as well?

-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.

NNir
Associate II

Hello @Amel NASRI​ ,

thanks for the reply. I have not tried HAL and LL in the same project for different peripherals (RCC, LPTIM4, etc.). I am exclusively using LL driver for the whole project. :)

Thanks and regards

Nirav Nirmal

NNir
Associate II

Hello @Amel,

to conclude the matter, the case number on the support page 00156777 could solve the issue. The solution is to add the line

 LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM34_CLKSOURCE_LSE);

before accessing the LPTIM peripheral registers. The generated code from STM32CubeMX misses something it seems.

Thanks and regards

Nirav Nirmal