2024-10-09 01:30 AM
Hello,
Once I thougt I measure the duration time after entering Stop mode with RTC to wakeup by EXTI interupt on the STM32L0538-Discovery.
But I noticed any timers don't work during Stop mode, is this right?
And I think after entering Stop mode, any variables are initialized, is this also right?
So now My conclusioin is that theere are no means to calculate the duration time.
Tell me if there are any other means.
Thanks
2024-10-09 02:33 AM
Hello @curiae,
RTC is available in all stop modes (check the Table 65. Functionalities depending on the working mode), so it can be used to wake up the device from Stop mode through an EXTI interrupt and you can calculate the duration.
Regarding variables initialization, when the device enters Stop mode, the contents of SRAM and registers are retained, so variables are not re-initialized upon waking up from Stop mode.
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-09 06:02 AM
Thank you for your answer
Of course I can understand that RTC still works under Power Stop.
Firstly I thought variables are retained so I checked like followings in WakeUp IRQ and EXTI IRQ.
But program counter didn't reach to break point (wake_count = 0;).
How could I increment numbers in IRQ?
I need to count measure the wake_count.
static uint32_t wake_count =0;
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
wake_count += 1;
if(wake_count > 2)
{
wake_count = 0;
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == KEY_BUTTON_PIN)
{
wake_count += 1;
if(wake_count > 2)
{
wake_count = 0;
}
}
}
2024-10-09 06:07 AM
>> Regarding variables initialization, when the device enters Stop mode, the contents of SRAM and registers are retained, so variables are not re-initialized upon waking up from Stop mode.
Please tell me where could I find the explanation in rm0367 or other document about STM32L052?
2024-10-09 08:34 AM
if the program counter is not reaching the breakpoint, there might be an issue with the configuration of the RTC wake-up timer or the EXTI interrupt, could you please share your RTC wakeup timer configuration?
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-09 03:42 PM
As for EXTI interrupt itself occurs.
As I wrote you before tell me where could I find the explanation in rm0367 or other document about STM32L052?
it's the SystemClock_Config() in my project
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
// Enable Power Control clock
__HAL_RCC_PWR_CLK_ENABLE();
// Configure the main internal regulator output voltage
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
// Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
// Initializes the CPU, AHB and APB buses clocks
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
GPIO_Init in my project
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
// GPIO Ports Clock Enable
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
// Configure GPIO pin Output Level
HAL_GPIO_WritePin(LD_R_GPIO_Port, LD_R_Pin, GPIO_PIN_RESET);
// Configure GPIO pin Output Level
HAL_GPIO_WritePin(GPIOB, ePD1_RESET_Pin|ePD1_PWR_ENn_Pin|ePD1_D_C_Pin|LD_G_Pin, GPIO_PIN_RESET);
// Configure GPIO pin : B1_Pin
GPIO_InitStruct.Pin = B1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
// EXTI interrupt init
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
}
2024-10-09 04:04 PM
As I asked in my first post, Systick or any timers work in Stop mode?
Please show me how to measure the time span between interrupt, using Systick or any timers if they works in stop mode.
2024-10-10 06:41 AM
>>As I asked in my first post, Systick or any timers work in Stop mode?
No, the system clock and most peripheral clocks are halted to minimize power consumption.
Only LPTIM is functionnal
As I said, you can use set up the RTC to generate periodic wake-up events, then enter stop mode then handle the wake up events to measure the time; something like this:
For RTC config
void RTC_Config(void)
{
RTC_HandleTypeDef hrtc;
RTC_WakeUpTypeDef sWakeUpConfig;
// Enable the RTC clock
__HAL_RCC_RTC_ENABLE();
// Configure the RTC
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.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
// Configure the wake-up timer
sWakeUpConfig.WakeUpClock = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
sWakeUpConfig.WakeUpCounter = 0xFFFF; // Set the wake-up counter
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, &sWakeUpConfig) != HAL_OK)
{
Error_Handler();
}
}
Entering stop mode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
Wake up timer callback
static uint32_t wake_count = 0;
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
wake_count += 1;
if (wake_count > 2)
{
wake_count = 0;
}
}
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.