 Last practical example we have in this course is about HID host, so how to create a host capable to communicate with various types of the human interface device which may be pretty spread and universal. So what we have inside the default shape of the STM32 USB library for the HID host is capable to communicate with the keyboard or with the mouse more complex devices like some gamepad and so on which are demanding the driver for example also for PC are not able to fully communicate with STM32 and some modification is needed in the code to be compatible also for this device but this is more or less logical you need the driver also for PC and with the microcontroller where you need to fit into much smaller memory it need to be somehow simplified and it's not possible to be compatible with all the devices by default. So as we already mentioned the human interface devices are using so called report descriptor which is holding the parameters of the device and need to be parsed on host side but this parsing is skipped inside of our library and only the basic configuration so-called bold configuration is expected from the device so the parsing is not in the libraries could be added but such step would demand a lot of memory both flash and RAM and then it couldn't fit completely with other application otherwise compared to different class handling of the HID host is quite easy it's more or less prepared and we will demonstrate again using QPemix so like for other examples we will use again F446 ZE nuclear board so almost routine clock source OTG full speed as host only upstairs in middleware find the class so HID we will initialize also the LEDs PB0 PB14 and PB7 additionally for the debug here we will really use it is the UART3 with alternative pins on PD9 and PD8 and as already showed before we need to enable the voltage on the bus so PG6 so that's all we need for now in the pinout we move to the clock configuration 8 megahertz input for high-speed external which we use and choose higher clock and we may generate a project so HID host through studio and we will increase both heap and stack to fit without any problem we open the project like before first what we will do is the USB-A conf where we will handle the VBus so PG6 reset and set first one is when we want to deactivate so reset for activation we need to set the GPIO so that's here in the main again we have the MX host process which is triggering the state machine and we will look inside of the libraries of what is there so the core and in the HID we have in source the HID itself so again the interface in it which can be then depending on the detected configuration use with the keyboard and various setting of the keyboard or for the mouse and there is very simplified parser which is not the true parser for the hit report descriptors so don't be mistaken here so back to main once we will connect the HID device so either mouse or the keyboard here it's already set in the way that it's fully able to communicate and we need only to read out the devices how read out the data from the device so for this there is the HID event callback so we can again search for the weak keyword here it is and this one we can use in main to reading out the data we will receive from the mouse and I will use the help of the presentation you may find in the attachment to get also the code so what what we will use there so I add the include for USB HID and create the buffer for the UART in the mouse type def info it's about the parsing of the receive message so x and y direction for the movement and buttons and I will also copy the code for the complete callback which is a bit complicated and I will translate and format to see better what is here so in the callback we get our active pico active class and from this the data and now we are differentiating if the innate if during the innate we detected the keyboard we need to parse the data we received as a keyboard data and from that we want to get the SCSI code of the press key and we will put it into our buffer and transmit so we have here information that key was press showing us that it was keyboard and printing out the key code if during the initialization we detected a mouse we need to parse the info for the mouse and then again we have here the notification that mouse action was done so the buttons and the direction x and y and again sanity using the UART so by that the device could already work for us but they are two things we need to change to be to achieve better compatibility with the device because our whole state machine is asking on some descriptor which are not mandatory from the specification point of view so some devices are not supporting this descriptor and in the host library there is no check on the number of repetition so it will get stuck and ask for the descriptor indefinitely even it gets style as the descriptor is not supported on the device side so we will skip some part of descriptor you have it again highlighted in the presentation in the upcoming versions of the library this should be not so strict so the not mandatory descriptor should not be asked by the device and then it will become more universal again so here is the request for the set protocol and we don't need him to return us the USB ok for us it's enough that the answer won't be usb h busy that mean that this the request for this descriptor completely pass with either stall or Ike so it was received but for us at the end it's not exactly important to get it so for us we need also to only to be sure that the transmission of this request is not still ongoing and similar we will do it also with the get the report so get the report and again here without getting the report we couldn't progress so again we will use only the USB h busy and now we are ready to for tests so let's slow to the micro controller I will also start the analyzer but in this case it won't be so crucial for us more important for us will be to see the input from the stealing utility so I'm not able to open right now okay now it seems correct so let's slow the code right now nothing is connected so now I'm connecting the mouse I can see some traffic and we are receiving action from the mouse so like that mouse is keyboard and other stuff can be connected to the STM32 very popular choice is the barcode readers which is acting as a keyboard in the end and for my experience most of the time it's working without any additional action needed so this is also working also what is supported is that the host can go to some low power mode and also the device will be put into suspended state and wake up from both host or device is supported in this case as usual for example with the PC there is another direct example in the repository but can be achieved also such example can be provided upon request