 Hello! Within this part I will demonstrate how we can use low power modes within FreeRTOS. FreeRTOS has built-in support for low power modes. It is disabled by default. It can be activated by setting config use tickless idle within FreeRTOS config.h file. The mode is called tickless idle as it is using idle task to detect and activate this mode. Nice kernel and tick can be stopped in case there is no active task except idle task. Active means run or ready state. In such a case with an idle task code at the end of this function body there is a procedure to enter into low power mode. From this moment we need an additional timer which would trigger a wake-up event after calculated time. System can be woken up either once the specified delay will pass or there would be any interrupt trigger within the system. Then an update of tick timer and number of ticks is done and system continues its execution. Within FreeRTOS implementation on STM32 devices as a low power mode sleep mode is selected. But it is possible to use as well as stop modes what will be demonstrated further within this section. As we discussed the low power mode support is activated within idle task once config use tickless idle is different from zero within FreeRTOS config.h file and there is no other active task. It is done at the end of idle task function execution to be sure that its other duties are finished. Just to remind you the idle task code is stored within port task function within task.c file. Let's have a closer look what is happening within idle task function body once we enable config use tickless idle. At the beginning there is a check estimation of the expected idle time which can be used to put the system into low power mode. If it will be too short it means shorter than a config expected idle time before sleep which is set to 2 in FreeRTOS.h file system will be not put into the low power mode and idle task function body will continue its execution. Otherwise the scheduler will be stopped by suspending all of the tasks and further another check of expected idle time will be done. After this there is a code to config, pre, suppress, ticks and sleep processing which is a place where we can locate a piece of code with preparation of the system to low power mode entrance. We can put here for example IO lines reconfiguration, the activation of some peripherals etc. After this a macro port suppress ticks and sleep is called which is activating the low power mode. With an STM32 port by default it is a sleep mode but we can replace it with stop mode which would be described later on in this section. Wakeup from low power mode is done either after estimated time elapses or on any other interrupt. After suspending the operating system between checking the expected sleep time and entrance into low power mode there is a code to config, pre, suppress, ticks and sleep processing macro. It is defined as empty macro event free or ds.h file. It can be used to define actions like watchdog refresh or freeze which should be performed before we enter into low power mode by calling port suppress ticks and sleep. We should define this macro by setting x expected idle time to zero if the application doesn't want to execute port suppress ticks and sleep. The main macro responsible for entering into low power mode within free rts is port suppress ticks and sleep. By default it is defined as an empty macro within free rts.h file. Then it is implemented within port.c file as a function vport suppress ticks and sleep. This function is defined as weak so it can be implemented by the user as well. You can find the connection between port suppress ticks and sleep and vport suppress ticks and sleep function within port macro.h file. We will have a closer look on this function. Let's have a closer look on vport suppress ticks and sleep function implemented for STM32 platform. There are the following operations down there in time order. Calculating reload value, maximum sleeping time, reading current value of the tick timer, stop the tick timer, further entering into critical section by disable interrupts CPSIDI. It is much stronger critical section as it is blocking all interrupts except reset and NMI. After this there is a check whether there is no context switch in between. If there was one there is an abort of low power mode entry. If there was no context switch there is a start of selected low power timer using expected delay value. Then preparation of the hardware to put application into low power mode. So for example IO lines, reconfiguration, peripherals, deactivation etc. At the end there is an entrance into desired low power mode. There is a necessity to describe why we can be woken up by interrupts while almost all interrupts except reset and NMI are blocked by pre-mask settings. For this it is necessary to carefully study an effect of WFI instruction execution. It is important that WFI suspense execution until one of the following event occurs. An unmask interrupt occurs and is taken, an interrupt mask by pre-mask becomes pending or a debug entry request occurs. The key here is a second condition so even almost all of the interrupts except NMI or reset are masked blocked. Those still can be in pending state which may cause the wake up from low power mode. More information we can find in the dedicated web page of ARM. Here below you can find the link to this page. Now let's have a look how we can exit from low power mode. After a wake up event we are still within viewport, suppress ticks and slip function and all of the interrupts are still being masked by pre-mask and are in a pending state. First operation is a call to the macro config post-slip processing where we can reconfigure all the peripherals like IOs, communication interfaces, etc. from low power to normal mode of operation. It is defined as a week within freeRTOES config.h file with redirection to empty post-slip processing function within freeRTOES.c file. This function is defined as well as week so it can be overwritten by the user. The next operation is to unmask interrupts to allow interrupt processing of the wake up event. After this all of the interrupts are masked again and an update of the tick time is done based on a slipping time. At the end restart of the tick timer is done and all of the interrupts are unmasked. On this moment operating system is continuing its normal operations. Thank you for watching this video.