 Hello and welcome to a new lab in this STMFA2 H5 MOOC. So this is another easy lab. So in this lab, we will learn how to redirect printf to a UART. So this is always useful to have such functionality for debug purposes. So one important note is that you need to have done the previous lab, so which is the toggle LED on button press in order to do this lab because we use the previous project as a base for this lab. The objective of this lab is to re-target the printf to a UART, so to display messages on a terminal. So UART 3 is connected to the stlink v3 that is operating as a USB virtual comport bridge. So we'll use these two IOS, so PD8 and PD9, which have a time function UART 3 in order to connect to the virtual comport of the stlink v3 that is on your nuclear border. So using the previous project that we had, remember the toggle LED on button press will open the IOC file, so which is the file for the SMA2 Cubamex, so for opening the graphical interface configuration. And then we will proceed to enable the UART on PD8 and PD9. So to do this, we'll go in the pinout configuration tab, connectivity, UART 3 will enable the asynchronous mode for the UART, so that will be done here in the UART mode and configuration. And then in the parameter settings, we choose the broad rates, the world length and the parity settings that we want. Okay, so now we are back to SMA2 Cubade. So this is the first project that we were working on in the first lab. And now we'll open the IOC file. So this is going to open, so click yes to open the Cubamex view, so the graphical interface. And this is going to load the IOC file. And we're going to come back to the view of the pinout and we'll have the possibility to add some new configuration to the previous IOC file that we had. All right, so in the pinout and configuration tab, open connectivity, then look for UART 3. And now what we can do for UART 3, we're going to choose asynchronous mode. And we want to select PD8 and PD9. So look for PD8, select UART 3TX. And then same thing for PD9. And select UART 3RX. Okay, so now we have the correct configuration for the IOs. We remapped to the correct IOs, connected to the STLink v3 virtual comports. And now we can complete the configuration of the UART 3. So we're going to use actually the same values, so 115,200 volts. And then we'll have 8 bits of data, no parity and one bit for stop. Okay, now the configuration is done, we can generate the code. So to generate the code as we saw before, there's different ways actually. We saw one method, but there's different other ways. You can use this icon right here with the gear, you see, in yellow. So that's one way. The other way is project generate code. And then there is another method, which is just by saving your project. So by saving this, that will ask you, you know, yes. And then it will ask you to generate the code. And now we can change perspective. So we are in the source code of the project now. The code has been generated. So we have the same messages as before. So yes, normally it's good to do it. But in this case, it's not really a big deal. So we can just press yes. We can now add some code. So first thing, in main.h of your project, double-click on it, open it, and we're going to add a first include for stdio.h. So again, for the code to be added, we have all the code to be added in the description of this video. So you can go there, copy and paste, or otherwise you can just type yourself. Now open your project from the project explorer in the include, so core include main.h. And in the includes, we're going to add stdio.h. So in main.c, at the beginning of the file, for example in the pfp section, so you're going to add this definition for the putcar prototype. So to redefine, you know, the io putcar. Scroll down, look for the callback function that we added in the previous lab. So it should be at the end right here and we're going to add one line of code for printf. So the idea is every time we press the button, so PC13, we're also going to see this message on the terminal. One more thing, one last thing. So in the user code for section, we're going to add this prototype function right here. Now build the projects. So project build all or you can use, you know, the little icon here, the hammer. Right. Make sure your board is connected to your host machine, to your system. So to my laptop here, you heard, you know, the board has been enumerated. So make sure you connected, you know, the right way, the connector one, which is connected to DST link on your nuclear wall. Now we can enter a debug session. So select the projects and then enter debug session. Switch to a new perspective. So this is going to be a debug session now. And execute a code with resume icon right here or F8. We are going to use the common shell console inside the cube ID. So this will be used, you know, to look at the printf outputs. So you can use also, of course, any other terminals that you like. For example, TerraTerm or Putti or whatever you use. It's fine. But here, I just wanted to show you that inside the cube ID, we have a terminal and we will learn how to use it. The important thing is, you know, in order to select the proper comports, you will have to go inside your device manager and find out, you know, which port and which com, you know, has been associated to the virtual comports of the ST-Link v3 that is on your nuclear board. So as an example here, you know, like we're displaying com6. But of course, on your machine, it could be something else. So we need to know what is this number because this is going to be part of the configuration of the terminal inside the cube ID later on. Okay, so I have a Windows machine. So in my case, I'm going to open device manager and this will indicate to me what is, you know, the comports associated to the virtual comports. So I need to look into the comports, so scroll down right here. As you can see on my machine, the ST-Link virtual comports is com 43. So let's remember this. Now we're going to configure the com and shell console inside cube ID. So to do this, there is an icon, you know, like on the lower right corner of your cube ID, an icon like this. Click on the little arrow, so the black arrow down. Click on that, then select com and shell console. This is going to open another window. Select for the connection type, comports. Then for the encoding, we can use the ISO 8859-1. And then we can click new. This is going to open another window. In here, you're going to give a name to your connection. So for example here, we give a name like h5 underscore serial. Then select the proper comports associated to your ST-Link on your board. So remember, in my case it was com 43. I'm going to select and then select exactly the same configuration you did to your user free that you did inside, you know, the cube ID previously. So in our case, 115200 boards for the board rates. Data size will be 8, parity none and stop bits will be 1. Then you can click finish and let's see what's going to happen. Ok, so follow my mouse. You see where I'm right here. So this is the icon that we are looking for. Go right here, command shell then select serial port select encoding 8859-1 and then new. Now give a name to your, you know, thing. So for example, we can give a serial h5 com 43 in my case. So for you, you know, it's going to change probably. And then we'll keep this by default. Click finish. Ok. And now let's test, you know this. So I'm going to press on my user button on my board. As you can see, every time I'm pressing on the button. So the blue button user button we have the callback and then inside the callback printing hello world. So it's working fine. So now you can stop the execution. So right there. And basically we are done with this lab. So congratulations on another lab completed.