2024-10-08 11:49 AM - edited 2024-10-12 11:32 AM
For the Nucleo-575ZI-Q, while in stop mode 2, I have the capture module enabled, I set CH1 IO Usage as input.
A square wave generator connected to PC1->LPTIM_CH1.
While the Micro is in stop mode 2 an indeterminate number of pulses trigger successive captures.
If the pulses on PC1 were odd CCR1 has the correct data.
If the pulses on PC1 were even CCR1 value doesn't updated at all.
Please note that all pulses arrive while STM32U575 is on stop mode.
I made a very short project isolating the problem, the RTC is used to exit stop mode 2 every second, when waking up only CRR1 is read and returns to stop mode 2.
void FM_MAIN_Main()
{
uint16_t capture = 0;
HAL_LPTIM_IC_Start(&hlptim1, LPTIM_CHANNEL_1);
__HAL_RCC_LPTIM1_CLKAM_ENABLE();
for (;;)
{
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
capture = LPTIM1->CCR1;
FM_DEBUG_UartUint16(capture);
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
HAL_SuspendTick();
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
HAL_ResumeTick();
}
}
/**
* @brief LPTIM1 Initialization Function
* None
* @retval None
*/
static void MX_LPTIM1_Init(void)
{
/* USER CODE BEGIN LPTIM1_Init 0 */
/* USER CODE END LPTIM1_Init 0 */
LPTIM_IC_ConfigTypeDef sConfig = {0};
/* USER CODE BEGIN LPTIM1_Init 1 */
/* USER CODE END LPTIM1_Init 1 */
hlptim1.Instance = LPTIM1;
hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
hlptim1.Init.Period = 65535;
hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
hlptim1.Init.RepetitionCounter = 0;
if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
{
Error_Handler();
}
sConfig.ICInputSource = LPTIM_IC1SOURCE_GPIO;
sConfig.ICPrescaler = LPTIM_ICPSC_DIV1;
sConfig.ICPolarity = LPTIM_ICPOLARITY_RISING;
sConfig.ICFilter = LPTIM_ICFLT_CLOCK_DIV1;
if (HAL_LPTIM_IC_ConfigChannel(&hlptim1, &sConfig, LPTIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN LPTIM1_Init 2 */
/* USER CODE END LPTIM1_Init 2 */
}
/**
* @brief RTC Initialization Function
* None
* @retval None
*/
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_PrivilegeStateTypeDef privilegeState = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
hrtc.Init.BinMode = RTC_BINARY_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
privilegeState.rtcPrivilegeFull = RTC_PRIVILEGE_FULL_NO;
privilegeState.backupRegisterPrivZone = RTC_PRIVILEGE_BKUP_ZONE_NONE;
privilegeState.backupRegisterStartZone2 = RTC_BKP_DR0;
privilegeState.backupRegisterStartZone3 = RTC_BKP_DR0;
if (HAL_RTCEx_PrivilegeModeSet(&hrtc, &privilegeState) != HAL_OK)
{
Error_Handler();
}
/** Enable the WakeUp
*/
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_CK_SPRE_16BITS, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
}
2024-10-11 09:33 AM - edited 2024-10-12 11:31 AM
Could please some one give some advises?
2024-10-14 01:44 AM
Hello @dhs,
Did you check the STM32U575 errata sheet in LPTIM section ?
Maybe you have the same condition here:
2024-10-14 04:48 AM
Hello @Imen.D
Yes, I saw it and I followed the workaround, but the problem persist.
To reproduce the issue, all pulses must arrive while the STM32U575 is in stop mode 2
Initially. I encountered this problem with a custom board using a STM32U575VIT6Q, LPTIM 3, after that I reproduce the problem on the Nucleo board using LPTIM 1 and 3.
I'm amazed how such a basic feature can fail.
2024-10-22 07:59 AM
Hello @dhs,
>>I made a very short project isolating the problem
can you please share it?
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.
2024-10-22 08:46 AM
What are your observations and how are they different from the expectations?
JW
2024-10-25 03:47 PM
Hello @Sarra.S
https://github.com/gamarrita/Nucleo-U575ZI-Q
I shot a video, please note that only for odd frequency the CCR1 register is updated.
Regards, Daniel.
2024-10-25 03:54 PM
2024-11-10 04:59 AM
@Sarra.S Could you reproduce in your side? Do you need further assistance to reproduce issue?
Regards, Daniel.
2024-11-12 02:16 AM
Hello @dhs,
I've tried your manipulation on my end, and I understand what you're doing, but, I'm not really sure I fully understood the issue (in the provided video, when you change the signal frequency, you can capture even values)!
Also, I have some recommendations, I would suggest using LPDMA in stop2 mode to store the captured values in an incrementing buffer. This way, when you wake up from stop 2, you can read the buffer and check for any lost data!
In the current implementation, you wake up the system every 2 seconds (with RTC) to read the CCR1 value captured, so you're not actually reading each period at each rising edge, the 2sec seems a black box to me, it would be optimal to put every captured CCR during these 2secs in a buffer.
For reference, my recommendation of using an LPDMA is implemented in a slightly different example, where LPTIM is used to measure the LSE frequency ( check cube examples: LPTIM_IC_LSE).
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.