0 0 0 0

Source address:: http://www. Stm32cube. com/article/141.

Related articles

1 , A stm32f042f6p6 usb device development minimum system keyboard example http://www. Stm32cube. com/article/143.

It's the board, Taobao 59.


Direct engineering configuration.

Tur & on SWD debugging, mapping, opening usb ( because of pin co & umption, usb must be turned on ), set up a pin output input mode corresponding to keys and led:

Set up the system clock, which is automatically set in here:

Set up usb mode to enter gpio configuration:

Set the key and the output mode of the led, the key is input, when the key is pressed to detect low:

Configure project output: set project name, project path, ide:

Click on the build project and wait for a while:

After the project has been built, keil is free to open, stm32f0 l0 series of mcu is free lICE ing, and you can't go to pirated crack, download the latest keil directly to the website, and the new keil compilation seems to be faster for details: http://www2. Keil. com/stmicroelectronics-stm32/mdk.

Open the project, compile, download ( I'm using st link download ), and after downloading, plug in usb cable to pc, and will automatically recognize new devices as follows:

You can modify the following file to modify the device name, and so on:

After modifying, compiling, downloading, the device name detected in the computer has changed:

Let's modify main. C, add key detection and led lights. When press the button, the lights are light, release, and add the following code under while ( 1 ):

 if(HAL_GPIO_ReadPin(KEY_GPIO_Port,KEY_Pin) == 0)

Then compile, download, and run again if the led is turned on when the button is pressed.

Continue adding the code for the usb mouse, adding the following header file to the program header of main. C:


Define a 4 bit array in the main function to hold the mouse action information to be sent to the computer:

 * buffer[0] - bit0: Left button 左键
 * bit1: Right button 右键
 * bit2: Middle button 中键
 * buffer[1] - Cursor movement X axis 水平移动
 * buffer[2] - Cursor movement Y axis 垂直移动
 * buffer[3] - Wheel vertical movement 滚轮转动
 */char buffer[4] = {0x00, 10, 10, 0};

Add a send statement to the judgment of the key detection:

USBD_HID_SendReport(&hUsbDeviceFS, buffer, 4);

After compiling and running again, the usb is pressed on the computer, press the button, the led light, and the mouse will move to the right. Other parameters of the mouse please add yourself.

More attention to smilefrog. Net.

Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs