 Okay, so in this section of the workshop we are now going to look at the different power operating modes of the STM32L4 and to do this we're going to use some real life applications. So this is a typical application profile for quite a substantial amount of microcontroller applications. So the application will start in its off state and then as you apply the power to the device the microcontroller will go for its start-up initialization, configuring peripherals, timers, GPIO pins, anything else that's connected on the outside of the world so it can configure all sensors and whatever else the microcontroller is talking to. Then the device will go into an inactive state or a low power mode and at that point it'll be sat waiting for some form of time event to happen, so the RTC for example, or it could be waiting for an external event to happen that can bring the device back into an active state where you process whatever information data you have received and then you go back into your low power mode and continue that type of cycle for pretty much the lifetime of the application. So here's an overview of all the different power modes we have available to you on the STM32L4. So we have two run modes, we have range one which has the capability of running up to the full speed of the device which is 80 MHz and we have range two which is limits the top speed of the device to 26 MHz but as you can see we get a better dynamic current consumption in range two so you can see that we have somewhere on the line we've had to optimise the technology to run at a particular speed and 26 MHz is the optimal current consumption for this particular technology. Then as we go through we have low power run which can limit the clock speed now down to 2 MHz and then we go into the various proper power down modes. So sleep, low power sleep, stop one, stop two. So stop one and stop two still have full RAM data retention and it maintains all the register configurations that you've had in the system. Then we have standby with 32 kb of RAM maintained and without the 32 kb of RAM. For standby you do need to come back through the reset cycle because we have lost all the peripheral register settings at this point. Then we have shut down which is a new power mode for the STM32 family so this gets us down as low as 30 nanoamps and we also have the V-BAT functionality where we can maintain when the power is being completely disconnected and you're running off a supercap or coin cell. For all of these different low power modes you can see on the left hand side the wake up time for the device to come back to full processing power. Sleep is where all peripherals are running, it's only the core that is asleep so you only have to wait six CPU cycles or six clock cycles before the core is able to start processing again. Stop mode, you're down in about four or five microseconds to wake up so this is primarily for the clock tree to start up correctly again and standby you're down at 40 microseconds so this is the time it takes to come through the reset cycle of the device. Shut down is the longest one because of the nature of what has to go on when you do a reset cycle from the shutdown position so there is a lot more configuration that has to happen in the system when you've come back from shutdown. So the key features from the power modes are we can run down as low as 100 microamps per megahertz when you're executing code from flash. In standby mode with 32 kilobytes of SRAM still powered we're down at 350 nanoamps and the new mode shut down where you can still use an IO pin to wake the device we're down at 30 nanoamps really really is a good low power mode. For most of these low power modes the RTC is always available if it has been enabled to wake you up but on the STM32L4 we have a lot more periphery that can actually bring the device out of these wake up modes and we will go through that later on during this part of the presentation. Inside the device we have two voltage regulators we have the main voltage regulator which powers everything for maximum performance and then we have a low power regulator which is then used in low power run, low power sleep and the stop modes. When you get down to standby and shutdown mode both of these regulators are switched off this is where some of the extra time takes for the wake up cycle because we have to wait for the regulator to power up and stabilize as well. So if we now look at run mode in range 1 this mode is where every single resource of the MCU is available to you. So you can see there everything in the pink or the dark pink is available and active. So you've got the flash, the RAMs, the core regulator in configured as range 1, low power regulator is available and the brown out reset on the left hand side is in use at this point. All the other periphery and the clocks are all available for you to use depending on what you need to do in your application. Run mode in range 2 so our main regulator now is selected to be range 2 this now limits us to the 26 megahertz. In range 2 you can do get the most optimal current consumption so 100 megahertz we will run from SRAM bank number one. As you can see on the left hand side two of the periphery have now gone white. So the USB cell and the random number generator have gone white so these periphery are no longer used because we have now limited the device speed to 26 megahertz and we need 48 megahertz to run the USB cell on the device. So let's go to our first hands on. We're going to use the SDM32 L4 discovery board you have in front of you. We're going to run all the examples on this particular board during the day and for this section you're going to need your ammeter as well connected to your board so that you can measure the current consumption of some real life applications. So each of these scenarios we've got for the different low power modes are actually based on real life applications. So to run the example if you're using the IAR toolchain you need to make sure your IAR tool is installed. You don't need Cubamex for this very first part but you will need to make sure that your ST link driver is installed correctly on your laptop so that we can communicate with the board and program the board. So all the examples were on the memory stick that we provided and hopefully you've extracted that onto the root of your C drive and a few quick key shortcuts really for the IAR toolchain. To build a project you can press the F7 button so when you have a workspace open you can select the F7 button. To download the compiled code into your target device without entering debug there is a section in the menu called project download download active application so here we can just download the binary file straight into the microcontroller or if you want to go into the debugging then you can go project download and debug so this will then program the micro and put the toolchain into the debug environment. And finally we need to be measuring the current consumption we are seeing on our board so we will need to attach our jumpers to JP5 which is on the left hand side of your board just below the segment display you need to remove the jumper and put your ammeter across the two pins as shown in the bottom right hand corner here of the slide. If you are running the AC6 toolchain we have the same set of shortcuts and information there and you can run this directly from the binaries so on the memory stick we have a folder with binaries inside for each of these low power examples and for this you can use the stlink utility tool and open each pre-compiled binary file and program it into the board so that you can do the same testing without the need of opening the IR toolchain. Okay so example number one run mode so this is where you are doing a high performance data processing application so what we are going to do in this application is we are going to execute the core mark algorithm so we are just doing a computational example here. You can see the flow diagram on the right hand side so we have the power up from the device being off we go into the reset state we will then configure what peripherals we need then we will run our core mark loop and then we will drop down into an infinite wire one loop so you should see a difference in current consumption while we are processing the core mark and it will be slightly lower when we are just in the infinite wire one loop. This application can be found in the hands on folder section number one systems operating modes and example number one run mode so the parameters we have used for the example here we are running a 24 megahertz clock or an 80 megahertz clock depending on the configuration you set and we have the ability to execute from flash or SRAM in this particular example so the binaries we have already prepared are for flash only that are on the binaries folder on the memory stick so to change the configuration between flash and SRAM there is a little drop down box in the tool so the IR tool and there is a different drop down box which will change the linker file that we are using for this particular example and then to change the clock speeds from the 24 megahertz to the 80 megahertz you need to go down to lines number 94 and 95 where you can comment and uncomment the different clocks that we are using and through the terminal program we can display the results that we get using our termite terminal program we need to make sure that the two solder bridges on the underside of the board are there and for this we will need to run our terminal program at 115 200 bits per second with eight data no parity and one stop so we will be able to see the output results that we get for the experiment that we're running so the core mark routine so then on your terminal program you will see a set of results like this which will tell you the total iterations per second which will give us our results and you should hopefully be getting around 14.3 milliamps for running the device at full speed from the flash so if we now go to our example so we go into our hands-on folder section number one system operating modes there's the binaries folder for those of you who want to use stlink and the prefix binary so we're going to open the run mode example and I will go into my e1 folder and I will open project EWW so there's our example so here you can see I have got the 24 megahertz clock enabled so I will comment that out first I will press my F7 button to start the compilation of the code so the warning is okay we can ignore the warning and now I have my board connected already so I will now go into projects download and the download active application so now program my board with the software we have just compiled so there we go that's all now programming to my board I will connect my ammeter into my target board