 Let's start the new and on so this time it was the master edge DFU host so that's mean we want to update The firmware which is inside our boards so What is we will create a first firmware that is able to detect a USB key on This USB key you can read a file which is the future firmware you want to run on your Target you can read it and we'll flash it at a specific location on after on the next boot We can push the button on jump to this new firmware, so it's way to update the firmware on your target It's a really common usage or use case that is needed when you need to update It's also what we call an in application programming. That's mean it's from the application that is inside You can program the flash on boot on it So let's see how we'll do this As it's written there, we will reuse the previous on zone We have done the master wage host because it's always the same mechanism to detect a USB key to have got the file system to read A file and then once we have read this file, we will flash it at a specific location Here only been a reformat just to have something very simple to do together for sure So let's keep all this part with describe What need to be done because I already done it. We already did it for you Just some information about what we prepare for you We are expected to have at the root level of the USB key a file image dot bin That will be written in a word flash after we proceed of the firmware We proceed again the firmware dates So we will see much more in details I think I've got nothing else to do how we already deal with it in the master wage host So let's switch to a tonic So let's import The archive we prepare to you Next one. Okay I take it all the way that's the same location see USB training and Df you asked So if we compare with the previous hounds on Nearly the same structures for sure because it's exactly the same infrastructure. You can see a new File which is flash underscore EF dot C just something we provided to you It's just a level of abstraction to access the flash to read it and to write in it So we can eras the sectors. We can write in it You can get the same tools It just to I will say simplify our project so Now let's see in the main Just to describe what this application is doing first when we boot we initialize everything for sure and if You will press the blue button You will jump to the new application which should be at this location already defined Okay, it was in the second sector. Okay, so we reserve for our application It's first sectors and the application that will be downloaded will be in the second sector on Other boot if you press a button you jump to this new firmware or you keep in this in application programming process So the in application Process is just there here again. So we just boot it without pushing the button The USB is ready. As soon as we detect a key We know that the app will be coming application ready. That's mean we are ready to do something if we press the button and release it and then we can access the file on the USB key. So I said The name is artcubedimage.pn This is just an example because it's something that you can take and verify if you need and It just to make you understanding. I will say the principle So we open it for sure. We can read it. We can read the different action to First it was just eras the sector because we want to eras if there is a previous firmware It's something we will need to do and then we can see here The common program flash memory where we will read the different address address And then with the f-read and then we will program for the different action we have to do. So let's check our our task to do Okay, so here we've got three tasks to achieve this hands-on the first one was to I Increase the size sorry about it To eras because we need first to eras the sector. So to do it Okay, I'll tell you that we already have some Flash interfaces with a different function. So first we have to unlock the flash Then we will error the sector or we just give the errors the sector address that we need to eras So, okay, let's do it So first Let's unlock it first I'm lazy and I don't want to type everything as usual Here first I unlock the flash Sorry Then once we have done this we just need I will say to eras it. So let's check it Flash interfaces Okay, the address will be the address of our application. So we have seen it before If I will remember it should be their application address again and Then the return value. I don't remember it. So let's check Eras sector Okay, zero if it's success from zero then Let's move some error message See each and let's say something like her has failed. Let's get stuck there if we've got an issue I prefer not to go further if we don't even manage to eras the sector for sure. I Think that's all for the first action Yeah, we eras it good so Let's come back to the second action So now We are in the command Program flash memory. So here we open the fight so I'm a read I will say Buffer by buffer in the in the F-read and now we just need to flash this So Flash interface If right, we need to address first as first argument and then the data So Okay, so the address when you want to flash Let's say the RAM address in the buffer the address of the application is where we want to flash Okay, then we can see that this one will be upgraded with the different side of what have been already flash so Here It was this one First on here, we've got a counter to how we say path the buffers So address after address so we've got a program counter need to be added to this address I think that's it for the first arguments here where we want to flash Yeah What we want to flash so here we can see we've got the RAM address which is a pointer on the buffer so Let's take this one and then we just need to pass it So we need also to add the program counter and we need to This is just a address and we do take the content of this. I'm sorry Yeah, maybe a cast would be better just to ensure you in 32 enters Okay, I think Let's take if it's different from zero. I hope it was the same logic whole life previously And then if we've got an issue, let's do some choices So let's take another Message from here and this time just say let's get stuck here. Okay. Let's read it again The address with the program counter should be okay Then enters directly the RAM address press program counters. Hmm. That's so good. Okay. Let's sell this Okay So now I would say all the code is ready to flash our content The next thing we want to modify it to do the jump on the user application on the next boot So if we click just on it Let's see what we've got to do. So here. I give you some information in the currents Where you can find the address to jump in the application? First at the application address plus four you will have the entry point. So where you need to jump the stack Pointer address will be available at this address. Okay, and to set the stack pointers You've got this function. So I would say mainly what we will have to do We just have to get the entry point for sure. Then we have to set the So stack pointer and then we can jump at this location that we read just before I Already defined for you some variable that we can use jump to application on the jump address So first, let's get the jump address So jump address where it is. Oh, it's just say that it was at this location. So Let's take this Let's take the content of this location I think it would be better to cast a little bit just to ensure we don't have any issue on it So it was a pointers on you in 32 pointers something like this It's already written there. So I'm a little bit not a little bit. I'm fully lazy past here So let's check the brackets soon You just So here we've got pointers take address. So this is our jump address for sure After we've got a variable jump to application. It's just a pointer often and function how you can see it So it just we need to convert who says this address in a pointer function So Just a cast operation, okay So now we're ready to jump But before jumping we have to set the stack pointer. So Let's do it We've got a function already defined for you. It will be at this address So let's just do it that way with a past Okay, I think it's good and then let's jump in the action in the in the function. I think that's it Okay So I propose you try to compile. I hope I don't have made too much mistake My PC a little bit slow this morning Okay, why it's so slow Oh, oh, sorry, I will try again Build the project. I hope I don't have a problem with my PC Okay, just very slow. Sorry about it I should ask too much task on my PC many warning, but the girl is finished Good Just have a look All these difference warning. Yes, it was it to do that I live. I hope I don't have any issues Okay, so let's flash it Sorry Okay, the flash is ongoing and I'll start the application So now let's open Our terror turn So don't forget you need to just to check what is a combo that she is used by your application Now let's prepare our USB key with our binary. Sorry. I forget this point because we want to update something. So If I just show you Okay USB training in the hands-on Yeah, we've got here and I prepare for you the binary should be just No, sorry And To okay, you've got the USB here. So I just plug a USB key We'll just and I just take this one and copy it To my USB key at the root level as expected That's it. Let's unplug it. So now I plug the USB key to my board So first we can't use that series in the textual application is ready So press the blue button to start from her date. So I press and release it The downloading is ongoing Okay, good. No error messages. So it's a good chance to work. So now we will Push the blue button and push your reset release the reset By keeping the blue button You can see on your board that there is two lights that have blinking we have updated this firmware So I will say mainly that's it. You've got firmware updates that have been done by your application As you can see, you know, it's not so much complicated and very interesting Okay, that's it