Associate
April 27, 2022
Question
LPTIM4 init stuck at REPOK on NUCLEO-U575ZI-Q
- April 27, 2022
- 9 replies
- 2463 views
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:
- Successfully configure the peripherals in STM32CubeMX.
- Successfully configure the clock in the STM32CubeMX.
- Select the low level device driver in the advanced project settings for everything.
- Generate code without TrustZone, without ICACHE, etc.
- 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);
}