Shenzhen YYW Tech. co., ltd. is a professional manufacturer on usb cable, chargers and headphones.

Tel:+86-0755-28518222 E-mail:jason@yyw.cn

News

Home> News> STM32 upload data by definition USBMore>

STM32 upload data by definition USBMore

Time:2024-08-16

With the rapid development of Internet technology and artificial intelligence, human beings are entering the intelligent society at an extremely fast speed. As intelligent home appliances contain some sensors or collection systems, how to quickly save the collected data and upload it to the PC for people to study has become a hot field. At present, the commonly used data transmission methods are serial port transmission, I2C, USB transmission, etc., among which USB transmission is the most widely used and most convenient. The biggest characteristic of USB transmission is the connection is simple, the speed is fast, the scalability is strong, supports the hot plug, the standard unification and so on. Now it has been widely used in all aspects of people's life.

    This paper realizes a custom USB function based on USB OTG_HS of STM32F429. Finally, the collected audio data is quickly uploaded to PC.

    1 Hardware platform construction

    1.1 Configure USB clock

    The system is based on STM32F429 sound acquisition, and then according to the custom USB data cable and PC communication. USB communication requires a frequency of 48MHz, so set the USB clock to that frequency.

    The crystal oscillator of this system is 25MHz. According to the formula, the PLL clock frequency dividing factor is set to 25, and the PLL frequency doubling factor N is set to 384. The PLL output clock is 384 MHz.

    The system configuration USB clock frequency factor is 8 can be configured successfully USB clock for 48MHz.

    1.2 USB GPIO configuration and sound acquisition module

    The system USES 5 USB interfaces, which are power cord VBUS, two DATA cables DATA+, DATA-, ID cable and ground cable GND. The PB12, PB13, PB14 and PB15 of STM32 are configured as USB ID, VBUS, DATA+ and DATA- respectively.

    This system adopts MEMS microphone and WM8978 chip to collect sound. The collected data is stored in SD card through the control of MCU, and the data is uploaded to PC through USB. Is based on WM8978 chip sound acquisition circuit diagram, its input connected to two MEMS microphone to achieve sound acquisition, the final acquisition system.

    2 Software platform construction

    2.1 Import core files

    This system downloads the USB OTG library from the official ST, imports the core files and driver files, among which the usbd_collect_core.c file is the file we wrote by ourselves.

    2.2 Configure the USB related descriptor

    (1)Configuration descriptor. Configuration descriptors are used to describe configuration information such as a USB device's properties, capabilities, number of interfaces, maximum current, and so on.

    (2)Interface descriptor. Interface descriptors are used to describe the properties of a particular interface, which is generally a collection of a series of endpoints for a particular USB data transfer function

    (3)Endpoint descriptor. The endpoint descriptor is used to describe the properties of the non-endpoint 0 used by the interface, including the IN\OUT direction, the endpoint, and the endpoint capacity, the size of the package, etc. Here we configure the IN and OUT of endpoint 1.

    The configuration descriptors, interface descriptors, and endpoint descriptors are all configured in the usbd_collect_core.c file, where the LOBYTE(x) and HIBYTE(x) macros are defined as (uint8_t) and (uint8_t) respectively. The device description class does not change much, and the resources can be configured.

    2.3 Rewrite the USB communication method in the custom file

    USB communication initialization calls the method structure USBD_Class_cb_TypeDef in the custom class USBd_collect_core, where the system calls the methods in turn. In the USBD_COLLECT_Init method, make sure that both endpoints are in an open state in order to find the corresponding communication channel.

    USBD_COLLECT_DataIn is a method of sending data, in which we need to call the sending data function sendData function to keep the USB in the sending data stage. USBD_COLLECT_DataOut data received by calling the function, we just need to make it return OK, without any other operations. Other method functions in the file can be written against the official routine and online information.

    3 Experimental verification

    3.1 Setting of experimental conditions and environment

    Connect the two MEMS microphones and the USART, and install the relevant driver. The computer of this system is win10 system. After successful installation of the driver, the computer prompts to identify USB. The identification name is set as "Collect Device in FS Mode" in the file usbd_desc.c.

    Open the serial debugging assistant and press the reset key to check whether the USB is properly initialized. This system added the print log "USBD_COLLECT_Init" in the initialization USB program, so it was proved that everything was ok if the related log was printed after starting. As shown in figure 8, all is normal.

    3.2 The experimental process

    Open the upper computer software, select the communication port number, and then press the circuit board recording button K2, start recording, after the end of the recording press K1. Finally, the file with dat as suffix is produced. In order to facilitate the observation, the dat file is changed to PCM format file, and then the Adobe Audition software is imported to observe its waveform. The original data of the recording is saved in the SD card, that is, the source file, and it is also imported into the Adobe Audition software to observe the waveform.

    3.3 Experimental results and analysis

    Matlab was used to analyze the histograms of the two waveforms and calculate the normalized correlation coefficient of the histograms. Finally, the normalized correlation coefficient was 0.98958, which was close to 1. It was proved that the similarity between the two graphs was very high and the waveform was similar without obvious distortion.

    4 conclusion

    This system puts forward a new USB transmission method, according to the user's needs from the definition of USB, USB to achieve the rapid upload function, for users want to upload data through USB to provide a simple, convenient, stable method. Finally, by comparing the waveform of the source data and the waveform of the transmitted data through USB, it is found that their normalized correlation coefficient is 0.98958, indicating that the two data waveforms are similar, so as to verify that the proposed custom USB data acquisition audio data upload method is effective and there is no data loss.

What is a USB cable

Takes Center Stage at the Asian International Expo Hong Kong 2024

Related Posts