Stm32 software reset and analog USB plugging

Source: Internet
Author: User

Recently, a USB client communicates with the host computer and the MCU needs to be reset by the software. If the USB is not plugged in after the reset, the PC will not reenumerate the USB to solve this problem, I made a software reset and simulated USB plug-in.

Here I use the software reset of the HAL database. Before resetting, I turn off the interrupt and then reset it. The Code is as follows:

_ Set_faultmask (1); // disable nvic_systemreset (); // Reset

As for how to implement analog USB plugging, you only need to perform a low-latency-high operation before USB initialization, generally, the PC can check the usb d + pin to determine whether the USB has changed. For the stm32 pa12, it corresponds to this pin, therefore, you can simulate the USB plugging operation by simulating this pin level change. First simulate the plugging, and then perform USB initialization, so that the PC can reenumerate the USB, the Code is as follows:

/** Configure pins as * analog * input * output * event_out * exti */void mx_gpio_init (void) {gpio_inittypedef gpio_initstruct; /* gpio ports clock enable */_ Export ();/* configure gpio pin output level */hal_gpio_writepin (gpioa, gpio_pin_12, gpio_pin_reset);/* configure gpio pin: pa12 */export = gpio_pin_12; export = export; export = gpio_pulldown; export = export; hal_gpio_init (gpioa, & gpio_initstruct); Aggregate (gpioa, gpio_pin_12, callback ); hal_delay (65); // pull the pa12 down first and then pull it up. Use D + to simulate USB plugging.
Hal_gpio_writepin (gpioa, gpio_pin_12, gpio_pin_set); hal_delay (65 );}

Only note that the analog plug-in is placed before the USB initialization, so that the plug-in can be simulated after each reset, and the PC can re-enumerate the USB.

Stm32 software reset and analog USB plugging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.