I use stm32f407 microcontroller, with freertos 8.0. I want to sleep the controller, use STOP mode, which is the lowest power use mode. In this mode the micro wake up only, external pin IT, or rtc wake up. In sleep, the controller must wake up every 30 second to reset a watchdog via I2C. To wake up the the device the user must push the wake up button for 2 second. If the time less than 2 second, the micro go back sleep. I don't know how can I do this.
If I understand your requirements correctly then the sleep mode you want to use can only be woken by the external interrupt or the RTC, and the RTC is to be used to wake the device every 30 seconds and the external interrupt by the user.
I would suggest three stages:
1) First create an application that functions as per your requirements, but ignoring low power modes. You can have a task that sets the RTC to generate an interrupt every 30 seconds, with a task that is waiting for the interrupt (you can have the task block on a semaphore, and have the ISR give the semaphore to unblock the task) and kicking the watchdog each time it unblocks, and another task that is likewise responding to external interrupts from the user.
2) Once the above is working as you want, set configUSETICKLESSIDLE to 1 in FreeRTOSConfig.h to use the default tickless idle mode and check the application still functions as you expected.
3) Override the default tickless idle mode, which just sleeps the core, with your own implementation that enters the chip specific low power mode you want, and check everything is still running once again. There is an example of this last step for the STM32L already, but I believe the 'L' devices have additional low power features when compared to the 'F' devices so you won't be able to copy it exactly - also you may find the low power clock used to generate ticks on the L device is different to the low power clock available on the 'F' devices.
Thank you very much the answer.
So about the requirements. I have periodic tasks, I use vTaskDelayUntil to set the periodic. At sleep mode, I want to stop all the task, until the user wake-up the system with the button. My problem is, if I suspend the tasks before sleep, then resume these, the scheduler call all task, instead of the set wake up time.
The good option for me is the systick stop until the user wake up the system, in the RTC wake--up handler I can send the I2C message, then go back sleep, but I dont know how can i measure the 2 second for the user button.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.