 Hello, and welcome to the second video of the STM32 Cube ID Advanced Debug Features. I'm Bruno and I'll be your host for this series. Alright, so now we are finally on the Cube ID ecosystem. This is just how the first window will actually open for you guys for the very first time. And as you can see, there are four major options from the get go, which includes how to start a new project from scratch, start a new project from an existing Cubemax configuration, or import from either the True Studio or the System Workbench for STM32, or the new feature available on the 1.4.0 release, which is the import from actually a cube example. So what I'm gonna do is actually, I already have this one project made for this video, so I'm gonna just ignore those four options and I'm gonna go through the file and open a project from file system. And then I'm just gonna type here the path for the project that I've created. It's meant for an F401 based on our nuclear board and I'll make sure that the links for that is on the video description as well and the code is available on our GitHub page, so you guys can give a closer look to that and be actually simpler to follow through. But since I've loaded my project here, I can actually browse a little bit through the folders and let me just start by showing the configuration for that. So if you ask me, hey, I'm gonna change the perspective so I can fit everything that is meant to be seen on the Cubemax side of it. So I'm gonna hit yes and I can actually see the screen appearing for the Cubemax. Alright, so we are initialization the device configuration tool and there it is, we can see how the pins were allocated. So let me just make sure you guys are aware of the system core and the C's. So I've added the debug trace asynchronous, it's the last option here. So once I do this, the SWO pin becomes enabled. So that's through this particular pin that we are gonna see all the advanced debug features. So that's one thing to keep in mind. And the other one that I added is just a simple LED here which I gave the name of LD2 because I'm very creative with the names. And the last thing that is very important for us to keep in mind is the clock configuration. So the first thing that we actually need to make sure that we are aware is that the frequency here is known to us because this frequency is something that we have to input in the debugger configuration to actually make sure that the output of the information of the advanced features through the SWO is actually matching with the CPU frequency. Alright, so since these two features are already done, I can go over and use the shortcut key to generate the project which is ALT plus K or I can always go through here and actually generate my code. So it will say, hey, I'm gonna change the perspective associated with that and yes, that's something you should be doing for me and the code is actually gonna start. So like I said, this is a project that I've already created for this video so let me just dig into the code and explain each and every line so we are on the same page. The first thing that I added is this particular include that will allow me to at some point use the print dive function. Then I've created this define here to actually allow me to use the internal trace macro cell so I can either monitor time or just bring very simple information through this. I've created two global variables. So one is called loop and the other one is called data. All the other parts of the code were created automatically by the cube. So those are actually things and functions that were created. I didn't had to interface and as you guys can probably see all the code that I added are within the user code begin and user code and brackets on the comments. That's how we can make sure that our code will not be changed by the automatically generated feature. So here I've just added the internal trace port just changing it to value number one and initializing the GPIO. This is also done by default by the cube. Then I'm using the printf function saying hey the GPIO initialization is done and then I change the value of the same port of the internal macro cell from one to two and then finally on our main loop. I'm just saying hey I'm on the main loop and then I'm tangling a GPIO adding delay and then printing against and hey I'm under this amount of number of the loop counter incrementing my loop counter and checking if it's higher than 100 then I just assign it to zero and 15 second delay and make another choice to either increment the data by five or decrement it by 1000. And that's pretty much the entire code. So since this one is my entire code now I can build it so there's a bunch of ways that we can perform this action. The easiest one is pressing control plus B or the longer version is going through the project and making a build all. So here we can see that all files are being compiled and once that is done I should get the zero error, zero warning message which is basically the desire and dream for every programmer. And just one small thing since the QBid relies on GCC the way that the low level function of the printf works is actually through a function called underscore write so we can here see through the navigation that I actually created my own write so the printf is using the internal trace same char function to actually output things so that is the way to avoid spending or using one UART for the printf function. All right so now that my code is done and it's compiled I can go through the debug and configure for the very first time so what I want to do is go through here and select debug yes and then I can go through the SDM32 application and once I click it's also going to say hey there's a newer version of the yes to link that is attached and it's asking if I want to update the version of the board as the link that I have and I'm just going to say yes so you guys can see the flow for that. So this window will pop up for us and all we have to do is just open in update mode you're going to see that the version is going to be shown to us and the current version and the updated version so I'm just going to say hey yes update that for me and there we have it it's already done so I can just close this window here and I'll set so if I go through the debug once again and go to the debug configuration then I can actually get a glimpse of how the tabs work for me. So the first thing that we want to make sure is that under the name the debug name is a match for the project that we are using. So I've used a very creative name again so it called debug so the binary file the ELF file is also called debug and for the debugger tab itself all I have to do is make sure that I'm selecting the debug probe that I have so in this nuclear board that I'm using is the ST-Link GDB server. One very important thing is that if I have more than one ST-Link connected I can always specify which one I want to use allowing this checkbox and clicking scan so we can see the serial number for the ST-Link that I'm using and if I were to debug a second one just make sure that the port number here is a different one than the default otherwise it will conflict through the GDB server. So once this is all set and done I have to enable the serial wire viewer to actually see the advanced features so here I'm going to just enable and make sure that the clock frequency is a match to the core clock frequency that I selected on the application as you guys recall it's h4 megahertz so this is already properly done so right now all I have to do is just hit debug and the application will be loaded onto the MCU so it's actually programming the MCU and I also have the information if I want to switch the perspective from the code editing to the debug edit alright so now I'm on the debug interface we can actually see on top that the icons have changed I have other options right now and I'm assuming that the basics are already known to you guys otherwise we do have awesome videos covering the basics for QBiD I'm going to leave the video in the link on the descriptions with the links and what I'm going to do right now is use the live expression which is still a basic feature but can really save some time so I'm just going to add those two variables here the loop and also the data and once I hit play without any breakpoints or holding the CPU I'll be able to actually see those two numbers just changing following the code instructions so there we have it, we can see the variables changing and being updated on their own but this is still the basic features but even though it's a basic feature we went through all the needed aspects of the code and the debug configuration to actually allow us to enhance and go through the advanced features that we're going to cover through individual features from now on and a few extra good information for us to be aware that the ID can provide are the footprint for the flash so we do have the build analyzer and the static stack which will get you an overview of the amount of footprint that your application is taking from flash, from run or for any linker file that you added on your own so that will be shown on the build analyzer and the static stack analyzer will actually explode this view and tell you hey on this given source file you're consuming this amount of flash and even further from this particular source file you have these functions and each one of those functions consume this other amount of flash so this is a value information if you ever need to optimize your code and then we have the output for the binary you guys saw that I was using the .elf file for the debug session but we can actually choose to have a .bin or .x that are more usual and standardized patterns of file to actually load your product into the platform so from our overall takeaway perspective we went through the serial wire debug, we managed to get the basic working we prepared a code to run the serial wire viewer and we added that on the configuration and now for the next videos we are finally digging into the advanced features which is the last step of this video tutorial so thank you again for watching up until this point I hope to see you on the next videos where we are actually digging through everything and just as a general reminder we do have the basic things being covered through another video series and the link is on our description so again thank you for watching and see you soon on the other videos