Skip to main content
Associate III
October 9, 2024
Question

About Timer work after Stop mode with RTC

  • October 9, 2024
  • 2 replies
  • 1268 views

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

    2 replies

    ST Employee
    October 9, 2024

    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.

     

    curiaeAuthor
    Associate III
    October 9, 2024

    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;
    }
    }
    }

    ST Employee
    October 9, 2024

    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? 

    curiaeAuthor
    Associate III
    October 9, 2024

    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);
    }