 Hello and welcome to our first lab in this STM32-H5 MOOC. So this is a very easy lab to make sure that you have the tools and libraries set up properly. This will also validate the hardware is operating correctly, and that the USB drivers on your systems are properly installed. In this lab, we will toggle LED when the user button is pressed. The objective of this lab is to get familiar with your Nucleo H563 Zi. So this is what we're going to be using for this MOOC and this lab. So we will generate a project for the STM32-H5 using our STM32 QxD. So then we'll add some user code in order to toggle the green LED. So connect it to PB0 on your STM32-H5. As you can see here in this schematic. And then, so it will be toggling the LED when the user button is pressed. And the user button, as you can see here, is connected to PC14 on your STM32-H5. First step is to open the STM32 QxD. So this is the tool that we will use during this MOOCs, so all the labs. And we recommend to have a version at least 1.13.0. You will see that's actually using a more advanced version of 1.13.2. So it's always, you know, good to use the latest versions available on ST.com. So to open a SM32 QxD, double-click on the icon on your desktop. Or if you can find it, use the Windows staff menu. So here, here is my icon. So I'm going to double-click on it to open STM32 QxD. So I'm using the version 1.13.2. So we recommend at least, you know, like a version 1.13.0. So, but, you know, like we say, if you can find an updated version, of course use the latest version. So I'm opening STM32 QxD. It can take some time, you know, like the first time. So, and now it's up. To create a new project, you have different options. So from this window here, you can directly click on this icon, start new STM32 project. Another option is to go here from file, new, STM32 project. So let's click on this. We will select the STM32 H563 ZIT6. So this is the part number of the microcontroller that is on your nuclear board. So from this window, so for the target selection, we will select the MCU, MPU selector. And we will look for the STM32 H563 ZIT6. So this is the one that is used on the nuclear H563 ZIT that you are using. So select the part number and then click next. In this window, you will give a name to your project. So for example, I'm going to put toggle LED. And then you keep the rest of the options by default. And you can press finish. So we will now change perspective. So we will use our device configuration tool. So this is called STM32 Cubemax. So to do this, click on yes. So once the IOC file has been loaded, you're going to be prompted by a window like this. So warning, code generation. So just telling you about the instruction cache and the main configuration. So and ask you, do you still want to generate the code? So we're going to click yes. OK. So first of all, find PV0 on the pinout and then configure it as GPIO output. So to look for like a pin, we have a little magnifier like in the window you will see. So you can input directly the name of the pin that you want to look for on your pinout. So here, we'll click PV0. And then once you have identified where it's PV0, click on it and select GPIO output. So this is the pinout of your STM32 H563. So as you can see, it's using a LQFP 144 package. And so we wanted to configure PV0. So look for PV0. So this is the place where to look for like a GPIO. And then once you have identified where it is, click on it. So left click on your mouse. And then select GPIO output. Now it's time to configure PC13. So remember PC13 is the IO that is connected to the user button on your nuclear board. We want to configure it as an external interrupt. So to do that, we look for PC13. And then we will select it as GPIO EXTI14. Then we will also verify or configure the GPIO mode and make sure that we select the external interrupt mode with rising edge trigger detection. Look for PC13. So remember this little magnifier window. Very helpful. Look for PC13. So it's located right here. Now left click and select GPIO EXTI14. So as you can see, once selected, once configured, the IO is marked as green. So for example PC13 now is configured as external interrupt. And we have PV0 that is configured as output. So actually output push pull. So if you want also to look at the configurations of the GPIO, you can go in the system core here. Like from the category window selection. Select GPIO. And here is listed all the GPIOs that you have configured. So we have configured PV0 as output push pull. And then PC13 as external interrupt with rising edge trigger detection. OK, perfect. So that's the configuration we wanted to configure. In this step, we will enable the EXTI13 interrupt. So to do this, you will go in the NVIC tab. So nested vector interrupt controller. So this is basically the interrupt controller that is inside your STM32H5. And in this tab, we will enable the EXTI13 interrupt. OK, so we were in the GPIO tab. Now we're going to switch to NVIC tab. And as you can see, EXTI13 interrupt will enable it. So click on enable. Next step, we'll configure the clocks of the SM32H5. To do this, we're going to go in a different section of the tool, which is the GUI. So we click on the clock configuration. And this will permit in order to configure the clock source and also the speed at which the SM32H5 is going to operate. We will run from the HSI, which is the high speed internal clock running at 64 MHz. And then we're going to configure the system clock running at 64 MHz. And then we'll select the PLL mode. So we'll use HSI with PLL in order to run at the maximum frequency, which is 250 MHz. So to do this, we'll select HSI, select PLL clock, and then here for H clock, which is the system clock, we'll use or we'll enter 250. And then press enter, and then that will configure the clock tree for us. Let's do this. Clock configuration. So right here, we were in the pinout configuration before. Now we move to the clock configuration. So as you can see, it's very complex, this clock tree. So this is to generate all the different clocks internally for the SM32H5. For now, we'll select the HSI as a clock input. So clock source. Then we'll use the PLL mode. And now we want to run at 250 MHz, which is the maximum speed of the SM32H5. So press enter. This will configure the clock tree for us with the proper values for the PLL. So for the multipliers and dividers. So here it found the solution. So we are running from HSI, internal clock. So at 64 MHz. We are using the PLL, so this PLL right here, the PLL1, in order to reach 250 MHz. So now we are done with the configuration. We can generate the code. To generate the code, so select project, click on project, and then generate code. Or if you like shortcuts, you can also do alt and k on your keyboard. So this will generate the code. And then it's going to ask us to change perspective. So we're going to go into a C and C++ perspective in order to have access to the source code of the project generated. So from the menu, go on project, and then select generate code. Yes, we want to change perspective. So this will open a C and C++ perspective and open main.c. There's a window here. Ok, that's a warning. So you can basically just click yes. Just change you about the instruction cache. That means be enabled. So that's true. So but in this example, we don't really care about this. But in a real application, so it's recommended to enable the eye cache, which is the instruction cache. But here, in this case, just click yes, and this will continue the code generation. So this is your project generated right here. In the project explorer window on the left side. And this is the structure of your project. So the includes right here. Then you have some core files we call. So core with includes and source files. So your main.c will be located inside core and source. So this is where also here you have your interrupt service routines that will be defined right here. You have the startup file right here. So assembly no code. And then you have the drivers. So the hard drivers are going to be located here. This is your linker files. And this is your IOC file, which is basically the SCM32 Cubemax. So graphical configuration. But here, we're going to open main.c. So it's actually open already. And we're going to add some code. We're going to add a callback function for the exci, so for the external interrupts. So we're going to add the code between some user code sections. So as you can see here in your main.c, for example, you can see that you have some sections of comments called user code begin and user code end. So here, for example, user code begin for user code end for. We're going to add the code, you know, like within these sections. So this will permit to preserve your code if regenerated from SCM32 Cubemax. So imagine if you are doing another configuration so changing your IOC file. So if you make a modification, your configuration regenerate the code. Then your code is going to be preserved. So user code is going to be preserved as long as you add your code between these user code sections. So it's very important. And also, so for the code to be added. So you can type it, but also we added the code to be added inside the description of this video. So if you want to copy and paste it, you can do that. So go to the description of the video. This callback function is going to be called every time we press on PC13. So which is EXTI, so extra interrupt, line 13. So we check that it's a line 13, so PC13 in particular. And then we'll toggle the LED using a HAL function, so HAL GPIO function to toggle the pin. So in this case, the port, so GPIO B and the pin, GPIO 0. So BIN 0, which is PB0 connected to the LED on your board. So in your main.c scroll down go all the way to the bottom of the file and look for the user code for section. So in this, we're going to add our callback function. So to find again, you know the code to be added, you can go to the description of the video and look for the code to be added. Otherwise, of course, you can type it yourself. Now we can build our project. So this will compile and link your project. So there is an icon right here. So you can use this. Just click on it. And this will build your project. So compile all the different, you know, file that we have in our project. And then at the end, link them and create even a binary file if you want. So at least create the ELF file that will be used, you know, to debug. As you can see, zero errors zero warnings. So this is wonderful for our first lab. So that's great. And now the next step will be to test, you know, this code on our target. So on the nuclear board. So we'll enter a debug session. So that's the next step. This is the nuclear board we are using for this MOOC and this lab. The user button is located right here. So this is the blue button. Actually, the black button right there is to reset the microcontroller. So do not press it during the lab. Just use the blue button which is connected to PC14 on your SM32 H5 that is located in the middle right here. The LEDs are going to be located right here in this section. And then we connect this USB connector right there. So it's a type C connector. And this is connected to the STLink onboard. So the STLink is used to debug and program the STM32 H5. So connect a USB cable to your system using this connector right here. So which is CN1. So use this one and do not use this one. So this one will be used later. This is to connect to the USB peripheral that is on your STM32 H5. So for this lab, connect this one and not this one. So connect to CN1. So we connect a USB cable, so type C to the CN1. So the type C connector on your nuclear board, the one connected to the STLink. And now we're going to insert it onto one of the port, the USB ports of our host or system machine et now you heard it's been enhumorated. So it should be enhumorated as STLink. So that's what we will be using. To interface, so that's our debugger to interface to the STM32 H5 onboard. Now we can enter a debug session. So first select your projects right here, so toggle ID. Then find a debugger right here. So as you can see here like the green little bug click on it. This will open the debug session. So right here there is nothing to change. It's everything is configured properly for your project. So just click OK. OK, so the first time usually what happens is STM32 QID reads version of your STLink. And then if there is a new version available, it offers the possibility to upgrade your STLink with a new firmware. So we're going to do that. So let's update the code of your STLink. So click yes. This is going to open another window, which is the STLink upgrade tool. So this is the STLink v3. OK, and now we're going to open in update mode. This is going to reconnect or re-enumerate. We found so there is a new version so you can upgrade to this new version. So we should be quick. The upgrade was successful right here, indicated right here. So now you can close this window. And we're going to enter debug session again. So the little icon, remember the green bug right here. Or you can also enter from run house stm32 c and c++ application. So in this case we'll use the little icon. So click on it. So now we're going to switch to perspective in a debug. So our program counter is right here. So that's where we're going to execute from the beginning of main. This is our main function and the code that we added right here. Now we can execute a code. To execute a code, what you can do is click on resume here or F8. So let's execute a code. And if you press the blue button you see your LD4, so which is the green LED that toggles every time you press the button. So this works perfectly fine. That's great. So I hope it works for you too. Now what we can do we can stop the execution and we can terminate you know the execution or the debug session. So this will exit and go back to the c and c++ perspective. This ends our first lab. So congratulations to you and let's move on to the next one.