AnsweredAssumed Answered

STM32F030F4P STOP mode: enter and exit

Question asked by David Martins on Nov 14, 2017
Latest reply on Nov 20, 2017 by David Martins

Hello.

I'm having some problems with the STOP mode of STM32F030F4P.

After having all my application working with standbye mode awake by the RTC alarm, I checked that my application can not have floating pins.

So I thought, sacrifice some uA in exchange for not having to "dirty" my PCB and use the STOP mode to keep at least weak pull-up resistor.

The problem is that I can not use the examples because some functions are not declared in the "stm32f0xx_hal_rtc_ex.h" file, for example: HAL_RTCEx_SetWakeUpTimer_IT.
They are only available for the STM32F030xC version.

But the RTC alarm should be enough to wake up, but the MCU does not enter STOP mode when I call the function "HAL_PWR_EnterSTOPMode (PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI)".

 

At this point my code is very simple, because I have been removing everything so that I can only test if the MCU enters Stop mode or not ...

Physically the LED is on 10s, turns off 100mS and repeats again ...
That is, nothing more happens...

PS: RTC and alrm work as expected, because if I put my code to enter STANDBY, the current drops to ~ 5uA as expected (during ~1min, the alarm duration).

 

    /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_SPI1_Init();
      MX_TIM17_Init();
      MX_I2C1_Init();
      MX_RTC_Init();


      /* USER CODE BEGIN 2 */


        __HAL_RCC_PWR_CLK_ENABLE();


        //Configura RTC
        HAL_RTC_MspInit (&hrtc);


        while (1)
        {


            HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, 1);


            HAL_Delay(10000);
            HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, 0);


            HAL_Delay(100);


            HAL_PWR_EnableBkUpAccess();


            __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
            HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
        }

 

    void MX_RTC_Init(void)
    {
      RTC_TimeTypeDef sTime;
      RTC_DateTypeDef sDate;
      RTC_AlarmTypeDef sAlarm;


        /**Initialize RTC Only
        */

      hrtc.Instance = RTC;
      hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
      hrtc.Init.AsynchPrediv = 100;
      hrtc.Init.SynchPrediv = 400;
      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(__FILE__, __LINE__);
      }


        /**Initialize RTC and set the Time and Date
        */

      sTime.Hours = 0x0;
      sTime.Minutes = 0x0;
      sTime.Seconds = 0x0;
      sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
      sTime.StoreOperation = RTC_STOREOPERATION_RESET;
      if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
      {
        _Error_Handler(__FILE__, __LINE__);
      }


      sDate.WeekDay = RTC_WEEKDAY_MONDAY;
      sDate.Month = RTC_MONTH_JANUARY;
      sDate.Date = 0x1;
      sDate.Year = 0x17;


      if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
      {
        _Error_Handler(__FILE__, __LINE__);
      }


        /**Enable the Alarm A
        */

      sAlarm.AlarmTime.Hours = 0x0;
      sAlarm.AlarmTime.Minutes = 0x1;
      sAlarm.AlarmTime.Seconds = 0x0;
      sAlarm.AlarmTime.SubSeconds = 0x0;
      sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
      sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
      sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS
                                  |RTC_ALARMMASK_SECONDS;
      sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
      sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;
      sAlarm.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY;
      sAlarm.Alarm = RTC_ALARM_A;
      if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
      {
        _Error_Handler(__FILE__, __LINE__);
      }


    }


    void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
    {


      if(rtcHandle->Instance==RTC)
      {
      /* USER CODE BEGIN RTC_MspInit 0 */


      /* USER CODE END RTC_MspInit 0 */
        /* RTC clock enable */
        __HAL_RCC_RTC_ENABLE();


        /* RTC interrupt Init */
        HAL_NVIC_SetPriority(RTC_IRQn, 0, 0);
        HAL_NVIC_EnableIRQ(RTC_IRQn);
      /* USER CODE BEGIN RTC_MspInit 1 */


      /* USER CODE END RTC_MspInit 1 */
      }
    }

 

 

I need help putting the MCU in stop mode.

Thank you.

Outcomes