CN108984457A - A kind of USB Host HID experimental method based on STM32F7 - Google Patents
A kind of USB Host HID experimental method based on STM32F7 Download PDFInfo
- Publication number
- CN108984457A CN108984457A CN201810617216.0A CN201810617216A CN108984457A CN 108984457 A CN108984457 A CN 108984457A CN 201810617216 A CN201810617216 A CN 201810617216A CN 108984457 A CN108984457 A CN 108984457A
- Authority
- CN
- China
- Prior art keywords
- usb
- host
- stm32f7
- hid
- routine
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G09—EDUCATION; CRYPTOGRAPHY; DISPLAY; ADVERTISING; SEALS
- G09B—EDUCATIONAL OR DEMONSTRATION APPLIANCES; APPLIANCES FOR TEACHING, OR COMMUNICATING WITH, THE BLIND, DEAF OR MUTE; MODELS; PLANETARIA; GLOBES; MAPS; DIAGRAMS
- G09B23/00—Models for scientific, medical, or mathematical purposes, e.g. full-sized devices for demonstration purposes
- G09B23/06—Models for scientific, medical, or mathematical purposes, e.g. full-sized devices for demonstration purposes for physics
- G09B23/18—Models for scientific, medical, or mathematical purposes, e.g. full-sized devices for demonstration purposes for physics for electricity or magnetism
- G09B23/183—Models for scientific, medical, or mathematical purposes, e.g. full-sized devices for demonstration purposes for physics for electricity or magnetism for circuits
- G09B23/186—Models for scientific, medical, or mathematical purposes, e.g. full-sized devices for demonstration purposes for physics for electricity or magnetism for circuits for digital electronics; for computers, e.g. microprocessors
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/42—Bus transfer protocol, e.g. handshake; Synchronisation
- G06F13/4282—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F15/00—Digital computers in general; Data processing equipment in general
- G06F15/76—Architectures of general purpose stored program computers
- G06F15/78—Architectures of general purpose stored program computers comprising a single central processing unit
- G06F15/7803—System on board, i.e. computer system on one or more PCB, e.g. motherboards, daughterboards or blades
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/4401—Bootstrapping
- G06F9/4403—Processor initialisation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2213/00—Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F2213/0042—Universal serial bus [USB]
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Computer Hardware Design (AREA)
- Software Systems (AREA)
- Algebra (AREA)
- Mathematical Physics (AREA)
- Microelectronics & Electronic Packaging (AREA)
- Computing Systems (AREA)
- Computational Mathematics (AREA)
- Mathematical Analysis (AREA)
- Mathematical Optimization (AREA)
- Computer Security & Cryptography (AREA)
- Pure & Applied Mathematics (AREA)
- Business, Economics & Management (AREA)
- Educational Administration (AREA)
- Educational Technology (AREA)
- Information Transfer Systems (AREA)
- Stored Programmes (AREA)
Abstract
The USB Host HID experimental method based on STM32F7 that the invention discloses a kind of, system includes mainboard, lease core module and various peripheral modules;Mainboard interface is abundant, can be reduced maintenance cost in design;Nucleus module can be replaced, to adapt to the upgrading of processor in future;Peripheral module is resourceful, almost covers all common teaching peripheral hardwares.The present invention is completed on the basis of the library HAL of standard and corresponding middleware.With good portable, versatility.Also, it is a routine that USB routine, which organically combines the VCP routine in the MSC routine and USB Device experiment in USB Device experiment, increases the difficulty of routine and the exploration interest of student.In addition, the routine of this experiment has good portability, in the experiment of USB Host, different from existing routine, without LCD as final display and debugging method, using more generally applicable serial ports as debugging display mode, it is avoided that due to not having LCD or can not correctly run display using what different LCD caused program.
Description
Technical field
The invention belongs to field of embedded technology, and in particular to a kind of USB experimental system and method based on STM32F7.
Background technique
Practical teaching is link indispensable in embedded teaching, it is Embedded teaching can be mainly divided into band Linux or
The teaching of the bare machine embedded platform of the teaching and non-tape operation system of the platform of person's Android operation system.At present without
The STM32 series processors of ST company occupy most of market in the teaching of the bare machine embedded platform of operating system, using most
It is extensive.ST series processors belong to ARM Cortex-M series processors.It is most commonly used at present to be in arm processor
ARM7 series, ARM9 series, ARM9E series, ARM10E series, ARM11 series and Cortex series.Cortex series belongs to
ARMv7 framework, and Cortex series processors are divided into tri- series of A, R, M, " A " series towards tip based on virtual memory
Operating system and user application;" R " series is directed to real-time system;" M " series is to microcontroller.
Learn embedded, suitable development board, the routine of standard, detailed interpretation is essential.Currently on the market
There are many companies for doing embedded board teaching, and do the company of STM32 series exploitation plate, such as prairie fire, positive point atom, micro- snow
Etc., establish one's own system after often the library HAL of ST is modified, mutual compatibility be not very well, can only be at oneself
It is used above oneself development board.
Summary of the invention
In order to solve the above-mentioned technical problems, the present invention provides a kind of USB experimental system and method based on STM32F7,
It is able to carry out the USB Device and USB Host two major classes experiment of USB FS rate.
The USB experimental system based on STM32F7 that the present invention provides a kind of, it is characterised in that: the USB based on STM32F7
DeviceCDC and MSC system includes SD card, STM32F7 processor, PC;Pass through between the SD card and STM32F7 processor
SDMMC interface links together, and is connected between the USB FS interface and PC of the STM32F7 processor by USB line.
The USB experimental system based on STM32F7 that the present invention also provides a kind of, it is characterised in that: based on STM32F7's
USB Host MSC experimental system includes USB flash disk, STM32F7 processor, PC;Pass through between the USB flash disk and STM32F7 processor
OTG mouthfuls of USB FS connect, and are attached between PC the and STM32F7 processor by serial ports.
The USB experimental system based on STM32F7 that the present invention also provides a kind of, it is characterised in that: based on STM32F7's
USB Host HID experimental system includes USB mouse, USB keyboard, STM32F7 processor, PC;The USB mouse, USB keyboard
It is connected between STM32F7 processor by OTG mouthfuls of USB FS, is attached between PC and STM32F7 processor by serial ports.
The USB experimental method based on STM32F7 that the present invention provides a kind of, it is characterised in that: the USB based on STM32F7
Device experiment, comprising the following steps:
Step 1: the SDMMC interface of SD card and STM32F7 processor being linked together, by the USB of STM32F7 processor
FS interface is connected by the USB interface of USB line and PC;
Step 2: the initialization library HAL restarts all external equipments, initializes Flash interface, initializes Systick;
Step 3: configuring and initialize STM32 system clock;
Step 4: the clock of the pin of enabled SD card and USB FS;
Step 5: initialization USB;
The step includes initializing the bottom configuration of USB, initializes USB device library, and class (VCP class) is supported in addition, and
Starting device library, then USB is just just initialized as VCP class equipment first;
Step 6: restarting STM32F7 processor, STM32F7USB equipment is identified as virtually going here and there by PC equipment manager at this time
Jaws equipment (such as USB virtual serial port COM18);
Step 7: the serial port terminal on opening PC, configuration serial ports parameter (including baud rate, stop position, check bit, COM
Mouthful), open serial ports;
Non-critical data (non-zero x02 data) are sent to STM32F7 processor, if STM32F7 virtual serial port receives at this time
To data be not critical data, nor 0x00, just echo is to PC;
Critical data (0x02 data) are sent to STM32F7 processor, the received data of STM32F7 processor are to close at this time
Key data;
Step 8: if STM32F7 processor has received critical data data, initializing SD card and the pin port of USB
Clock;
Step 9: initialization SD card;
Step 10: reinitializing equipment library, cancel original CDC equipment library, USB and CDC class is unbinded.Again initial
Change USB, reinitializing USB includes the bottom configuration for initializing USB, initializes USB device library, and class (MSC class) is supported in addition,
And starting device library, then USB is just just initialized as MSC class equipment first;
Step 11:PC equipment manager identifies USB mass-memory unit, SD card drive is read in PC, and to it
It is written and read and format manipulation, it is noted here that FAT file system can only be formatted as to it.
The USB experimental method based on STM32F7 that the present invention also provides a kind of, it is characterised in that: based on STM32F7's
USB Host MSC experiment, comprising the following steps:
Step 1: enabled CPU Cache;
Step 2: the initialization library HAL restarts all external equipments, initializes Flash interface, initializes Systick;
Step 3: configuration system clock;
Step 4: the GPIO clock of enabled USB and USART3;
Step 5: initialization serial ports DMA;
Step 6: initialization USART3;
Step 7: initialization LED, key and USB Host MSC menu;
Step 8: class (MSC class) is supported in initialization USB, including initialization usb host library, addition, starts USB Host master
Hangar;
Step 9: executing the processing function of USB Host different conditions, different states includes HOST_IDLE, HOST_
DEV_WAIT_FOR_ATTACHMENT、HOST_DEV_ATTACHED、HOST_ENUMERATION、HOST_INPUT、HOST_
SET_CONFIGURATION、HOST_CHECK_CLASS、HOST_CLASS_REQUEST、HOST_CLASS、HOST_DEV_
DISCONNECTED,HOST_ABORT_STATE;
Step 10: executing USB Host MSC menu and handle function;
First if msc_demo.state state is MSC_DEMO_START, user key-press is waited, user key-press is laggard
Enter MSC_DEMO_FILE_OPERATIONS state, executes MSC_File_Operations ();Create USBHost.txt text
Part, and character string " USB Host Library:Mass Storage Example " is written into USBHost.txt file and reads
It is shown on serial port terminal, and is continued waiting for by key pressing out, after pressing key pressing, execution Explore_Disk (" 0 :/", 1);
Show the directory file structure of USB flash disk.
The USB experimental method based on STM32F7 that the present invention also provides a kind of, it is characterised in that: based on STM32F7's
USB Host HID experiment, comprising the following steps:
Step 1: enabled CPU Cache;
Step 2: the initialization library HAL restarts all external equipments, initializes Flash interface, initializes Systick;
Step 3: configuration system clock;
Step 4: the GPIO clock of enabled USB and USART3;
Step 5: initialization serial ports DMA;
Step 6: initialization USART3;
Step 7: initialization LED, key and USB Host HID menu;
Step 8: initialization USB;
Including initializing usb host library, class (HID class) is supported in addition, starts USB Host host library;
Step 9: executing the processing function of USB Host different conditions, different states includes HOST_IDLE, HOST_
DEV_WAIT_FOR_ATTACHMENT、HOST_DEV_ATTACHED、HOST_ENUMERATION、HOST_INPUT、HOST_
SET_CONFIGURATION、HOST_CHECK_CLASS、HOST_CLASS_REQUEST、HOST_CLASS、HOST_DEV_
DISCONNECTED,HOST_ABORT_STATE;
Step 10: executing USB Host HID menu and handle function;
If connection is USB mouse, by the key-case of serial ports real-time display mouse (left button, right button, middle key with
And press/release state) and coordinate situation (x, y-coordinate and the x of last time, y-coordinate);If connection is USB key
Disk then shows keyboard character by serial ports when having by key pressing.
System of the invention further includes mainboard, and mainboard interface is abundant, and mainboard also provides various other than providing module jack
Standard interface, such as Ethernet interface, USB HOST/SLAVE interface, CAN bus transceiver interface.And it can be reduced on designing
Maintenance cost, if there is module damage, it is only necessary to replace module, repair mainboard without going.
Module resource of the invention is abundant.One shares 16 module boards and four mainboard interfaces for being tested, completely
The various teaching of foot and application demand.And core board can be replaced, and to adapt to the needs of the upgrading of processor in future, mainboard is therefore
Mainboard may be reused.
Software section of the invention is all to complete on the basis of the library HAL of standard and corresponding middleware, is not had
There is the modification library HAL, there is good portable, versatility.The library ST HAL used in the present invention is 1.6 versions, is not
Current newest 1.7 version, so comparatively more stable, also relatively new, Integrated Development Environment used in the present invention
For MDK, the version of version v5.23, compiler Compiler are v5.06 comparatively more stable also relatively new.
The experiment of all USB of the present invention is equipped with detailed description, from the basic conception of USB, to the USB of STM32F7
Interface, then to ST the library HAL introduction, then to ST USB middleware introduction, arrive operating process, hardware introduction, program solution
It reads, experimental phenomena etc. is all discussed in detail.In addition explanation video, the exploitation of religion classmate's introduction STM32F7 of teach-by-doing are also equipped with.
The routine that the present invention is developed completely in accordance with the library HAL of standard and USB middleware library, did not modify ST's
The library HAL, comparatively more versatility.In addition the present invention has selected the F7 series processors of STM32, and performance is more preferable, can more fit
In response to the market demand.USB communication protocol was an extremely complex communication protocol originally, and the USB of general embedded board is real
Test be only list experiment should how to operate, for student be only replication experiment, more knowledge can not be acquired,
And the present invention is by theoretical knowledge, hardware knowledge, routine explanation is all detailed to be provided in the form of document, moreover it is possible to is not limited to single
Experiment, can combine single experiment, inspiring to see, exploration, innovative.
Detailed description of the invention
Fig. 1 is the STM32F7USB Device Experimental Hardware structural block diagram of the embodiment of the present invention;
Fig. 2 is the SD card SDMMC interface diagram of the embodiment of the present invention;
Fig. 3 is the STM32F7USB Device CDC 2MSC experiment flow figure of the embodiment of the present invention;
Fig. 4 is that the STM32F7USB Host MSC Experimental Hardware of the embodiment of the present invention connects block diagram;
Fig. 5 is the STM32F7USB Host HID mouse Experimental Hardware connection figure of the embodiment of the present invention;
Fig. 6 is the STM32F7USB Host HID keyboard Experimental Hardware connection figure of the embodiment of the present invention;
Fig. 7 is the USB Host MSC USB flash disk experiment flow figure of the embodiment of the present invention;
Fig. 8 is the USB Host HID mouse-keyboard experiment flow figure of the embodiment of the present invention.
Specific embodiment
Understand for the ease of those of ordinary skill in the art and implement the present invention, with reference to the accompanying drawings and embodiments to this hair
It is bright to be described in further detail, it should be understood that implementation example described herein is merely to illustrate and explain the present invention, not
For limiting the present invention.
The object of the present invention is to provide one kind preferably based on the USB experiment porch of STM32F7 series processors, Neng Goujin
USB Device and USB the Host two major classes of row USB FS rate are tested.
In conjunction with attached drawing 1, USB DeviceCDC and the MSC experimental system based on STM32F7, hardware mainly by SD card,
STM32F7 processor, PC composition.Wherein linked together between SD card and STM32F7 by SDMMC interface, interface connection
See attached drawing 2.It is connected between the USB FS interface and PC of STM32F7 by USB line.In conjunction with attached drawing 3, STM32F7USB
The characteristics of Device CDC 2MSC experiment flow figure is in an experiment by traditional USB Device MSC experiment and USB
Device CDC experiment has cleverly been combined into an experiment.Program initializes the library HAL first, configures system clock, enables SD
Card and USB FS GPIO clock, then first initialization USB is VCP class equipment, will in this when PC equipment manager
STM32F7USB equipment is identified as virtual serial port equipment, if the data that STM32F7 virtual serial port receives at this time are not crucial
Data (for example the present embodiment is set as 0x02 here), nor 0x00, just echo is to PC.If received data are to close at this time
Key data (for example the present embodiment is set as 0x02 here), then initialize SDMMC interface, reinitializes equipment library, cancels former
The CDC equipment library come unbinds USB and CDC class.It reinitializes as MSC equipment library, addition MSC class, and starting device library.This
Sample, the equipment manager of the present embodiment just will recognise that the USB device of the present embodiment is a mass-memory unit, Ke Yi
SD card drive is read in my computer, and it can be written and read.
In conjunction with attached drawing 4, the USB Host MSC experimental system based on STM32F7, hardware is mainly by USB flash disk, STM32F7
Manage device, PC composition.Wherein pass through serial ports between PC and STM32F7 by OTG mouthfuls of USB FS connections between USB flash disk and STM32F7
It is attached.In conjunction with attached drawing 7, the characteristics of STM32F7USB Host MSC experiment flow figure is all using serial ports as adjusting
Examination and display means, avoid the versatility that program is reduced because of the difference of LCD.Program first enables CPU Cache, initialization
The library HAL configures system clock, enables the GPIO clock of USB and USART3, initializes serial ports DMA, initializes USART3, initially
Change LED, key and USB Host MSC menu, initialization USB is Host MSC mode, executes the processing of USB Host different conditions
Function finally executes USB Host MSC menu and handles function, which handles function and execute following application:
First if msc_demo.state state is MSC_DEMO_START, user key-press is waited, enters MSC_ after user key-press
DEMO_FILE_OPERATIONS state executes MSC_File_Operations ();Creation USBHost.txt file, and to
Character string " USB Host Library:Mass Storage Example " is written in USBHost.txt file and reads display
On serial port terminal, and continue waiting for by key pressing, after pressing key pressing, execution Explore_Disk (" 0 :/", 1);Show U
The directory file structure of disk.
In conjunction with attached drawing 5,6, the USB Host HID experimental system based on STM32F7, hardware is mainly by USB mouse, USB
Keyboard, STM32F7 processor, PC composition.Wherein pass through OTG mouthfuls of companies of USB FS between USB mouse, USB keyboard and STM32F7
It connects, is attached between PC and STM32F7 by serial ports.In conjunction with attached drawing 8, STM32F7USB Host HID experiment flow figure
Feature is to avoid the versatility that program is reduced because of the difference of LCD all using serial ports as debugging and display means.Journey
Sequence first enables CPU Cache, initializes the library HAL, configures system clock, enables the GPIO clock of USB and USART3, initialization string
Mouth DMA initializes USART3, initialization LED, key and USB Host HID menu, and initialization USB is Host HID mode,
It executes USB Host different conditions and handles function, finally execute USB Host HID menu and handle function, if that connection is USB
Mouse then passes through the key-case (press/release) and coordinate situation of serial ports real-time display mouse.If connection is
USB keyboard then shows keyboard character by serial ports when having by key pressing.
The content of this patent is furtherd elucidate below with reference to the software implementing course of the present embodiment:
1. being tested for USB Device, with reference to attached drawing 1,2, experimental system hardware is connected, opens routine, this implementation
The Integrated Development Environment that example uses is MDK5, and the version of version v5.23, compiler Compiler are v5.06, the HAL used
Library version is v1.6, comparatively more stable also relatively new.Since the mass-memory unit that the present embodiment uses is SD card, just need
First the handling function of SD card to be supplemented completely, these functions are in usbd_storage_if.c file:
-static int8_t STORAGE_Init_FS(uint8_t lun);
-static int8_t STORAGE_GetCapacity_FS(uint8_t lun,
- uint32_t*block_num,
- uint16_t*block_size);
-static int8_t STORAGE_IsReady_FS(uint8_t lun);
-static int8_t STORAGE_IsWriteProtected_FS(uint8_t lun);
-static int8_t STORAGE_Read_FS(uint8_t lun,
- uint8_t*buf,
- uint32_t blk_addr,
- uint16_t blk_len);
-static int8_t STORAGE_Write_FS(uint8_t lun,
- uint8_t*buf,
- uint32_t blk_addr,
- uint16_t blk_len);
-static int8_t STORAGE_GetMaxLun_FS(void);
In addition, having different definition or reality since many of two routines have identical macro name or function name
Existing macro name and function, the present embodiment need to change these macro names and function name when merging routine to distinguish them, such as:
-#define VCP_USBD_VID 1155
-#define VCP_USBD_LANGID_STRING 1033
-#define VCP_USBD_MANUFACTURER_STRING"STMicroelectronics"
-#define VCP_USBD_PID_FS 22336
-#define VCP_USBD_PRODUCT_STRING_FS "STM32Virtual ComPort"
-#define VCP_USBD_SERIALNUMBER_STRING_FS"00000000001A"
-#define VCP_USBD_CONFIGURATION_STRING_FS "CDC Config"
-#define VCP_USBD_INTERFACE_STRING_FS "CDC Interface"
-
-
-#define MSC_USBD_VID 1155
-#define MSC_USBD_LANGID_STRING 1033
-#define MSC_USBD_MANUFACTURER_STRING"STMicroelectronics"
-#define MSC_USBD_PID_FS 22314
-#define MSC_USBD_PRODUCT_STRING_FS "STM32Mass Storage"
-#define MSC_USBD_SERIALNUMBER_STRING_FS"00000000001A"
-#define MSC_USBD_CONFIGURATION_STRING_FS "MSC Config"
-#define MSC_USBD_INTERFACE_STRING_FS"MSC Interface"
It is different macro above by will be distinguished before former macro name plus MSC or VCP.
-uint8_t*VCP_USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed,uint16_
t*length);
-uint8_t*VCP_USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*VCP_USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef
speed,uint16_t*length);
-uint8_t*VCP_USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*VCP_USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*VCP_USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*VCP_USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-
-
-uint8_t*MSC_USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed,uint16_
t*length);
-uint8_t*MSC_USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*MSC_USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef
speed,uint16_t*length);
-uint8_t*MSC_USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*MSC_USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*MSC_USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
-uint8_t*MSC_USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed,
uint16_t*length);
It is by distinguishing different functions for MSC or VCP is added before original function name above.
In principal function:
It first defines and receives array uint8_t Buf [1]={ 0xff };Length is uint32_t Len [1]={ 1 };Only
The data of 1Byte can once be received.
-HAL_Init();Initialize all peripheral hardwares, Flash interface and Systick.
-SystemClock_Config();System clock is initialized as the configuration in MSC experiment.
-MX_GPIO_Init();The clock of GPIOA, GPIOC, GPIOD are opened as MSC experiment.
-VCP_MX_USB_DEVICE_Init();USB is initialized as VCP class equipment first, initializes CDC equipment library,
CDC class is added, library is started.
Next enter major cycle:
STM32F7USB equipment is identified as virtual serial port equipment in this when PC equipment manager, STM32F7 virtually goes here and there at this time
If the data that mouth receives are not particular value (for example the present embodiment are set as 0x02 here), nor 0x00, just echo is to PC.
If received data are 0x02 at this time, MX_SDMMC1_SD_Init () is executed;SDMMC interface is initialized,
Execute USBD_DeInit (&hUsbDeviceFS);Reinitialize equipment library, cancel original CDC equipment library, by USB and
CDC class unbundlings.It reinitializes as MSC equipment library, addition MSC class, and starting device library.In this way, the equipment management of the present embodiment
Device just will recognise that the USB device of the present embodiment is a mass-memory unit.
2. being tested for USB Host MSC, with reference to attached drawing 4, experimental system hardware is connected, opens routine, reference is attached
Fig. 7, program circuit are as follows:
Cpu data Instruction Cache enabled first.
Following HAL_Init ();Initialize all peripheral hardwares, Flash interface and Systick.
Then SystemClock_Config ();Configure system clock:
* System Clock source=PLL (HSE)
* SYSCLK (Hz)=216000000
* HCLK (Hz)=216000000
* Prescaler=1 AHB
* APB1Prescaler=4
* APB2Prescaler=2
* HSE Frequency (Hz)=8000000
* PLL_M=8
* PLL_N=432
* PLL_P=2
* PLL_Q=9
* VDD (V)=3.3
* Main regulator output voltage=Scale1mode
* Flash Latency (WS)=7
Here the present embodiment selects source of the HSE as PLL, and the source of HSE is 8MHz, the frequency dividing of the present embodiment design and times
The following PLLM=8 of frequency parameter;PLLN=432;PLLP=2;PLLQ=9;Source of the PLLCLK as SYSCLK is selected, selects the PLLQ to be
The source of USB, AHB Prescaler=1;APB1Prescaler=4;APB2Prescaler=2.
SYSCLK=PLLCLK=HSE/PLLM*PLLN/PLLP=8M/8*432/2=216MHz.
USB clock=PLLQ=HSE/PLLM*PLLN/PLLQ=8M/8*432/9=48M.
APB1 Peripheral clock=SYSCLK/AHB Prescaler/ APB1Prescaler
=216M/1/4=54MHz;
APB2 Peripheral clock=SYSCLK/AHB Prescaler/ APB2Prescaler
=216M/1/4=108MHz;
Current embodiment require that the clock of USB is after 48MHz is configured so that, the clock of USB is just 48MHz.
Here it is 54MHZ that the clock source of USART3, which is PCLK1,;
-MX_GPIO_Init();Enabled GPIO PortD mouthfuls of clock, because that USART3 uses is exactly PD8 and PD9,
PD8 is USART3TX, PD9 USART3RX.
-MX_DMA_Init();Enabled serial ports DMA transfer.
-MX_USART3_UART_Init();Initialize USART3, baud rate 9600.
Initialize LED, key and menu.
Usb host library is initialized, MSC class is added, starts host library.
Next enter major cycle;
-USBH_Process(&hUSBHost);The different conditions of function processing usb host.
Have the institute of USB stateful here:
1.HOST_IDLE
2.HOST_DEV_WAIT_FOR_ATTACHMENT、
3.HOST_DEV_ATTACHED
4.HOST_ENUMERATION
5.HOST_INPUT
6.HOST_SET_CONFIGURATION
7.HOST_CHECK_CLASS
8.HOST_CLASS_REQUEST
9.HOST_CLASS
10.HOST_DEV_DISCONNECTED
11.HOST_ABORT_STATE
Every kind of state has different processing.
-MSC_MenuProcess();Function is menu process flow.First if msc_demo.state state is
MSC_DEMO_START waits user key-press, enters MSC_DEMO_FILE_OPERATIONS state after user key-press, execute
MSC_File_Operations();USBHost.txt file is created, and character string is written into USBHost.txt file
" USB Host Library:Mass Storage Example " and reading are shown on serial port terminal, and continue waiting for key
It presses, after pressing key pressing, execution Explore_Disk (" 0 :/", 1);Show the directory file structure of USB flash disk.
Here all LCD_ErrLog (...);LCD_UsrLog(...);LCD_DbgLog (...) is all output to
Serial ports redefines printf in principal function and is output to serial ports:
Experimental phenomena: downloading program opens serial port terminal, opens serial ports, is inserted into USB flash disk, and serial ports assistant shows the big of USB flash disk
It is small, after pressing user key-press, a file USBHost.txt will be created in USB flash disk, and character string " USB is written into file
Host Library:Mass Storage Example " is simultaneously read out.After pressing the button again, it is shown that the file mesh in USB flash disk
Record and file.Computer is opened, checks the file in USB flash disk as catalogue and file structure that serial ports assistant shows.It opens
There are the character string " USB Host Library:Mass Storage Example " of write-in in USBHost.txt file, the inside:
3. being tested for USB Host HID, with reference to attached drawing 5 or 6, experimental system hardware is connected, opens routine, ginseng
Attached drawing 8 is examined, program circuit is as follows:
Cpu data Instruction Cache enabled first.
Following HAL_Init ();Initialize all peripheral hardwares, Flash interface and Systick.
Then SystemClock_Config ();Configure system clock:
-MX_GPIO_Init();Enabled GPIO PortD mouthfuls of clock, because that USART3 uses is exactly PD8 and PD9,
PD8 is USART3TX, PD9 USART3RX.
-MX_DMA_Init();Enabled serial ports DMA transfer.
-MX_USART3_UART_Init();Initialize USART3, baud rate 9600.
Following HID_InitApplication ();It is applied for initializing HID: initialization LED, user key-press, and
Start HID interface, initializes HID Menu.
Following three functions are the initialization of USB, initialize the library USB Host, and class (HID class) is supported in addition, starting
The library Host.
Then program enters major cycle.
-USBH_Process(&hUSBHost);Function handles the different state of USB Host, with 2.
- Host has different processing in the state of difference.
-HID_MenuProcess();Function is used to manage USB Host HID menu.
Processing mouse corresponding routine when-hid_demo.state is HID_DEMO_MOUSE:
HID_MouseMenuProcess();
USBH_MouseDemo(&hUSBHost);
Processing keyboard corresponding routine when-hid_demo.state is HID_DEMO_KEYBOARD:
HID_KeyboardMenuProcess();
USBH_KeybdDemo(&hUSBHost);
Experimental phenomena: serial ports assistant is opened in compiler, downloading, opens serial ports, connects one for OTG mouthfuls of USB FS first
A USB OTG conversion head is connecting USB mouse, reset STM32, and single left button mouse click shows that left button is pressed, and left button unclamps;
A mouse click right button, display right button are pressed, and right button unclamps;Key in a mouse click, key pressing in display, middle key unclamp;Mobile mouse
Mark shows the coordinate prev_x_y of the last time mouse and coordinate loc_x_y of present mouse.Mouse is extracted, keyboard is inserted into,
And any key on keyboard is keyed in, it would indicate that corresponding character on serial ports assistant.
The system of the present embodiment mainly includes mainboard, lease core module and various peripheral modules;Mainboard interface is abundant, if
It can be reduced maintenance cost on meter;Nucleus module can be replaced, to adapt to the upgrading of processor in future;Peripheral module is resourceful,
Almost cover all common teaching peripheral hardwares.Software section of the invention be standard the library HAL and corresponding middleware
On the basis of complete.With good portable, versatility.Also, USB routine is innovated, and USB Device is tested
In MSC routine and USB Device experiment in VCP routine organically combine be a routine, increase the difficulty and of routine
Raw exploration interest.In addition, the routine of this experiment has good portability, in the experiment of USB Host, it is different from it
The routine of his producer, without LCD as final display and debugging method, using more generally applicable serial ports as debugging display
Mode can be not limited to specific LCD display.
It should be understood that the part that this specification does not elaborate belongs to the prior art.
It should be understood that the above-mentioned description for preferred embodiment is more detailed, can not therefore be considered to this
The limitation of invention patent protection range, those skilled in the art under the inspiration of the present invention, are not departing from power of the present invention
Benefit requires to make replacement or deformation under protected ambit, fall within the scope of protection of the present invention, this hair
It is bright range is claimed to be determined by the appended claims.
Claims (2)
1. a kind of USB Host HID experimental method based on STM32F7, real applied to the USB Host HID based on STM32F7
In check system;The system comprises USB mouse, USB keyboard, STM32F7 processors, PC;The USB mouse, USB keyboard and
It is connected between STM32F7 processor by OTG mouthfuls of USB FS, is attached between PC and STM32F7 processor by serial ports;
It is characterized in that, the described method comprises the following steps:
Step 1: enabled CPU Cache;
Step 2: the initialization library HAL restarts all external equipments, initializes Flash interface, initializes Systick;
Step 3: configuration system clock;
Step 4: the GPIO clock of enabled USB and USART3;
Step 5: initialization serial ports DMA;
Step 6: initialization USART3;
Step 7: initialization LED, key and USB Host HID menu;
Step 8: initialization USB;
Including initializing usb host library, HID class is added, USB Host host library is started;
Step 9: executing the processing function of USB Host different conditions, different states includes HOST_IDLE, HOST_DEV_
WAIT_FOR_ATTACHMENT、HOST_DEV_ATTACHED、HOST_ENUMERATION、HOST_INPUT、HOST_SET_
CONFIGURATION、HOST_CHECK_CLASS、HOST_CLASS_REQUEST、HOST_CLASS、HOST_DEV_
DISCONNECTED,HOST_ABORT_STATE;
Step 10: executing USB Host HID menu and handle function;
If connection is USB mouse, pass through the key-case and coordinate situation of serial ports real-time display mouse;If connection
Be USB keyboard, then when having by key pressing pass through serial ports show keyboard character.
2. the USB Host HID experimental method according to claim 1 based on STM32F7, it is characterised in that: the system
System further includes mainboard, and mainboard provides module jack and various standard interfaces.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810617216.0A CN108984457A (en) | 2017-07-20 | 2017-07-20 | A kind of USB Host HID experimental method based on STM32F7 |
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810617216.0A CN108984457A (en) | 2017-07-20 | 2017-07-20 | A kind of USB Host HID experimental method based on STM32F7 |
CN201710596790.8A CN107403573B (en) | 2017-07-20 | 2017-07-20 | A kind of USB experimental system and method based on STM32F7 |
Related Parent Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710596790.8A Division CN107403573B (en) | 2017-07-20 | 2017-07-20 | A kind of USB experimental system and method based on STM32F7 |
Publications (1)
Publication Number | Publication Date |
---|---|
CN108984457A true CN108984457A (en) | 2018-12-11 |
Family
ID=60401018
Family Applications (3)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810617216.0A Pending CN108984457A (en) | 2017-07-20 | 2017-07-20 | A kind of USB Host HID experimental method based on STM32F7 |
CN201810617208.6A Pending CN108845972A (en) | 2017-07-20 | 2017-07-20 | A kind of USB Host MSC experimental method based on STM32F7 |
CN201710596790.8A Active CN107403573B (en) | 2017-07-20 | 2017-07-20 | A kind of USB experimental system and method based on STM32F7 |
Family Applications After (2)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810617208.6A Pending CN108845972A (en) | 2017-07-20 | 2017-07-20 | A kind of USB Host MSC experimental method based on STM32F7 |
CN201710596790.8A Active CN107403573B (en) | 2017-07-20 | 2017-07-20 | A kind of USB experimental system and method based on STM32F7 |
Country Status (1)
Country | Link |
---|---|
CN (3) | CN108984457A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112000374A (en) * | 2020-07-13 | 2020-11-27 | 深圳市智微智能软件开发有限公司 | USB touch screen replacing method, device, equipment and medium applied to android system |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111782572A (en) * | 2020-06-15 | 2020-10-16 | 北京航空航天大学杭州创新研究院 | Baud rate self-adaptive USB serial port device and method |
CN111913783B (en) * | 2020-10-13 | 2021-02-02 | 江苏润和软件股份有限公司 | Single-chip microcomputer USB software development system and method based on objectification |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN203520727U (en) * | 2013-11-02 | 2014-04-02 | 常州信息职业技术学院 | Portable STM32 one-chip microcomputer teaching experiment instrument |
CN105931540A (en) * | 2016-04-27 | 2016-09-07 | 北京航空航天大学 | FPGA-based on-line experiment system and on-line experiment method |
US20170039151A1 (en) * | 2015-08-05 | 2017-02-09 | American Megatrends, Inc. | Universal intelligent platform management interface (ipmi) host to baseboard management controller (bmc) communication for non-x86 and legacy free systems |
CN106933371A (en) * | 2015-12-29 | 2017-07-07 | 哈尔滨恒誉名翔科技有限公司 | A kind of keyboard equipment of USB-HID agreements |
Family Cites Families (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN100367263C (en) * | 2006-04-18 | 2008-02-06 | 杭州华三通信技术有限公司 | Universal serial port bus data transportation processing method |
KR20090132818A (en) * | 2008-06-23 | 2009-12-31 | 사이넵스주식회사 | Double security system using usb token finger print |
CN101833887B (en) * | 2010-04-02 | 2011-09-14 | 江苏教育家教学装备有限公司 | Digital exploration experiment method based on universal wireless interface technology |
CN204028888U (en) * | 2014-04-16 | 2014-12-17 | 福建师范大学 | A kind of data storage device with USB principal and subordinate interface |
CN103973889A (en) * | 2014-04-25 | 2014-08-06 | 方小祥 | Device and method for using intelligent handheld device as wireless USB HID device |
CN204667684U (en) * | 2015-05-20 | 2015-09-23 | 江苏建筑职业技术学院 | A kind of teaching type ARM development board based on LM3S8962 chip |
CN204990829U (en) * | 2015-09-30 | 2016-01-20 | 无锡职业技术学院 | Embedded real device of instructing of application technique |
-
2017
- 2017-07-20 CN CN201810617216.0A patent/CN108984457A/en active Pending
- 2017-07-20 CN CN201810617208.6A patent/CN108845972A/en active Pending
- 2017-07-20 CN CN201710596790.8A patent/CN107403573B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN203520727U (en) * | 2013-11-02 | 2014-04-02 | 常州信息职业技术学院 | Portable STM32 one-chip microcomputer teaching experiment instrument |
US20170039151A1 (en) * | 2015-08-05 | 2017-02-09 | American Megatrends, Inc. | Universal intelligent platform management interface (ipmi) host to baseboard management controller (bmc) communication for non-x86 and legacy free systems |
CN106933371A (en) * | 2015-12-29 | 2017-07-07 | 哈尔滨恒誉名翔科技有限公司 | A kind of keyboard equipment of USB-HID agreements |
CN105931540A (en) * | 2016-04-27 | 2016-09-07 | 北京航空航天大学 | FPGA-based on-line experiment system and on-line experiment method |
Non-Patent Citations (3)
Title |
---|
刘海龙: "基于USB OTG的Android手机与ARM卡通信的研究", 《中国优秀硕士学位论文全文数据库 信息科技辑》 * |
张洋: "《STM32F7原理与应用 HAL库版 下》", 30 June 2017 * |
徐建功: "Cortex 系统中FAT32文件读写的硬件及软件设计", 《中国优秀硕士学位论文全文数据库 信息科技辑》 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112000374A (en) * | 2020-07-13 | 2020-11-27 | 深圳市智微智能软件开发有限公司 | USB touch screen replacing method, device, equipment and medium applied to android system |
CN112000374B (en) * | 2020-07-13 | 2024-01-02 | 深圳市智微智能软件开发有限公司 | USB touch screen replacement method, device, equipment and medium applied to android system |
Also Published As
Publication number | Publication date |
---|---|
CN107403573A (en) | 2017-11-28 |
CN108845972A (en) | 2018-11-20 |
CN107403573B (en) | 2018-12-14 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
TWI421766B (en) | Providing virtual device access via firmware | |
US8010843B2 (en) | System and method for debugging a target computer using SMBus | |
WO2018018978A1 (en) | Universal serial bus controller verification method, system and device | |
CN107403573B (en) | A kind of USB experimental system and method based on STM32F7 | |
Brown | Discovering the STM32 microcontroller | |
CN101359303B (en) | On-line debugging microcontroller and apparatus and debug method of external device thereof | |
CN109426613A (en) | The method and its computer system of tune-up data are retrieved in UEFI | |
CN108664264A (en) | A kind of device and method remotely updating FPGA by JTAG modes based on CPU | |
US7212961B2 (en) | Interface for rapid prototyping system | |
Ramon | Intel Galileo and Intel Galileo Gen 2: API Features and Arduino Projects for Linux Programmers | |
CN114064458A (en) | JTAG debugging method and system with extensible interface and universality | |
US20050144436A1 (en) | Multitasking system level platform for HW/SW co-verification | |
WO2024046362A1 (en) | Verification system, verification method, electronic device, and storage medium | |
CN109840172A (en) | A kind of Nand flash memory analytical equipment and method based on SoC main control chip | |
CN101281507A (en) | USB interface type DSP real-time simulation development system | |
CN111294985A (en) | Portable miner lamp communication system based on 4G, communication method and construction method | |
Jeřábek | FPGA Based CAN Bus Channels Mutual Latency Tester and Evaluation | |
US8160864B1 (en) | In-circuit emulator and pod synchronized boot | |
Hillebrand | VxWorks BSP for Pandaboard | |
Kumar et al. | Design and Functional Verification of A SPI Master Slave Core using UVM | |
Ruiz González et al. | Using Quartus and Buildroot for building Embedded Linux Systems with De1-SOC | |
Ahola | Host Adapter Firmware Implementation with CircuitPython | |
Nema et al. | ERAS: Enabling the Integration of Real-World Intellectual Properties (IPs) in Architectural Simulators | |
Aho | Inter-processor communication in virtualized environment | |
Dalmasso | MC2101: A RISC-V-based Microcontroller for Security Assessment and Training |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20181211 |
|
RJ01 | Rejection of invention patent application after publication |