 So, right now we are moving to first theoretical part of this day and here is the topic USB hardware design with STM32. What we are able to see very often that the customers are using the design from our board. I see it very logical step before I entered ST as a student. I make exactly the same, my intention was okay, they are manufacturing it, they should know how to design it, it should be correct. Unfortunately, this is not the true and we are trying to make everything possible to force the designer to make it correct. Unfortunately, ST is composed of the many groups and so for example the MCD group microcontroller is not directly connected to the group which is taking care about the ESD protection and put together meaning of these two groups and then forced to another group which is designing the boards. It's a nightmare. So, we have at least collected the information for this group and put it into this material. So, we have here the guidance how to make it so that everything is correct but as you can see it's working also with the not exactly correct design. So, starting by example with the typical connection. This is the connection from the nuclear boards you have also available at your desk. So, for the OTG there are the D minus D plus so the data line of the USB. Then there is the VBUS pin. On the VBUS there is the typical the 5 volt provided by the host application and device can be powered from this line or it can be self-powered depending on the application purpose and also from the VBUS line you can check the connection, this connection using the PA9 TB13. I touched a little bit yesterday. I will talk about it a bit more later. Then on some devices that will be covered by friends a bit later. You need also to have the external 1.5 kilo pull-up. The pull-up resistor is there is there for the detection of the USB device. In the newer IPs, newer devices this pull-up resistor is already internal but for the older devices you need to have it externally and handle the connection in your application. So, for our board F4 this pull-up resistor is already internal so we don't need to take care about it. It's turning off turning on inside of the application. You are able to find for the bit which is controlling the pull-up resistor inside of the reference manual. Then very important thing is the ESD protection. From the specification ESD is not any how touched so it's not exactly mandatory to use but it's very strongly recommended to have the ESD protection for the real-world usage to protect your device. But here comes the problems. On some older ST boards, so for example the Discovery boards for F4, F407, 429 the ESD protection use was not correct and have the internal pull-up resistor. I have it on one slide later so I know it's a bit or I can jump there as I'm speaking about it. Okay so this is the old design. So this part have the internal resistor on the line. So here between the D plus out and D plus in there is 33 ohm resistor. So this 22 ohm resistor are used here only as a workaround to have correct USB signal as we are using not correct part. So in the parallel combination we have 13 ohms and it's able to communicate but if you choose longer cable for example up to 5 meter which is out the USB there is possibility that you have the problems because the electrical signal are affected by this resistance on the bus. USB IP inside STM32 already matched the characteristic impedance so there shall be no serial resistance on the bus. So we are able then to see that some customers are using the design with 22 ohms because they see it here but then with some different ESD protection so there is no meaning why to use the 22 ohms but that's also our fault that we don't have it so clearly in the documentation and we made it like that. I'm sorry for that but nothing more I can do right now. So back to the our original one this is the ESD protection used on the nuclear board this one is correct from the signal point of view it's not harming the signal it will work correctly also with the 5 meters during the electrical testing I will show you some measurement that you will be able to see it on the on the oscilloscope pictures but what I then get from the ESD group it's not exactly correct for the complete protection of the lines so this is the theory I'm not able to understand at all so some I don't know time constants how quickly it's able to discharge the charge from the line and so on so I just took their guidance and their recommendation for the correct parts. So a bit different part shall be used I have it I have mentioned it a bit more later with complete schematic of according our recommendation. What have it the last pin we have here it's the ID pin used for the OPG functionality so using this pin it's decided if you are acting as a host or device if you intend to switch so for one purpose only application you don't need to handle this pin you don't need to connect it to the microcontroller only connect to the ground it's a short later. So this is for the device and if you intend to act as a host you should also provide the voltage on the bus so here is the LDO for controlling the voltage of the bus and as a host you need to turn it on to provide the power on the bus so here is no problem GPIO we've pulled down to have it disabled by default so we already passed this slide so now for the recommendation for the ESD group there is multiple parts that are recommended according to the usage so for the basic usage device only powered from the bus so you don't need to check if the PA9 for the V-Bus connection because you know every time you powered you are connected to the USB so you don't need to check the V-Bus so just simply use the USB LC6 slash 2 and connect the D-minus ground V-Bus and that's all the part fit the need of the USB it's also recommend it's also capable to have or to handle the high speed communication now we are more as talking about the full speed because for the high speed it's already possible to use the guidance from ST boards datasheet this one is correct with the full speed is the problem but for the high speed it's mandatory to have the EMI filter inside from the ESD point of view again so it's better to use this part because with the USB LC6 we would put this filter additionally so it would be one additional part and the cost would be higher so this is more optimal way for the high speed so here is the typical application so host device without the ID so no OTG and device self-powered battery powered sorry bus powered only but for the self-powered device it get a little bit complicated because as a device you have the poor resistor on D pass and you also need to detect if the whole if the device is connected or only suspended so you need to put the bigger version of the USB LC6 with the more diodes inside and connect in different way so the V bus is not connected here so it's not protected on the upper side or through the diode but you still are able to detect the voltage on the D plus and ID pin otherwise it would go through the diode to the poor resistor so we would not be able to detect with the poor resistor V bus sensing and so on there is also one hands-on in the slides we have passed so it's for the HID device low power and there is shown for what purpose is the V bus sensing used so maybe I could take a chance and explain the V bus again so the purpose is if you are a self-powered device so the power is provided from some other source or up to you are charging the battery then from the USB you need to somehow change your behavior according to the state of the USB so if the USB host go to the suspend so for example if you put your laptop to the sleep the device is still connected so the mouse is still connected it's also capable to wake you up but from the specification point of view the amount amount of current you are able to drain for the host it's limited depend on the configuration it's limited to two and a half milliamps or 10 milliamps and this can be quite restrictive so you also need to go to some low power mode or or some disable some functionality because it could be possible that if you extend the consumption host disconnect you this is not true in the practice but it may happen if you violate this condition so for this purpose you should check if you are in the suspend so the there is no activity on the data lines no start of frame just the suspend or if you are completely disconnected so again no activity but also no V bus and so again as I talked yesterday on our peripheral on the OTG peripheral there is a dedicated pin on for this functionality so it's PA9 for the OTG full speed or PB13 for the OTG high speed and now I can show you also in the documentation how to find the actual restriction for this pin as we can see in the datasheet here here is the mention that PB13 and PA9 are assigned to the V bus sensing so here we have it but with the usage of this feature is connected also some power consumption so you need to provide typically 200 micro amps to this pin so it's functional if you put the correct voltage on this pin for during the V bus sensing activity or when the V bus sensing is active and you don't load there enough current so for example by some voltage divider setting if you use very high values there is not enough current to the peripheral and it's not detected even there is enough enough voltage so you need to make it accordingly and second thing is why why actually we need to handle this is the absolute maximum rating so for the input voltage on 5 volt or on pin we have maximally VDD plus 4 if you are battery powered the battery is completely empty so there is zero on the VDD and you connect the V bus so the 5 volt directed to the PA9 you are violating this condition so this should be prevented but it's on all our boards and never see any problem but to be 100% in line with the specification this should be handled then is also the possibility that instead of the PA9 and PB13 you use any other GPIO for the interrupt and so on so again you shall fulfill the condition of the absolute maximum rating so the VDD plus 4 but you don't need to care about any current because typical GPIO is voltage sensitive so it sends only the level of the voltage so it's enough if you use any type of the voltage divider that fulfill the condition that you are below 4 volts but still in the range that VDD times 0.7 and it will be detected only it's not automatically handled by the peripheral so you need to take care about it inside of your firmware so detect the interrupt from the from this pin and turn on the peripheral and the same if you detect the disconnection so PA9, PA, PB13 do it automatically with the any GPIO you need to handle it manually about this topic we have also some remarks on the community in the FAQ and all of this is described here so how to handle the V bus so back to the ESD protection this is what we have recommended for the USB high speed actually this is used in our schematics for the various boards so for example f4 eval boards f7 discovery eval boards the design schematic for the USB high speed is correct in our documentation and you can follow this recommendation it's it's fine so here it's again the V bus sensing VDD plus 4 consumption and usage of the any GPIO so here I have the schematics you have it also in your materials about the recommendation we have with all the consideration for all the use cases so USB bus power device so you have here the USB LC6 which is protecting the data lines no other serial resistor on the lines for the ID pin which is on the USB connector just connect through 100 kilo ohms to the ground and some voltage regulator to power the MCU quite simple not many parts needed so then if you are acting as a self-powered device so here in in this scenario there is no battery so it's quite similar to the to the use case we have with the nuclear board so we have independent power for the board and then the USB application don't source anyhow the microcontroller on the or don't source the battery so in this scenario we need to use the bigger version of the USB LC6 again the ID pin is connected only to the ground but still connected to the ESD protection and then according to the specification we should take care about the VBUS sensing but if you intend not to use the suspend or don't care in the difference between suspend and disconnection you can somehow align according to that in the next use case is also added to the proposal for some battery charging but it's only in the block with the battery so it's then up to so here it's the proposal that you have the battery and either you are powered from the battery or from the VBUS and you are you should be also able to charge the battery so quite standard way but you need to somehow handle the battery for the host it's almost the same so just simple ESD protection and you need to handle the VBUS and source the bus in this case and if you intend to use the on the go functionality you mix the views examples and that's it but as we already mentioned there is no support for this functionality inside our library so the peripheral is supporting it not our library if you need this functionality and don't want to write by our own there are some software partners providing already such solutions but it's not free of charge but if you want we are able to provide you a list of our partners where you can find who could help you with this now any other this is a next problem that customers time to time find some high-speed fi so as was mentioned yesterday our usb high-speed peripheral or in the most cases there is only one exception so in most cases we need to have external high-speed fi only exception is f7 23 where the high-speed fi is already embedded inside so this is the only exception otherwise for f2 f4 other f7 h7 chip you need to have the external usb fi which is connected through the urpi interface and we have some some tested parts which are used on our board some other parts are tested during some developments for example during support of some customers and so on so we have a list of recommended files then we have two files which were tested and at the end we were not able to run with them due to some timing constraints or some other problems so please if you intend to use the usb high-speed and don't want to use f2 f7 23 with the embedded high-speed fi take this list into your consideration it can ease your job significantly as already mentioned the schematic for the high-speed is correct inside the schematics of the discovery boards evaluation board so feel free to use this one without any constraints so the summary of the hardware design for usb board do not use the serial resistor on data lines later on during the electrical testing i will show you what this can done in your application then get some esd protection from our side its recommendation of the st part for sure there is a lot of other vendors if you are confident about the solution feel free to use it but we have st recommendations and be aware about the reba sensing it can be tricky last mention here is again the repetition that if you use the otg high-speed peripheral you can use as a full speed with the embedded fi with the advantage of the dma usage so this is also possible if you have some f4 f7 which have both so the otg full speed and otg high-speed uh they are independent each of them have the independent five four so you can use both of them in one time for the power supply uh yes inside of the datasheet uh you may find that the usb prefer demands to have at least three volt supply voltage so uh on some l0s and some other microcontrollers out for you may found also the vdd usb so the peripheral and the pins connected to the peripheral have the independent voltage so for example you may run your microcontroller on two volts but if you want to use the usb you need to have the three volts for the vdd usb then if you use this for example l0 and you don't want to use the usb and you don't need to use the pa uh nine uh pa 11 12 and pa 9 so the pins connected to the otg you don't need to power the vdd usb at all but it need to be at least grounded connected to some potential if you want to then use the for example the p nine as a standard gpao don't want to use the uh usb on the l0 you can connect it also to two volts so the maximum voltage on the pa nine in this example will be also two volts so gpao is working in standard way but you are not able to use the usb peripheral then on the h7 which is for now our most high performance microcontroller they are too high speed peripheral with some additional features and also with the dedicated internal regulator for from 5 volt to 3 volts but here is the restriction that you are not able to use the voltage from the regulator for any outside functionality it's only for the internal powering of the peripheral for the clocking uh the usb is very sensitive on the clock precision so for the most of the application uh you need to use the high speed external the exceptions are the device for the device where there is some synchronization so for example l4 l0 f0 on some of this device you can find a so-called clock recovery system so there is internal oscillator which is fine-tuned from some other source for example from a host start of frames signal so this is uh in with the frequency 1 millisecond and this can fine-tune the internal oscillator in the demanded precision from the usb peripheral so as then it's called usb crystal a solution so you are you don't need to use the crystal in such application another thing is on the l4 76 and similar rates there is the possibility to fine-tune the internal oscillator from low speed external but this is enough only for the device functionality when you want to use the host functionality high speed external is mandatory because the clock frequency needed by the host it's higher and the last one the high speed 5 you are about the constraints for the types okay so now we pass the chapter about hardware design so now as i promise you there i will show you where it's mentioned in the specification that you need to have the correct precision okay so it's mentioned here so the high speed iterate 480 megabit per second and accuracy of plus minus 500 ppm and this is mandatory for host hops and high speed capable functions functions from the specification mean mean the device here is the device is mentioned as a usb in some usb in the overall and function mean device only from i don't know normal normal way of usage for the regular people they are not able to pretend what is the function so any type of host so full speed host high speed host need to have this precision also the same for a hop and the high speed device only also need to have this precision so that make the bit constraint for us for full speed function only there is two and a half ppm so it's not so strict and we are able to run from different source and also what happen if you don't have the correct source the usual scenario is that you are not correctly synchronized with the host and typical from the for the windows is that he asked for any type of descriptor three times and as you are not correctly synchronized you get the error during the communication so you are not able to answer with any handshake on any of the three requests for the descriptor and you are disconnected so usually you get some message like unknown device corrupted device or something like that we will be able to see it on the electrical testing during the end and there is also the measurement that the frequency of the device is out of the range