 Hello. Good morning everybody. Let me introduce myself. My name is Danyek. Can you hear me well? So the goal of this presentation is to show you how to develop the USB application with the QMX. Are you anybody familiar with this solution? Or are you developers of the applications? More or less. So what is the most boring part when you develop the application? When you start to develop the application, you have to first configure the peripherals, configure the core clocks and so on. It's time consuming, isn't it? So this could be a solution for you and we call it Qube. So the purpose of the Qube is to ease developers' lives by developing efforts. It reduces your efforts' time and therefore even the cost because time is money. The Qube part of the Qube is Qube MX. Qube MX is an application on the PC. It's a graphical wizard which allows you to initialize the microcontroller. It generates the initialization C code which you can download then to the application. This is a solution for all our microcontrollers through the performance microcontrollers which are F4 through to the low-power devices. This Qube you can download it for free from the st.com slash stm32Qube. The Qube is based on the HAL. It's a hardware abstraction layer. It's a set of the driver for peripherals. It includes the middlewares for USB and Ethernet, graphics and so on. I will be talking about USB. Do you plan to develop the USB application? Is it your goal? Do you know how to use the USB? Are you familiar with USB? If you are not, what is your expectation? How much time do you need to develop the USB application? 3-4 weeks. Now you will be able to do it in 10 minutes. Do you believe that it's possible? I tried. I will show you how to create the USB mouse. This USB mouse will be this board. We will connect this board to the PC and it will behave as a USB mouse. It will be moving with your cursor over the PC. The Qube includes drivers. It's a layer approach. The first layer is HAL. It's a hardware abstraction layer. These are drivers for peripherals. Above these are middlewares. Middleware is several stacks. The first is Ethernet solution, USB, graphics, file system and freeRTUS. If you want, you can develop even the USB flash stick. On this board, it can behave as a USB mouse, USB flash or something else. The last layer is a bunch of examples. Inside of the Qube, there are examples. You can open them in your working environment. You can compile it and download it. How it works? On your PC, after the download and installation on your PC, you will create the initialization code. In the working environment, you have to finish only the application. For the USB mouse, it's just one function, which is called or used. You will see later. Then, this complete solution with initialization code, you have to download it to your hardware. In our case, we will use the discovery board. This discovery board will be connected to the PC. It will be moving with the mouse. For those of you who know the USB, I don't think that there are USB experts. If there is someone over there, he can tell us how this USB mouse works. Basically, if you want to implement the USB mouse, you need a data structure, which is called a scriptor. This is the structure of the scriptor. If you want to send to the PC information about the mouse, you need to send the x-axis, y-axis and the wheel or the buttons. There are information which button is pressed. That's all what you have to send to the PC if you want to move your cursor. You should remember this structure because we will use it in writing of the code. How it works between the PC and the device? On the USB, PC as a host always asks for the data. If the device doesn't have the data, it will send not a knowledge. It indicates to the PC that the host doesn't have the data. And twice versa, if the application as a device has a data, it will send back the scriptor. The function which we will use in our application is only one. Send report. That's all what you have to write in your application. The rest is created by the QPMX. Is there any volunteer who wants to create this application? I will guide him. Together we can create this application. Nobody wants to try it. It's easy. Don't worry. You can win something. The board for volunteers. Or two boards for volunteers. Okay, I will try it. So now I'm going to open the QPMX. This is first window which you will see when you open the QPMX. Of course it has a help. It allows you to open the old project if you have one already created. Now I will start with the new project. The second window which you will see is configuration. Here you can select the device. We will use L0 device. In the second box you can select subfamily. So it's 0x3 and the package. As you can see here in the MCU list, we selected or we filtered the devices. In our example I will use this L0538T. Okay, now we have selected the device. What next we have to do? So we have selected the device. And now we want to configure the peripheral. I'm going to select the USB peripheral. Here in this tab, the first tab is the pinout which we will use. And I want to use the USB. So I will select the USB. Immediately in this pinout view in this package you see which pin are assigned to the USB. For the USB there are two pins, data plus and data minus. Between the middle there I will select which stack I want to use. It's USB. And as you can see we have several solutions for the USB. The one which we are going to use is a human interface device. It's the class for the USB mouse. If you want to implement USB mouse, it's this one. Because I want to download this application, I have to select the serial wire debugger. It's the interface for debugging and downloading application to the hardware. That's it. And now I see where is it. In the second tab is a clock tree. So here you can select the clock configuration. In this example we will use the two clocks. The first one will be 16 MHz internal RC. This clock will be multiplied in the PLL. So I'm going to choose the multiplication by 4. And I will get 32 MHz for the core. It's the maximum for this device. And for the USB I need 48 MHz. It's given by the USB standard. So that's all what I need to do if I want to configure the microcontroller for the USB mouse. Shall I do something else? Any idea? So what do you expect? What will happen if I have this configuration? So that's all what I need to do if I want to create the USB mouse. Maybe one last point is the project configuration settings. I have to create the name of the project. So let's call it USB mouse. This tool allows you to choose between three working environments. Here we have IAR, KYLE and TRUE Studio. I use the TRUE Studio. So for this example, two chains selected is TRUE Studio. Okay, this problem already exists. So I will call it mouse A. And the last action in the QPemix is the generate project. Now the QPemix generates the code, initialization code. And immediately it will open your working environment. So in a few seconds you will have a complete project with zero teams. Okay, now I'm asked to open the project. And this is my project. I created mouse A. So it's the empty project with all routines. In the main, I have all functions necessary for the USB mouse. Hardware abstraction layer is initialized. The clock system is ready. This function sets the requirement or configuration for the clock. GPOs are initialized. USB stack is initialized. Only action which I have to do now is to find the function which will send the data as a mouse. Do you remember which function is it? Pardon? Right, exactly. Correct answer and the winner price is... U, as B, D. How was the name of the function? Yeah, HID. HID is the name of the class. And what else? Which data we want to send? Do you remember the report descriptor structure? How many bytes it was? Eight. We want to send one byte with button four. And two bytes about the position of the mouse. And one byte about the wheel. Okay? You said it first. Four bytes. So I'm going to create the structure which will have the eight bytes. I didn't say that. The QPMX in the main create the user section. These sections are sections where you can write your code. So I have to create the structure of four bytes. In the user section, too, I will use this structure and I fill it. So here, in the first position, I don't want to send information about the buttons pressed. So the first byte will be zero. The second byte is X position. So I want to a little bit move with the mouse. So let's put here 10 value. The third byte is Y position. I don't want to move in the Y axis. And the last byte is the wheel. Again, I do want to turn with the wheel. So that's all what I need to do. I will get some errors because the centerport function... Where is the mistake? Semi-colon. I don't see it. Sorry. You need here a semicolon instead of a colon. And here, too. That's a semicolon. Ah, thanks. Thanks for your help. There is a semicolon. It's okay. Are you sure? In the function, there are no parameters. Now it's better. So I want to see which parameter are required by this function. The first function is a handler. It's the device handler. It's already defined, specified in this USB underscore device. And I have to publish this in the main. So it's this variable. So I have to extend. So now this handler for the USB device is visible in the main. And I will use it as a parameter in the function centerport. The second parameter is the buffer which I want to send. And the last parameter is the number of the bytes which I want to send. I want to send complete buffer, so I put there four bytes. So this function is not known in the main. Therefore, I have to include another module. It's USB, I guess, FDE. USB HID. This function is in this module. And now it should be all what I need. Okay, this function requires the pointer. And that's it. Now it will work. I don't want to move too fast, so I will use the function how. How delay, how delay. So each 100 milliseconds, the mouse will send the information about the change of the position. So I'm going to program this device. And after this, you will see how this board moves with the cursor on my PC. This board has embedded debugging stealing. So I will use this one. So what I need is just the connection of the USB cable for programming. Now this board is programmed with the mouse application. So, and if I will use the second USB interface, you will see the moving of the cursor over my screen. Now you see I'm not moving my PC and the cursor is moving. Okay, now you have a USB mouse. So was it easy? So now you have a solution. If you want to implement your USB application, it takes approximately 10 minutes. So what do you think about this solution? Is it okay? Is it fancy? So now all of you are USB experts. You can go home and say, I'm a USB expert. I know how to create the application in 10 minutes. If you want to homemade mouse, here it is. So that's all. Thank you for your attention. Thank you.