AVR assembly and debugging with VSCode and Platform IO

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello again in this new video we are going to continue with our examples of summary programming for the AVR so so far we have done a very basic program we have seen the right way to do it in a VR assembly and we have used the tool chain directly the gnu avr-2 chain directly executing the compiler and the debugger simulator and everything so normally we will want to use an integrated development environment some kind of interface to the tools okay for the AVR family there are different options so we can use the raw tools in the tool chains we have that but we also can use a make file system make is a system to automate a program execution that comes from the Unix operating systems and there are options to do that in in Unix systems like Linux or Windows okay and another option is to use a more integrated environment so the official environment for AVR design is the microchip Studio which is the former at Mel Studio a software it's an integrated development environment based on Visual Studio from Microsoft it is the visual studio Suite not the the visual studio code okay it runs in Windows only and it includes different options for using tool chain a different kind of projects and so on it's a pretty much complete and has a very nice debug interface and now in the from the free software well we have platform IO platform IO is a system which is designed to develop software for for embedded systems and it supports many different platforms including the AVR platform and basically does the same it solves the problem of installing the tool change and interfacing with the debugger and also simplifying the writing of code and platform IO also have an integrated development environment that works with Visual Studio code and and so you can if you have an installation of Visual Studio code you can ask platform i o as an extension and it will it's a not as advanced as the microchip Studio IDE for example but if you are used to programmers into ready development environments like Visual Studio code it's a nice option to use so in this video we are going to do the same example as in the previous videos but using platform IO and basically the same tasks writing our code debugging uploading to the board and and everything okay so in Ubuntu Visual Studio code can be installed from the Ubuntu package manager in the Ubuntu software package manager you can search for it is search for code or vs code and here it is it is distributed as a snap package and yes go and install it and once we have Visual Studio code install we just install platform IO as an extension okay and what we are going to do is just use the same example we have done in previous videos but we are going to use it convert it into project or visual of platform IO Okay so let's start with the visual Stone Studio codes thing code is here you know there is you may know vs codium vs kodium is a is the same free base of Visual Studio code but it's an independent compilation it means that while independent compilations are free software the visual studio code product from Microsoft even if the if it is the same software is not free software Unfortunately today platform IO only works uh at least it only works legally with the visual studio code compilation from Microsoft not with the free Alternatives okay it can be solved it's a technical problem it may be solved in the future but for now you have to use the distributed version from Microsoft foreign so this is a fresh install you have plenty of messages here okay we'll try to go directly and do all the configuration and here we have the extensions this kind of programs this type of programmers development environments are well known because these are very very flexible in in the sense that the programs does some basic things but most of the functionality is obtained by installing extensions so we go for the platform IO into ready development environment here we install it once we have platform IO installed it will take a charge of installing the tool chains on the tools you you have to use to develop in any platform you select so you don't need to install the assembler or compiler or anything for the AVR platform okay the platform IO will take care of the details for you so this is the first round so now it's downloading things okay okay now we have a message here there's some package we don't have installed okay so it says to install this package okay the Python 3 V and which is for creating virtual environments for python okay so we'll copy this and we'll open the terminal it haven't happened to me before probably because I already had that uh packet installed already Okay so to the app you can install so what I'm going to do now is is that I will probably uninstall it and install it again okay just in case platform IO okay let's go and try to install it again now it's finished we have to reload the editor click reload okay now it's fine now because we are going to develop for the AVR platform there's another extension that is useful we look for AVR is this AVR support okay Assembly Language support this is used to it's an extension that provides syntax highlighting for assembly code so it's nice to have we are going to install it as well okay now it's done now once we have platform i o we have the this icon here okay with the platform i o menu platform area is a very big extension actually so we are going to start by creating a first project with platform i o so we can go here to to home we can I think it's we go to open and it will load the interface okay and you see it's a very complex uh extension actually okay and you can develop four many different platforms not only the AVR for different microcontrollers and this is different tool sets it's a bit complex but for us it's not that difficult we are first thing we are going to do is that we are going to create a new project so you see you see how it works and our our project is a an AVR uh assembly code project that we want to run in an Arduino Uno board so we go directly here and we look for Uno okay Arduino Uno it will select for us then the the framework and the tool chain that we have to use we give it a a name we are going to call it example one a b and that's it if you see this framework the framework means the set of tools and libraries that you are have available to develop for that mode okay by default platform EO uses the Arduino framework it means that it will create something like is like an Arduino product Arduino is uh is a framework to develop for the Arduino boards that uh uses lots of libraries to make a programming the these microcontrollers in a very easy way so it will create an Arduino project with the files typical yes or that okay we are not interested in creating an Arduino project but we will see how to transform this project for Arduino in something more simple the thing we need to program directly in Assembly Language but it is important that the first time we create a standard Arduino project because it will make the platform to install all the libraries and all the tool chain we need to develop for that okay so black for me works like that this is our new project we have a configuration for our project it selects the the platform is at mail AVR it basically defines that the tool chain is what we already have seen in previous videos is the genu compiler debugger and everything the ball is the unit so because of the board the platform knows how to program it what tools it needs to compile the code to program it okay so we don't really have to know the details and this is the framework which is the set of libraries and other tools we need to program that okay so how and where do we put our code in the source directory here it creates a template file main CPP because Arduino projects are programmed in um in in C plus plus language okay so it creates the typical structure of an Arduino project a setup function and a loop function okay so if you want to program like arduinos if you already have experience using Arduino a development environment you can use that this platform i o as your Arduino developing platform it's perfectly fine so from here you can go there but we are not interested on that so first thing we are going to do is that a I have a repository explaining how to how to transform it so let's go uncheck that is these these uh a platform i o template or an AVR bear project it means a project that uses the tool chain directly without any framework not Arduino or anything this is the how you can if you have you can configure your project in platform IO to program it in Assembly Language or in C language directly okay so this is a repository itself is the template you can download the Repository and as a zip file and compressing any folder and then you go here and then you have all the files okay or this is the Quick Start described here it will work when if you have previously run or created any previous Arduino project for the system to set up the tool chain okay so that's an option you can download the folder and compress and then you have everything set up or you can the alternate a thing is to do it a bit manually okay we are going to do it manually because we have already started our first project so what we have to do is that we go to our configuration project configuration file here and we make a few changes as it is described here okay the changes are really simple okay basically what we say is that we don't want to use any framework so we can comment out or we can delete this line here we don't want to use the Arduino framework if we comment it out the the system we'll just use the regular set of tools the tool chain as it is and now we normally want to debug our programs using a simulator so we add this line here we say that the back tool is going to be the same AVR simulator as we have done in the terminal before in previous examples okay and then we want to a when we simulate our our devices it is possible to create an interface to the peripherals registers so we can we can we have an easy access to the peripherals we don't have to display the memory content to look at that okay so in this repository we have prepared a file with the definition to make it easy to access the peripherals and then you you can put this one means that this is the the back option which is this SVD file okay so this is a configuration for the Arduino Uno or for any project that uses the atmega 328 okay so this is our small bits now this file we have to download it is it is here in the report story so we can go here and actually we can download the whole Repository we can open it in the in the in the archive manager and we can copy this file to our project folder okay where is it so we um a let me see I think it's in the home page I don't remember where but for meal actually here in in documents folder platformeo creates a the default folder for the projects okay so this is the folder for our project so we simply copy that file here okay so now we have update the configuration for the project we have the file defining the peripherals and okay and we have our here we have our C plus plus file we don't want to program in C plus plus so simply we change it to main.s uppercase s and it's going to be our Assembly Language file okay and we what we include here is that well we had in our previous examples okay we save the file and this is all set okay once we have that I will recommend to you to close the thing okay and reopen it again because we have changed some configurations here it should not affect but if you have problems you may close everything and open it again okay I will try to follow as it is here okay so now it is set now we have our file here just to check how it works what I'm going to do is I'm going to copy the code from our previous example you see I will copy exactly the same code okay we you see we have some syntax highlighting because it detects it's an Assembly Language a program a file okay but it's a a standard assembly it's not a AVR specific so if we click here we because we have installed the AVR assembler extension okay we can select this and it will make a better syntax highlighting in our file okay now up to now the now we have a very Advanced Editor to edit our code now what can we do can do everything if you we could go to the platform IO a tab here we see all the tasks we can run in our project so remember previously we run the simulator or the assembler in manually okay now it is here in the build uh link here if you if we press bill because the system already knows what is our bolt it knows what is the tool chain it has to use it will execute the assembler or the compiler for us automatically okay so you you to to make the compiling we just press build and it will tell us in a terminal here what it's done doing and will tell what's the result okay so it has generated the program of 150 bytes and that's it okay okay now we can upload to the boat the it knows about the AVR dude comment it knows what are the options to the comment it knows everything it knows it knows the the which board we are using okay the Uno and so it knows all the details it's already proven there so we can upload our program right away so we are going to to do that actually in the previous video we we did the program we debug the program we executed the program at debugger but we actually did not test it in the boat so we can try to do it from here uh so let's come here and let's click on upload here okay oh let's see what happened okay it's not working very well okay it's not working uh because I'm using a virtual machine to record these examples so I have my ball that's not connected to the virtual machine it's connected to the real machine okay I'll go to my virtual matching options and just connect it connect the boat to the machine now okay normally platform IO will detect automatically at which Port it's connected so I will repeat the upload foreign is blinking in the boat so it should be running now okay and we can we can we can we can test if it's working or not so in my input is in ground here so it's the the output is zero and if we unplug the cable okay the lid here will light okay we don't need to connect it to to the power rail because we have a pull-up activated here okay so it's working fine so imagine we don't have the board and so we want to simulate it as we did in in the terminal in previous videos so we also have the debugger interface here okay so if we go here automatically platform IO has created some debugging configurations for us it means that we just have to clock to click in a Pio at the back and it should run the debugger okay and now we click play here and it will run the debugger in the background okay it's not working very well you see it's running this is are the debugger controls but it's not really working okay this is the glitch I told you about okay finally it makes an error here who knows I think it's working okay I had a problem in my computer it's working here I think okay so it's interesting if you have seen the previous videos that the back console is actually the console for the ginu debugger okay you can you can write comments here to print and set things and and write a break set breakpoints from here okay but this is captured by the interface so we have a nice uh interest rates here okay so these are the debugger controls we can move it here and from these controls you can continue the execution you can step one instruction and everything okay you can restart the simulator you can stop the debugging session and here we have many things here we will close all these and here we have the the peripherals the peripherals are not showing um yes I don't know what the problem is okay so let me check maybe we have to do as I told you before we have to get out of the editor and get in again okay so let me stop it we will close the project close everything let's run it again it's not really a problem if we find some problems because the idea is that you may run into similar problems actually okay so you see it opens the same project again and we'll go to the bug interface and let's run the debugging again if you see it will compile the the project again every time you debug it because normally it uses different options to compile for debugging or not and you see this time it it is here okay you can see the ports here so it is it's a bit easier now remember our program will read one bit from Port D it will actually from p d a p number seven here and we'll write pin five import B which is the PIN five pb5 import B okay so these are the bits we are interested in okay this is the input this is the output so we can stop debugging you can we can use uh shortcuts it's very interesting to learn the shortcut okay you can step over or step into they are similar here they are the same F10 or f11 just to go one step at a time you you can also set breakpoints breakpoints has said just by clicking here on this side here normally or we need to activate an option for that okay I'll do it in a minute and and if not you can just press f11 okay okay so we have set 4D pd7 for the trigger this one so we you can check here okay This is 40 here we have set 40 bit number here okay 14 beat number seven so the port now is eight zero you want to see the bits you have we have set bit number seven import D to configure it as a uh that be to configure the pull up here okay we set the port five in 40 here we are going this here we are going to set this bit here okay just to make it an output okay so execute the instruction and we see it set so that way we can check that it's working correctly and you can see how it changes okay so you see pb5 is one because pd7 is one now if we want to check to change the value of pd7 you can do it in two different ways you you can use the new debugger console as we did in the previous example we can say set a ping D equal to zero so we are going to pin the set all the bits equal to zero okay that's it it's not refreshed here immediately okay but it's done okay it's done in the debugger so if we continue the execution now it's refreshed here and then this is zero now so the port B5 will change to zero the next time it's checked okay so this is a way to do it but you we can also edit the value here in the value in the menu here if we update the value we this is at one bit we can set it to one okay and then we can continue the execution and next time it's checked Port B is changed to one okay and in the same way we can we are not using the registers here but we can check the registers values okay we can also hear print memory we can put that memory address it will open a window with the memory portion we want to to see we will see in following examples and also very interesting is the watch the watch is very similar to the display if you remember if we want to display if for example we want to display PD as we have done in in previous example and we want to display Port B okay so we can see the input and output okay you you know we we can do it in the console here and it works as when done in the terminal we will have this information okay PDM Port B printed here but the watch is similar we can add an expression here for example we can write 40 or pnd okay and we will have the value of the expression all the time here and we can put Port B for example okay so we don't have to see all the peripherals and scroll through the peripherals and so on because we can watch here the information we are interested so normally we may try that unfortunately in right now Visual Studio code does not have a way to select the format of the of this data okay so we can remove the expression but we don't have a way to do it note that we can do any expression we like for example we can we can we have Hindi which is 128 because this is the seventh bit we may want an expression that makes it more easy to understand so we can see Pindi and we can a divide by 128 now this expression will be 1 when the input is 1 and will be zero when the input is zero okay and the same for Port B we can say we want to display port B divided by 32 so it is easier to to [Music] to check maybe if you if you prefer like that okay so as we execute our program we can do that and if we want to change the value we can do it as we have done before okay so our expression is updated so normally these these peripheral view this is okay for simple examples but when you try to debug complex program programs you normally want to Define your watch Expressions yes to have the information ready of exactly what you want to check okay Okay so um so that's it this is the an introduction to on how to use the platform IO development environment so what do you have to do if you want to create a new project you don't have to go through all these steps okay if you want to create a new project you can let's stop the debugger first and let's close it so if you want to start a new project you are in the platform in your projects folder you can just copy an older project okay or you can just download the the um I think it's over here you're not here anymore or now you can just go to these template repository downloaded as I have done before okay open with an archive manager and then you can copy it right to your computer and change the name okay my new project okay and you are set okay here you have everything ready you have a you have a source folder with your source file these are compiled you don't really need that and then you have everything you have the platform IO a file already configured okay it has the configuration and have comments with other interesting configurations that are possible but basically you are set just by copying the file okay but the first time it is nice that you do it a bit more manually so you understand what you are doing okay that's it thank you
Info
Channel: Jorge Juan Chico
Views: 3,687
Rating: undefined out of 5
Keywords:
Id: BM-w1pcekxA
Channel Id: undefined
Length: 36min 0sec (2160 seconds)
Published: Fri Sep 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.