 Hello, within this part we will focus on Tickless mode, within FreeR2S and CMC's OS version 2 layer, but within this part we will focus on Stop Low Power Modes Usage, which is not a default setup provided by FreeR2S, you need some more code modification to be inserted inside a generated code. So for this exercise I would use the following setup, Nucleo L476-LG, this is this white board which you can see on the screen, then it will be supplied by XNucleo LPM01 board, which is the regulated power supply, which is sending data about the current delivered to the target board via virtual COM port, and it can be displayed on the CUBE monitor power application. Both boards are connected by two wires, which you can see on the screen. On XNucleo board it is a white connector marked CN14, and I'm using pins 1 and the third one, counting from the glass LCD. The first pin is a GND and the third pin is a PLUS voltage. This PLUS voltage is connected to JP6 connector, so I remove the jumper and I connect this red jumper to the left pin of this connector and the black one is connected to any of GND pins on the Nucleo board. Both boards are connected as well to the PC using USB cables, so I need micro USB cable for XNucleo board, the power measurement board, and I need mini USB cable for my Nucleo L476-LG board. Okay, I start new project using STM32Cube IDE, you can use as well CUBE MX with your preferred toolchain to do this. So I go to File, New, STM32 Project, I select L476-LG microcontroller, press Next. The name of this exercise would be in my case 13, underscore T-class, underscore stop. Press Finish. I will use the same hardware setup like in case of previous exercise, so T-class sleep, and I would perform all of the steps one by one quite fast, so in case you would like to have more information, more comments, please refer to the video which is describing this T-class sleep mode usage. Okay, first point is enabling the debug interface within the system core and Sys. I select the debug trace at the asynchronous SW which would be used to program the micro, you run the debug session and have single wire trace. Within this Sys, I'm exchanging the time-based source from SysTik to Timer 6 as SysTik is used by operating system. I would need LSE crystal which is connected on my Nucleo board. It will be used to give the clock to our low-power Timer 1. Then, within Timers, I'm selecting low-power Timer 1. I select it, configure it as LSE counts, internal clock events. I enable its interrupt, so it's in NVIC settings, and within parameter settings, I'm just changing only the pre-scaler to have 1 kHz on its input. So I use the divider 32 and to finalize this, I go to clock configuration. I can see that I'm still working on 4 MHz complete system. But below, I can see that low-power Timer 1 is clocked by the peripheral clock 4 MHz. I would change it to LSE, 32 kHz. And now, if I come back to pinout and configuration, I can see that using this pre-scaler, I will have 1 kHz on my, let's say, low-power Timer 1 input as a clock. Okay, then it's time to configure the middleware. So freeR2S, so I go middleware. I need to scroll it down somehow. So middleware, freeR2S. I'm selecting interfaceCMCs v2. From this, I need to enable the tickless mode. So this is your tickless idle. I'm selecting build-in functionality enabled to have code generated, which would modify. Then, within tasks and queues, I would rename this default task into task1. PriorityNormal, I would keep 256 words as, let's say, stack size and start task1 as, let's say, entry function. So that's it. I can generate the code. Okay, I open main.c file. It's in core source main.c, and I can perform some code modifications. Within main.c, I would start with my sign-of-life function. So first, declare the prototype, void task underscore action, her message. Then I would define this function bit below with an user code, user code 4 here. I will use ITM interface to send the data. So ITM, send, send char and select message. That's it. And I would send a sign-of new line. That's it. My sign-of-life function is done. Then the task1 body function. So first, I would send my task for five seconds into the blocked state to give the space for the idle task and the tickless mode. Then I would, after, let's say, wake up, I would like to have some sign-of-life. This is why I would like to send one over the ITM data console, and I would like to keep this task for half a second when the run or at least ready state do not go into the blocked state. That's it for main.c file. Now it's time to prepare our tickless mode and to prepare the system to work after tickless mode. For this, I would need this handler, which we will reuse within free.s.c file, which contains those functions, press-leep-processing and post-leep-processing, which are used to prepare our system to low-power mode and to prepare it to work after low-power mode. So we need this extern to use it when those two functions. So the first thing to prepare the system to work after low-power mode is to stop our tick timer. So timer six in our case. Suspend tick. There is no arguments here. And then the second argument would be how low-power timeout function. So to, let's say, configure our low-power timer to wake up as expected, let's say, timeout, which is given by this argument within this press-leep-processing function. So low-power timeout timeout to start it. This is our handler. Maximum period we will use. This is auto-reload register of low-power timer one, which is 16-bit. And here we would like to send this argument from the function. Let's say after we will wake up from low-power mode, we need to perform those operations in a reverse order. So first we would like to stop low-power timer one. Of course, there are no more arguments than this handler. And the next thing is to resume the timer six. And that's it. So we are done with the basic code-processing. This is now, if we compile the code run at the start of the mock session, we will have the situation that we are working with sleep mode. But the goal of this session is to perform some modifications within port.cfile to use stop-modes instead of the sleep. So let's continue with code-processing. Now we will switch to port.cfile. Okay, port.cfile can be found within middleware's third-party 3-year-towels source, portable GCC and ARM-C Cortex-M4 so CM4F port.cfile. This is it. We are looking for the main function which is responsible for the service of the GCCS mode. So I use the CTRL-F and then I press V port, so press, I can just put soup.sup That's it. And you can see this is in my case starting from line 508 and within this function we need to perform a few modifications. Let's say restart of the sys-tick. So we should go over here and we need to block this line. In my case it is 571 to not restart sys-tick because it will wake up us from the stop-mode. Let's say complete stop. Then we will replace this WFI instruction so the classical and runs to the sleep mode with stop-modes of HAL PWR EX because this is typical for the L4 extended version so then enter stop1 mode and then we need to enter somehow and we will enter with WFI. The argument for this is PWR stop N3 so we would like to go here by interrupt. If you are not sure about the argument you can always go to the function body and you see the arguments here. So we will enter stop-mode with let's say WFI instruction. So in fact if we see here it will be an extension of previous call. In previous call we've got only this WFI. So if we just call this function let's say the micro will stop code execution and it is classical sleep-mode. But if we enable deep sleep or sleep-dip within the Cortex system control register it means that it is the sign for Cortex-M core that we would like to stop all of the high-frequency clocks and enter into classical stop-mode. This is our case. Okay, so let's come back to our .c file and let's say we need to verify one more thing. So I scrolled up at the top and I need to include the main.h file as well. Over here to have an access to all of the components from the main code. Okay, that's all modifications we need to perform at the moment. If we scroll down once again to this line 570 we can see that we are entering into stop-mode. We can replace it. We will do it a bit later on with stop-2 and check the difference. So at the moment I'm building the code so I press the hammer icon. Okay, no worries, no warnings. We can start the debug session. Okay, let's start the debug session. This guy got ready connected Nucleo board with XNucleo LPM01 with those red and black wires. So red wire is connected between CN14 on the blue board and left pin of JP6 on Nucleo board. This is the plus. And the GND is connected as well, CN14 on XNucleo LPC and it is connected so pin 1 on this and then GND on Nucleo board. Both boards are connected as well to PC using USB cables. Micro USB cable, XNucleo LPM01 and mini USB cable Nucleo L476 at GND. I can start the debug session but before this as we will use low power mode stop it is good to disable all components which could affect our current consumption so I would go to click on this arrow, go to debug configuration and then I will go to the debugger I will not enable this serial wire viewer in this case and I would disable the debug in low power modes. So I just click debug Ok, there is an error because we need to enable power supply for hour to hour board. So I run a cube monitor power and select the board. It is count 1. I take control then I set the sampling frequency to the highest possible acquisition time to infinite and I start acquisition. After this I will try once again to start the debug Ok and when it is done I just started and stop. Just not to add additional current consumption. Let's have a look on the cube monitor power. So I would just stop one of the sequences. Stop and I can see right now 5 seconds total stop time in between I can see this wake up caused by overflow of cystic so after 4194 milliseconds and then I can see this remaining part of 5 seconds then wake up for task 1 for half a second. If we check now the current consumption I can just select part of it and zoom it. So the current consumption in stop 1 is more or less on the level between 7.5 up to maximum 17 in some peaks. My crampers average it is more or less 8 that's something my crampers. So it's the result for stop 1 I can start acquisition once again just to give the power to the board and I can do some corrections to use stop 2 instead. If I go to port C I can just replace this stop 1 into stop 2 and rebuild the code once again. So just to remind you this is inside the function Vport, suppress, ticks and slip line in my case it is 585 okay code is compiled I can start a debugger resume and stop. It is working I would stop 2 complete sequences let me wait a bit there's 2 complete sequences now I can zoom the area of stop I can see that current consumption is much lower it's a more or less 2 my crampers over in stop 2 so the result is like let's say we expected now we need to it is auto let's say scaling to the result. So the result is like expected Of course you can change let's say your task action function from SWO LED blinking and observe the difference so that's it for this exercise in next one we will add the semaphore usage to wake up the system before this maximum timeout will be done so thank you for watching this video