 So we are on the STM32 USB library, so this is really some software that we give you for free It's a full stack that is functional for sure There is bug as in any softwares not abuse for sure But yes, it's something that you can use as it is and it works pretty well so Okay, sorry my pointer doesn't works Okay, sorry Okay, got it Yes, so it's integrated with cuba mix as we've seen before we just go in cuba mix Configure sync generate the code and the stack is over there So it's really easy for you to integrate it in your project if you start it with cuba mix supported configure configuration host or device for sure, but When you are host we don't support the hubs as I only answer this morning I already correct the guys about this topic and about the OTG are always or already run you about the fact that It's hardware supported, but it's not supported by our stack today. So Now the device library organization if you want you can have a look also at the same time in your Atolic project you will find those files, but we will switch from atolic on the slides that way you can find the files At the lower level here, we've got the UI USB IP So the hardware's the registers to access them. We will use our sorry about this It was the STM 32 H6 ll underscore USB dot C This file is really to access the registers. This file is really the lower level that You've got in the stack You can directly use it if you want if you want to reprogram all your stack by yourself You can do it, but it's a huge works and very complicated for sure Then we've got some hash out PC PCD dot C who will handle the year queue that's coming on our using this low level So we will receive some information from the top and will also use a register to configure and to push chains But you will handle all the year queue and we will see that it's very important Mainly everything's coming from a IQ from the from the from the bottom. Okay Then we've got a file which name is USB D underscore conf dot C If you look in atolic, you will found it in your source folder That's me. It's something that you are about to modify or to adapt or think like that But it's I will say between the really low layers and the device drivers It's earlier to adapt the interface regarding what kind of device you've got to ensure to have the communication with this There is really two level of if you were looking in your atolic project You will see this at the same level of the application But it's not in the organization at the same level It's really an interface from device drivers to the lower one, but sometimes you will handle and modify something there Then regarding the device drivers, so here we are in the folder middle where if I don't tell something stupid and we'll check after Here we've got some core files. So we've got a USB D core files dot C So here we'll just handle I will say all the setup request and think like that And we'll rule the request to the control request higher request or to the class if it's a request for the class Then in the class you can communicate with the application Thanks, the CDC underscore EF EF or interface So it's the one we already modified together when we want to send something on the VCP or to receive something It's really the lower the lower the upper parts of the stack In this application, we also have the USB device dot C Well, we say concentrate all the information of our device whereas the interfaces you make the link between the different software components We will see that it under the huge structures And you will be afraid by the next slide for sure because it was just a huge strict truth on pointer on pointer on elements on things like that and Then we've got a USB D underscore desk crypto dot C. I think the name is theirs. It's for descriptors But think about descriptors descriptors things some configuration some on points configuration on on point is more Link to the class So if you've got a part of the descriptor there, you will also have I will say the lower part of the descriptors Remember, we've got a device descriptors and you've got configuration register on point What is important such kind of thing will be defined in the class because it's in the class that you will define My on point is a bulk one. This one is for command. This one is for interrupt and such kind of thing Okay, so here you just have another view of the file organization That's just to afraid you for those who managed to read it at this distance because it was just the structures That are being dealt in the code. You've got here all I will say the device descriptors who pointing some descriptor Descriptors structures who point here on the class type descriptors It just some link What I propose is just to check in atolic What we've got So come back here Okay so Now you should Find out what I said to you here. We've got all the files that are the source We've got this interface one the usb deconf.c If you will remember it's a link between the middleware and the lower parts. Okay Here we've got the interfaces. We already modified together and The USB descriptors. So if we go in it You will find some function to access to the descriptor and also the descriptors So what are the class? What are the up-0 size and such kind of things so many information about the device descriptors? But you don't find the description of the on-point and something like that because it will be down inside the class file then we go now in the device library here we've got The core one which is generic and we've got the class one. So this one is really specific here At the beginning you've got the configuration so for high speed, but we should have the same for the full speed Yeah the full speed descriptors you will find many information and One of those information who could be interesting It's what are the on-point defined for the VCP because this morning we discussed in VCP, but do you have any idea of what kind of? Discussion is it a bulk is a chronos is that What do you think you have an idea about this? In fact, we will have three on points. Well, we will have some one which is not Can be I will say Imagine it was a common on point which is the type of interrupt this one is just I will say to Do some configuration of the communication, but we've got two on points on point out and I point in on those one are in Burke tip so what's we observed what we use this morning? It was a Configuration with three and points so I don't talk about on point zero who is always here But we've got one further in one further out on their bulk So our a or this later we send this morning go through this bulk And you come back with another bulk Okay, we don't choose this common The common on point wise don't choose this morning particular speaking, but it could be This is a standard word. This is as it is defined in the USB org Okay, so this is really to give you some points where are the information? Now what I will do I will just put a break point Inside the code or maybe I would just okay. Let's see what how we launch everything in the device Because we generated the code we launch it, but we don't have a look in it So if you are in the main You can see we've got some HL in it so generic Initialization for the main We've got some system clock config here is done all the clock configuration We have done together you remember we put the eight megahertz are some things if coming from another part We set all the the coefficient in the PLL to have got the good cloaking for the USB and also for our system This is under by this function. I won't go into details, but it's not interest GPIO in it. Okay. I think you know what is the GPIO? We just configure the one we seen together and for example when we added the software Output for the traces. It just added what configuration for ggpio with a proper alternate function and then we just call a USB device in it and We do nothing After everything is ready. I will say what's happening We initialize all the structures enable all the interrupts and it's only on interrupt That's there were some treatments that will be down inside the code So let's go what is it in it? so quite simple it just Do it in it first. So here you can see we've got a huge structure We hold information and we do the link with the descriptor So here we started to put some pointer inside another Structures, okay. I can go inside, but it's quite complicated We'll see a huge link, but I will sum up this in my style letter. Okay, just think here We do the link with the descriptors and A huge structures then we will register the class that's mean in the structures We memorize that we've got a USB CDC class that is available in our configuration So now we point on the function to access but to access but to accept some CDC connection Then we have to register the interfaces interfaces define the function that should be available As interfaces in your application. So we have to link all those things together. It's really what is done by those Different function if you go in it, you will just see mainly the copy pointers on pointers on different function And after the stack can found all the information together Then we start Started it just put everything in place and enable the interrupt at the lower level. I Really sum up the things because I just want to fix you Heidi about what is done. I Will go further maybe in the code after Okay, I will come back on the slide So here is an internal structures and pointer on pointer, but let's forget it. It's too complicating I think The unit I just told you about Okay, it just show that you take the descriptors and just put This pointer inside this huge Structure, okay, you can't read it. Just believe me just a copy of some pointers So it just create a connection Here when you register the class we do the same thing. We just register this function available to this Then you register the interfaces So it's allow you to see I would say to call from this side or for the upper side The different function that I hear if the one we use this morning receive FS But the control the in it and the day in it Then we start the USB device library, so When we started there is some LL in it So if you remember the LL for the low layers So here is the initialization of the first structures and we go up in deeper and deeper This function is in the usb conf.c and here you can see the different parameters that has been set It's created by cuba mix for sure. It's regarding which speed you are using the number of unpoints It's not the number of unpointed use but the maximum Unpoints that could be used frankly speaking because you can look here There is six on point declared, but we have seen together. We only use three four with U0 and Then you've got the speed in the structures if the DMA internal DMA is used This is only a variable on high speed. You can use an internal DMA But here the EP0 max packet size Then we can enable the soft the start of frame intergeneration So we already deal with this morning remember and configuration I could enable it on cuba mix on that allow you to generate a signal at the same With the frequencies at the set of frame which is One millisecond for the low speed high speed full speed. Sorry on the high speed 0.1 125 microseconds, sorry and That's it for the device parameters before location Okay, so then about some five four In our USB device, there is some five four that could be used There is one common five four for all the RX and there is one five four pair takes on point. Okay The usage of a few of five four It's allow you to push as much as possible that I want to send and prevent you to have a lot of Interrupt each time you need to see something so you can push the things and when it's ready It will be send for the takes and for the RX it could take and let you more time to do other things with your MCU So the dimensioning of those five four is really interesting or I will say it's a really fine tuning and that could change the performance of All your system because it's depending on this side that you've got more interrupt or less There is some constraint on them I think we will under this in another part the size the total size is 4k 4k back 4k bit if you are in high speed on if you are in low speed high speed It's one dot 25 kilobits for the old so you can tune it there So we can see that for the RX. We just say the number of 32 bits world Take care about this. It's a trick for sure it's not the size but it was an argument and 32 bits and After you've got the takes path of size on the difference There is no check that mean if you do a mistake there if you over sizing them if you Go upper than these parts. It will compile, but you will get in trouble for sure We are I don't say often, but I've seen many requests on with this issue People try to tune them, but they don't use them properly forget it was an argument in word and First an issue after Though for the first one there is no on point in the argument because it's a common one for all the on point on for the Takes five four you have to give the argument of the on point So now we'll try to transmit a full speed It will be the part that is a little bit long because I will go in each function But it's something you can go experiment by yourself by a step by step in your code If you try to do it with the code we generated together It's not very funny because there is an optimization on the code generation So when you do some step jump to other path, but you can deactivate it and go this So what's happened when I want to transmit something in the bulk? So first I just call the CDC transmit full speed It will just I will say set in a in a structures the lens or the stores or buffer sources on the size It will just give those points and then it will I need it with this picture will be Allocated on the hip. So you remember when you started the and zone will modify the hip size This is you may need to this allocation could be huge So depending on the class that you are using you have to adapt the hip of your project This is also a common tricks So really think about your hip side when you define your project You can always change it if it's not fit, but it's something regarding the class. You are using you need to have a bigger or smaller one so Now he will try to do the transmit packets so at this level he will just Change his date to the buffers to say is okay. We just copy I will say the address of the buffer So now we can't modify it anymore that mean we can't use it in the upper size now It's ready to be send or I will say it will be sent. So don't modify it anymore And we call a lower level part just say okay transmit this This one will call the HLPC detransmit and At the end it will call I will say LL function. So you have to be a P start extruder That's could be I will say a little bit The name is a little bit strange, but it's like this So the function here put all the unpoint registers how much packet will be sent What is the size how we how many packets then we just enable the file for empty That means you want to send something but what you need to know if if there is something under send You have to wait. So he just waiting that the file for his empty As soon as he will receive this interrupt will push Then the data in the file for So here we just enable the file for we still have the data I will say in our level and now the on point is enabled. That's me. We are ready to transmit data When you remember what will trigger a transmit data We are in bulk It's awesome trick. We should receive a token which is in As soon as we will receive a token in from the host now, we should provide some data Okay So yeah, we imagine. Okay, the five four is empty. There is nothing here then we will really write inside the five four Once you have done that that means you data is ready to be sent as soon as we receive the token so that I believe It's okay for you So yeah, we said we are really the most lower level So has I said, okay now when we have a hint we've got the data You remember that I've said that what happened with we don't receive a hack We will need to send again our data That's mean the data is still in the five four. Okay. It will be I will say remove from the five four as soon as we receive a hack This means, okay, we don't receive it So when everything in transfer again, we will have I will say some IQ So for the takes complete because when you send something you are happy to know if it's was sent or not if there is a Problem of such kind of thing. So again, it's an IQ that's coming from the layer level Down the information will cross the different stage to come back until the application so PCD data installed code batch and Then low-level So it's come just here Again, they just show you that it's coming to the device Sang the pointer on the structures on the data hint Then it was in the CDC data in static one. So in your case and We just set the takes data is sent to zero to allow a next transmit That's the way we are aware that the transmission is okay is as soon as the take state was set to zero That's mean we finished to transmit things. I think if I will remember in the next hands-on we will do is with Lou Bosch, sorry, we will handle this plug just to ensure that the transmission have been finished and we will do something with this So, okay, this is a bulk transmit Now in bulk RX some question about this part. I Know it's should not be clear for you. It's really to give you a clue Okay, think about just a structure of the file low-layer HL come come back to the middlewares with a device and come back to the interface if needed Okay, if you've got always this in mind, it's better after put a breakpoint in your code And you will see this stack quite easily. Okay So now we are on the bulk RX. We have transmit a Character, but we want to receive some of them. So here we need to be ready I would say because when we receive a how it that I could come just after though the endpoint need to be activated Okay, so our library enable the endpoint after an immigration that's mean we are ready to receive But after a successful received we need to re-enable again The on points that mean each time when you receive something if you want to be ready to receive to receive something again You have to re-enable your on point again When I say you have to this is done by the stack. Okay, it's not something you have to undo But you it's just to make you understand how it's working at the lower level. So Here to be ready to receive you we have to provide I will say some Eric's buffer to say, okay If you receive something pushes in this buffer So we prepare with a set Eric's buffer. So nearly symmetric with a transmission Which call the CDC receive packets. So in the device class Who will say we go through the comf to go the low level and Then again, we prepare to receive and again. We find the op start transfer. It's the same function than for the Eric's for the take sorry and Then everything will be under strength the PCG here to under So if I just I will say some of the mechanism Thanks think about everything should be ready at the low level to receive or to transmit on everything will be under by here Q regarding all the other on point that mean you will receive a Any IQ you have check what is an point concern? Okay. It's an point out. It's something I have something to do Yes, there is something to transmit. I push it inside the five four. I have something to read Okay, I read it from the five four and go upstairs. I Just give you will say a huge draw of the stack just to understand how it will be under So mainly it's many IQ from the low level and just push and get back from some five four With many intelligence on the top because this is just to send basic packet But think about the setup transaction with all this morning a Setup transaction, which is already some transaction that what command I should have do forget descriptor on such kind of thing All this intelligence is in the USB device core This one is really complex So here the bulk Eric's to continue you've got any IQ you need to read a packet and Then you call back the information to go upstairs to say okay We receive something data out to out stage We show the low level thanks a pointer on the different device. We can go in the class The CDC receive full speed. So we have seen it this morning in the interfaces Which is defined there So As I say, it was the most simplest one here on the control packet handling maybe I will go less deeper in this part because It's really what is tricky Just by explaining by sale by by slide is quite complicated. So I will give you some clue again, but here Okay Not an easy stuff for sure so again, we will have an interrupt at the data stage and seeing that we receive some data and We enable some interrupt on point setup. That means that we are ready to receive a setup stage call back We will have such kind of thing and we will be in the core Okay, and the core will look what kind of setup is received Remember in this first step the setup stage will do some setup, but we say something. I want a descriptor I want to set an address we've got I will say what kind of transfer that will be down in the data stage or Directly just set the address. We don't have data to send but you've got action to do Okay to with this So in the setup, he will check what is it for? Is it for a device is it for the interface or just for a standard on point or should I just a store? That's mean. I'm not ready to do anything. This is the different possibilities that will be tested by the core On regarding this it will do the right correct action just by calling Control send data that mean you will need to send some data and the send status And we will transmit data if we need to transmit data in the data stage So you can see that we've got an analyze of this setup stage and we decide if we are something to send or not in the data stage So sorry, we receive the setup stage and we decide regarding what we receive if we need to have a data stage or not So here the control and so it's the end then we transmit we receive again an interrupt to say, okay We receive something and then we will go back this information And after we've got the control packet handling so the output stage output again to send you remember the size of this that hire It was for the set the state stage when everything is okay Zero we don't send anything just send an empty packets. That means okay. Everything was okay for the setup So here is just some details how you can Navigate in the code as I say we copy many pointer to other pointer places So when you are looking in the code of the GPS class you always pointers on function For the interface and you can find the definition of those those function here So it was just when you navigate in this code when you see that you call some in it You just have to check the structures if you search the structures in all projects You will see normal anomaly one instantiation here with the definition of the real function For the device class structures, so it means so it's the same I mean for the device You've got all the device functions that are defined here So when sometime in the code you can see some data in you can just check the name of the structures So here is a USB D class type def and you will find exactly What is the different function for this? The device structures, so it was a top one who I will say concentrate all the information on all the pointer on the other structures So you've got the configuration the different on points some state of Unpoint zero The state of unpoint zero is is used during the stage the setup Transaction you have to remember what's happened on the on point zero to decide if you have to receive or to send data later and Then we can find those pointer the pointer on the class which is defined in the USB D CDC so with the the core of the class Then you've got the class data will handle the all the dynamically allocated buffer for this class Then we've got the user data where there is an interface is and finally the lower drivers that are pointing by the P data So I'm sure you will forget all those things As soon as I switch off or change the slide, but you can keep them come back to them when you are lost in your navigation in the code Okay, oh spot for the last part. It will be under tomorrow by Lubos, I think we just focus here on the device one Do you have any question on this part? Or have I killed you? It's okay. So as I say, it's more clue or way of thinking now you should have I will see in mind Just I was information in splitting the file Remember how it's Let's forget it. It's one hour. It's not possible. Just remember everything coming from interrupt from the lower levels So it's always triggered by interrupt at the lower level. You've got this story of okay I've got a rx file for on many types takes five four and I will just push or get data from this at the good All the setup will be in the core that will handle the core We just say okay this information or this setup is for device descriptors. It's for the class or sync like that Okay, now we should have idea of where are the functionality?