‎2022-04-27 04:10 AM
Hello together,
Aim:
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:
Problem:
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);
}
‎2022-05-11 04:18 AM
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.
‎2022-05-11 04:26 AM
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
‎2022-05-11 09:14 AM
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.
‎2022-05-12 12:47 AM
Greetings Amel,
the .ioc is attached with this ticket. :)
Thanks and regards
Nirav Nirmal
‎2022-05-18 01:47 AM
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:
==> 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.
‎2022-05-18 02:08 AM
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
‎2022-05-20 08:34 AM
Hi @NNir​ ,
To update you on the current status on my side and to make sure that we have the same behavior:
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.
‎2022-05-23 08:57 AM
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
‎2022-05-24 02:00 AM
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