 Okay so it's time for a lab again and in this lab we're going to have a look at creating a device tree so that we can use a pin to do a function in the application. So what we're going to do is generate our device tree we're going to add a timer 1 or a PWM signal on timer number 1 to our device tree that we currently have. That particular PWM is also connected to an LED and we're going to set that LED to blink once every second. So yes we are going to use a dual Cortex-A7 to flash an LED. Something about us engineers you like to see an LED flashing it means you know that everything is functioning correctly in your circuit and the timings are working well. So what we have on our MP157C discovery board is from the schematics you can see that port E12 or PE12 is connected to LED number 9 which is one of our green LEDs on the bottom of our circuit board and if we look at our datasheet PE12 is connected to timer 1 channel 3 negative. So it's timer 1 channel 3 negative we're going to use to control the LED which is going to cause our LED which is on PE12 to flash on and off once every second. So first thing we need to do is make sure that our Cube MX firmware package for the MP1 is unzipped and extracted correctly so if you're using our download from the Google Drive then we need to make sure that this package has been unzipped correctly. So we've got these commands there to enter into our terminal window. So if I go along and do that now so it's in this terminal window I need to be so they're yellow commands. There we go so that's now zipping the library files for the MP1 into our repository location for our Cube MX tool. It takes a few minutes to do that. There we go so that's complete. So now we want to create a brand new project using the Cube MX tool. So what we're going to do in the Cube MX tool is we are going to select a board so that we get our discovery board to appear and we're going to create a project with all peripherals initialized in their default mode. This is important because our base demo needs all those peripherals to be set up in default modes so that the current device tree will match with the new timer that we're going to add so we do need everything else enabled inside there. So if we go back to our Linux environment Cube MX should be installed here on the left hand side. I launch Cube MX and if you get this proxy message up then we can say no at the moment. It just means you need to go online and download and check for any updates. So we want to access a board selection our slide said should now bring up the product selector. The quickest way to find the board is actually using the search part and key in in the part number. So it's STM32 MP1 57C and you can see there it's now the top of the list dash DK2. So if we double click on that board and there's that box we say initialize all peripherals with default mode so we need to say yes and then eventually we should get presented with a pinout diagram. There's the pinout diagram for our board. Now the first thing we need to do is give our project a name and a location. So if we move across the tab so pinout and configuration is what's currently highlighted. If we move across to the project manager tab and if we give our board a name and a location project manager tab. So the location is correct so that is the correct location home osboxes desktop. So we need to give the project a name and it was DK2 underscore timer underscore a seven. So now we need to go back to the pinout configuration tab and we need to follow these steps through. So we need to select the timers in the left hand side scroll down till we see timer number one. We need to assign it to be in the a seven nonsecure context and then you might need to scroll down depending on your screen resolution to see where channel three is. Then you'll hit the little down arrow to the right hand side of channel three. See all the different configurations channel three can be and we want to set it to be PWM generation channel three negative and then in the bottom half of that screen we want to click on the GPIO settings and to make sure we've got the right pin that should be matching our schematic from earlier which should be PE12. So if we go back to our Linux or our Cubamex go back to pinout and configurations so expand timers. Timer number one we have to set the context first then we hit the little down arrow and you have to scroll down on this list till you see PWM channel three negative and then if you click on the GPIO settings which is defaulted for me and it's PE12 so we definitely got the correct pin that we need for our projects. So once you made sure it's PE12 we can then hit the big blue button in the top right hand corner just below all the social media icons and generate code and then we want to open project when we're prompted to. So generate code is up there so it's now going and pulling from those repositories that we extracted earlier to generate our project. We now want to open project but if our file association is correct it should automatically open a system workbench project like mine is doing here. So system workbench is an eclipse based GCC environment so we have to define a workspace first so it's given me a possible workspace location I'm going to accept that and say okay and then it should eventually open the actual project in the environment. So successfully imported the project so I'll say okay make that bigger there we go and if I now expand everything on the left hand side you can see everything that's being brought in for the project. If we go and expand device tree for the A7 and the kernel we can see that we now have a device tree source if I double-click on that source file and open it and if I now scroll down to about a line 1174. So there we go it's about 1174 we can see that timer one has a PWM pin generated by MX so QMX has generated timer one with PWM interface and then if we scroll back up to about line 451 or 453 to be exact we can see there that timer one PWM generated by MX is on port E12 and it's timer one channel 3 negative. So that's just to prove that we've now added that extra peripheral into our device tree that we are generating. To build the project we go and re-highlight the project and we go and hit the hammer. So now that should go off and build our project so if I go back to my console window we can see what's going on. So fingers crossed as you always say we're doing anything live hopefully we will get zero errors and zero warnings at the end of this build. So there we go so we've got a file size it's complete and we've got 11k of data there and we've generated the L file and a .hex file so the project is built so that we can use this project now. Now for the sake of today we're going to save time so that DTS file that you've just seen that the cuba mechs is generated we can't use the DTS we need a DTB. There are some commands that you need to enter which are coming on the next two slides to actually generate a DTB. For the sake of our hands-on today we've already generated that DTB and it's in the input lab material that we've got on our memory stick. So we're now going to use that DTB and copy it to the target. If you want to do the conversion there is a lot of typing to do here or a lot of copying and pasting you can follow these slides along so the next two slides as I say it is it's practical slide but we're actually defining it as information only. So here you have to go through the commands and it will convert the DTS into the DTB rather than using a memory stick I'm using s copy here down at the bottom of this yellow box and then once you've done all that you would have the same DTB we're providing you on the memory stick and you now need to copy across and then sync and reboot again. So we're going to do it from the memory stick we're not going to do those two slides because there's a lot of typing and a lot of places where we can get some errors. So we want to go back to our minicom window so you shouldn't have to do this and you should already have this window already open inside your host environment. You now need to plug your USB stick into the target board so it was already on the USB stick you had at the start of the day. If not you need to copy it to the USB stick from the folder and copy it onto your target board. Again as we saw earlier as soon as you plug the USB stick in your terminal window recognize that a device mass storage has been attached to the target board and then we will need to mount the memory stick and copy the file across. So if we now go back to our environment and we go back to our terminal window that one so you can see our mass storage has been connected and now we want to mount our memory stick and as before mine wasn't unmounted correctly and now if everything is in the default locations on the memory stick we should be able to copy from our location into there and then we want to sync as normal once we've done a copy and now we want to reboot. Now if everything has gone well with our copy across when we enter this command now we should be able to see our PE12 has been configured as timer 3 channel negative and then we will be able to observe that there are no parameters set for the period and duty cycle and polarity we'll then have to go and set those. So if we start with our cat command so that we can see if our port E12 has been configured correctly. So there we go so our port E12 is there it's been configured so our copy has gone across and our synchronization has gone through correctly so we can now see our port E12 and now if we go and see the actual PWM parameters we can see that there are no parameters currently set so we now need to go and set the parameters. So to do that we need to change directory so that we're in the correct folder for our PWM and then we need to go and enter our parameters for our period and our duty cycle. So we'll follow those steps through now. I'll change directory. Once we've entered our period in our duty cycle we can now then send through either the command echo1 into the enable bit or echo0 into enable bit and that will have a start or stop the PWM and then once our PWM is running we can then go and have a look at our PWM parameters again and we'll see our parameters are visible and when you enable the PWM hopefully on the underside of the board near one of the Arduino connectors you should see your green LED flashing. So let's go and see if we can view our green LED flashing so I will send in our echo of one for the enable bit so hopefully now if you turn your board over you should see a green LED flashing and if we go and view our parameters again using the cat command you should now be able to see that it's enabled with a period of one and a duty cycle of that's off the visible part of the screen there so you can see that things are enabled and if I now change my echo1 to an echo0 so your LED should have stopped flashing on the underside of your board and if we look at the values you can see it's no longer enabled or you can see is the period and duty cycle values again.