 Okay, so welcome in this new hands-on. So here we are on the master wage, but this time we are host. That's mean that we will plug a USB stick to our board. We should detect it for sure. Then we will write on it, read on it, such kind of thing. So we have to deal with the FATFS. We are also the, it's the OS side that will take care about this. So here, just what I've said, so as previously explained, we will use the SCSC command usage on the lower part. So just a little warning about flash stick. Most of the USB flash stick are not certified. Why we underline this in this hands-on? Because we have some, I will say some requests from customers say, okay, it's working with this flash stick and not with this one. It's because many flash sticks don't respect fully, I will say the known. So you have to adapt your software to ensure that it's working. Some customer complain and say, oh, on Windows they handle all the flash stick. But I will say they go out of spec. So maybe if you have flash stick that is not properly detected or things like that, you have to analyze the signal, analyze what is the traffic on the bus. Because now you know how to see it and try to modify the stack if needed. But that's maybe another topic. So let's start with this hands-on. We don't start from scratch. I mean, I already prepare for you the first steps that are always the same. So I just show you what are prepared. So I created the Cubemix project for sure. I've selected that I'm in full speed. I'm the horse mode. I use the external crystal for the quality that's needed. I think you will remember this point. We also configure one button. That means we will use a user button of our board just to trigger what we want to do on the USB stick. And I think that's it. Okay. Let NGPIO not our tag. So we select the communication class, so master age one. No, sorry, there is a mistake in the slide. It's not communication auth, but master age one in the middle world. We configure the FAT, FAT file system on USB stick for sure. So we say, okay, we are with FAT SS, USB stick. That means we will generate, Cubemix will generate already everything integrated. That's mean your FAT FS is linked with the USB. And you are sure that you can just create a file with F open. We will see this in this on zone. There, CC clock. And the USART three that will be used to just to get out some traces. Okay. Other things I already prepared to you. Remember, we have to connect the PG-6 just to the power delivery. So it has to be done. Then I generated a project with this MSC host. So you already have the zip, you can unzip it. So just show you that I increase the IP and the stack. Always the same issue with something you have to remember. What I already down is the driver of the VEBUS. So I just added this pin enable and disable when we detect it. Just to drive the level of power. And after, this is our exercise. So let's switch to hydraulic now. So first let's import our project. To import from an existing project into workspace. As usual, I will say. We have storage in the USB training on zone. Melano and on air. So just import like me. Nothing else to be done. Okay. So what we've got in the code generated. Let's have a short look. So as usual, the main, the middleware, we've got the USB host. We've got the VATFS already generated. So configured. We've got our on the master which previously the core with all those and the master which places with the SCSC command that will be used. So nothing new here. Just in our part, what have been generated as usual the USB H in the score comb file which is an interface with the lower part with the driver, the host and this file who is a mapping I would say between the VATFS and the USB command. Can just have a short look here. So here we just define the different function that will be used by the VATFS and for, let's switch to the header maybe. It's sorry, I have difficulties to switch to header. Toggle headers, okay. Just to have a short look in it. So here we will define this structures which is the one that will be used by the VATFS. So we need to have the, this conditionalize this status, this read, this write, okay. So it's exactly what is done in this file. And we just mapping to this function. And if we go in it for the read, we are using the USB H, MSC read and MSC write. So all the things that already declared are we see in the USB stack. Okay, so let's come back to our project and let's see what we have got to do. So here we still have our list of tasks to be done. So three tasks here. What is the purpose of this hands-on? So as I say, we will detect the USB key, but this is already configured. And when we detect it, we will have to mount the file system. Then when I push on the button on the blue button, the purpose is to create a file, writing in this file, read it back and just compare if it's matched and just do some traces, okay. So for that, we will need to modify the project I delivered to you. Okay, let's be a little cleaned up. So first we got on the USB host. I will just use one. So we are in the host process. And this is, I will say, the main function that is regularly called. And you've got the different state of your application. So here we've got the connection, the application is ready. So now we just have to mount the file system for sure. Okay, so something I will say, trivial or I will say it's more what we've done when we want to use the FATFS system. So okay, I just give you some clue. We've got already defined on variable USB path. So you can find them in this file, if I remember. Okay, so the FATFS system, we've got the variable. We already have the USB path which already declared with a good volume. So let's go again to what we've got to do. Okay, so here, let's do it together. So I don't know if you are familiar with FATFS, but we just need to F mount. F mount, the first argument of F mount will be the USB file system. So USB H, well, we just copy it because I'm a lazy guy here. Then we have to give the USB path and just the last parameters. It was just too safe to sync or not if I will remember. Let's see if I can find it. Open declaration, option byte. Doon and moon, delimount or moon to it immediately. In our case, we can just delimount when we will access it. So just zero. Okay, let's check that it's okay. So we have some return code for sure. And it was the FROK. So if it's different from okay, that's mean we've got an issue. So maybe we could write something on the route to say, okay, it was not working properly. Let's reuse this syntax. Let's write a little message that F mount fail. F mount fail. Okay, I think that's it. So here we just mounting the system. Okay, those that were the first step. Second step, here we are in the main, so the main. We've got the in need, the system clock, the different initialization of the different we'll say layer or components. All after we just add this while where we've got the auth process that is a regular code. And here it's not something very clever but we will just add a code to this function. This function is the user function that will check the current written status do if you need to do some things. Let's see what's happened here. So here we just need to have this code. Something not very clever. Oh, sorry, not very clever but it just to show you when this function is called. That means we're in the main loop. Something really bad is here. I already declared it for you for sure. So let's see now what we've got in this function. And this is the third step that we have to do. Here now we will write what exactly we want to do in our application. So in the user function, we just check the pin C11, which is the button. So when the button is pressed, we will execute this code. I just had a directive just not to compile this part because as you can see, you have to complete a chain, a string, sorry. So you have to modify this to do the action. So first let's activate this part of the code just to ensure that we manage to do it. And then now we will complete this file just to do the different modification we need to do to ensure that we manage to open the file and touch kind of things. So let's complete the skeleton. First, we need to open the file, sure. So here they have open function. The first arguments will be the file name. So here we've got this, my file. I should have declared it for you if I will remember, yes, zestrotor, okay. So this will be the pointer on it. Then we need to pass the name of the file, already prepared it. So as you can see, we've got a counter that means when it will create more than one file, it will be name one, two, three, and touch kind of things. So the name of the file. Then there are another arguments for the fopen. Yes, we have to select if what we will do, if we open it in write, if we want to create it always, if it's already existing. Here we've got some special flag in FatFS, which is find create always. So that means if it's already existing, we will create it again. Then we want to be a write access because the first action we will do is just to write in this file. I hope I spelled it, no, not properly. Okay, just check, okay, write, open existing, creating new, creating always. I think we've got the good flag here. So, okay, and let's check that it's not different from FLK. So now, if we've got an issue, we've got this message cannot open file. If it's okay, now we're in this branch. The file is created within the traces. So first, let's write something in this. So you can use the variable w text and byte regions that have been declared for you with this text that will be inside the file that you created. So here we just need to do an F write. Oh, now we have to path the argument. Oh, I forgot, it was an address of it. Yeah, sorry about it. So let's pass the structures of the file. Then the text we want to write and the size of it. Size of, okay. This function will return the number of bytes that have been written. So let's use this function. Okay, let's check the prototype. Okay, pointer on the file object, the buffers. Oh, sorry. Okay, it's not a written error, it's just written in return, okay, it was an error, okay. The return value will be stored in the rest that we will test just after. Okay, so now we just want to be sure if we need to uncast usb, okay, and this one, what is exactly the prototype? And it should be okay. Okay, so just let's close the file now. So just, then we check the number of written bytes. If it's equal to zero. And if it's okay, then we can open it again and just read it. So I would say mainly the same that F open that is here. But this time we will just do it, let's do it, but just in a read mode, it could be. So here the purpose is really to show you that all the FATFS should be under in this part. So now you can drive just created files. It's quite simple. So, okay, so the F open now will be in a read mode. So just F read, no need to create it again for sure. Okay, file open fail, we've got a message error. And if it's well done, let's read it. So let's put the read F read, E M file, whether we see the same structures, then the text variable can be used. Then we will raise the size of text them. Okay, and then we just need to know the number of bytes that have been written. I think I've missed something here. Sorry about it. Okay, if that's okay now, I just double check already to gain just to be sure. No, no, no, do the right to transmit. Okay, so I think it should be okay. Read and just do the F close again. okay so let's try to compile i hope i forget nothing but no they should i should have okay let's build it should be a we should have some some taxi roll or i will be really surprised okay let's increase the size of the windows just some running okay good i can feel that something is not good there and declare okay so i should have not fight it okay it's not a gfe i think okay on this one what i've done my fail i miss okay over the one thing 30 okay let's check so i still up okay i miss this one this time all those in written file i hope it's the last bug okay use the function so now i still have any shoe there to have but just a half for sure sorry for all this syntax error on my side in live okay i probably miss spelling this now which will build i hope so yes this time it's okay okay so sorry for all this issue when i'm just write the different things i'll hold the developers and it's not very easy on the ballpoint side but okay now it should be okay let's download it on our targets okay so typical connection and now i don't choose so first i will let's switch to first let's check which you are we need to do okay so in your system just check okay the virtual compose is 87 and let's use to our term already connected to the good and let's see what is configuration for the serial ports okay both rates good so everything should be okay so now let's plug the usb stick on our board so we need a hundred letters for sure let's just forget and if i plug the usb key we've got application ready so that's mean now the application detected remember we moved the file system and now i will push on the blue button okay so the file have been created verification is okay remember but it's equal if i push the button again create a second file okay i unplug the usb key and now i will plug it on my pc just to show you what have been created okay so if i show you here we've got the remote disk and you can see those files that have been created with sorry usb also very messed up each example so i think it's working so that's it for this answer so what we have seen that thanks kubemix everything it generated very properly and very quickly and we just need to do some i wish we can just use it frankly speaking you have seen that we've just managed to do everything we just don't do just write something to access a file system as usual so nothing specific here i will just come back again on this just think all the plastic are not certified just remember this for sure is the message of this hands on also and as you learn during the theoretical part now you know how to check what is on the line what it failed during negotiation of the kind of things okay thanks that's all for this hands on