 and to welcome on our STM32Cube IDE by Zeke's training session. In this part, I will demonstrate how to create a project using STM32Cube IDE and HALA libraries for the zero family to use external interrupts to control our LED on board. The objective of this session is to properly configure IO line to work as an external interrupt source and use it to control our LED. In this part I would demonstrate as well how to configure the interrupt controller built in within Cortex-M devices. It is so-called NVIC, nested vector interrupt controller. This is the block diagram of external interrupt module which is built in within STM32G0 microcontrollers. As you can see on the left, this block is connecting all of IO pins. We can have up to five IO ports within STM32G0 lines. We can have as well some other sources, wake-up sources, events which can act as an external interrupts. We will focus on usage of external lines coming from GPIO port C because our blue button which we will use as an external interrupt is connected to PC13 pin. If you are interested in more details concerning external interrupt module, Cortex-M core details, you can refer to our online training dedicated to STM32G0 family. We will use in our exercise as well the green LED which is connected to port PA5 and our blue button which is connected to PC13. As you can see we should detect the following edge of external interrupt. Let's start STM32Q ID project. I would use the same workspace like previously generated G0 underscore LED to toggle LEDs. The first thing I would like to do is to close the current project. This is very nice feature of an eclipse because if I close it all of the files related to this project will be closed as well. So I just click on the right button on mouse and select close project. So now the project is still present in the workspace but I would be sure that I would operate on the proper one and all of the files related to these projects are closed as well. To open it I just double click on the name and the project is open again. Okay so let's close it and let's create a new one related to our external interrupts. To do this I can go either to file new STM32 project or I can use this icon over here. So new and STM32 project. It is starting with initialization of the micro selection so we can select the micro controller we would like to use. In our case it would be G071RB and we'll use this LQFP64 package version. I press next. Now I need to specify the name of now the project. In our case it will be G0XT. I press finish. Now the application will start the device configuration perspective. Okay we can see our micro controller. I can scroll on the mouse to zoom it in. The first thing is connection of the debug interface. So I would go to system core sys cdr wire then PA13 and 14 would be dedicated for the debug interface SWD. The second point is a configuration of our green LED pin PA5. Left button on mouse and I select GPIO output and I would like to set the label on it. I click right button on mouse and I select enter user label and I would select LED underscore green enter and we need to configure properly the pin which is used by our blue button. It is PC13. I'm looking for this pin using this search window. PC13 it's over on the left side. Again I click left button on mouse. I select the last option GPIO XT13. You see that we see some warning within the sys peripheral which means that system wake up 2 will be not accessible anymore because we selected this pin PC13 as GPIO XT13. If I would click once again on the left mouse button we see here several functions which can be selected for this pin. One of those is system wake up 2 like it's visible on the left side of the screen. This is why this is highlighted right now on red which means that this function will be not available anymore. Okay let's come back to our pin. So we've got GPIO XT13. Let's add a label as well to this pin so over the pin I click right button on mouse. I select enter user label. I would select the name blue button enter. You can refer to those settings within main.h file. All the labels are started there. Concerning the pins this is all we would like to do. We will do not perform any clock configuration notification. What we need to do as well is to properly configure this external interrupt input pin to be active on following etch. How to do this? We will go to the system core GPIO configuration select PC13. I can see some additional configurations. GPIO mode this is something which is important for us. I can see here external interrupt mode with rising etch trigger detection. This is the default setting. We will change it by scrolling down to interrupt mode with following etch detection. We will not select any pull up or pull down which is available on the pin and will not change the blue button. The last point which is necessary to be done to have active interrupt external line is to enable the interrupt signal with an interrupt controller. How to do this? We can go either within GPIO to the NVIC tab and just select enable or we can go directly to NVIC settings and enable this signal on this site. Once it is done this is the time to generate the code. The easiest way to do this is just to save the current project so control S. We see some action is going. Right now the application is generating the code based on the selections on the configuration of the device of the peripherals we have just done within this perspective. Okay, the code is generated. We can go to the source files. So let's go to the main.c and we can see here a lot of lines a lot of comments and sections like user code begin user code end. This is the place where our code should be located in order to keep it in project regenerations. So what we need to do? So the first thing is to define the flag the variable which would be changed within the interrupt routine and based on this on this value we will toggle LED or not. Okay, so let's scroll up and we've got section private variables it's more or less line 47 and we will define the 8-bit value which could be called flag with initial value set to zero. Next point would be to implement the LED toggling in case the flag is set and set of the flag would be done within the interrupt routine. I would start with the flip if one flag and now we need to toggle LED. So we are using hall libraries this is why this prefix hall then GPIO and control space to select the function. I would select toggle pin. The first argument here is a port name as I'm using labels I would start with the label name LED green that's of the port and the same for the pin number I would select my labels control space and the pin. So within this function I will toggle LED if the flag is set then we need to click this flag afterwards. So the missing point is to create the procedure where we will set the flag and the location of this procedure should be related somehow to our interrupt. How to do this? Let's go to the interrupt routines file which is stm32g0xx underscore it.c. Let's scroll down this is the file which contains all implemented interrupt routines so at the beginning you can see some system functions like fold handlers, cystic handler which is used to generate the timeouts and below more or less line 145 you can see as well the external interrupt handler which is called xt4215 in this in Cortex M0 plus which is the base core for this microcontroller some external interrupts are grouped together and our number 13 is within the common vector used from channels from 4 to 15. If you are interested in more details about the the structure of this external interrupt but if it are please refer to the separate online training which is available on our web page. Now we will focus on handling the interrupt so within the hall library once you generate the code using external interrupts or any other interrupts this kind of the interrupt procedure would be generated automatically and there would be only one function which is located within the hall library i would go to its location it is located in a GPIO peripheral source file and the role of this function is to select the source of the interrupt clear the flag and at the end call the proper callback in our case we will use the following edge interrupt so we will call this callback we should call this callback those callbacks are implemented within the library as an empty functions with weak attribute which means that we can implement them as well in our code and during the compilation we should not receive any warning this is the role of this weak attribute here okay so i will just copy the name of the callback and its arguments into my code very good location for this is section user code begin for which is below the main function so i would put this function over here so as you have seen the flags concerning to the external interrupt are cleared by the by the hall library so the only thing is to implement some action which is necessary for us and as you remember what we need to do within the interrupt procedure is to set the flag so i set the flag i save the code and i'm trying to build it i click the camera icon it takes some time at the end i can see the size of the of the code completion time and in case of any warnings or errors those should be visible as well within this console window once it's done let's start a debug session for this i'm clicking this bug i need to select the way i would like to debug the application i would select stm32 mcocc plus plus application i would not change anything in the edit configuration this is why i press okay those windows would be displayed on during the first run of the debug session for the project in the meantime i can see the switch from the cc plus plus perspective into the debug perspective this is quite well visible because i can see the different toolbar on the right side of the screen i can see the window with a possible visibility of the variables breakpoints expressions and the registers within the micro we will use it in the in the next next sections okay now we will just run the application so i press the play button and now if i press the blue button on each blue button press i can see the change of the green led state to exit this debug session i just need to press this terminate button thank you for watching this video