 We're now going to show you how easy it is using the Cubamex tool to create a low power example. So for those of you who've never used Cubamex, Cubamex is a configuration and an initialisation tool that lets you generate the whole IAR environment ready for you to just start adding code to your application. So you'll see this in action during this Cubamex low power lab session. So the goal of this session is to show you exactly how quick and easy it is to start from absolutely zero to something that uses the stop mode 2 as an example. So what we're going to do is configure some GPIOs, an external interrupt to wake the device up, and that will use the NVIC part of the Cortex M4 device. So first thing we need to do, we need to create our project in the Cubamex tool. So if you launch Cubamex, we have our Cubamex tool, and then we need to select the microcontroller that is on our discovery board. So we will start with a new project. This will produce the MCU selector. So we have an L4 device. It's a 4x6, and it is a 100 pin package. So that gives us four options to choose from. And if we read the top of our device, we are a 476 VGT, which is the third option on the list. And then we OK that, and we will now be presented with our pinout diagram for our microcontroller. So the pinout diagram is where you can actually go and configure the GPIO pins. So we need to configure two pins, one for an LED so we can visually see something happening, and one for the push button so we can generate the interrupt. So to generate the LED pin, you click on PE8. So on our hardware you can see that PE8 is the green LED that's on our target board. And if we look at our hardware diagram, you can see that PA0 is the joystick pushdown button. So the center button of that. So again we need to select that one to be an external interrupt on our device. So if we go back to our cube tool, so we are now looking for PE8, zoom in a bit. So to quickly find PE8, I will type it in there. And now you can see PE8 flashing at the bottom of the diagram. So now I will go and click on PE8 and select that to be the GPIO output for our LED. And PA0, I can quickly see PA0 because it is written in the right layout. So for PA0 we need to select GPIO external interrupt 0. So that's our two pins configured now, ready for our push button and our LED. So now we want to go and set the configuration and initialization conditions for these GPIOs. So we need to change the tab to go to the configuration tab. And we need to select the GPIO button on the right hand side of the screen. We will select our configuration tab. And then we go and select our GPIO configuration over there. So the default configuration for PE0 is OK. For PA0 we do need to select the interrupt mode and make sure it is correct for how our button is going to operate. So we need to make sure that PA0 is external interrupt mode with rising edge trigger. So if we click on our PA0, external interrupt mode with rising edge trigger. So that configuration is also correct. So the default configuration for both the LED and the push button are correct. So we can OK that screen. So now we need to go and configure the interrupts. So we need to select the interrupt configuration tab. And here we need to enable the interrupt for the external line 0. So we go back to our cube tool and we select our NVIC and external interrupt line 0. We now need to enable and then select OK. So that's now enabled our interrupt on that pin 0. So that's all we need to do to configure our project. We've only got GPIO pins. So we now need to save the project somewhere. Select the tool chain that we want to generate the project for and give the project a name. So this is all done in the project and generate code section. So we now want to go to project generate code. So I already have a default location set up for all of my examples. So I will give the project a name. I'll call it low power application. I'm going to leave the tool chain set to the IAR tool that we've been using already during the rest of this morning's session. And we now want to make sure that all unused pins are set to be analog pins as this will give us the lowest power consumption configuration for the project that we're working on. So if I go back to cube again and I now go on to code generator and I want to set all three pins to analog so that we have our lowest configuration. So when I go OK now it will go off and generate my entire IAR workspace ready for me to open. There we go. So this is the flow of what's going on based on what we have just generated. So we have the initialization of the peripherals. So we have the initialization of our control controller. We have the initialization of our GPIO. Then we will need to add a bit of code to define that we want to enter stop mode. Then in the hardware when we press the button we will create a rising edge. This will then cause the software to jump off into the external interrupt handler which will then move into the area where it will clear the flags and make sure all the settings are correct to exit the interrupt. Then we will jump into the callback routine for that particular interrupt handler. Once we've executed our code in the callback routine for what we want to do when that interrupt actually happens we then reconfigure the clock as the device will now then have woken up from the stop mode and then it will continue and run its application. So depending on which tool chain you selected you can now go and open the project. So this is back to using the project EWW we had from earlier today. Open the folder that's just been generated. Go into my EWARM and open my project EWW. Here is our complete project now. So you can see it's pulled in all the relevant drivers for all the various periphery that are being used by our application and by the hardware abstract layer itself. It's pulling in the ARM-CMSIS files as well and it has generated the startup file for the EWARM software tool chain. And it's generated our three user files. So we're going to now open main.c and we can see now that we have our HAL initialisation, our GPIO initialisation and then an empty while one loop has now been created in there. So we now need to add some application code to our example. So when we edit our code we need to make sure we place it between a user code begin and a user code end tag in the main.c. This is so that if we choose to run the cube MX tool again our code will be maintained when we regenerate the files again for the project. So the first thing we need to do is switch off unused peripheral clocks that we're not going to use. So we were using port E and port A. So we need to disable all the other GPIO ports on the device. So we have four lines of code there we need to add to do this task. Then we need to get the instruction for the wait for interrupt so that we can enter the stop mode. So if you noticed when we were doing the configuration the sys tick is also generating an interrupt. So we have to make sure we suspend the sys tick before we enter the stop mode otherwise the sys tick every 10 milliseconds will wait the device up. So this is why we have a suspend sys tick and a resume sys tick in those lines. So we now need to go and add those seven lines of code to our project. Now we need to duplicate that for other ports. So port C, D and port H. Then a bit further down in our while one loop we need to do our how suspend tick and then finally our how resume tick. So there's the lines of codes for us to enter the stop mode and make sure we've disabled all unused clocks so that we can get the lowest power consumption for our project. So the last part we need to enter is the interrupt handler. So this is where we will put the actions that happen when we do press the button. This action will be to toggle the LED pin, so toggle PE8. So again we need to add two more lines of code into this section which is in the interrupt.c file. So if we go and open our interrupt.c file and scroll down to where our interrupt handler is located. So there's our interrupt handler. So from the configuration you can all automatically see one line has been placed in there. So we now need to add the toggle line. You can see that IAR is prompting us with the format of each of these commands as I'm typing them. So there we go, so we toggle our GPIO pin. So that is our editing of software complete. So now what we have, we'll be able to press this button and the device will enter stop mode. We keep our Amita connected to JP5 as we have done like the previous examples and we should now be able to toggle this LED. So we will now go and build the project. So we will press F7. So there's the project built. We'll switch on our Amita again. And now project, download, download active application. Put the firmware in the micro. So that's complete now. And now we reset our board and every time we press our blue button we will toggle our LED on and off. And you will see that your current consumption switches between stop mode and run mode. So when the LED is off you are in stop mode. When the LED is on you are in run mode. And you can see how much current consumption your LED is actually taking now from your Amita. So when the LED is off you are down at about 1.9, 1.8 microamps which agrees with stop mode. Stop mode is meant to be, stop mode 2 is meant to be about the 2 microamp mark. And then when you enter the run mode to switch the LED back on we're now consuming about 3.2 milliamps which will be the current consumed by the LED. So you've seen very quickly how easy it is to get started using the Cubimx tool for a low power based application. Is there any questions?