cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U575 + FreeRTOS - waking up from Stop Mode - an interesting time trying to get it to work - it doesn't yet...

JAsh.2
Associate II

Using an STM32U575 on our own design. Aim is to put it into Stop2 Mode and wake up from three sources:

a) GPIO pin

b) Wake up timer (RTC)

c) AlarmA (RTC)

I have these three sources setup as interrupts and when the CPU is running (i.e. not stopped) these interrupts fire and are handled correctly. However, when entering stop mode, the device cannot be woken when any of these 'interrupts' occur - those of you familiar with this will recognise that while the interrupts don't wake up the CPU, these interrupt sources are used to wakeup the CPU when they occur after which the interrupt will be serviced.

Debugging in low power mode is troublesome, so my best insight comes from using the STM32Cube Programmer, attaching in 'hot' mode and examining the SFRs. Here I can see the WUTF and ALRMAF are set, but still no wake-up.

Frustratingly, I have used the examples referred to in this rather good tutorial and based on this I can (using a Nucleo board) enter Stop2Mode and exit is successfully using the RTC wakeup timer. I am unable to replicate this with our own hardware and project code.

So what are the differences? well, the Nucleo example is frustratingly simple:

/* Enable ultra low power mode */

 HAL_PWREx_EnableUltraLowPowerMode();

 /* Enable the Autonomous Mode for the RTC Stop0/1/2 */

 __HAL_RCC_RTCAPB_CLKAM_ENABLE();

 /* Set RTC wakeup timer for 2s */

 HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 2, RTC_WAKEUPCLOCK_CK_SPRE_16BITS, 0);

 /* 4 - Measure consumption in Stop 2 mode Full SRAM retention */

 /* Enter in Stop 2 mode */

 HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

but in our code, I am using FreeRTOS which adds a further complication, but on the face of it, it should be as straightforward as with the HAL-only based example. It appears that something somewhere isn't being enabled or setup correctly. I was hoping that someone might have some insight or been where I am at the moment and escaped!

My PreSleepProcessing is getting more and more complex each day!

void PreSleepProcessing(uint32_t ulExpectedIdleTime)

{

    /* Called by the kernel before it places the MCU into a sleep mode because

    configPRE_SLEEP_PROCESSING() is #defined to PreSleepProcessing().

    NOTE:  Additional actions can be taken here to get the power consumption

    even lower.  For example, peripherals can be turned off here, and then back

    on again in the post sleep processing function.  For maximum power saving

    ensure all unused pins are in their lowest power state. */

    if (allow_deep_sleep == true)

    {

        //HAL_TIM_Base_DeInit(&htim3)

        //TIM3->CCR1 &= ~0x01;

        HAL_SuspendTick();

        /*

          (*ulExpectedIdleTime) is set to 0 to indicate that PreSleepProcessing contains

          its own wait for interrupt or wait for event instruction and so the kernel vPortSuppressTicksAndSleep

          function does not need to execute the wfi instruction  

        */    

        ulExpectedIdleTime = 0;

       

//      GPIOB->ODR |= OPTICAL_EN_Pin;

//      GPIOB->ODR &= ~OPTICAL_EN_Pin;

//      //GPIOB->ODR |= OPTICAL_EN_Pin;

//      GPIOB->ODR &= ~OPTICAL_EN_Pin;

       

        // Apparently this is helpful for ensuring that Stop mode is entered

        HAL_PWREx_EnableUltraLowPowerMode();

       

        // This ensures that the RTC is still clodked in stop mode

        __HAL_RCC_RTCAPB_CLKAM_ENABLE();

        // The following two wakeup pin enables set the RTC and PB7 (CLI) to wake up the CPU

        // RM0456 Rev 3 Table 86

        HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN6_HIGH_3);

        HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN7_HIGH_3);

        HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN8_HIGH_3);

        HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4_LOW_2);

        // Now clear the relevant flags

        __HAL_RTC_CLEAR_FLAG(&hrtc, RTC_CLEAR_WUTF);

        //__HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_ALL_FLAG);

        if (__HAL_PWR_GET_FLAG(PWR_FLAG_STOPF) != RESET)

        {

        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_STOPF);

        }

        if (__HAL_PWR_GET_FLAG(PWR_WAKEUP_FLAG4) != RESET)

        {

        __HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_FLAG4);

        }

        if (__HAL_PWR_GET_FLAG(PWR_WAKEUP_FLAG7) != RESET)

        {

        __HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_FLAG7);

        }

       

        // This puts the CPU into stop mode

        HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFE);

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Haithem Rahmani
ST Employee

Hi @TC2sh​ 

the X-CUBE-FREERTOS expansion package has been just published on st.com.

https://www.st.com/en/embedded-software/x-cube-freertos.html

it mainly supports the STM32H5 and STM32U5 Series.

the application NUCLEO-U575ZI-Q\FreeRTOS_Semaphore_LowPower shows how to enter/exit the lowpower mode using a LPTIM interrupts. It can be easily adapted to use RTC wakeup.

Hope this helps

regards

Haithem.

View solution in original post

4 REPLIES 4
Haithem Rahmani
ST Employee

Hi @TC2sh​ 

the X-CUBE-FREERTOS expansion package has been just published on st.com.

https://www.st.com/en/embedded-software/x-cube-freertos.html

it mainly supports the STM32H5 and STM32U5 Series.

the application NUCLEO-U575ZI-Q\FreeRTOS_Semaphore_LowPower shows how to enter/exit the lowpower mode using a LPTIM interrupts. It can be easily adapted to use RTC wakeup.

Hope this helps

regards

Haithem.

Thanks for your pointers on this - I think I had seen the second one before, but not the first!

@Haithem Rahmani​ Thanks for this, it looks very helpful - I have been working with a Cube FreeRTOS L4 project as my starting point and in so many ways, I've been wishing that there was still support for FreeRTOS with the U5. I will take a look at what you have pointed me in the direction of.

Thanks again.