 now type of USB transfer first we got our device, our host and the software there is one physical connection I mean our 4 cables or 5 cables but now when we want to discuss from the host to a device we will always discuss a virtual connection with the on point on point is a channel to discuss that means when a host want to send something you talk to one on point of the device so to address a device you will need the address of the device on the on point each on point will have some characterization or I will say some qualities it's the way it can discuss and we will see we have got different on point type just keep in mind on point zero is very special is one used for the signalization of the protocol or the other one you will be able to configure it in your device and say this on point is for this purpose and is working that way we will see after how we do that ok so just for remember multiple on point different type of on point setup, bulk, interrupt is a chronos ok the squaring is not easy to keep in mind so I will just associated for you with basic USB device on that way you can fix ID setup ok setup is just for the protocol I will say ok so it's on point zero we will use some setup on point for the other one we use bulk what is bulk? bulk is typically when you are using a USB key when you are using a USB key what kind of transfer is there? you are not in time constraint I mean a transfer file do you best guy it's not something that you need you don't have timing constraint you want to have integrity constraint that means you want to be sure that your file is well transferred so we will have some check of the content ensure that everything is well arrive and think like that so keep in mind bulk is like my storage interrupt interrupt it will be like a mouse so you remember who driving the traffic do you think when I move the mouse the information is sent to the host any idea? or we think it's pulled by the host that means it's the host who will request to the mouse or do you have something to tell it to me do you have move? so interrupt it will be something so it will be really timing request from the host who will ask to the device do you have something for me so interrupt is there something that is timing and with information that should be acknowledged I will be sure to receive this one ok? so I will request request and request the last one is a chronos so as you can know there is chronos inside so some timing issue it is typically for the OU when you use a USB micro here you need to have something really time constraint but do you think you are I will say a constraint of the content any idea? do you think it's important to miss some audio frame or not? in fact you don't care that's mean when you recording and you do if you miss one or two frame you won't heard it what is important is to have all the packet at a good speed I would say you could imagine this or it's not clear for you for the audio you can miss some sound you can still understand the sentence I would say but if you don't have the right timing you will have some echo the word will change and something like that so it's not possible so it's just an example to fix your idea on the different transfer type bulk master wage so some things you don't mind about the timing you just do your best effort but ensure that the data are correct interrupt it's something that's come regularly or it's pulled regularly by the host an isochronos it's something it's time constraint and I really don't care if I receive it or not when I say don't care much of the time we should receive it for sure but it's not a constraint on point zero as I said whether for enumération and configuration so it's a setup we will really detail this part what is the enumeration configuration when you plug a device the device will need to know the host sorry need to know what is the device capability what is the device purpose in the beginning it will try to get the descriptors we will see after it's a huge structures who will define all the behavior of your device you can see ok it's a mouse how I will connect it which with on point and which type of on point all this information will be shared saying the on point zero maximum number of on point is 16 bidirectional I will say this is in the norm but that's really depending on your hardware we will see that some of our device can go up to 8 on some others much more that's really depending so it's something that you have to check in the data sheet of the device that you have chosen so USB pipe connection from host to specific on point so when you want to discuss with a device it's always through an address but also in an on point so we need both information to discuss with your final device so now we will talk about the basic packet basic packet could be seen at the word in a sentence ok now we see to do a sentence we need to put a specific words before and then for the one after the first word we will talk about is a token packet so a token packet it's composed of some synchronized fill so it's just a toggle from zero to one and then a PID so packet fill information would take which kind of token is it then we've got the address and the on point so through those both parameters I'm sure that this token will be received by one device in my network USB and in one on point in this device it's ok for you then we've got a CRC just to ensure that all those information are good and the end of packet is all also I miss but in the PID there is 4 bits for the value and there is 4 bit mirror it just to check or ensure there is no corruption just to show you there is 2 mechanisms to ensure this packet is correct the PID coherency and the CRC then we've got another word with it start of frame packet this is a special one who is just send on the network regularly by the host just to I will say do the timing for the full speed and the low speed this start of frame packet will come every 1 millisecond at any time always always if you miss it you don't send it during 3 millisecond that means the host is sleeping ok so it's really something that comes a lot on the network so you will see when you use a USB analyzer you remove the start of frame packet because they are coming a lot and in full speed it goes speed every 1 millisecond but when you are in high speed so the IS on it was 125 microsecond so it's micro frame so other word we can use will be the data packet so the data packet just to synchronize a PID who just say what kind of data is here and after the data we want to send a CRC and end of packets so you can see that in this world you don't have any address or hand point so it will be first token packet that will go on the networks and say ok I am talking to this hand point to this address then we will send some data packet to this one now you started to see the transaction transaction will be something like there is a token packet who will say what happened after and after we got the data that coming on the bus you got it this is really important this is a usb transaction the basic one is a different block now we got the word and we got the last word that is important is the acknowledge packet it's a packet who say ok hack,nack,store,net in fact it will be ok I will send you something and there is another words who say ok I have received it it's correct so I will put a hack so now you can see that using this word we can do some transaction and we will see the different transaction regarding what kind of traffic we've got remember we've got bulk we've got some isochronous and we've got some interrupt for all of them we are using this wording to do the transaction and we will see what kind of transaction we will do it's clear for everybody it's really important because it's the basics words if it's not working we can come back later but don't hesitate so I come back about this token packet what kind of token packet we've got we've got hout,hin,start of frame setup ok something important in usb it's the wording hout and in it's always from the host point of view we are host centric sometimes it can drive you crazy if you are not used with this that means on the device when I'm talking about hout it's something that I receive it's not logical but not natural but you have to think that way because we will always talk about a hout token that means it will be a traffic that will be generated from the host to the device but if you are inside the device it's a hout packet that means something that I will receive but keep in mind in and out it's always from the host point of view so the type of this token packet we can say ok what will happen after it's something that will be hout it's something that will be sent from the host to the device what's happen after is a in that means it's something that's coming from the device to the host we can start off frame so the specific frame we just on the net from the host the setup this one is just for the configuration to the on point zero we already talk together the setup packet will be always sent first by the host as you can see everything is I will say driven by the host so it will be the host that will use the token then we've got the data packet so when we've got a data packet we've got two kind of packets so now we're not in the say what we're doing we're just sending or receiving data we put some data on the bus or we read data on the bus but these data have two types zero and one and we will see that on some traffic we always send data first a data zero then a data one we toggle this flag just to ensure we don't miss one frame you could imagine what is the purpose of this it's sometimes you don't know if how many frames you will come and if you see twice arrive data zero say ok there is a problem I miss one data one we will see after in the protocol the purpose of this for the high speed communication there is some additional data data two on m data but I won't cover this in this presentation about the uncheck so hack, knack I think you know what is it store that mean not supported I will say in high speed and full speed low speed and full speed sorry and then we've got a not yet this is just for the high speed not yet that mean I'm not ready, try later for the moment it's not possible but at not meaning it's not possible at all that's the difference with the store and then we've got some special with error, split and ping I will have a couple of word on this but for the moment it's not so important so ok we come back on the address on how we allocate the address when we plug in it after we will go in the transaction sending this word so the maximum number of devices is 127 you know address zero is for the new one not for the host ok it will be for the device before a host attribute an address to it so we will see what happen when I plug a new device when a new device is plugged the hub will see something I will say ok so do you think the hub will want the host in fact no always send it's host centric it's a host that will request to the hub do you have something new so it will be always the host that will a, is there something change I just insist on this just to keep in mind it's always the host that is pulling the things ok the device don't change something oh it's not working ok I receive something no it's the host that request information from the different device or different hub ok for you so the host require is there something change and the host will say yes there is something on port zero I see something that have been connected so the host will say ok turn on the port zero that mean power this and let's get some information from it so first it will be with the address zero we only have one device with the address zero at one time and it will be temporary ok then it will set four to this one it just look which address is I will say free it will send it and after we got these networks so this is dynamically if you remove one it will let the address free for another one and such kind of things nothing really complicating it's ok for you the how we do the address couple of word of frame so this one is send periodically one millisecond interval for the low speed full speed and 125 microsecond for the high speed so it's a bad stemming reference ok keep in mind we don't have any line for the clocking so it's important to have some synchronization or kind of synchronization I already told you about the fact we got some device with internal oscillators which can achieve I will say the good quality to do some USB transfer but this device will use this start of frame to re synchronize and to ensure it was well aligned so it's really important for us to have this and so you can see in full speed you got such kind of I speed this one and the suspend command is detected by no start of frame during 3 millisecond that mean you PC don't do anything if you go in hibernation you stop sending the start of frame and this is aware about it so we can do some low power management or say ok I don't have anything to do for the moment on waiting that it was wake up again by the host or we can wake up the host there is a capability of this you know this because when your PC is in hibernation you can still put put something on your keyboard and you will wake up your PC or you move your mouse and your PC wake up so you got always the capabilities to wake up the host so now we have defined our words token, data and the onshake packet let's talk about transaction regarding what kind of transfer we will do so control set the chronos interrupt bulk remembers the associated example master edge yes so you just want to be as much as possible so there is nobody with book by the host for this for the isochronous where you've got a huge constraint of time on the interrupt where you've got some timing constraint the host will book some bandwidth for this traffic and if there is some places for the bulk it will put it there but it could happen that there is no and you have to wait let's imagine you are recording some audio on the USB and at the same time you do some file transfer privilege the audio with the isochronous transfer regarding the file transfer because you don't mind about this bulk ok so it's just important to understand you the constraint of this different type of endpoints because when you will define yours if you are not using the standard one from the standardization you can define your own and this is one of these constraints ok so hack next I am not storing yet I already talk about this ok now we started to define a transaction so as I say a transaction will be all be organized that way a token then some data then uncheck so file transfers only if USB of bandwidth and we want to have error on link that means we want to be sure that our file will transfer and it's not available in low speed in low speed you only have some interrupt transfer not this one so first we will have a token token always send by the host that means it's the host that started to talk in this token there is the address and the on point ok so first the host will put on the network ok now it's a in transaction for this on point to this device and then the device will receive it and will put on the bus ok this is the data you remember in transaction is from the host point of view that means the host want to receive something so the device will put the data first data 0 and the next one it will put a data 1 and it will receive a hack from the host to say ok I receive your packets ok the device could also say no I'm not ready to receive a token there is something that's not working we will see after we can answer stole that means no I don't support this kind of transfer do something else miss this on point it's not working like this my device is not configured for this so here just basic one so a first transaction the host want to receive something so we will put the token on the bus the device will receive it because you know it's for it's address on it's on point it will put the data 0 first and then expect it to receive a hack from the host that mean it's finish another example so it was correct and sending a hack now what happen we are in little bit in trouble imagine we send a packet the device send the next one so it switch from data 0 to data 1 just to ensure we don't have lose something but it was not received for reason and another on the host side so what kind of time out on the host say ok nack there is something that is not correct in what I receive so CRC is not correct or I don't know there is something in the PID for example it's not a data 0 it's something I don't catch so it could request a nack that mean that the device will send again the same packet so on the device side when you send something you will arise it from your 5.4 or from your buffer as soon as you receive the hack if you haven't receive a nack you should be able to send it again you got it this is hard by the hard word just for you to understand what could happen what you could see with a usb analyzer so device no receive so it started again ok the host request a new packet because he haven't received the previous one the previous one was not correct then he receive it but he don't receive it he don't manage to get it so he will request it again and again until he manage to receive it on have the hack the other possibility is to install that mean the on point is not configured it's not possible to do this kind of traffic so it's a way to suspend so here we have described describe the bulk in transition so that mean we receive some information about the file from the device to the host now the bulk transition out that mean from the host point of view I write a file in my usb key so here you can see first a token from the device to say ok device you will receive something when the device receive it or you can read this token then the host will put on the bus the different data and then it up to the device to say ok I acknowledge I will receive your packets or no there is something wrong in your packets I can't support it with this tool and not yet that mean not for the moment wait a little bit but this is for the high speed so again you can see it's quite similar I will say but I think it's always centric a hot packet we put the data and just receive the hack so not so much complicated so you can see the constraint we got some acknowledgement now when it's not working fine that means there is some corruption ok we send a knack that mean again it will send again the same data one and for the stall when it's not prepared under high speed it just wait just a couple of world on this so why in high speed we got such kind of not yet it just avoid to try to do many transfer for example in high speed so you prepared a huge bulk you send it and in fact the purpose is not ready you take all the bandwidth and it was waste when the host will receive a not yet he will stop sending this bulk he will just send a ping I will say an empty packet special just say are you available now and you save the bandwidth for the purpose of this not yet just to say for the moment I can't but don't take all the bandwidth and after we will use a ping just to say ok now the bandwidth I'm ready and I can send all the packets so data acknowledgement I think we already so two things the CRC and the PID complimentary value device and the hack when it's successful knack when it's not ready to accept or if there is a problem stall it stops the string mission so it's really it's not supported and ok so other things and think about the toggle data PID transfer you always switch from data 0 to data 1 so this was for the bulk any question on this no ok so now we are talking about isochronous so here no hack no handshake because we don't care if it's received or not when I say we don't care we at least receive some data for sure but there is no error management so here with time basis so one packet per frame so data 0 and up to 3 packets per micro frame micro frame you remember the size we've seen it before and it's not supported in load speed also typically audio playback audio recording so here it's a little bit different from the transaction syntax so always ost centric think about it put the token in ok I'm ready to receive data and the device just put the data ok I would say ok there is no much example there just in here just receive here we request some data we don't receive it ok we miss a packet but it's time in constraint so we have to receive this is a in transaction the house is much more simple you just say how to push the data it's up to the device to get the good reason to get it it's ok for you now the entire transaction so for the mouse the keyboard so data is relatively limited packet size that means we don't have huge transfer with such kind of thing you can custom it to have some very custom size of maximum you can send but I don't remember I think it's 64 bytes something like that but I don't remember not sure about this about the pool interval 1ms remember why always the same currency but you can also always say that it's not to the 1ms you just want to be pooled to 2ms 10ms it's up to the device to say I want to be pooled at this reason it's up to you because think this one it will book some bandwidth on your usb traffic often we don't mind because we often use just one device on our STM32 but you could imagine if you have many things to plug together you could have some constraints so always think that when you are using usb if you plug a host on many things on this it works less less well than when you have only one device we don't think about it because we don't see the impact but it has one maximum 90% of one bandwidth for isochronous so interrupt and isochronous can take 90% of the bandwidth and it's available on all the speed so low speed it's mainly for setup and the interrupt just for this one error detection and correction because you want to see if it's not working so transition both are on the same so here again so regularly the host will put in token ok I want to receive some data it will put the address it will put the on point and we know this on point is interrupt on point so we will receive the answers quickly on the next one and then we can uncheck ok I receive it or I not receive it you can do a knack install and for the out it's the same in the other way it's ok for you so now we've got some intransation I want to receive something it send the data one then on the next one you will do some sorry some data toggling so just say ok we have both the one because we have a knack there so it's still the data one that will be send until we receive a hack ok this is the purpose of this data 0 data 1 you ensure that you keep the data inside so always keep in mind also from the device point of view the data or host also is keeping in mind keeping in memory sorry until you receive a hack for this transaction for the output I would say not so much difference so a control setup it's a little bit more complicated because it's a transaction will be composed of 3 transactions so we'll see it's a transaction we started with a setup transaction then some data transfer and then last uncheck so first similar to the block just put a setup so it's a special token it's always on point 0 because this is for signalization and then it's always an out that mean first we will have a setup transaction I mean the host will say it's a setup transaction then it will send the data to the device who will acknowledge it this is a first step that is needed ok now I will say a complete setup transaction is composed of 3 phases this setup one some data transfer and after uncheck so as I say setup data hack it's always such kind of thing ok to the on point 0 transaction here just a error that is still the same so setup you remember I say it for signalization what is the configuration of the device is it a mouse, is it a keyboard I don't know a USB key and if you don't manage to get this information you will say ok I don't know this one I ignore this device you know this windows I think you already seen it and it's in the case that if the device don't answer after 3 setup so 3 setup to get the information you will say ok I ignore it ok so here is a complete setup transaction so there is a setup stage data stage on a stage stage ok so for the moment we have seen the word with token data on acknowledgement then we see some transaction bulk things interrupt and isochronous and then we got the setup which is a little bit different it started with a setup transaction who will put some of that then some data stage bulk transaction that means some transfer that will be just for signalization on a stage transfer which is an in out bulk just to say ok everything is fine so for the setup it's really one upper it's ok for you it's a point that is not always easy to undo so for the control rights in the setup we will say what happened after and in fact we will say ok what happened after is something I will send you some data so we will put in the setup we will say ok in the data stage it will be an out it's something that will come from the source to the device and we will also set here the length of the data that will be send ok and for the control read the same things then you could have some setup we just send information to the device and you don't expect it to receive something so what control sequence write that means it's a setup and you want to write something to the device first a setup stage so a setup token then a data 0 which describe that we will have some out transaction after on what are the lengths the number of data that will be received and the device just say hack then we've got the data stage so now ok we are aware the device that we will send in data and then we'll send the different packet with the toggling and just receive hack once we have received all the data we have some state stage that means something to understand if what happened before is ok have you received all the data that expated are you happy with what you receive so it's a intransfer that means you want to receive something from the device and he will send empty data he will send some data with a length of 0 and for him he say hack that means ok everything was fine previously if there is an issue he could send something there or here he can just send a store that is not supported or a knack if there is something that is not working during the transfer ok so it was described here how token so I think I already told you about this so at the end just send a zero length packet just to say all this transaction is ok the data stage was ok I received the information it was well for me as I said told that the command is not supported and the knack the device is still working on the command that something it's not finished so this was the control rights control rate is quite similar but now it's data that's coming from the device so typically they get descriptors when you want to know what are the capability of the device it will start with this kind of transaction always started with a setup with the data zero with information to say ok it will be a read sequences and I expect to receive this amount of data receive a hack and then you've got the transfer of the data with the data toggling on always some error on check for the status and the last one could be just to a setup but without any data to transfer could happen that you just have to send information and don't expect it to receive something from the device or to send something to the device so here it's quite simple just the setup but you still have state stage step to say that what happened before was ok oh this one I will skip ok so let's come back to this setup package what there is inside this data zero and what is inside describe what has the data stage what kind of transaction we are doing during this setup ok so we've got some request type just to see if it's host to device device to host so just regarding this you know what is I will say the data stage sense or how transaction do you expect it to send something to the device or to receive something for the device then so after you've got some type transfers and I will say some request format and here you've got the length on 2 bytes who will say the amount of data that you expected to receive or to send depending on the first parameters then the different request possible so it's different you've got some set status, set, set address so we already seen that it will be at the descriptor you connect so then they all say ok your address is this one for example when you do a set address you don't expect it to send anything else because you've got everything there set descriptors get configuration, get interface and synchronous from here is an example now at the beginning of this chapter I just saw you so here now we should better understand it it's not so easy that now it will be clear for you for the first step but ok we know we've got some transfer we'll be complete with a transaction so it's a setup one so it will start with a setup token ok so a setup transaction on the length is 0 so that means we will have no data to transfer so it's much more simple to define that means I will just do a setup and then I will have done check no data to transfer before I haven't lost you it's ok so now let's see so we've got again first the token so the token is coming from the host to the device as all the token because it's a host centric we say ok we are talking to the address 24 and the 1.0 for sure it's a setup so we are discussing with the 1.0 we know that then here the data with a set configuration we just produce like data that are sent directly to the device and we receive a hack from the device so here we have done the setup part of the transaction ok and then as it was 0 length there is no data transfer we just maybe come back on this we have this one setup we have seen on now we just have this state stage ok so in packets so let's check if it's what we've got in our traces here it was bien it was well in transaction ok with no length so we just steal a token then it was answered by the device with some data with 0 byte this is acknowledgement of our setup ok do you feel more comfortable now to try to read I will say some traces yeah more or less ok this is an example where I stole that means you do the setup transaction and receive a stole that's no so much experience just a couple work on the special split and ping you know this is some token we have seen before ok it's for high speed I will tell you just a little words about this one so the split is when you've got a host and a device who are talking in high speed sorry a host and a hub a host and a hub are talking in high speed ok very quick and then you've got a device which is just a full speed ok so I have to split I will say the traffic that means I don't receive in all micro frame all the information for this device but I will receive just a split of the traffic and then it will be reassembled by the hub which will transfer it this token is to say ok split the traffic for this device because you will need to receive less speedy you got it just to give you the idea but for sure we don't support the hub in our STM32 stack that means you can configure as a device as a host and you have all the stack for this but the hub is not supported in our device about the ping I think I already told you a little bit it's just to prevent to have some bandwidth waste because you try to communicate in bulk the device is not really stop sending a huge packet you just send a little packet and when it's ready I start it again to send my huge bulk ok about the bandwidth constraints so here you got the different speed and you got what is supported so interrupt and the maximum packet size that you can do so in full speed 10% is reserved for the control transfer and 90% could be reserved for the periodic transaction interrupt for sure if there is no of them or the band could be taken by the bulk ok on the high speed reservation is more important with the control transfer but as it's speedy the bandwidth is still bigger for sure